Backed out changeset 8477472996e0 (bug 1442737) for frequent mochitest failures e.g.: toolkit/components/alerts/test/test_principal.html

This commit is contained in:
Margareta Eliza Balazs 2018-06-26 11:28:50 +03:00
Родитель 62f22c5f61
Коммит 616a3ce82b
8 изменённых файлов: 52 добавлений и 32 удалений

Просмотреть файл

@ -185,7 +185,7 @@ function compartment_test(finish)
function ok(x, msg) { results.push({ result: x ? "PASS" : "FAIL", message: msg }) };
let cpowLocation = Cu.getRealmLocation(obj);
ok(/shared JSM global/.test(cpowLocation),
ok(/Privileged Junk/.test(cpowLocation),
"child->parent CPOWs should live in the privileged junk scope: " + cpowLocation);
is(obj(), 42, "child->parent CPOW is invokable");
try {

Просмотреть файл

@ -302,7 +302,7 @@
Cu.getGlobalForObject(unprivilegedObject),
"all parent->child CPOWs should live in the same scope");
let cpowLocation = Cu.getRealmLocation(getUnprivilegedObject);
ok(/shared JSM global/.test(cpowLocation),
ok(/Privileged Junk/.test(cpowLocation),
"parent->child CPOWs should live in the privileged junk scope: " + cpowLocation);
// Make sure that parent->child CPOWs point through a privileged scope in the child

Просмотреть файл

@ -6,6 +6,7 @@
#include "ScriptPreloader-inl.h"
#include "mozilla/ScriptPreloader.h"
#include "mozJSComponentLoader.h"
#include "mozilla/loader/ScriptCacheActors.h"
#include "mozilla/URLPreloader.h"
@ -436,7 +437,7 @@ ScriptPreloader::InitCache(const nsAString& basePath)
// Grab the compilation scope before initializing the URLPreloader, since
// it's not safe to run component loader code during its critical section.
AutoSafeJSAPI jsapi;
JS::RootedObject scope(jsapi.cx(), xpc::CompilationScope());
JS::RootedObject scope(jsapi.cx(), CompilationScope(jsapi.cx()));
// Note: Code on the main thread *must not access Omnijar in any way* until
// this AutoBeginReading guard is destroyed.
@ -950,6 +951,12 @@ ScriptPreloader::DoFinishOffThreadDecode()
MaybeFinishOffThreadDecode();
}
JSObject*
ScriptPreloader::CompilationScope(JSContext* cx)
{
return mozJSComponentLoader::Get()->CompilationScope(cx);
}
void
ScriptPreloader::MaybeFinishOffThreadDecode()
{
@ -968,7 +975,7 @@ ScriptPreloader::MaybeFinishOffThreadDecode()
AutoSafeJSAPI jsapi;
JSContext* cx = jsapi.cx();
JSAutoRealm ar(cx, xpc::CompilationScope());
JSAutoRealm ar(cx, CompilationScope(cx));
JS::Rooted<JS::ScriptVector> jsScripts(cx, JS::ScriptVector(cx));
// If this fails, we still need to mark the scripts as finished. Any that
@ -1038,7 +1045,7 @@ ScriptPreloader::DecodeNextBatch(size_t chunkSize, JS::HandleObject scope)
AutoSafeJSAPI jsapi;
JSContext* cx = jsapi.cx();
JSAutoRealm ar(cx, scope ? scope : xpc::CompilationScope());
JSAutoRealm ar(cx, scope ? scope : CompilationScope(cx));
JS::CompileOptions options(cx);
options.setNoScriptRval(true)

Просмотреть файл

@ -394,6 +394,11 @@ private:
void MaybeFinishOffThreadDecode();
void DoFinishOffThreadDecode();
// Returns the global scope object for off-thread compilation. When global
// sharing is enabled in the component loader, this should be the shared
// module global. Otherwise, it should be the XPConnect compilation scope.
JSObject* CompilationScope(JSContext* cx);
size_t ShallowHeapSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf)
{
return (mallocSizeOf(this) + mScripts.ShallowSizeOfExcludingThis(mallocSizeOf) +

Просмотреть файл

@ -89,7 +89,7 @@ class mozJSComponentLoader final : public mozilla::ModuleLoader,
protected:
virtual ~mozJSComponentLoader();
friend class XPCJSRuntime;
friend class mozilla::ScriptPreloader;
JSObject* CompilationScope(JSContext* aCx)
{

Просмотреть файл

@ -515,13 +515,13 @@ UnprivilegedJunkScope()
JSObject*
PrivilegedJunkScope()
{
return XPCJSRuntime::Get()->LoaderGlobal();
return XPCJSRuntime::Get()->PrivilegedJunkScope();
}
JSObject*
CompilationScope()
{
return XPCJSRuntime::Get()->LoaderGlobal();
return XPCJSRuntime::Get()->CompilationScope();
}
nsGlobalWindowInner*
@ -2821,7 +2821,8 @@ void
XPCJSRuntime::Initialize(JSContext* cx)
{
mUnprivilegedJunkScope.init(cx, nullptr);
mLoaderGlobal.init(cx, nullptr);
mPrivilegedJunkScope.init(cx, nullptr);
mCompilationScope.init(cx, nullptr);
// these jsids filled in later when we have a JSContext to work with.
mStrIDs[0] = JSID_VOID;
@ -3071,6 +3072,24 @@ XPCJSRuntime::InitSingletonScopes()
rv = CreateSandboxObject(cx, &v, nullptr, unprivilegedJunkScopeOptions);
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
mUnprivilegedJunkScope = js::UncheckedUnwrap(&v.toObject());
// Create the Privileged Junk Scope.
SandboxOptions privilegedJunkScopeOptions;
privilegedJunkScopeOptions.sandboxName.AssignLiteral("XPConnect Privileged Junk Compartment");
privilegedJunkScopeOptions.invisibleToDebugger = true;
privilegedJunkScopeOptions.wantComponents = false;
rv = CreateSandboxObject(cx, &v, nsXPConnect::SystemPrincipal(), privilegedJunkScopeOptions);
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
mPrivilegedJunkScope = js::UncheckedUnwrap(&v.toObject());
// Create the Compilation Scope.
SandboxOptions compilationScopeOptions;
compilationScopeOptions.sandboxName.AssignLiteral("XPConnect Compilation Compartment");
compilationScopeOptions.invisibleToDebugger = true;
compilationScopeOptions.discardSource = ShouldDiscardSystemSource();
rv = CreateSandboxObject(cx, &v, /* principal = */ nullptr, compilationScopeOptions);
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
mCompilationScope = js::UncheckedUnwrap(&v.toObject());
}
void
@ -3081,20 +3100,10 @@ XPCJSRuntime::DeleteSingletonScopes()
RefPtr<SandboxPrivate> sandbox = SandboxPrivate::GetPrivate(mUnprivilegedJunkScope);
sandbox->ReleaseWrapper(sandbox);
mUnprivilegedJunkScope = nullptr;
mLoaderGlobal = nullptr;
}
JSObject*
XPCJSRuntime::LoaderGlobal()
{
if (!mLoaderGlobal) {
RefPtr<mozJSComponentLoader> loader = mozJSComponentLoader::GetOrCreate();
dom::AutoJSAPI jsapi;
jsapi.Init();
mLoaderGlobal = loader->GetSharedGlobal(jsapi.cx());
MOZ_RELEASE_ASSERT(!JS_IsExceptionPending(jsapi.cx()));
}
return mLoaderGlobal;
sandbox = SandboxPrivate::GetPrivate(mPrivilegedJunkScope);
sandbox->ReleaseWrapper(sandbox);
mPrivilegedJunkScope = nullptr;
sandbox = SandboxPrivate::GetPrivate(mCompilationScope);
sandbox->ReleaseWrapper(sandbox);
mCompilationScope = nullptr;
}

Просмотреть файл

@ -575,7 +575,8 @@ public:
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);
JSObject* UnprivilegedJunkScope() { return mUnprivilegedJunkScope; }
JSObject* LoaderGlobal();
JSObject* PrivilegedJunkScope() { return mPrivilegedJunkScope; }
JSObject* CompilationScope() { return mCompilationScope; }
void InitSingletonScopes();
void DeleteSingletonScopes();
@ -610,7 +611,8 @@ private:
JS::GCSliceCallback mPrevGCSliceCallback;
JS::DoCycleCollectionCallback mPrevDoCycleCollectionCallback;
JS::PersistentRootedObject mUnprivilegedJunkScope;
JS::PersistentRootedObject mLoaderGlobal;
JS::PersistentRootedObject mPrivilegedJunkScope;
JS::PersistentRootedObject mCompilationScope;
RefPtr<AsyncFreeSnowWhite> mAsyncSnowWhiteFreer;
friend class XPCJSContext;

Просмотреть файл

@ -453,16 +453,13 @@ UnwrapReflectorToISupports(JSObject* reflector);
JSObject*
UnprivilegedJunkScope();
/**
* This will generally be the shared JSM global, but callers should not depend
* on that fact.
*/
JSObject*
PrivilegedJunkScope();
/**
* Shared compilation scope for XUL prototype documents and XBL
* precompilation.
* precompilation. This compartment has a null principal. No code may run, and
* it is invisible to the debugger.
*/
JSObject*
CompilationScope();