diff --git a/dom/base/ScriptSettings.cpp b/dom/base/ScriptSettings.cpp index 5507c9060cd..e3156ebef90 100644 --- a/dom/base/ScriptSettings.cpp +++ b/dom/base/ScriptSettings.cpp @@ -244,6 +244,7 @@ AutoEntryScript::AutoEntryScript(nsIGlobalObject* aGlobalObject, , ScriptSettingsStackEntry(aGlobalObject, /* aCandidate = */ true) , mAc(cx(), aGlobalObject->GetGlobalJSObject()) , mStack(ScriptSettingsStack::Ref()) + , mWebIDLCallerPrincipal(nullptr) { MOZ_ASSERT(aGlobalObject); MOZ_ASSERT_IF(!aCx, aIsMainThread); // cx is mandatory off-main-thread. diff --git a/dom/base/ScriptSettings.h b/dom/base/ScriptSettings.h index a033034d5ac..0bbbe40ac5f 100644 --- a/dom/base/ScriptSettings.h +++ b/dom/base/ScriptSettings.h @@ -179,7 +179,14 @@ public: private: JSAutoCompartment mAc; dom::ScriptSettingsStack& mStack; - nsCOMPtr mWebIDLCallerPrincipal; + // It's safe to make this a weak pointer, since it's the subject principal + // when we go on the stack, so can't go away until after we're gone. In + // particular, this is only used from the CallSetup constructor, and only in + // the aIsJSImplementedWebIDL case. And in that case, the subject principal + // is the principal of the callee function that is part of the CallArgs just a + // bit up the stack, and which will outlive us. So we know the principal + // can't go away until then either. + nsIPrincipal* mWebIDLCallerPrincipal; friend nsIPrincipal* GetWebIDLCallerPrincipal(); };