Bug 993772 - Introduce a singleton compilation scope. r=mrbkap

This commit is contained in:
Bobby Holley 2014-04-20 11:48:13 -07:00
parent 8cb91cd665
commit f56f915374
4 changed files with 42 additions and 4 deletions

View File

@ -587,6 +587,14 @@ GetJunkScopeGlobal()
return GetNativeForGlobal(junkScope);
}
JSObject *
GetCompilationScope()
{
XPCJSRuntime *self = nsXPConnect::GetRuntimeInstance();
NS_ENSURE_TRUE(self, nullptr);
return self->GetCompilationScope();
}
JSObject *
GetSafeJSContextGlobal()
{
@ -3045,6 +3053,7 @@ XPCJSRuntime::XPCJSRuntime(nsXPConnect* aXPConnect)
mObjectHolderRoots(nullptr),
mWatchdogManager(new WatchdogManager(MOZ_THIS_IN_INITIALIZER_LIST())),
mJunkScope(MOZ_THIS_IN_INITIALIZER_LIST()->Runtime(), nullptr),
mCompilationScope(MOZ_THIS_IN_INITIALIZER_LIST()->Runtime(), nullptr),
mAsyncSnowWhiteFreer(new AsyncFreeSnowWhite())
{
DOM_InitInterfaces();
@ -3476,7 +3485,7 @@ XPCJSRuntime::GetJunkScope()
if (!mJunkScope) {
AutoSafeJSContext cx;
SandboxOptions options;
options.sandboxName.AssignASCII("XPConnect Junk Compartment");
options.sandboxName.AssignLiteral("XPConnect Junk Compartment");
RootedValue v(cx);
nsresult rv = CreateSandboxObject(cx, &v, nsContentUtils::GetSystemPrincipal(), options);
NS_ENSURE_SUCCESS(rv, nullptr);
@ -3486,8 +3495,27 @@ XPCJSRuntime::GetJunkScope()
return mJunkScope;
}
JSObject *
XPCJSRuntime::GetCompilationScope()
{
if (!mCompilationScope) {
AutoSafeJSContext cx;
SandboxOptions options;
options.sandboxName.AssignLiteral("XPConnect Compilation Compartment");
options.invisibleToDebugger = true;
RootedValue v(cx);
nsresult rv = CreateSandboxObject(cx, &v, /* principal = */ nullptr, options);
NS_ENSURE_SUCCESS(rv, nullptr);
mCompilationScope = js::UncheckedUnwrap(&v.toObject());
}
return mCompilationScope;
}
void
XPCJSRuntime::DeleteJunkScope()
XPCJSRuntime::DeleteSingletonScopes()
{
mJunkScope = nullptr;
mCompilationScope = nullptr;
}

View File

@ -88,7 +88,7 @@ nsXPConnect::nsXPConnect()
nsXPConnect::~nsXPConnect()
{
mRuntime->DeleteJunkScope();
mRuntime->DeleteSingletonScopes();
mRuntime->DestroyJSContextStack();
// In order to clean up everything properly, we need to GC twice: once now,

View File

@ -557,7 +557,8 @@ public:
AutoMarkingPtr** GetAutoRootsAdr() {return &mAutoRoots;}
JSObject* GetJunkScope();
void DeleteJunkScope();
JSObject* GetCompilationScope();
void DeleteSingletonScopes();
PRTime GetWatchdogTimestamp(WatchdogTimestampCategory aCategory);
void OnAfterProcessNextEvent() { mSlowScriptCheckpoint = mozilla::TimeStamp(); }
@ -598,6 +599,7 @@ private:
nsRefPtr<WatchdogManager> mWatchdogManager;
JS::GCSliceCallback mPrevGCSliceCallback;
JS::PersistentRootedObject mJunkScope;
JS::PersistentRootedObject mCompilationScope;
nsRefPtr<AsyncFreeSnowWhite> mAsyncSnowWhiteFreer;
mozilla::TimeStamp mSlowScriptCheckpoint;

View File

@ -435,6 +435,14 @@ GetJunkScope();
nsIGlobalObject *
GetJunkScopeGlobal();
/**
* Shared compilation scope for XUL prototype documents and XBL
* precompilation. This compartment has a null principal. No code may run, and
* it is invisible to the debugger.
*/
JSObject *
GetCompilationScope();
/**
* If |aObj| is a window, returns the associated nsGlobalWindow.
* Otherwise, returns null.