bug 1328964 add CycleCollectedJSContext::GetAsWorkletJSContext() and use it in IsOnWorkletThread() r=smaug
authorKarl Tomlinson <karlt+@karlt.net>
Fri, 06 Apr 2018 09:45:56 +1200
changeset 412955 06872fbe3904f267f66932d07d20f8311a14ae6f
parent 412954 c3c9f4525efb7898bab818432f44d9ee25ca4c11
child 412956 e90079d5f339e7515298f3c5b8ef30c6737ac3d1
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 add CycleCollectedJSContext::GetAsWorkletJSContext() and use it in IsOnWorkletThread() r=smaug MozReview-Commit-ID: BUujWXYho1G
dom/worklet/WorkletThread.cpp
xpcom/base/CycleCollectedJSContext.h
--- a/dom/worklet/WorkletThread.cpp
+++ b/dom/worklet/WorkletThread.cpp
@@ -165,16 +165,18 @@ public:
     }
 
     delete static_cast<WorkletThreadContextPrivate*>(JS_GetContextPrivate(cx));
     JS_SetContextPrivate(cx, nullptr);
 
     nsCycleCollector_shutdown();
   }
 
+  WorkletJSContext* GetAsWorkletJSContext() override { return this; }
+
   CycleCollectedJSRuntime* CreateRuntime(JSContext* aCx) override
   {
     return new WorkletJSRuntime(aCx);
   }
 
   nsresult
   Initialize(JSRuntime* aParentRuntime)
   {
@@ -421,18 +423,18 @@ const WorkletLoadInfo&
 WorkletThread::GetWorkletLoadInfo() const
 {
   return mWorkletLoadInfo;
 }
 
 /* static */ bool
 WorkletThread::IsOnWorkletThread()
 {
-  const char* threadName = PR_GetThreadName(PR_GetCurrentThread());
-  return threadName && !strcmp(threadName, "worklet");
+  CycleCollectedJSContext* ccjscx = CycleCollectedJSContext::Get();
+  return ccjscx && ccjscx->GetAsWorkletJSContext();
 }
 
 /* static */ void
 WorkletThread::AssertIsOnWorkletThread()
 {
   MOZ_ASSERT(IsOnWorkletThread());
 }
 
--- a/xpcom/base/CycleCollectedJSContext.h
+++ b/xpcom/base/CycleCollectedJSContext.h
@@ -27,16 +27,17 @@ class nsWrapperCache;
 
 namespace mozilla {
 class AutoSlowOperation;
 
 class CycleCollectedJSRuntime;
 
 namespace dom {
 class Exception;
+class WorkletJSContext;
 } // namespace dom
 
 // Contains various stats about the cycle collection.
 struct CycleCollectorResults
 {
   CycleCollectorResults()
   {
     // Initialize here so when we increment mNumSlices the first time we're
@@ -125,16 +126,18 @@ private:
   void CleanupIDBTransactions(uint32_t aRecursionDepth);
 
 public:
   enum DeferredFinalizeType {
     FinalizeIncrementally,
     FinalizeNow,
   };
 
+  virtual dom::WorkletJSContext* GetAsWorkletJSContext() { return nullptr; }
+
   CycleCollectedJSRuntime* Runtime() const
   {
     MOZ_ASSERT(mRuntime);
     return mRuntime;
   }
 
   already_AddRefed<dom::Exception> GetPendingException() const;
   void SetPendingException(dom::Exception* aException);