diff --git a/dom/base/nsFrameMessageManager.cpp b/dom/base/nsFrameMessageManager.cpp index b061a6bdc7b1..9c3535be0455 100644 --- a/dom/base/nsFrameMessageManager.cpp +++ b/dom/base/nsFrameMessageManager.cpp @@ -1719,7 +1719,6 @@ nsMessageManagerScriptExecutor::InitChildGlobalInternal( AutoSafeJSContext cx; nsContentUtils::GetSecurityManager()->GetSystemPrincipal(getter_AddRefs(mPrincipal)); - nsIXPConnect* xpc = nsContentUtils::XPConnect(); const uint32_t flags = nsIXPConnect::INIT_JS_STANDARD_CLASSES; JS::CompartmentOptions options; @@ -1730,14 +1729,13 @@ nsMessageManagerScriptExecutor::InitChildGlobalInternal( options.creationOptions().setSharedMemoryAndAtomicsEnabled(true); } - nsCOMPtr globalHolder; - nsresult rv = - xpc->InitClassesWithNewWrappedGlobal(cx, aScope, mPrincipal, - flags, options, - getter_AddRefs(globalHolder)); + JS::Rooted global(cx); + nsresult rv = xpc::InitClassesWithNewWrappedGlobal(cx, aScope, mPrincipal, + flags, options, + &global); NS_ENSURE_SUCCESS(rv, false); - mGlobal = globalHolder->GetJSObject(); + mGlobal = global; NS_ENSURE_TRUE(mGlobal, false); // Set the location information for the new global, so that tools like diff --git a/ipc/testshell/XPCShellEnvironment.cpp b/ipc/testshell/XPCShellEnvironment.cpp index d8edcc626e78..c8c4b9e9dab9 100644 --- a/ipc/testshell/XPCShellEnvironment.cpp +++ b/ipc/testshell/XPCShellEnvironment.cpp @@ -423,13 +423,6 @@ XPCShellEnvironment::Init() mGlobalHolder.init(cx); - nsCOMPtr xpc = - do_GetService(nsIXPConnect::GetCID()); - if (!xpc) { - NS_ERROR("failed to get nsXPConnect service!"); - return false; - } - nsCOMPtr principal; nsCOMPtr securityManager = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); @@ -455,18 +448,17 @@ XPCShellEnvironment::Init() if (xpc::SharedMemoryEnabled()) options.creationOptions().setSharedMemoryAndAtomicsEnabled(true); - nsCOMPtr holder; - rv = xpc->InitClassesWithNewWrappedGlobal(cx, + JS::Rooted globalObj(cx); + rv = xpc::InitClassesWithNewWrappedGlobal(cx, static_cast(backstagePass), principal, 0, options, - getter_AddRefs(holder)); + &globalObj); if (NS_FAILED(rv)) { NS_ERROR("InitClassesWithNewWrappedGlobal failed!"); return false; } - JS::Rooted globalObj(cx, holder->GetJSObject()); if (!globalObj) { NS_ERROR("Failed to get global JSObject!"); return false; diff --git a/js/xpconnect/idl/nsIXPConnect.idl b/js/xpconnect/idl/nsIXPConnect.idl index 97a415e7ce72..b66515171b30 100644 --- a/js/xpconnect/idl/nsIXPConnect.idl +++ b/js/xpconnect/idl/nsIXPConnect.idl @@ -279,29 +279,6 @@ interface nsIXPConnect : nsISupports NS_DEFINE_STATIC_CID_ACCESSOR(NS_XPCONNECT_CID) %} - /** - * Creates a new global object using the given aCOMObj as the global - * object. The object will be set up according to the flags (defined - * below). If you do not pass INIT_JS_STANDARD_CLASSES, then aCOMObj - * must implement nsIXPCScriptable so it can resolve the standard - * classes when asked by the JS engine. - * - * @param aJSContext the context to use while creating the global object. - * @param aCOMObj the native object that represents the global object. - * @param aPrincipal the principal of the code that will run in this - * compartment. Can be null if not on the main thread. - * @param aFlags one of the flags below specifying what options this - * global object wants. - * @param aOptions JSAPI-specific options for the new compartment. - */ - nsIXPConnectJSObjectHolder - initClassesWithNewWrappedGlobal( - in JSContextPtr aJSContext, - in nsISupports aCOMObj, - in nsIPrincipal aPrincipal, - in uint32_t aFlags, - in JSCompartmentOptions aOptions); - const uint32_t INIT_JS_STANDARD_CLASSES = 1 << 0; const uint32_t DONT_FIRE_ONNEWGLOBALHOOK = 1 << 1; const uint32_t OMIT_COMPONENTS_OBJECT = 1 << 2; diff --git a/js/xpconnect/loader/mozJSComponentLoader.cpp b/js/xpconnect/loader/mozJSComponentLoader.cpp index bdbc272ad8f1..23cf219ed55b 100644 --- a/js/xpconnect/loader/mozJSComponentLoader.cpp +++ b/js/xpconnect/loader/mozJSComponentLoader.cpp @@ -513,17 +513,15 @@ mozJSComponentLoader::CreateLoaderGlobal(JSContext* aCx, // Defer firing OnNewGlobalObject until after the __URI__ property has // been defined so the JS debugger can tell what module the global is // for - nsCOMPtr holder; - rv = nsXPConnect::XPConnect()-> - InitClassesWithNewWrappedGlobal(aCx, - static_cast(backstagePass), - nsContentUtils::GetSystemPrincipal(), - nsIXPConnect::DONT_FIRE_ONNEWGLOBALHOOK, - options, - getter_AddRefs(holder)); + RootedObject global(aCx); + rv = xpc::InitClassesWithNewWrappedGlobal(aCx, + static_cast(backstagePass), + nsContentUtils::GetSystemPrincipal(), + nsIXPConnect::DONT_FIRE_ONNEWGLOBALHOOK, + options, + &global); NS_ENSURE_SUCCESS_VOID(rv); - RootedObject global(aCx, holder->GetJSObject()); NS_ENSURE_TRUE_VOID(global); backstagePass->SetGlobalObject(global); diff --git a/js/xpconnect/src/XPCShellImpl.cpp b/js/xpconnect/src/XPCShellImpl.cpp index a989e150439c..7a1dfe18c5a5 100644 --- a/js/xpconnect/src/XPCShellImpl.cpp +++ b/js/xpconnect/src/XPCShellImpl.cpp @@ -1306,14 +1306,13 @@ XRE_XPCShellMain(int argc, char** argv, char** envp, if (xpc::SharedMemoryEnabled()) options.creationOptions().setSharedMemoryAndAtomicsEnabled(true); options.behaviors().setVersion(JSVERSION_DEFAULT); - nsCOMPtr holder; - rv = nsXPConnect::XPConnect()-> - InitClassesWithNewWrappedGlobal(cx, - static_cast(backstagePass), - systemprincipal, - 0, - options, - getter_AddRefs(holder)); + JS::Rooted glob(cx); + rv = xpc::InitClassesWithNewWrappedGlobal(cx, + static_cast(backstagePass), + systemprincipal, + 0, + options, + &glob); if (NS_FAILED(rv)) return 1; @@ -1343,7 +1342,6 @@ XRE_XPCShellMain(int argc, char** argv, char** envp, #endif { - JS::Rooted glob(cx, holder->GetJSObject()); if (!glob) { return 1; } diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index 5de144f0cae7..c21817fe251b 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -560,19 +560,16 @@ InitGlobalObject(JSContext* aJSContext, JS::Handle aGlobal, uint32_t return true; } -} // namespace xpc - -NS_IMETHODIMP -nsXPConnect::InitClassesWithNewWrappedGlobal(JSContext * aJSContext, - nsISupports* aCOMObj, - nsIPrincipal * aPrincipal, - uint32_t aFlags, - JS::CompartmentOptions& aOptions, - nsIXPConnectJSObjectHolder** _retval) +nsresult +InitClassesWithNewWrappedGlobal(JSContext* aJSContext, + nsISupports* aCOMObj, + nsIPrincipal* aPrincipal, + uint32_t aFlags, + JS::CompartmentOptions& aOptions, + MutableHandleObject aNewGlobal) { MOZ_ASSERT(aJSContext, "bad param"); MOZ_ASSERT(aCOMObj, "bad param"); - MOZ_ASSERT(_retval, "bad param"); // We pass null for the 'extra' pointer during global object creation, so // we need to have a principal. @@ -598,10 +595,12 @@ nsXPConnect::InitClassesWithNewWrappedGlobal(JSContext * aJSContext, if (!InitGlobalObject(aJSContext, global, aFlags)) return UnexpectedFailure(NS_ERROR_FAILURE); - wrappedGlobal.forget(_retval); + aNewGlobal.set(global); return NS_OK; } +} // namespace xpc + static nsresult NativeInterface2JSObject(HandleObject aScope, nsISupports* aCOMObj, diff --git a/js/xpconnect/src/xpcpublic.h b/js/xpconnect/src/xpcpublic.h index 7818bfe65743..74782a8364c6 100644 --- a/js/xpconnect/src/xpcpublic.h +++ b/js/xpconnect/src/xpcpublic.h @@ -175,6 +175,29 @@ XrayAwareCalleeGlobalForSpecializedGetters(JSContext* cx, void TraceXPCGlobal(JSTracer* trc, JSObject* obj); +/** + * Creates a new global object using the given aCOMObj as the global + * object. The object will be set up according to the flags (defined + * below). If you do not pass INIT_JS_STANDARD_CLASSES, then aCOMObj + * must implement nsIXPCScriptable so it can resolve the standard + * classes when asked by the JS engine. + * + * @param aJSContext the context to use while creating the global object. + * @param aCOMObj the native object that represents the global object. + * @param aPrincipal the principal of the code that will run in this + * compartment. Can be null if not on the main thread. + * @param aFlags one of the flags below specifying what options this + * global object wants. + * @param aOptions JSAPI-specific options for the new compartment. + */ +nsresult +InitClassesWithNewWrappedGlobal(JSContext* aJSContext, + nsISupports* aCOMObj, + nsIPrincipal* aPrincipal, + uint32_t aFlags, + JS::CompartmentOptions& aOptions, + JS::MutableHandleObject aNewGlobal); + } /* namespace xpc */ namespace JS {