bug 1328964 add CycleCollectedJSContext::GetAsWorkletJSContext() and use it in IsOnWorkletThread() r?smaug draft
authorKarl Tomlinson <karlt+@karlt.net>
Fri, 06 Apr 2018 09:45:56 +1200
changeset 780862 f4917bf3e0eef1ffed9b06f60aef89cbebfe53b8
parent 780861 e443ea752776949f9b32faceec79f2510ea2b5b6
child 780863 f9a03a2c7d191376dfb4a58a77f0a81f25e3a633
push id106145
push userktomlinson@mozilla.com
push dateThu, 12 Apr 2018 05:09:40 +0000
reviewerssmaug
bugs1328964
milestone61.0a1
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);