bug 1328964 use nsContentUtils::GetCurrentJSContext() on all threads r=smaug
authorKarl Tomlinson <karlt+@karlt.net>
Mon, 09 Apr 2018 12:11:18 +1200
changeset 412956 e90079d5f339e7515298f3c5b8ef30c6737ac3d1
parent 412955 06872fbe3904f267f66932d07d20f8311a14ae6f
child 412957 55823ab4098ad331e48a4caad64ea422d4e232cd
push id33828
push userarchaeopteryx@coole-files.de
push dateThu, 12 Apr 2018 19:19:41 +0000
treeherdermozilla-central@6e22c4a726c2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1328964
milestone61.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 1328964 use nsContentUtils::GetCurrentJSContext() on all threads r=smaug nsContentUtils::GetCurrentJSContextForThread() originally needed to use workers::GetCurrentThreadJSContext() in https://hg.mozilla.org/mozilla-central/rev/366a45b41539#l2.18 because CycleCollectedJS*()->Context() did not exist until https://hg.mozilla.org/mozilla-central/rev/1a0cd542e1e9#l7.12 nsContentUtils::GetCurrentJSContext() is thread-safe since these changes: https://hg.mozilla.org/mozilla-central/rev/e636c7186286#l3.12 https://hg.mozilla.org/mozilla-central/rev/c8029c072776#l2.12 MozReview-Commit-ID: 2f1eGS9uBBO
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
dom/bindings/Exceptions.cpp
dom/script/ScriptSettings.cpp
js/xpconnect/src/XPCDebug.cpp
xpcom/base/nsTraceRefcnt.cpp
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -59,17 +59,16 @@
 #include "mozilla/dom/Promise.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/dom/TabParent.h"
 #include "mozilla/dom/Text.h"
 #include "mozilla/dom/TouchEvent.h"
 #include "mozilla/dom/ShadowRoot.h"
 #include "mozilla/dom/XULCommandEvent.h"
 #include "mozilla/dom/WorkerPrivate.h"
-#include "mozilla/dom/WorkletThread.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/EventListenerManager.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/gfx/DataSurfaceHelpers.h"
 #include "mozilla/HTMLEditor.h"
 #include "mozilla/IMEStateManager.h"
 #include "mozilla/InternalMutationEvent.h"
 #include "mozilla/Likely.h"
@@ -6063,40 +6062,23 @@ nsContentUtils::URIIsLocalFile(nsIURI *a
                                 &isFile)) &&
          isFile;
 }
 
 /* static */
 JSContext *
 nsContentUtils::GetCurrentJSContext()
 {
-  MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(IsInitialized());
   if (!IsJSAPIActive()) {
     return nullptr;
   }
   return danger::GetJSContext();
 }
 
