Bug 1547923 part 5. Start using nsIGlobalObject::GetGlobalJSObjectPreserveColor where possible. r=mccr8,jonco

Differential Revision: https://phabricator.services.mozilla.com/D29706

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2019-05-03 15:15:31 +00:00
parent ff72e84ac1
commit 356eb6dfd9
8 changed files with 32 additions and 20 deletions

View File

@ -7438,7 +7438,8 @@ bool Document::IsScriptEnabled() {
return false;
}
return xpc::Scriptability::Get(globalObject->GetGlobalJSObject()).Allowed();
return xpc::Scriptability::Get(globalObject->GetGlobalJSObjectPreserveColor())
.Allowed();
}
void Document::RetrieveRelevantHeaders(nsIChannel* aChannel) {

View File

@ -30,7 +30,7 @@ nsIGlobalObject::~nsIGlobalObject() {
}
nsIPrincipal* nsIGlobalObject::PrincipalOrNull() {
JSObject* global = GetGlobalJSObject();
JSObject* global = GetGlobalJSObjectPreserveColor();
if (NS_WARN_IF(!global)) return nullptr;
return nsContentUtils::ObjectPrincipal(global);

View File

@ -108,7 +108,10 @@ void CallbackObject::FinishSlowJSInitIfMoreThanOneOwner(JSContext* aCx) {
}
mIncumbentGlobal = GetIncumbentGlobal();
if (mIncumbentGlobal) {
mIncumbentJSGlobal = mIncumbentGlobal->GetGlobalJSObject();
// We don't want to expose to JS here (change the color). If someone ever
// reads mIncumbentJSGlobal, that will expose. If not, no need to expose
// here.
mIncumbentJSGlobal = mIncumbentGlobal->GetGlobalJSObjectPreserveColor();
}
} else {
// We can just forget all our stuff.

View File

@ -206,7 +206,10 @@ class CallbackObject : public nsISupports {
mCreationStack = aCreationStack;
if (aIncumbentGlobal) {
mIncumbentGlobal = aIncumbentGlobal;
mIncumbentJSGlobal = aIncumbentGlobal->GetGlobalJSObject();
// We don't want to expose to JS here (change the color). If someone ever
// reads mIncumbentJSGlobal, that will expose. If not, no need to expose
// here.
mIncumbentJSGlobal = aIncumbentGlobal->GetGlobalJSObjectPreserveColor();
}
}

View File

@ -479,8 +479,9 @@ void Promise::HandleException(JSContext* aCx) {
already_AddRefed<Promise> Promise::CreateFromExisting(
nsIGlobalObject* aGlobal, JS::Handle<JSObject*> aPromiseObj,
PropagateUserInteraction aPropagateUserInteraction) {
MOZ_ASSERT(js::GetObjectCompartment(aGlobal->GetGlobalJSObject()) ==
js::GetObjectCompartment(aPromiseObj));
MOZ_ASSERT(
js::GetObjectCompartment(aGlobal->GetGlobalJSObjectPreserveColor()) ==
js::GetObjectCompartment(aPromiseObj));
RefPtr<Promise> p = new Promise(aGlobal);
p->mPromiseObj = aPromiseObj;
if (aPropagateUserInteraction == ePropagateUserInteraction &&

View File

@ -134,7 +134,8 @@ ScriptSettingsStackEntry::ScriptSettingsStackEntry(nsIGlobalObject* aGlobal,
MOZ_ASSERT(!mGlobalObject || mGlobalObject->HasJSGlobal(),
"Must have an actual JS global for the duration on the stack");
MOZ_ASSERT(
!mGlobalObject || JS_IsGlobalObject(mGlobalObject->GetGlobalJSObject()),
!mGlobalObject ||
JS_IsGlobalObject(mGlobalObject->GetGlobalJSObjectPreserveColor()),
"No outer windows allowed");
}
@ -286,7 +287,8 @@ void AutoJSAPI::InitInternal(nsIGlobalObject* aGlobalObject, JSObject* aGlobal,
MOZ_ASSERT(aCx == danger::GetJSContext());
MOZ_ASSERT(aIsMainThread == NS_IsMainThread());
MOZ_ASSERT(bool(aGlobalObject) == bool(aGlobal));
MOZ_ASSERT_IF(aGlobalObject, aGlobalObject->GetGlobalJSObject() == aGlobal);
MOZ_ASSERT_IF(aGlobalObject,
aGlobalObject->GetGlobalJSObjectPreserveColor() == aGlobal);
#ifdef DEBUG
bool haveException = JS_IsExceptionPending(aCx);
#endif // DEBUG

View File

@ -341,20 +341,20 @@ WorkerRunnable::Run() {
// If we're on the parent thread and have a reflector and a globalObject,
// then the realms of cx, globalObject, and the worker's reflector
// should all match.
MOZ_ASSERT_IF(globalObject, js::GetObjectCompartment(wrapper) ==
js::GetContextCompartment(cx));
MOZ_ASSERT_IF(globalObject, js::GetObjectCompartment(wrapper) ==
js::GetObjectCompartment(
globalObject->GetGlobalJSObject()));
MOZ_ASSERT_IF(globalObject,
js::GetNonCCWObjectRealm(wrapper) == js::GetContextRealm(cx));
MOZ_ASSERT_IF(globalObject,
js::GetNonCCWObjectRealm(wrapper) ==
js::GetNonCCWObjectRealm(
globalObject->GetGlobalJSObjectPreserveColor()));
// If we're on the parent thread and have a reflector, then our
// JSContext had better be either in the null realm (and hence
// have no globalObject) or in the realm of our reflector.
MOZ_ASSERT(
!js::GetContextCompartment(cx) ||
js::GetObjectCompartment(wrapper) == js::GetContextCompartment(cx),
"Must either be in the null compartment or in our reflector "
"compartment");
MOZ_ASSERT(!js::GetContextRealm(cx) ||
js::GetNonCCWObjectRealm(wrapper) == js::GetContextRealm(cx),
"Must either be in the null compartment or in our reflector "
"compartment");
ar.emplace(cx, wrapper);
}

View File

@ -3227,7 +3227,8 @@ void nsPrintJob::TurnScriptingOn(bool aDoTurnOn) {
if (propThere != NS_PROPTABLE_PROP_NOT_THERE) {
doc->DeleteProperty(nsGkAtoms::scriptEnabledBeforePrintOrPreview);
if (go->HasJSGlobal()) {
xpc::Scriptability::Get(go->GetGlobalJSObject()).Unblock();
xpc::Scriptability::Get(go->GetGlobalJSObjectPreserveColor())
.Unblock();
}
window->Resume();
}
@ -3241,7 +3242,8 @@ void nsPrintJob::TurnScriptingOn(bool aDoTurnOn) {
doc->SetProperty(nsGkAtoms::scriptEnabledBeforePrintOrPreview,
NS_INT32_TO_PTR(doc->IsScriptEnabled()));
if (go && go->HasJSGlobal()) {
xpc::Scriptability::Get(go->GetGlobalJSObject()).Block();
xpc::Scriptability::Get(go->GetGlobalJSObjectPreserveColor())
.Block();
}
window->Suspend();
}