diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 4c72813315d..17fe89f8eeb 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -108,6 +108,7 @@ class nsIDragSession; class nsPIDOMWindow; class nsPIDOMEventTarget; class nsIPresShell; +class nsIXPConnectJSObjectHolder; #ifdef MOZ_XTF class nsIXTFService; #endif @@ -1466,6 +1467,25 @@ public: * method returns PR_TRUE, otherwise PR_FALSE. */ static PRBool CanAccessNativeAnon(); + + static nsresult WrapNative(JSContext *cx, JSObject *scope, + nsISupports *native, const nsIID* aIID, jsval *vp, + // If non-null aHolder will keep the jsval alive + // while there's a ref to it + nsIXPConnectJSObjectHolder** aHolder = nsnull, + PRBool aAllowWrapping = PR_FALSE); + + // Same as the WrapNative above, but use this one if aIID is nsISupports' IID. + static nsresult WrapNative(JSContext *cx, JSObject *scope, + nsISupports *native, jsval *vp, + // If non-null aHolder will keep the jsval alive + // while there's a ref to it + nsIXPConnectJSObjectHolder** aHolder = nsnull, + PRBool aAllowWrapping = PR_FALSE) + { + return WrapNative(cx, scope, native, nsnull, vp, aHolder, aAllowWrapping); + } + private: static PRBool InitializeEventTable(); diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index ffe7111ebf8..9ca93a997d4 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -166,6 +166,7 @@ static NS_DEFINE_CID(kXTFServiceCID, NS_XTFSERVICE_CID); #include "nsDOMDataTransfer.h" #include "nsHtml5Module.h" #include "nsPresContext.h" +#include "nsLayoutStatics.h" #ifdef IBMBIDI #include "nsIBidiKeyboard.h" @@ -5092,3 +5093,43 @@ nsContentUtils::DispatchXULCommand(nsIContent* aTarget, PRBool dummy; return target->DispatchEvent(event, &dummy); } + +// static +nsresult +nsContentUtils::WrapNative(JSContext *cx, JSObject *scope, nsISupports *native, + const nsIID* aIID, jsval *vp, + nsIXPConnectJSObjectHolder **aHolder, + PRBool aAllowWrapping) +{ + if (!native) { + NS_ASSERTION(!aHolder || !*aHolder, "*aHolder should be null!"); + + *vp = JSVAL_NULL; + + return NS_OK; + } + + NS_ENSURE_TRUE(sXPConnect && sThreadJSContextStack, NS_ERROR_UNEXPECTED); + + // Keep sXPConnect and sThreadJSContextStack alive. + nsLayoutStaticsRef layoutStaticsRef; + + JSContext *topJSContext; + nsresult rv = sThreadJSContextStack->Peek(&topJSContext); + NS_ENSURE_SUCCESS(rv, rv); + + PRBool push = topJSContext != cx; + if (push) { + rv = sThreadJSContextStack->Push(cx); + NS_ENSURE_SUCCESS(rv, rv); + } + + rv = sXPConnect->WrapNativeToJSVal(cx, scope, native, aIID, aAllowWrapping, + vp, aHolder); + + if (push) { + sThreadJSContextStack->Pop(nsnull); + } + + return rv; +} diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp index 110201cdeb4..a6c9b300317 100644 --- a/content/events/src/nsEventListenerManager.cpp +++ b/content/events/src/nsEventListenerManager.cpp @@ -832,17 +832,13 @@ nsEventListenerManager::RegisterScriptEventListener(nsIScriptContext *aContext, if (aContext->GetScriptTypeID() == nsIProgrammingLanguage::JAVASCRIPT) { nsCOMPtr holder; - rv = nsContentUtils::XPConnect()-> - WrapNative(cx, (JSObject *)aScope, aObject, NS_GET_IID(nsISupports), - getter_AddRefs(holder)); + jsval v; + rv = nsContentUtils::WrapNative(cx, (JSObject *)aScope, aObject, &v, + getter_AddRefs(holder)); NS_ENSURE_SUCCESS(rv, rv); - JSObject *jsobj = nsnull; - rv = holder->GetJSObject(&jsobj); - NS_ENSURE_SUCCESS(rv, rv); - rv = nsContentUtils::GetSecurityManager()-> - CheckPropertyAccess(cx, jsobj, + CheckPropertyAccess(cx, JSVAL_TO_OBJECT(v), "EventTarget", sAddListenerID, nsIXPCSecurityManager::ACCESS_SET_PROPERTY); diff --git a/content/html/content/src/nsHTMLScriptElement.cpp b/content/html/content/src/nsHTMLScriptElement.cpp index a8619711ed4..fbd5b9df174 100644 --- a/content/html/content/src/nsHTMLScriptElement.cpp +++ b/content/html/content/src/nsHTMLScriptElement.cpp @@ -224,22 +224,13 @@ nsHTMLScriptEventHandler::Invoke(nsISupports *aTargetObject, // wrap the target object... JSContext *cx = (JSContext *)scriptContext->GetNativeContext(); - JSObject *scriptObject = nsnull; JSObject *scope = sgo->GetGlobalJSObject(); nsCOMPtr holder; - nsContentUtils::XPConnect()->WrapNative(cx, scope, - aTargetObject, - NS_GET_IID(nsISupports), - getter_AddRefs(holder)); - if (holder) { - holder->GetJSObject(&scriptObject); - } - - // Fail if wrapping the native object failed... - if (!scriptObject) { - return NS_ERROR_FAILURE; - } + jsval v; + rv = nsContentUtils::WrapNative(cx, scope, aTargetObject, &v, + getter_AddRefs(holder)); + NS_ENSURE_SUCCESS(rv, rv); // Build up the array of argument names... // @@ -277,7 +268,7 @@ nsHTMLScriptEventHandler::Invoke(nsISupports *aTargetObject, void* funcObject = nsnull; NS_NAMED_LITERAL_CSTRING(funcName, "anonymous"); - rv = scriptContext->CompileFunction(scriptObject, + rv = scriptContext->CompileFunction(JSVAL_TO_OBJECT(v), funcName, // method name argc, // no of arguments args, // argument names diff --git a/content/xbl/src/nsXBLBinding.cpp b/content/xbl/src/nsXBLBinding.cpp index 00c3f7fe679..e76c3bcce6b 100644 --- a/content/xbl/src/nsXBLBinding.cpp +++ b/content/xbl/src/nsXBLBinding.cpp @@ -1089,17 +1089,15 @@ nsXBLBinding::ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocumen pusher.Push(cx); nsCOMPtr wrapper; - nsresult rv = nsContentUtils::XPConnect()-> - WrapNative(cx, global->GetGlobalJSObject(), - mBoundElement, NS_GET_IID(nsISupports), - getter_AddRefs(wrapper)); + jsval v; + nsresult rv = + nsContentUtils::WrapNative(cx, global->GetGlobalJSObject(), + mBoundElement, &v, + getter_AddRefs(wrapper)); if (NS_FAILED(rv)) return; - JSObject* scriptObject = nsnull; - rv = wrapper->GetJSObject(&scriptObject); - if (NS_FAILED(rv)) - return; + JSObject* scriptObject = JSVAL_TO_OBJECT(v); // XXX Stay in sync! What if a layered binding has an // ?! diff --git a/content/xbl/src/nsXBLProtoImpl.cpp b/content/xbl/src/nsXBLProtoImpl.cpp index aa0d5428aab..322e2cc08de 100644 --- a/content/xbl/src/nsXBLProtoImpl.cpp +++ b/content/xbl/src/nsXBLProtoImpl.cpp @@ -131,20 +131,16 @@ nsXBLProtoImpl::InitTargetObjects(nsXBLPrototypeBinding* aBinding, JSContext* jscontext = (JSContext*)aContext->GetNativeContext(); JSObject* global = sgo->GetGlobalJSObject(); nsCOMPtr wrapper; - rv = nsContentUtils::XPConnect()->WrapNative(jscontext, global, - aBoundElement, - NS_GET_IID(nsISupports), - getter_AddRefs(wrapper)); - NS_ENSURE_SUCCESS(rv, rv); - JSObject * object = nsnull; - rv = wrapper->GetJSObject(&object); + jsval v; + rv = nsContentUtils::WrapNative(jscontext, global, aBoundElement, &v, + getter_AddRefs(wrapper)); NS_ENSURE_SUCCESS(rv, rv); // All of the above code was just obtaining the bound element's script object and its immediate // concrete base class. We need to alter the object so that our concrete class is interposed // between the object and its base class. We become the new base class of the object, and the // object's old base class becomes the new class' base class. - rv = aBinding->InitClass(mClassName, jscontext, global, object, + rv = aBinding->InitClass(mClassName, jscontext, global, JSVAL_TO_OBJECT(v), aTargetClassObject); if (NS_FAILED(rv)) return rv; diff --git a/content/xbl/src/nsXBLProtoImplMethod.cpp b/content/xbl/src/nsXBLProtoImplMethod.cpp index 31b79116687..0d67a5b84e6 100644 --- a/content/xbl/src/nsXBLProtoImplMethod.cpp +++ b/content/xbl/src/nsXBLProtoImplMethod.cpp @@ -295,16 +295,13 @@ nsXBLProtoImplAnonymousMethod::Execute(nsIContent* aBoundElement) JSObject* globalObject = global->GetGlobalJSObject(); nsCOMPtr wrapper; + jsval v; nsresult rv = - nsContentUtils::XPConnect()->WrapNative(cx, globalObject, - aBoundElement, - NS_GET_IID(nsISupports), - getter_AddRefs(wrapper)); + nsContentUtils::WrapNative(cx, globalObject, aBoundElement, &v, + getter_AddRefs(wrapper)); NS_ENSURE_SUCCESS(rv, rv); - JSObject* thisObject; - rv = wrapper->GetJSObject(&thisObject); - NS_ENSURE_SUCCESS(rv, rv); + JSObject* thisObject = JSVAL_TO_OBJECT(v); JSAutoRequest ar(cx); diff --git a/content/xul/templates/src/nsXULTemplateBuilder.cpp b/content/xul/templates/src/nsXULTemplateBuilder.cpp index 87f4d3bd620..7b6f293b697 100644 --- a/content/xul/templates/src/nsXULTemplateBuilder.cpp +++ b/content/xul/templates/src/nsXULTemplateBuilder.cpp @@ -1397,31 +1397,23 @@ nsXULTemplateBuilder::InitHTMLTemplateRoot() JSAutoRequest ar(jscontext); - nsIXPConnect *xpc = nsContentUtils::XPConnect(); - - JSObject* jselement = nsnull; - + jsval v; nsCOMPtr wrapper; - rv = xpc->WrapNative(jscontext, scope, mRoot, NS_GET_IID(nsIDOMElement), - getter_AddRefs(wrapper)); + rv = nsContentUtils::WrapNative(jscontext, scope, mRoot, + &NS_GET_IID(nsIDOMElement), &v, + getter_AddRefs(wrapper)); NS_ENSURE_SUCCESS(rv, rv); - rv = wrapper->GetJSObject(&jselement); - NS_ENSURE_SUCCESS(rv, rv); + JSObject* jselement = JSVAL_TO_OBJECT(v); if (mDB) { // database - rv = xpc->WrapNative(jscontext, scope, mDB, - NS_GET_IID(nsIRDFCompositeDataSource), - getter_AddRefs(wrapper)); + jsval jsdatabase; + rv = nsContentUtils::WrapNative(jscontext, scope, mDB, + &NS_GET_IID(nsIRDFCompositeDataSource), + &jsdatabase, getter_AddRefs(wrapper)); NS_ENSURE_SUCCESS(rv, rv); - JSObject* jsobj; - rv = wrapper->GetJSObject(&jsobj); - NS_ENSURE_SUCCESS(rv, rv); - - jsval jsdatabase = OBJECT_TO_JSVAL(jsobj); - PRBool ok; ok = JS_SetProperty(jscontext, jselement, "database", &jsdatabase); NS_ASSERTION(ok, "unable to set database property"); @@ -1431,19 +1423,14 @@ nsXULTemplateBuilder::InitHTMLTemplateRoot() { // builder + jsval jsbuilder; nsCOMPtr wrapper; - rv = xpc->WrapNative(jscontext, jselement, - static_cast(this), - NS_GET_IID(nsIXULTemplateBuilder), - getter_AddRefs(wrapper)); + rv = nsContentUtils::WrapNative(jscontext, jselement, + static_cast(this), + &NS_GET_IID(nsIXULTemplateBuilder), + &jsbuilder, getter_AddRefs(wrapper)); NS_ENSURE_SUCCESS(rv, rv); - JSObject* jsobj; - rv = wrapper->GetJSObject(&jsobj); - NS_ENSURE_SUCCESS(rv, rv); - - jsval jsbuilder = OBJECT_TO_JSVAL(jsobj); - PRBool ok; ok = JS_SetProperty(jscontext, jselement, "builder", &jsbuilder); if (! ok) diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 58f24aff6f7..e515a3b6229 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -1648,27 +1648,6 @@ nsDOMClassInfo::DefineStaticJSVals(JSContext *cx) return NS_OK; } -// static -nsresult -nsDOMClassInfo::WrapNative(JSContext *cx, JSObject *scope, nsISupports *native, - const nsIID* aIID, PRBool aAllowWrapping, jsval *vp, - nsIXPConnectJSObjectHolder **aHolder) -{ - if (!native) { - NS_ASSERTION(!aHolder || !*aHolder, "*aHolder should be null!"); - - *vp = JSVAL_NULL; - - return NS_OK; - } - - NS_ENSURE_TRUE(sXPConnect, NS_ERROR_UNEXPECTED); - - return sXPConnect->WrapNativeToJSVal(cx, ::JS_GetGlobalForObject(cx, scope), - native, aIID, aAllowWrapping, vp, - aHolder); -} - static nsresult CreateExceptionFromResult(JSContext *cx, nsresult aResult) { diff --git a/dom/base/nsDOMClassInfo.h b/dom/base/nsDOMClassInfo.h index 62bb682470e..bf9fc317831 100644 --- a/dom/base/nsDOMClassInfo.h +++ b/dom/base/nsDOMClassInfo.h @@ -48,6 +48,7 @@ #include "nsIScriptContext.h" #include "nsDOMJSUtils.h" // for GetScriptContextFromJSContext #include "nsIScriptGlobalObject.h" +#include "nsContentUtils.h" class nsIDOMWindow; class nsIDOMNSHTMLOptionCollection; @@ -137,7 +138,11 @@ public: PRBool aAllowWrapping, jsval *vp, // If non-null aHolder will keep the jsval alive // while there's a ref to it - nsIXPConnectJSObjectHolder** aHolder = nsnull); + nsIXPConnectJSObjectHolder** aHolder = nsnull) + { + return nsContentUtils::WrapNative(cx, scope, native, aIID, vp, aHolder, + aAllowWrapping); + } // Same as the WrapNative above, but use this one if aIID is nsISupports' IID. static nsresult WrapNative(JSContext *cx, JSObject *scope, diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 9752a8b63f4..4690a4c4b78 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -1679,6 +1679,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument, nsCOMPtr thisChrome = do_QueryInterface(static_cast(this)); nsCOMPtr navigatorHolder; + jsval nav; PRBool isChrome = PR_FALSE; @@ -1757,9 +1758,9 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument, nsIDOMNavigator* navigator = static_cast(mNavigator.get()); - xpc->WrapNative(cx, currentInner->mJSObject, navigator, - NS_GET_IID(nsIDOMNavigator), - getter_AddRefs(navigatorHolder)); + nsContentUtils::WrapNative(cx, currentInner->mJSObject, navigator, + &NS_GET_IID(nsIDOMNavigator), &nav, + getter_AddRefs(navigatorHolder)); } } @@ -1983,12 +1984,10 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument, if (navigatorHolder && st_id == nsIProgrammingLanguage::JAVASCRIPT) { // Restore window.navigator onto the new inner window. - JSObject *nav; JSAutoRequest ar(cx); - navigatorHolder->GetJSObject(&nav); ::JS_DefineProperty(cx, newInnerWindow->mJSObject, "navigator", - OBJECT_TO_JSVAL(nav), nsnull, nsnull, + nav, nsnull, nsnull, JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY); @@ -2000,7 +1999,8 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument, static_cast(mNavigator); xpc-> - ReparentWrappedNativeIfFound(cx, nav, newInnerWindow->mJSObject, + ReparentWrappedNativeIfFound(cx, JSVAL_TO_OBJECT(nav), + newInnerWindow->mJSObject, navigator, getter_AddRefs(navigatorHolder)); } diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index 649a7efb70a..d6e2b9c291c 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -1893,12 +1893,7 @@ nsJSContext::JSObjectFromInterface(nsISupports* aTarget, void *aScope, JSObject // later. nsresult rv; jsval v; - rv = nsContentUtils::XPConnect()->WrapNativeToJSVal(mContext, - (JSObject *)aScope, - aTarget, - &NS_GET_IID(nsISupports), - PR_FALSE, - &v, nsnull); + rv = nsContentUtils::WrapNative(mContext, (JSObject *)aScope, aTarget, &v); NS_ENSURE_SUCCESS(rv, rv); #ifdef NS_DEBUG @@ -2551,9 +2546,9 @@ nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject) nsCOMPtr ci(do_QueryInterface(aGlobalObject)); if (ci) { - rv = xpc->WrapNative(mContext, global, aGlobalObject, - NS_GET_IID(nsISupports), - getter_AddRefs(holder)); + jsval v; + rv = nsContentUtils::WrapNative(mContext, global, aGlobalObject, &v, + getter_AddRefs(holder)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr wrapper(do_QueryInterface(holder)); @@ -2699,15 +2694,11 @@ nsJSContext::ConvertSupportsTojsvals(nsISupports *aArgs, "Don't pass nsISupportsPrimitives - use nsIVariant!"); #endif nsCOMPtr wrapper; - rv = xpc->WrapNative(mContext, (JSObject *)aScope, arg, - NS_GET_IID(nsISupports), - getter_AddRefs(wrapper)); + jsval v; + rv = nsContentUtils::WrapNative(mContext, (JSObject *)aScope, arg, + &v, getter_AddRefs(wrapper)); if (NS_SUCCEEDED(rv)) { - JSObject *obj; - rv = wrapper->GetJSObject(&obj); - if (NS_SUCCEEDED(rv)) { - *thisval = OBJECT_TO_JSVAL(obj); - } + *thisval = v; } } } @@ -2906,20 +2897,14 @@ nsJSContext::AddSupportsPrimitiveTojsvals(nsISupports *aArg, jsval *aArgv) AutoFree iidGuard(iid); // Free iid upon destruction. - nsresult rv; - nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID(), &rv)); - NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr wrapper; - rv = xpc->WrapNative(cx, ::JS_GetGlobalObject(cx), data, - *iid, getter_AddRefs(wrapper)); + jsval v; + nsresult rv = nsContentUtils::WrapNative(cx, ::JS_GetGlobalObject(cx), + data, iid, &v, + getter_AddRefs(wrapper)); NS_ENSURE_SUCCESS(rv, rv); - JSObject *obj; - rv = wrapper->GetJSObject(&obj); - NS_ENSURE_SUCCESS(rv, rv); - - *aArgv = OBJECT_TO_JSVAL(obj); + *aArgv = v; break; } diff --git a/dom/src/threads/nsDOMWorker.cpp b/dom/src/threads/nsDOMWorker.cpp index b05338b02b4..bbb21407a0b 100644 --- a/dom/src/threads/nsDOMWorker.cpp +++ b/dom/src/threads/nsDOMWorker.cpp @@ -310,24 +310,17 @@ nsDOMWorkerFunctions::NewXMLHttpRequest(JSContext* aCx, return JS_FALSE; } - nsIXPConnect* xpc = nsContentUtils::XPConnect(); - nsCOMPtr xhrWrapped; - rv = xpc->WrapNative(aCx, aObj, static_cast(xhr), - NS_GET_IID(nsISupports), getter_AddRefs(xhrWrapped)); + jsval v; + rv = nsContentUtils::WrapNative(aCx, aObj, + static_cast(xhr), &v, + getter_AddRefs(xhrWrapped)); if (NS_FAILED(rv)) { JS_ReportError(aCx, "Failed to wrap XMLHttpRequest!"); return JS_FALSE; } - JSObject* xhrJSObj; - rv = xhrWrapped->GetJSObject(&xhrJSObj); - if (NS_FAILED(rv)) { - JS_ReportError(aCx, "Failed to get JSObject from wrapper!"); - return JS_FALSE; - } - - *aRval = OBJECT_TO_JSVAL(xhrJSObj); + *aRval = v; return JS_TRUE; } @@ -377,24 +370,16 @@ nsDOMWorkerFunctions::NewWorker(JSContext* aCx, return JS_FALSE; } - nsIXPConnect* xpc = nsContentUtils::XPConnect(); - nsCOMPtr workerWrapped; - rv = xpc->WrapNative(aCx, aObj, static_cast(newWorker), - NS_GET_IID(nsISupports), getter_AddRefs(workerWrapped)); + jsval v; + rv = nsContentUtils::WrapNative(aCx, aObj, static_cast(newWorker), + &v, getter_AddRefs(workerWrapped)); if (NS_FAILED(rv)) { JS_ReportError(aCx, "Failed to wrap new worker!"); return JS_FALSE; } - JSObject* workerJSObj; - rv = workerWrapped->GetJSObject(&workerJSObj); - if (NS_FAILED(rv)) { - JS_ReportError(aCx, "Failed to get JSObject from wrapper!"); - return JS_FALSE; - } - - *aRval = OBJECT_TO_JSVAL(workerJSObj); + *aRval = v; return JS_TRUE; } @@ -1214,12 +1199,11 @@ nsDOMWorker::InitializeInternal(nsIScriptGlobalObject* aOwner, NS_ASSERTION(!mGlobal, "Already got a global?!"); - nsIXPConnect* xpc = nsContentUtils::XPConnect(); - nsCOMPtr thisWrapped; - nsresult rv = xpc->WrapNative(aCx, aObj, static_cast(this), - NS_GET_IID(nsISupports), - getter_AddRefs(thisWrapped)); + jsval v; + nsresult rv = nsContentUtils::WrapNative(aCx, aObj, + static_cast(this), &v, + getter_AddRefs(thisWrapped)); NS_ENSURE_SUCCESS(rv, rv); NS_ASSERTION(mWrappedNative, "Post-create hook should have set this!"); diff --git a/js/src/xpconnect/idl/nsIXPConnect.idl b/js/src/xpconnect/idl/nsIXPConnect.idl index fbf8394a08a..d938757ff83 100644 --- a/js/src/xpconnect/idl/nsIXPConnect.idl +++ b/js/src/xpconnect/idl/nsIXPConnect.idl @@ -467,6 +467,9 @@ interface nsIXPConnect : nsISupports * asking for an nsISupports wrapper. * If aAllowWrapper, then the returned value will be wrapped in the proper * type of security wrapper on top of the XPCWrappedNative (if needed). + * This method doesn't push aJSContext on the context stack, so the caller + * is required to push it if the top of the context stack is not equal to + * aJSContext. */ void wrapNativeToJSVal(in JSContextPtr aJSContext, diff --git a/js/src/xpconnect/src/nsXPConnect.cpp b/js/src/xpconnect/src/nsXPConnect.cpp index 28a826102a5..8a8d219a5a6 100644 --- a/js/src/xpconnect/src/nsXPConnect.cpp +++ b/js/src/xpconnect/src/nsXPConnect.cpp @@ -1197,6 +1197,30 @@ nsXPConnect::InitClassesWithNewWrappedGlobal(JSContext * aJSContext, return NS_OK; } +static nsresult +NativeInterface2JSObject(XPCLazyCallContext & lccx, + JSObject * aScope, + nsISupports *aCOMObj, + const nsIID * aIID, + PRBool aAllowWrapping, + jsval *aVal, + nsIXPConnectJSObjectHolder **aHolder) +{ + nsresult rv; + if(!XPCConvert::NativeInterface2JSObject(lccx, aVal, aHolder, aCOMObj, aIID, + nsnull, nsnull, aScope, + aAllowWrapping, OBJ_IS_NOT_GLOBAL, + &rv)) + return rv; + +#ifdef DEBUG + NS_ASSERTION(!XPCNativeWrapper::IsNativeWrapper(JSVAL_TO_OBJECT(*aVal)), + "Shouldn't be returning a native wrapper here"); +#endif + + return NS_OK; +} + /* nsIXPConnectJSObjectHolder wrapNative (in JSContextPtr aJSContext, in JSObjectPtr aScope, in nsISupports aCOMObj, in nsIIDRef aIID); */ NS_IMETHODIMP nsXPConnect::WrapNative(JSContext * aJSContext, @@ -1206,10 +1230,18 @@ nsXPConnect::WrapNative(JSContext * aJSContext, nsIXPConnectJSObjectHolder **aHolder) { NS_ASSERTION(aHolder, "bad param"); + NS_ASSERTION(aJSContext, "bad param"); + NS_ASSERTION(aScope, "bad param"); + NS_ASSERTION(aCOMObj, "bad param"); + + XPCCallContext ccx(NATIVE_CALLER, aJSContext); + if(!ccx.IsValid()) + return UnexpectedFailure(NS_ERROR_FAILURE); + XPCLazyCallContext lccx(ccx); jsval v; - return WrapNativeToJSVal(aJSContext, aScope, aCOMObj, &aIID, PR_FALSE, - &v, aHolder); + return NativeInterface2JSObject(lccx, aScope, aCOMObj, &aIID, PR_FALSE, &v, + aHolder); } /* void wrapNativeToJSVal (in JSContextPtr aJSContext, in JSObjectPtr aScope, in nsISupports aCOMObj, in nsIIDPtr aIID, out JSVal aVal, out nsIXPConnectJSObjectHolder aHolder); */ @@ -1229,23 +1261,10 @@ nsXPConnect::WrapNativeToJSVal(JSContext * aJSContext, if(aHolder) *aHolder = nsnull; - XPCCallContext ccx(NATIVE_CALLER, aJSContext); - if(!ccx.IsValid()) - return UnexpectedFailure(NS_ERROR_FAILURE); - XPCLazyCallContext lccx(ccx); + XPCLazyCallContext lccx(NATIVE_CALLER, aJSContext); - nsresult rv; - if(!XPCConvert::NativeInterface2JSObject(ccx, aVal, aHolder, aCOMObj, aIID, - nsnull, nsnull, aScope, aAllowWrapping, - OBJ_IS_NOT_GLOBAL, &rv)) - return rv; - -#ifdef DEBUG - NS_ASSERTION(!XPCNativeWrapper::IsNativeWrapper(JSVAL_TO_OBJECT(*aVal)), - "Shouldn't be returning a native wrapper here"); -#endif - - return NS_OK; + return NativeInterface2JSObject(lccx, aScope, aCOMObj, aIID, aAllowWrapping, + aVal, aHolder); } /* void wrapJS (in JSContextPtr aJSContext, in JSObjectPtr aJSObj, in nsIIDRef aIID, [iid_is (aIID), retval] out nsQIResult result); */ diff --git a/layout/build/nsLayoutStatics.h b/layout/build/nsLayoutStatics.h index ebda3f6cdc2..e113b392c6c 100644 --- a/layout/build/nsLayoutStatics.h +++ b/layout/build/nsLayoutStatics.h @@ -61,4 +61,17 @@ private: static void Shutdown(); }; +class nsLayoutStaticsRef +{ +public: + nsLayoutStaticsRef() + { + nsLayoutStatics::AddRef(); + } + ~nsLayoutStaticsRef() + { + nsLayoutStatics::Release(); + } +}; + #endif // nsLayoutStatics_h__