From 15e9284f508008a3e5da23f6e18fd1a729b693c5 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Fri, 9 Aug 2013 09:25:15 -0700 Subject: [PATCH] Bug 902718 - Fold EnsureScriptEnvironment into GetCompilationGlobal. r=bz --- content/xbl/src/nsXBLDocumentInfo.cpp | 62 ++++++++++++--------------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/content/xbl/src/nsXBLDocumentInfo.cpp b/content/xbl/src/nsXBLDocumentInfo.cpp index 74e78fb48c13..26fe4a5622f5 100644 --- a/content/xbl/src/nsXBLDocumentInfo.cpp +++ b/content/xbl/src/nsXBLDocumentInfo.cpp @@ -54,7 +54,6 @@ public: void UnmarkCompilationGlobal(); void Destroy(); nsIPrincipal* GetPrincipal(); - nsresult EnsureScriptEnvironment(); static bool doCheckAccess(JSContext *cx, JS::Handle obj, JS::Handle id, uint32_t accessType); @@ -205,39 +204,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXBLDocGlobalObject) NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXBLDocGlobalObject) -nsresult -nsXBLDocGlobalObject::EnsureScriptEnvironment() -{ - if (mJSObject || mDestroyed) { - // Already initialized. - return NS_OK; - } - - AutoSafeJSContext cx; - JS::CompartmentOptions options; - options.setZone(JS::SystemZone) - .setInvisibleToDebugger(true); - mJSObject = JS_NewGlobalObject(cx, &gSharedGlobalClass, - nsJSPrincipals::get(GetPrincipal()), - JS::DontFireOnNewGlobalHook, - options); - if (!mJSObject) - return NS_OK; - - NS_HOLD_JS_OBJECTS(this, nsXBLDocGlobalObject); - - // Set the location information for the new global, so that tools like - // about:memory may use that information - nsIURI *ownerURI = mGlobalObjectOwner->DocumentURI(); - xpc::SetLocationForGlobal(mJSObject, ownerURI); - - // Add an owning reference from JS back to us. This'll be - // released when the JSObject is finalized. - ::JS_SetPrivate(mJSObject, this); - NS_ADDREF(this); - return NS_OK; -} - void nsXBLDocGlobalObject::ClearGlobalObjectOwner() { @@ -255,7 +221,33 @@ nsXBLDocGlobalObject::GetCompilationGlobal() { // The prototype document has its own special secret script object // that can be used to compile scripts and event handlers. - EnsureScriptEnvironment(); + if (mJSObject || mDestroyed) { + // We've been initialized before - what we have is what you get. + return mJSObject; + } + + AutoSafeJSContext cx; + JS::CompartmentOptions options; + options.setZone(JS::SystemZone) + .setInvisibleToDebugger(true); + mJSObject = JS_NewGlobalObject(cx, &gSharedGlobalClass, + nsJSPrincipals::get(GetPrincipal()), + JS::DontFireOnNewGlobalHook, + options); + if (!mJSObject) + return nullptr; + + NS_HOLD_JS_OBJECTS(this, nsXBLDocGlobalObject); + + // Set the location information for the new global, so that tools like + // about:memory may use that information + nsIURI *ownerURI = mGlobalObjectOwner->DocumentURI(); + xpc::SetLocationForGlobal(mJSObject, ownerURI); + + // Add an owning reference from JS back to us. This'll be + // released when the JSObject is finalized. + ::JS_SetPrivate(mJSObject, this); + NS_ADDREF(this); return mJSObject; }