Bug 1103324 - Instantiate an AutoNoJSAPI when dispatching IPC messages. r=billm
authorBobby Holley <bobbyholley@gmail.com>
Sat, 06 Dec 2014 09:51:14 -0800
changeset 244449 96dbd5483c059a498a98062077ed8e81d4cc6b7e
parent 244448 ba5e60f0a2580680a382d64bbdeebc1071d31bd2
child 244450 96d9c1de3a5b9624acd4cc4af0be7e7f28fd5c98
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1103324
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1103324 - Instantiate an AutoNoJSAPI when dispatching IPC messages. r=billm
dom/base/ScriptSettings.cpp
dom/base/ScriptSettings.h
ipc/glue/MessageChannel.cpp
--- a/dom/base/ScriptSettings.cpp
+++ b/dom/base/ScriptSettings.cpp
@@ -99,21 +99,28 @@ InitScriptSettings()
     if (!success) {
       MOZ_CRASH();
     }
   }
 
   sScriptSettingsTLS.set(nullptr);
 }
 
-void DestroyScriptSettings()
+void
+DestroyScriptSettings()
 {
   MOZ_ASSERT(sScriptSettingsTLS.get() == nullptr);
 }
 
+bool
+ScriptSettingsInitialized()
+{
+  return sScriptSettingsTLS.initialized();
+}
+
 ScriptSettingsStackEntry::ScriptSettingsStackEntry(nsIGlobalObject *aGlobal,
                                                    bool aCandidate)
   : mGlobalObject(aGlobal)
   , mIsCandidateEntryPoint(aCandidate)
   , mOlder(nullptr)
 {
   MOZ_ASSERT(mGlobalObject);
   MOZ_ASSERT(mGlobalObject->GetGlobalJSObject(),
--- a/dom/base/ScriptSettings.h
+++ b/dom/base/ScriptSettings.h
@@ -58,16 +58,17 @@ private:
 } /* namespace danger */
 
 /*
  * System-wide setup/teardown routines. Init and Destroy should be invoked
  * once each, at startup and shutdown (respectively).
  */
 void InitScriptSettings();
 void DestroyScriptSettings();
+bool ScriptSettingsInitialized();
 
 /*
  * Static helpers in ScriptSettings which track the number of listeners
  * of Javascript RunToCompletion events.  These should be used by the code in
  * nsDocShell::SetRecordProfileTimelineMarkers to indicate to script
  * settings that script run-to-completion needs to be monitored.
  * SHOULD BE CALLED ONLY BY MAIN THREAD.
  */
--- a/ipc/glue/MessageChannel.cpp
+++ b/ipc/glue/MessageChannel.cpp
@@ -3,16 +3,18 @@
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/ipc/MessageChannel.h"
 #include "mozilla/ipc/ProtocolUtils.h"
 
+#include "mozilla/dom/ScriptSettings.h"
+
 #include "mozilla/Assertions.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/Move.h"
 #include "nsDebug.h"
 #include "nsISupportsImpl.h"
 #include "nsContentUtils.h"
 
 #include "prprf.h"
@@ -74,16 +76,18 @@
  * more difficult to determine whether one message is nested inside
  * another. Consequently, intr handling uses mOutOfTurnReplies and
  * mRemoteStackDepthGuess, which are not needed for sync messages.
  */
 
 using namespace mozilla;
 using namespace std;
 
+using mozilla::dom::AutoNoJSAPI;
+using mozilla::dom::ScriptSettingsInitialized;
 using mozilla::MonitorAutoLock;
 using mozilla::MonitorAutoUnlock;
 
 template<>
 struct RunnableMethodTraits<mozilla::ipc::MessageChannel>
 {
     static void RetainCallee(mozilla::ipc::MessageChannel* obj) { }
     static void ReleaseCallee(mozilla::ipc::MessageChannel* obj) { }
@@ -1053,16 +1057,19 @@ MessageChannel::OnMaybeDequeueOne()
         DispatchMessage(recvd);
     }
     return true;
 }
 
 void
 MessageChannel::DispatchMessage(const Message &aMsg)
 {
+    Maybe<AutoNoJSAPI> nojsapi;
+    if (ScriptSettingsInitialized() && NS_IsMainThread())
+        nojsapi.emplace();
     if (aMsg.is_sync())
         DispatchSyncMessage(aMsg);
     else if (aMsg.is_interrupt())
         DispatchInterruptMessage(aMsg, 0);
     else
         DispatchAsyncMessage(aMsg);
 }