diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 9dfd43840ba3..f36941131c96 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -2364,9 +2364,9 @@ nsIDocument::ResetToURI(nsIURI* aURI, mFontFaceSet->RefreshStandardFontLoadPrincipal(); } - // Refresh the principal on the compartment. + // Refresh the principal on the realm. if (nsPIDOMWindowInner* win = GetInnerWindow()) { - nsGlobalWindowInner::Cast(win)->RefreshCompartmentPrincipal(); + nsGlobalWindowInner::Cast(win)->RefreshRealmPrincipal(); } } diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index 4e86e6e21e57..a078b2114118 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -3632,10 +3632,10 @@ nsGlobalWindowInner::GetChildWindow(const nsAString& aName) } void -nsGlobalWindowInner::RefreshCompartmentPrincipal() +nsGlobalWindowInner::RefreshRealmPrincipal() { - JS_SetCompartmentPrincipals(js::GetObjectCompartment(GetWrapperPreserveColor()), - nsJSPrincipals::get(mDoc->NodePrincipal())); + JS::SetRealmPrincipals(js::GetNonCCWObjectRealm(GetWrapperPreserveColor()), + nsJSPrincipals::get(mDoc->NodePrincipal())); } already_AddRefed diff --git a/dom/base/nsGlobalWindowInner.h b/dom/base/nsGlobalWindowInner.h index d2f0bd405654..7bfcc0ed9ea8 100644 --- a/dom/base/nsGlobalWindowInner.h +++ b/dom/base/nsGlobalWindowInner.h @@ -377,7 +377,7 @@ public: virtual void MaybeUpdateTouchState() override; // Inner windows only. - void RefreshCompartmentPrincipal(); + void RefreshRealmPrincipal(); // For accessing protected field mFullScreen friend class FullscreenTransitionTask; diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp index 325bcd7b888f..cf8168ddd550 100644 --- a/dom/base/nsGlobalWindowOuter.cpp +++ b/dom/base/nsGlobalWindowOuter.cpp @@ -1747,24 +1747,26 @@ nsGlobalWindowOuter::SetNewDocument(nsIDocument* aDocument, } // Inner windows are only reused for same-origin principals, but the principals - // don't necessarily match exactly. Update the principal on the compartment to - // match the new document. - // NB: We don't just call currentInner->RefreshCompartmentPrincipals() here + // don't necessarily match exactly. Update the principal on the realm to match + // the new document. + // NB: We don't just call currentInner->RefreshRealmPrincipals() here // because we haven't yet set its mDoc to aDocument. - JSCompartment *compartment = js::GetObjectCompartment(newInnerGlobal); + JS::Realm* realm = js::GetNonCCWObjectRealm(newInnerGlobal); #ifdef DEBUG bool sameOrigin = false; nsIPrincipal *existing = - nsJSPrincipals::get(JS_GetCompartmentPrincipals(compartment)); + nsJSPrincipals::get(JS::GetRealmPrincipals(realm)); aDocument->NodePrincipal()->Equals(existing, &sameOrigin); MOZ_ASSERT(sameOrigin); -#endif + + JSCompartment* compartment = JS::GetCompartmentForRealm(realm); MOZ_ASSERT_IF(aDocument == oldDoc, xpc::GetCompartmentPrincipal(compartment) == aDocument->NodePrincipal()); +#endif if (aDocument != oldDoc) { - JS_SetCompartmentPrincipals(compartment, - nsJSPrincipals::get(aDocument->NodePrincipal())); + JS::SetRealmPrincipals(realm, + nsJSPrincipals::get(aDocument->NodePrincipal())); // Make sure we clear out the old content XBL scope, so the new one will // get created with a principal that subsumes our new principal. xpc::ClearContentXBLScope(newInnerGlobal); diff --git a/js/src/gc/GC.cpp b/js/src/gc/GC.cpp index cae6178b35cf..7a32b250cca7 100644 --- a/js/src/gc/GC.cpp +++ b/js/src/gc/GC.cpp @@ -7961,7 +7961,7 @@ js::NewRealm(JSContext* cx, JSPrincipals* principals, const JS::RealmOptions& op return nullptr; // Set up the principals. - JS_SetCompartmentPrincipals(JS::GetCompartmentForRealm(realm), principals); + JS::SetRealmPrincipals(realm, principals); JSCompartment* comp = realm->compartment(); if (!comp->realms().append(realm)) { diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp index caacbb5cfe8b..fcf1060eb9f2 100644 --- a/js/src/jsfriendapi.cpp +++ b/js/src/jsfriendapi.cpp @@ -169,10 +169,9 @@ JS::GetRealmPrincipals(JS::Realm* realm) } JS_FRIEND_API(void) -JS_SetCompartmentPrincipals(JSCompartment* compartment, JSPrincipals* principals) +JS::SetRealmPrincipals(JS::Realm* realm, JSPrincipals* principals) { // Short circuit if there's no change. - Realm* realm = JS::GetRealmForCompartment(compartment); if (principals == realm->principals()) return; diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h index 79b2653c16d0..4e26b6b27b06 100644 --- a/js/src/jsfriendapi.h +++ b/js/src/jsfriendapi.h @@ -190,9 +190,6 @@ JS_GetIsSecureContext(JSCompartment* compartment); extern JS_FRIEND_API(JSPrincipals*) JS_GetCompartmentPrincipals(JSCompartment* compartment); -extern JS_FRIEND_API(void) -JS_SetCompartmentPrincipals(JSCompartment* compartment, JSPrincipals* principals); - extern JS_FRIEND_API(JSPrincipals*) JS_GetScriptPrincipals(JSScript* script); @@ -328,6 +325,9 @@ IsGCPoisoning(); extern JS_FRIEND_API(JSPrincipals*) GetRealmPrincipals(JS::Realm* realm); +extern JS_FRIEND_API(void) +SetRealmPrincipals(JS::Realm* realm, JSPrincipals* principals); + } // namespace JS /** diff --git a/js/src/vm/HelperThreads.cpp b/js/src/vm/HelperThreads.cpp index 52ca973d7531..690f9ee257ab 100644 --- a/js/src/vm/HelperThreads.cpp +++ b/js/src/vm/HelperThreads.cpp @@ -753,7 +753,7 @@ CreateGlobalForOffThreadParse(JSContext* cx, const gc::AutoSuppressGC& nogc) Rooted global(cx, &obj->as()); - JS_SetCompartmentPrincipals(global->compartment(), currentRealm->principals()); + JS::SetRealmPrincipals(global->realm(), currentRealm->principals()); return global; }