зеркало из https://github.com/mozilla/gecko-dev.git
Bug 535079 - Get the XPCNativeWrapper class without compiling and running JS code. r=jst sr=sicking
This commit is contained in:
Родитель
2e37e51b5b
Коммит
8f5d1a781e
|
@ -2556,9 +2556,7 @@ nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject)
|
|||
// Now check whether we need to grab a pointer to the
|
||||
// XPCNativeWrapper class
|
||||
if (!nsDOMClassInfo::GetXPCNativeWrapperClass()) {
|
||||
JSAutoRequest ar(mContext);
|
||||
rv = FindXPCNativeWrapperClass(holder);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsDOMClassInfo::SetXPCNativeWrapperClass(xpc->GetNativeWrapperClass());
|
||||
}
|
||||
} else {
|
||||
// There's already a global object. We are preparing this outer window
|
||||
|
@ -2958,52 +2956,6 @@ nsJSContext::AddSupportsPrimitiveTojsvals(nsISupports *aArg, jsval *aArgv)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJSContext::FindXPCNativeWrapperClass(nsIXPConnectJSObjectHolder *aHolder)
|
||||
{
|
||||
NS_ASSERTION(!nsDOMClassInfo::GetXPCNativeWrapperClass(),
|
||||
"Why was this called?");
|
||||
|
||||
JSObject *globalObj;
|
||||
aHolder->GetJSObject(&globalObj);
|
||||
NS_ASSERTION(globalObj, "Must have global by now!");
|
||||
|
||||
const char* arg = "arg";
|
||||
NS_NAMED_LITERAL_STRING(body, "return new XPCNativeWrapper(arg);");
|
||||
|
||||
// Can't use CompileFunction() here because our principal isn't
|
||||
// inited yet and a null principal makes it fail.
|
||||
JSFunction *fun =
|
||||
::JS_CompileUCFunction(mContext,
|
||||
globalObj,
|
||||
"_XPCNativeWrapperCtor",
|
||||
1, &arg,
|
||||
(jschar*)body.get(),
|
||||
body.Length(),
|
||||
"javascript:return new XPCNativeWrapper(arg);",
|
||||
1 // lineno
|
||||
);
|
||||
NS_ENSURE_TRUE(fun, NS_ERROR_FAILURE);
|
||||
|
||||
jsval globalVal = OBJECT_TO_JSVAL(globalObj);
|
||||
jsval wrapper;
|
||||
|
||||
JSBool ok = ::JS_CallFunction(mContext, globalObj, fun,
|
||||
1, &globalVal, &wrapper);
|
||||
if (!ok) {
|
||||
// No need to notify about pending exceptions here; we don't
|
||||
// expect any other than out of memory, really.
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_ASSERTION(JSVAL_IS_OBJECT(wrapper), "This should be an object!");
|
||||
|
||||
nsDOMClassInfo::SetXPCNativeWrapperClass(
|
||||
::JS_GET_CLASS(mContext, JSVAL_TO_OBJECT(wrapper)));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static JSPropertySpec OptionsProperties[] = {
|
||||
{"strict", (int8)JSOPTION_STRICT, JSPROP_ENUMERATE | JSPROP_PERMANENT},
|
||||
{"werror", (int8)JSOPTION_WERROR, JSPROP_ENUMERATE | JSPROP_PERMANENT},
|
||||
|
|
|
@ -205,8 +205,6 @@ public:
|
|||
|
||||
protected:
|
||||
nsresult InitializeExternalClasses();
|
||||
// aHolder should be holding our global object
|
||||
nsresult FindXPCNativeWrapperClass(nsIXPConnectJSObjectHolder *aHolder);
|
||||
|
||||
// Helper to convert xpcom datatypes to jsvals.
|
||||
JS_FORCES_STACK nsresult ConvertSupportsTojsvals(nsISupports *aArgs,
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
/***************************************************************************/
|
||||
|
||||
[ptr] native JSContextPtr(JSContext);
|
||||
[ptr] native JSClassPtr(JSClass);
|
||||
[ptr] native JSObjectPtr(JSObject);
|
||||
[ptr] native JSValPtr(jsval);
|
||||
native JSVal(jsval);
|
||||
|
@ -394,7 +395,7 @@ interface nsIXPCFunctionThisTranslator : nsISupports
|
|||
{ 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
|
||||
%}
|
||||
|
||||
[uuid(44d52d63-6575-4b09-a29f-e6708203fa9d)]
|
||||
[uuid(96540596-c21e-4183-bb47-f6a5c1ad2dba)]
|
||||
interface nsIXPConnect : nsISupports
|
||||
{
|
||||
%{ C++
|
||||
|
@ -859,4 +860,6 @@ interface nsIXPConnect : nsISupports
|
|||
PRBool allowShortCircuit) const = 0;
|
||||
#endif
|
||||
%}
|
||||
|
||||
[notxpcom] JSClassPtr getNativeWrapperClass();
|
||||
};
|
||||
|
|
|
@ -2714,6 +2714,12 @@ nsXPConnect::GetPrincipal(JSObject* obj, PRBool allowShortCircuit) const
|
|||
return nsnull;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(JSClass *)
|
||||
nsXPConnect::GetNativeWrapperClass()
|
||||
{
|
||||
return XPCNativeWrapper::GetJSClass();
|
||||
}
|
||||
|
||||
/* These are here to be callable from a debugger */
|
||||
JS_BEGIN_EXTERN_C
|
||||
JS_EXPORT_API(void) DumpJSStack()
|
||||
|
|
Загрузка…
Ссылка в новой задаче