-/* static */
-JSContext *
-nsContentUtils::GetCurrentJSContextForThread()
-{
-  MOZ_ASSERT(IsInitialized());
-  if (MOZ_LIKELY(NS_IsMainThread())) {
-    return GetCurrentJSContext();
-  }
-
-  if (WorkletThread::IsOnWorkletThread()) {
-    return WorkletThread::Get()->GetJSContext();
-  }
-
-  return GetCurrentWorkerThreadJSContext();
-}
-
 template<typename StringType, typename CharType>
 void
 _ASCIIToLowerInSitu(StringType& aStr)
 {
   CharType* iter = aStr.BeginWriting();
   CharType* end = aStr.EndWriting();
   MOZ_ASSERT(iter && end);
 
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -2042,17 +2042,16 @@ public:
    * the document header and use it later on after rendering.
    *
    * See Bug #436083
    */
   static nsresult ProcessViewportInfo(nsIDocument *aDocument,
                                       const nsAString &viewportInfo);
 
   static JSContext *GetCurrentJSContext();
-  static JSContext *GetCurrentJSContextForThread();
 
   /**
    * Case insensitive comparison between two strings. However it only ignores
    * case for ASCII characters a-z.
    */
   static bool EqualsIgnoreASCIICase(const nsAString& aStr1,
                                     const nsAString& aStr2);
 
--- a/dom/bindings/Exceptions.cpp
+++ b/dom/bindings/Exceptions.cpp
@@ -182,17 +182,17 @@ CreateException(nsresult aRv, const nsAC
     new Exception(aMessage, aRv, EmptyCString(), nullptr, nullptr);
   return exception.forget();
 }
 
 already_AddRefed<nsIStackFrame>
 GetCurrentJSStack(int32_t aMaxDepth)
 {
   // is there a current context available?
-  JSContext* cx = nsContentUtils::GetCurrentJSContextForThread();
+  JSContext* cx = nsContentUtils::GetCurrentJSContext();
 
   if (!cx || !js::GetContextCompartment(cx)) {
     return nullptr;
   }
 
   static const unsigned MAX_FRAMES = 100;
   if (aMaxDepth < 0) {
     aMaxDepth = MAX_FRAMES;
--- a/dom/script/ScriptSettings.cpp
+++ b/dom/script/ScriptSettings.cpp
@@ -220,17 +220,17 @@ GetEntryDocument()
 nsIGlobalObject*
 GetIncumbentGlobal()
 {
   // We need the current JSContext in order to check the JS for
   // scripted frames that may have appeared since anyone last
   // manipulated the stack. If it's null, that means that there
   // must be no entry global on the stack, and therefore no incumbent
   // global either.
-  JSContext* cx = nsContentUtils::GetCurrentJSContextForThread();
+  JSContext* cx = nsContentUtils::GetCurrentJSContext();
   if (!cx) {
     MOZ_ASSERT(ScriptSettingsStack::EntryGlobal() == nullptr);
     return nullptr;
   }
 
   // See what the JS engine has to say. If we've got a scripted caller
   // override in place, the JS engine will lie to us and pretend that
   // there's nothing on the JS stack, which will cause us to check the
@@ -242,17 +242,17 @@ GetIncumbentGlobal()
   // Ok, nothing from the JS engine. Let's use whatever's on the
   // explicit stack.
   return ClampToSubject(ScriptSettingsStack::IncumbentGlobal());
 }
 
 nsIGlobalObject*
 GetCurrentGlobal()
 {
-  JSContext* cx = nsContentUtils::GetCurrentJSContextForThread();
+  JSContext* cx = nsContentUtils::GetCurrentJSContext();
   if (!cx) {
     return nullptr;
   }
 
   JSObject* global = JS::CurrentGlobalOrNull(cx);
   if (!global) {
     return nullptr;
   }
@@ -743,17 +743,17 @@ AutoEntryScript::DocshellEntryMonitor::E
   if (window && window->GetDocShell()) {
     nsCOMPtr<nsIDocShell> docShellForJSRunToCompletion = window->GetDocShell();
     docShellForJSRunToCompletion->NotifyJSRunToCompletionStop();
   }
 }
 
 AutoIncumbentScript::AutoIncumbentScript(nsIGlobalObject* aGlobalObject)
   : ScriptSettingsStackEntry(aGlobalObject, eIncumbentScript)
-  , mCallerOverride(nsContentUtils::GetCurrentJSContextForThread())
+  , mCallerOverride(nsContentUtils::GetCurrentJSContext())
 {
   ScriptSettingsStack::Push(this);
 }
 
 AutoIncumbentScript::~AutoIncumbentScript()
 {
   ScriptSettingsStack::Pop(this);
 }
--- a/js/xpconnect/src/XPCDebug.cpp
+++ b/js/xpconnect/src/XPCDebug.cpp
@@ -33,17 +33,17 @@ static void DebugDump(const char* fmt, .
   __android_log_write(ANDROID_LOG_DEBUG, "Gecko", buffer);
 #endif
   printf("%s", buffer);
 }
 
 bool
 xpc_DumpJSStack(bool showArgs, bool showLocals, bool showThisProps)
 {
-    JSContext* cx = nsContentUtils::GetCurrentJSContextForThread();
+    JSContext* cx = nsContentUtils::GetCurrentJSContext();
     if (!cx) {
         printf("there is no JSContext on the stack!\n");
     } else if (JS::UniqueChars buf = xpc_PrintJSStack(cx, showArgs, showLocals, showThisProps)) {
         DebugDump("%s\n", buf.get());
     }
     return true;
 }
 
--- a/xpcom/base/nsTraceRefcnt.cpp
+++ b/xpcom/base/nsTraceRefcnt.cpp
@@ -138,17 +138,17 @@ struct SerialNumberRecord
   mozilla::UniquePtr<char[]> jsStack;
 
   void SaveJSStack() {
     // If this thread isn't running JS, there's nothing to do.
     if (!CycleCollectedJSContext::Get()) {
       return;
     }
 
-    JSContext* cx = nsContentUtils::GetCurrentJSContextForThread();
+    JSContext* cx = nsContentUtils::GetCurrentJSContext();
     if (!cx) {
       return;
     }
 
     JS::UniqueChars chars = xpc_PrintJSStack(cx,
                                              /*showArgs=*/ false,
                                              /*showLocals=*/ false,
                                              /*showThisProps=*/ false);