Bug 1342513. Set up a scripted caller override in AutoEntryScript. r=bholley
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 28 Feb 2017 12:41:35 -0500
changeset 490611 37962f55384708d9e045181d22353f4b4fa3edfd
parent 490610 87ea3256dd8b3bf3f6f924525f44d12212b936ff
child 490612 2e7d6509b02a5aa39870f8a4a898628c4375e231
push id47156
push userbmo:lockhart@cs.dal.ca
push dateTue, 28 Feb 2017 22:47:20 +0000
reviewersbholley
bugs1342513
milestone54.0a1
Bug 1342513. Set up a scripted caller override in AutoEntryScript. r=bholley Otherwise if we have no explicit incumbent script we can end up getting an incumbent off the script stack _above_ the AutoEntryScript, which is wrong. MozReview-Commit-ID: LG3540tgRQ
dom/base/ScriptSettings.cpp
dom/base/ScriptSettings.h
--- a/dom/base/ScriptSettings.cpp
+++ b/dom/base/ScriptSettings.cpp
@@ -650,16 +650,19 @@ AutoJSAPI::IsStackTop() const
 }
 #endif // DEBUG
 
 AutoEntryScript::AutoEntryScript(nsIGlobalObject* aGlobalObject,
                                  const char *aReason,
                                  bool aIsMainThread)
   : AutoJSAPI(aGlobalObject, aIsMainThread, eEntryScript)
   , mWebIDLCallerPrincipal(nullptr)
+  // This relies on us having a cx() because the AutoJSAPI constructor already
+  // ran.
+  , mCallerOverride(cx())
 {
   MOZ_ASSERT(aGlobalObject);
 
   if (aIsMainThread && gRunToCompletionListeners > 0) {
     mDocShellEntryMonitor.emplace(cx(), aReason);
   }
 }
 
--- a/dom/base/ScriptSettings.h
+++ b/dom/base/ScriptSettings.h
@@ -374,16 +374,17 @@ private:
   // 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* MOZ_NON_OWNING_REF mWebIDLCallerPrincipal;
   friend nsIPrincipal* GetWebIDLCallerPrincipal();
 
   Maybe<DocshellEntryMonitor> mDocShellEntryMonitor;
+  JS::AutoHideScriptedCaller mCallerOverride;
 };
 
 /*
  * A class that can be used to force a particular incumbent script on the stack.
  */
 class AutoIncumbentScript : protected ScriptSettingsStackEntry {
 public:
   explicit AutoIncumbentScript(nsIGlobalObject* aGlobalObject);