From ad9f69cbf957f0d8c3f696b1045b84fd0c409a99 Mon Sep 17 00:00:00 2001 From: Karl Tomlinson Date: Fri, 6 Apr 2018 09:45:56 +1200 Subject: [PATCH] bug 1328964 add CycleCollectedJSContext::GetAsWorkletJSContext() and use it in IsOnWorkletThread() r=smaug MozReview-Commit-ID: BUujWXYho1G --HG-- extra : rebase_source : 78bb6736f74bb59913bc9499fcfdf7b0baa7870d --- dom/worklet/WorkletThread.cpp | 6 ++++-- xpcom/base/CycleCollectedJSContext.h | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dom/worklet/WorkletThread.cpp b/dom/worklet/WorkletThread.cpp index 140378ee71ec..4b36e3433051 100644 --- a/dom/worklet/WorkletThread.cpp +++ b/dom/worklet/WorkletThread.cpp @@ -170,6 +170,8 @@ public: nsCycleCollector_shutdown(); } + WorkletJSContext* GetAsWorkletJSContext() override { return this; } + CycleCollectedJSRuntime* CreateRuntime(JSContext* aCx) override { return new WorkletJSRuntime(aCx); @@ -426,8 +428,8 @@ WorkletThread::GetWorkletLoadInfo() const /* 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 diff --git a/xpcom/base/CycleCollectedJSContext.h b/xpcom/base/CycleCollectedJSContext.h index 2d2913aee8dc..3425e37e9a9b 100644 --- a/xpcom/base/CycleCollectedJSContext.h +++ b/xpcom/base/CycleCollectedJSContext.h @@ -32,6 +32,7 @@ class CycleCollectedJSRuntime; namespace dom { class Exception; +class WorkletJSContext; } // namespace dom // Contains various stats about the cycle collection. @@ -130,6 +131,8 @@ public: FinalizeNow, }; + virtual dom::WorkletJSContext* GetAsWorkletJSContext() { return nullptr; } + CycleCollectedJSRuntime* Runtime() const { MOZ_ASSERT(mRuntime);