mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1052089 - Rename JunkScope to PrivilegedJunkScope and remove fallibility of singleton scope access. r=billm
These two things ended up getting mushed together in my tree.
This commit is contained in:
parent
be093d15f0
commit
365f71849d
@ -107,9 +107,7 @@ nsDOMFileReader::Init()
|
||||
// Instead of grabbing some random global from the context stack,
|
||||
// let's use the default one (junk scope) for now.
|
||||
// We should move away from this Init...
|
||||
nsCOMPtr<nsIGlobalObject> global = xpc::GetJunkScopeGlobal();
|
||||
NS_ENSURE_TRUE(global, NS_ERROR_FAILURE);
|
||||
BindToOwner(global);
|
||||
BindToOwner(xpc::GetNativeForGlobal(xpc::PrivilegedJunkScope()));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -2142,7 +2142,7 @@ nsDocument::Init()
|
||||
// we use the default compartment for this document, instead of creating
|
||||
// wrapper in some random compartment when the document is exposed to js
|
||||
// via some events.
|
||||
nsCOMPtr<nsIGlobalObject> global = xpc::GetJunkScopeGlobal();
|
||||
nsCOMPtr<nsIGlobalObject> global = xpc::GetNativeForGlobal(xpc::PrivilegedJunkScope());
|
||||
NS_ENSURE_TRUE(global, NS_ERROR_FAILURE);
|
||||
mScopeObject = do_GetWeakReference(global);
|
||||
MOZ_ASSERT(mScopeObject);
|
||||
|
@ -352,9 +352,7 @@ nsXMLHttpRequest::Init()
|
||||
// Instead of grabbing some random global from the context stack,
|
||||
// let's use the default one (junk scope) for now.
|
||||
// We should move away from this Init...
|
||||
nsCOMPtr<nsIGlobalObject> global = xpc::GetJunkScopeGlobal();
|
||||
NS_ENSURE_TRUE(global, NS_ERROR_FAILURE);
|
||||
Construct(subjectPrincipal, global);
|
||||
Construct(subjectPrincipal, xpc::GetNativeForGlobal(xpc::PrivilegedJunkScope()));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -2531,7 +2531,7 @@ nsXULPrototypeScript::Serialize(nsIObjectOutputStream* aStream,
|
||||
{
|
||||
NS_ENSURE_TRUE(aProtoDoc, NS_ERROR_UNEXPECTED);
|
||||
AutoSafeJSContext cx;
|
||||
JS::Rooted<JSObject*> global(cx, xpc::GetCompilationScope());
|
||||
JS::Rooted<JSObject*> global(cx, xpc::CompilationScope());
|
||||
NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED);
|
||||
JSAutoCompartment ac(cx, global);
|
||||
|
||||
@ -2553,8 +2553,7 @@ nsXULPrototypeScript::Serialize(nsIObjectOutputStream* aStream,
|
||||
// been set.
|
||||
JS::Handle<JSScript*> script =
|
||||
JS::Handle<JSScript*>::fromMarkedLocation(mScriptObject.address());
|
||||
// Note - Inverting the order of these operands is a rooting hazard.
|
||||
MOZ_ASSERT(xpc::GetCompilationScope() == JS::CurrentGlobalOrNull(cx));
|
||||
MOZ_ASSERT(xpc::CompilationScope() == JS::CurrentGlobalOrNull(cx));
|
||||
return nsContentUtils::XPConnect()->WriteScript(aStream, cx,
|
||||
xpc_UnmarkGrayScript(script));
|
||||
}
|
||||
@ -2621,7 +2620,7 @@ nsXULPrototypeScript::Deserialize(nsIObjectInputStream* aStream,
|
||||
aStream->Read32(&mLangVersion);
|
||||
|
||||
AutoSafeJSContext cx;
|
||||
JS::Rooted<JSObject*> global(cx, xpc::GetCompilationScope());
|
||||
JS::Rooted<JSObject*> global(cx, xpc::CompilationScope());
|
||||
NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED);
|
||||
JSAutoCompartment ac(cx, global);
|
||||
|
||||
@ -2731,7 +2730,7 @@ NotifyOffThreadScriptCompletedRunnable::Run()
|
||||
JSScript *script;
|
||||
{
|
||||
AutoSafeJSContext cx;
|
||||
JSAutoCompartment ac(cx, xpc::GetCompilationScope());
|
||||
JSAutoCompartment ac(cx, xpc::CompilationScope());
|
||||
script = JS::FinishOffThreadScript(cx, JS_GetRuntime(cx), mToken);
|
||||
}
|
||||
|
||||
@ -2757,9 +2756,8 @@ nsXULPrototypeScript::Compile(JS::SourceBufferHolder& aSrcBuf,
|
||||
nsIOffThreadScriptReceiver *aOffThreadReceiver /* = nullptr */)
|
||||
{
|
||||
// We'll compile the script in the compilation scope.
|
||||
NS_ENSURE_TRUE(xpc::GetCompilationScope(), NS_ERROR_UNEXPECTED);
|
||||
AutoSafeJSContext cx;
|
||||
JSAutoCompartment ac(cx, xpc::GetCompilationScope());
|
||||
JSAutoCompartment ac(cx, xpc::CompilationScope());
|
||||
|
||||
nsAutoCString urlspec;
|
||||
nsContentUtils::GetWrapperSafeScriptFilename(aDocument, aURI, urlspec);
|
||||
|
@ -1113,7 +1113,7 @@ Console::ProcessCallData(ConsoleCallData* aData)
|
||||
// mStorage, but that's a bit fragile. Instead, we just use the junk scope,
|
||||
// with explicit permission from the XPConnect module owner. If you're
|
||||
// tempted to do that anywhere else, talk to said module owner first.
|
||||
JSAutoCompartment ac2(cx, xpc::GetJunkScope());
|
||||
JSAutoCompartment ac2(cx, xpc::PrivilegedJunkScope());
|
||||
|
||||
JS::Rooted<JS::Value> eventValue(cx);
|
||||
if (!ToJSValue(cx, event, &eventValue)) {
|
||||
|
@ -495,7 +495,7 @@ SmsRequestParent::DoRequest(const SendMessageRequest& aRequest)
|
||||
// jsval to ::Send. Only system code should be looking at the result here,
|
||||
// so we just create it in the System-Principaled Junk Scope.
|
||||
AutoJSContext cx;
|
||||
JSAutoCompartment ac(cx, xpc::GetJunkScope());
|
||||
JSAutoCompartment ac(cx, xpc::PrivilegedJunkScope());
|
||||
JS::Rooted<JS::Value> params(cx);
|
||||
const SendMmsMessageRequest &req = aRequest.get_SendMmsMessageRequest();
|
||||
if (!GetParamsFromSendMmsMessageRequest(cx,
|
||||
|
@ -359,7 +359,6 @@ void
|
||||
AssertInCompilationScope()
|
||||
{
|
||||
AutoJSContext cx;
|
||||
// Note - Inverting the order of these operands is a rooting hazard.
|
||||
MOZ_ASSERT(xpc::GetCompilationScope() == JS::CurrentGlobalOrNull(cx));
|
||||
MOZ_ASSERT(xpc::CompilationScope() == JS::CurrentGlobalOrNull(cx));
|
||||
}
|
||||
#endif
|
||||
|
@ -240,8 +240,7 @@ nsXBLProtoImpl::CompilePrototypeMembers(nsXBLPrototypeBinding* aBinding)
|
||||
// bind the prototype to a real xbl instance, we'll clone the pre-compiled JS into the real instance's
|
||||
// context.
|
||||
AutoSafeJSContext cx;
|
||||
JS::Rooted<JSObject*> compilationGlobal(cx, xpc::GetCompilationScope());
|
||||
NS_ENSURE_TRUE(compilationGlobal, NS_ERROR_UNEXPECTED);
|
||||
JS::Rooted<JSObject*> compilationGlobal(cx, xpc::CompilationScope());
|
||||
JSAutoCompartment ac(cx, compilationGlobal);
|
||||
|
||||
mPrecompiledMemberHolder = JS_NewObjectWithGivenProto(cx, nullptr, JS::NullPtr(), compilationGlobal);
|
||||
|
@ -911,8 +911,7 @@ nsXBLPrototypeBinding::Read(nsIObjectInputStream* aStream,
|
||||
}
|
||||
|
||||
AutoSafeJSContext cx;
|
||||
JS::Rooted<JSObject*> compilationGlobal(cx, xpc::GetCompilationScope());
|
||||
NS_ENSURE_TRUE(compilationGlobal, NS_ERROR_UNEXPECTED);
|
||||
JS::Rooted<JSObject*> compilationGlobal(cx, xpc::CompilationScope());
|
||||
JSAutoCompartment ac(cx, compilationGlobal);
|
||||
|
||||
bool isFirstBinding = aFlags & XBLBinding_Serialize_IsFirstBinding;
|
||||
@ -1064,8 +1063,7 @@ nsXBLPrototypeBinding::Write(nsIObjectOutputStream* aStream)
|
||||
// computed on demand.
|
||||
|
||||
AutoSafeJSContext cx;
|
||||
JS::Rooted<JSObject*> compilationGlobal(cx, xpc::GetCompilationScope());
|
||||
NS_ENSURE_TRUE(compilationGlobal, NS_ERROR_UNEXPECTED);
|
||||
JS::Rooted<JSObject*> compilationGlobal(cx, xpc::CompilationScope());
|
||||
JSAutoCompartment ac(cx, compilationGlobal);
|
||||
|
||||
uint8_t flags = mInheritStyle ? XBLBinding_Serialize_InheritStyle : 0;
|
||||
|
@ -395,7 +395,7 @@ JavaScriptShared::findObjectById(JSContext *cx, uint32_t objId)
|
||||
}
|
||||
|
||||
// If there's no TabChildGlobal, we use the junk scope.
|
||||
JSAutoCompartment ac(cx, xpc::GetJunkScope());
|
||||
JSAutoCompartment ac(cx, xpc::PrivilegedJunkScope());
|
||||
if (!JS_WrapObject(cx, &obj))
|
||||
return nullptr;
|
||||
return obj;
|
||||
|
@ -561,30 +561,15 @@ EnableUniversalXPConnect(JSContext *cx)
|
||||
}
|
||||
|
||||
JSObject *
|
||||
GetJunkScope()
|
||||
PrivilegedJunkScope()
|
||||
{
|
||||
XPCJSRuntime *self = nsXPConnect::GetRuntimeInstance();
|
||||
NS_ENSURE_TRUE(self, nullptr);
|
||||
return self->JunkScope();
|
||||
}
|
||||
|
||||
nsIGlobalObject *
|
||||
GetJunkScopeGlobal()
|
||||
{
|
||||
JSObject *junkScope = GetJunkScope();
|
||||
// GetJunkScope would ideally never fail, currently it is not yet the case
|
||||
// unfortunately...(see Bug 874158)
|
||||
if (!junkScope)
|
||||
return nullptr;
|
||||
return GetNativeForGlobal(junkScope);
|
||||
return XPCJSRuntime::Get()->PrivilegedJunkScope();
|
||||
}
|
||||
|
||||
JSObject *
|
||||
GetCompilationScope()
|
||||
CompilationScope()
|
||||
{
|
||||
XPCJSRuntime *self = nsXPConnect::GetRuntimeInstance();
|
||||
NS_ENSURE_TRUE(self, nullptr);
|
||||
return self->CompilationScope();
|
||||
return XPCJSRuntime::Get()->CompilationScope();
|
||||
}
|
||||
|
||||
JSObject *
|
||||
@ -3130,7 +3115,7 @@ XPCJSRuntime::XPCJSRuntime(nsXPConnect* aXPConnect)
|
||||
mWrappedJSRoots(nullptr),
|
||||
mObjectHolderRoots(nullptr),
|
||||
mWatchdogManager(new WatchdogManager(MOZ_THIS_IN_INITIALIZER_LIST())),
|
||||
mJunkScope(MOZ_THIS_IN_INITIALIZER_LIST()->Runtime(), nullptr),
|
||||
mPrivilegedJunkScope(MOZ_THIS_IN_INITIALIZER_LIST()->Runtime(), nullptr),
|
||||
mCompilationScope(MOZ_THIS_IN_INITIALIZER_LIST()->Runtime(), nullptr),
|
||||
mAsyncSnowWhiteFreer(new AsyncFreeSnowWhite())
|
||||
{
|
||||
@ -3561,13 +3546,13 @@ XPCJSRuntime::InitSingletonScopes()
|
||||
nsresult rv;
|
||||
|
||||
// Create the Junk Scope.
|
||||
SandboxOptions junkScopeOptions;
|
||||
junkScopeOptions.sandboxName.AssignLiteral("XPConnect Junk Compartment");
|
||||
junkScopeOptions.invisibleToDebugger = true;
|
||||
junkScopeOptions.wantComponents = false;
|
||||
rv = CreateSandboxObject(cx, &v, nsXPConnect::SystemPrincipal(), junkScopeOptions);
|
||||
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));
|
||||
mJunkScope = js::UncheckedUnwrap(&v.toObject());
|
||||
mPrivilegedJunkScope = js::UncheckedUnwrap(&v.toObject());
|
||||
|
||||
// Create the Compilation Scope.
|
||||
SandboxOptions compilationScopeOptions;
|
||||
@ -3582,6 +3567,6 @@ XPCJSRuntime::InitSingletonScopes()
|
||||
void
|
||||
XPCJSRuntime::DeleteSingletonScopes()
|
||||
{
|
||||
mJunkScope = nullptr;
|
||||
mPrivilegedJunkScope = nullptr;
|
||||
mCompilationScope = nullptr;
|
||||
}
|
||||
|
@ -1468,7 +1468,7 @@ SetAddonInterposition(const nsACString &addonIdStr, nsIAddonInterposition *inter
|
||||
// We enter the junk scope just to allocate a string, which actually will go
|
||||
// in the system zone.
|
||||
AutoJSAPI jsapi;
|
||||
jsapi.Init(xpc::GetJunkScopeGlobal());
|
||||
jsapi.Init(xpc::GetNativeForGlobal(xpc::PrivilegedJunkScope()));
|
||||
addonId = NewAddonId(jsapi.cx(), addonIdStr);
|
||||
if (!addonId)
|
||||
return false;
|
||||
|
@ -619,7 +619,7 @@ public:
|
||||
|
||||
AutoMarkingPtr** GetAutoRootsAdr() {return &mAutoRoots;}
|
||||
|
||||
JSObject* JunkScope() { return mJunkScope; }
|
||||
JSObject* PrivilegedJunkScope() { return mPrivilegedJunkScope; }
|
||||
JSObject* CompilationScope() { return mCompilationScope; }
|
||||
|
||||
void InitSingletonScopes();
|
||||
@ -663,7 +663,7 @@ private:
|
||||
nsTArray<xpcContextCallback> extraContextCallbacks;
|
||||
nsRefPtr<WatchdogManager> mWatchdogManager;
|
||||
JS::GCSliceCallback mPrevGCSliceCallback;
|
||||
JS::PersistentRootedObject mJunkScope;
|
||||
JS::PersistentRootedObject mPrivilegedJunkScope;
|
||||
JS::PersistentRootedObject mCompilationScope;
|
||||
nsRefPtr<AsyncFreeSnowWhite> mAsyncSnowWhiteFreer;
|
||||
|
||||
|
@ -448,14 +448,7 @@ UnwrapReflectorToISupports(JSObject *reflector);
|
||||
* using this compartment. If you don't, bholley will hunt you down.
|
||||
*/
|
||||
JSObject *
|
||||
GetJunkScope();
|
||||
|
||||
/**
|
||||
* Returns the native global of the junk scope. See comment of GetJunkScope
|
||||
* about the conditions of using it.
|
||||
*/
|
||||
nsIGlobalObject *
|
||||
GetJunkScopeGlobal();
|
||||
PrivilegedJunkScope();
|
||||
|
||||
/**
|
||||
* Shared compilation scope for XUL prototype documents and XBL
|
||||
@ -463,7 +456,7 @@ GetJunkScopeGlobal();
|
||||
* it is invisible to the debugger.
|
||||
*/
|
||||
JSObject *
|
||||
GetCompilationScope();
|
||||
CompilationScope();
|
||||
|
||||
/**
|
||||
* If |aObj| is a window, returns the associated nsGlobalWindow.
|
||||
|
Loading…
Reference in New Issue
Block a user