Bug 902718 - Fold EnsureScriptEnvironment into GetCompilationGlobal. r=bz

This commit is contained in:
Bobby Holley 2013-08-09 09:25:15 -07:00
parent fd5cde0bec
commit c609bc28f8

View File

@ -54,7 +54,6 @@ public:
void UnmarkCompilationGlobal();
void Destroy();
nsIPrincipal* GetPrincipal();
nsresult EnsureScriptEnvironment();
static bool doCheckAccess(JSContext *cx, JS::Handle<JSObject*> obj,
JS::Handle<jsid> 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;
}