diff --git a/dom/base/Console.cpp b/dom/base/Console.cpp index b09396a34d4d..e563cdc0d7a0 100644 --- a/dom/base/Console.cpp +++ b/dom/base/Console.cpp @@ -371,7 +371,7 @@ private: RefPtr runnable = new ConsoleReleaseRunnable(mWorkerPrivate, this); - runnable->Dispatch(nullptr); + runnable->Dispatch(); } void diff --git a/dom/base/WebSocket.cpp b/dom/base/WebSocket.cpp index 4cc13b24f5ff..a605902dd41c 100644 --- a/dom/base/WebSocket.cpp +++ b/dom/base/WebSocket.cpp @@ -2546,7 +2546,7 @@ WebSocketImpl::Cancel(nsresult aStatus) MOZ_ASSERT(mWorkerPrivate); RefPtr runnable = new CancelRunnable(mWorkerPrivate, this); - if (!runnable->Dispatch(nullptr)) { + if (!runnable->Dispatch()) { return NS_ERROR_FAILURE; } @@ -2749,7 +2749,7 @@ WebSocketImpl::Dispatch(already_AddRefed&& aEvent, uint32_t aFlags) RefPtr event = new WorkerRunnableDispatcher(this, mWorkerPrivate, event_ref.forget()); - if (!event->Dispatch(nullptr)) { + if (!event->Dispatch()) { return NS_ERROR_FAILURE; } diff --git a/dom/canvas/ImageBitmap.cpp b/dom/canvas/ImageBitmap.cpp index 6b6d7826b8f0..98856168ebce 100644 --- a/dom/canvas/ImageBitmap.cpp +++ b/dom/canvas/ImageBitmap.cpp @@ -894,7 +894,7 @@ AsyncFulfillImageBitmapPromise(Promise* aPromise, ImageBitmap* aImageBitmap) } else { RefPtr task = new FulfillImageBitmapPromiseWorkerTask(aPromise, aImageBitmap); - task->Dispatch(GetCurrentThreadWorkerPrivate()->GetJSContext()); // Actually, to the current worker-thread. + task->Dispatch(); // Actually, to the current worker-thread. } } @@ -1167,7 +1167,7 @@ AsyncCreateImageBitmapFromBlob(Promise* aPromise, nsIGlobalObject* aGlobal, } else { RefPtr task = new CreateImageBitmapFromBlobWorkerTask(aPromise, aGlobal, aBlob, aCropRect); - task->Dispatch(GetCurrentThreadWorkerPrivate()->GetJSContext()); // Actually, to the current worker-thread. + task->Dispatch(); // Actually, to the current worker-thread. } } diff --git a/dom/fetch/Fetch.cpp b/dom/fetch/Fetch.cpp index 3a4732820710..779fb3aede06 100644 --- a/dom/fetch/Fetch.cpp +++ b/dom/fetch/Fetch.cpp @@ -326,9 +326,7 @@ WorkerFetchResolver::OnResponseAvailableInternal(InternalResponse* aResponse) new WorkerFetchResponseRunnable(mPromiseProxy->GetWorkerPrivate(), this, aResponse); - AutoJSAPI jsapi; - jsapi.Init(); - if (!r->Dispatch(jsapi.cx())) { + if (!r->Dispatch()) { NS_WARNING("Could not dispatch fetch response"); } } @@ -345,9 +343,7 @@ WorkerFetchResolver::OnResponseEnd() RefPtr r = new WorkerFetchResponseEndRunnable(mPromiseProxy->GetWorkerPrivate(), this); - AutoJSAPI jsapi; - jsapi.Init(); - if (!r->Dispatch(jsapi.cx())) { + if (!r->Dispatch()) { NS_WARNING("Could not dispatch fetch response end"); } } @@ -611,8 +607,7 @@ public: if (mBody->mWorkerPrivate) { RefPtr> r = new FailConsumeBodyWorkerRunnable(mBody); - AutoSafeJSContext cx; - if (!r->Dispatch(cx)) { + if (!r->Dispatch()) { MOZ_CRASH("We are going to leak"); } } else { @@ -662,8 +657,7 @@ public: aStatus, aResultLength, nonconstResult); - AutoSafeJSContext cx; - if (!r->Dispatch(cx)) { + if (!r->Dispatch()) { // XXXcatalinb: The worker is shutting down, the pump will be canceled // by FetchBodyFeature::Notify. NS_WARNING("Could not dispatch ConsumeBodyRunnable"); diff --git a/dom/indexedDB/ActorsChild.cpp b/dom/indexedDB/ActorsChild.cpp index 17d2e01811e1..3e9487ea11aa 100644 --- a/dom/indexedDB/ActorsChild.cpp +++ b/dom/indexedDB/ActorsChild.cpp @@ -943,7 +943,7 @@ public: RefPtr runnable = new WorkerPermissionOperationCompleted(mWorkerPrivate, this); - MOZ_ALWAYS_TRUE(runnable->Dispatch(nullptr)); + MOZ_ALWAYS_TRUE(runnable->Dispatch()); return; } diff --git a/dom/notification/Notification.cpp b/dom/notification/Notification.cpp index b1f717d5a46f..bd8b0ff879b5 100644 --- a/dom/notification/Notification.cpp +++ b/dom/notification/Notification.cpp @@ -503,12 +503,10 @@ public: RefPtr r = new ReleaseNotificationRunnable(notification); - AutoJSAPI jsapi; - jsapi.Init(); - if (!r->Dispatch(jsapi.cx())) { + if (!r->Dispatch()) { RefPtr r = new ReleaseNotificationControlRunnable(notification); - MOZ_ALWAYS_TRUE(r->Dispatch(jsapi.cx())); + MOZ_ALWAYS_TRUE(r->Dispatch()); } } else { notification->AssertIsOnTargetThread(); @@ -1554,8 +1552,7 @@ WorkerNotificationObserver::Observe(nsISupports* aSubject, const char* aTopic, } MOZ_ASSERT(r); - AutoSafeJSContext cx; - if (!r->Dispatch(cx)) { + if (!r->Dispatch()) { NS_WARNING("Could not dispatch event to worker notification"); } return NS_OK; @@ -1726,8 +1723,7 @@ Notification::ShowInternal() RefPtr r = new NotificationEventWorkerRunnable(this, NS_LITERAL_STRING("error")); - AutoSafeJSContext cx; - if (!r->Dispatch(cx)) { + if (!r->Dispatch()) { NS_WARNING("Could not dispatch event to worker notification"); } } else { @@ -2153,7 +2149,7 @@ public: proxy, Move(mStrings)); - r->Dispatch(aCx); + r->Dispatch(); return NS_OK; } diff --git a/dom/promise/Promise.cpp b/dom/promise/Promise.cpp index aee724c61aa5..c5513529ce4f 100644 --- a/dom/promise/Promise.cpp +++ b/dom/promise/Promise.cpp @@ -2905,7 +2905,7 @@ PromiseWorkerProxy::RunCallback(JSContext* aCx, RefPtr runnable = new PromiseWorkerProxyRunnable(this, aFunc); - runnable->Dispatch(aCx); + runnable->Dispatch(); } void diff --git a/dom/promise/PromiseWorkerProxy.h b/dom/promise/PromiseWorkerProxy.h index 32e8a3de4e5b..c3b3e451626b 100644 --- a/dom/promise/PromiseWorkerProxy.h +++ b/dom/promise/PromiseWorkerProxy.h @@ -84,9 +84,7 @@ class WorkerPrivate; // // RefPtr runnable = // new FinishTaskWorkerRunnable(proxy->GetWorkerPrivate(), proxy, result); -// AutoJSAPI jsapi; -// jsapi.Init(); -// if (!r->Dispatch(jsapi.cx())) { +// if (!r->Dispatch()) { // // Worker is alive but not Running any more, so the Promise can't // // be resolved, give up. The proxy will get Release()d at some // // point. diff --git a/dom/push/PushManager.cpp b/dom/push/PushManager.cpp index 54f8c9aba228..26edf18bcb1a 100644 --- a/dom/push/PushManager.cpp +++ b/dom/push/PushManager.cpp @@ -442,12 +442,9 @@ public: return NS_OK; } - AutoJSAPI jsapi; - jsapi.Init(); - RefPtr r = new UnsubscribeResultRunnable(proxy, aStatus, aSuccess); - r->Dispatch(jsapi.cx()); + r->Dispatch(); return NS_OK; } @@ -644,9 +641,6 @@ public: return NS_OK; } - AutoJSAPI jsapi; - jsapi.Init(); - nsAutoString endpoint; nsTArray rawP256dhKey, authSecret; if (NS_SUCCEEDED(aStatus)) { @@ -661,7 +655,7 @@ public: mScope, rawP256dhKey, authSecret); - r->Dispatch(jsapi.cx()); + r->Dispatch(); return NS_OK; } @@ -913,11 +907,9 @@ public: state ); - AutoJSAPI jsapi; - jsapi.Init(); RefPtr r = new PermissionResultRunnable(mProxy, rv, state); - r->Dispatch(jsapi.cx()); + r->Dispatch(); return NS_OK; } diff --git a/dom/workers/DataStore.cpp b/dom/workers/DataStore.cpp index 6284b6388b22..ce5eec2a97f1 100644 --- a/dom/workers/DataStore.cpp +++ b/dom/workers/DataStore.cpp @@ -954,11 +954,7 @@ DataStoreChangeEventProxy::HandleEvent(nsIDOMEvent* aEvent) RefPtr runnable = new DispatchDataStoreChangeEventRunnable(this, event); - { - AutoSafeJSContext cx; - JSAutoRequest ar(cx); - runnable->Dispatch(cx); - } + runnable->Dispatch(); return NS_OK; } diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index d6fc505a8514..71974ba408c3 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -601,7 +601,7 @@ public: NS_DECL_ISUPPORTS_INHERITED bool - Dispatch(JSContext* aCx) + Dispatch() { AutoSyncLoopHolder syncLoop(mWorkerPrivate); @@ -609,7 +609,6 @@ public: MOZ_ASSERT(mSyncLoopTarget); if (NS_FAILED(NS_DispatchToMainThread(this))) { - JS_ReportError(aCx, "Failed to dispatch to main thread!"); return false; } @@ -642,9 +641,7 @@ ContentSecurityPolicyAllows(JSContext* aCx) RefPtr runnable = new LogViolationDetailsRunnable(worker, fileName, lineNum); - if (!runnable->Dispatch(aCx)) { - JS_ReportPendingException(aCx); - } + runnable->Dispatch(); } return worker->IsEvalAllowed(); @@ -1255,7 +1252,7 @@ WorkerCrossThreadDispatcher::PostTask(WorkerTask* aTask) RefPtr runnable = new WorkerTaskRunnable(mWorkerPrivate, aTask); - return runnable->Dispatch(nullptr); + return runnable->Dispatch(); } WorkerPrivate* @@ -2587,7 +2584,7 @@ LogViolationDetailsRunnable::Run() RefPtr response = new MainThreadStopSyncLoopRunnable(mWorkerPrivate, mSyncLoopTarget.forget(), true); - MOZ_ALWAYS_TRUE(response->Dispatch(nullptr)); + MOZ_ALWAYS_TRUE(response->Dispatch()); return NS_OK; } diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp index 321b602622ea..663a968a4ba6 100644 --- a/dom/workers/ScriptLoader.cpp +++ b/dom/workers/ScriptLoader.cpp @@ -1252,7 +1252,7 @@ private: RefPtr runnable = new ScriptExecutorRunnable(*this, mSyncLoopTarget, IsMainWorkerScript(), firstIndex, lastIndex); - if (!runnable->Dispatch(nullptr)) { + if (!runnable->Dispatch()) { MOZ_ASSERT(false, "This should never fail!"); } } @@ -1682,7 +1682,7 @@ public: RefPtr runnable = new MainThreadStopSyncLoopRunnable(mParentWorker, mSyncLoopTarget.forget(), true); - if (!runnable->Dispatch(nullptr)) { + if (!runnable->Dispatch()) { NS_ERROR("This should never fail!"); } diff --git a/dom/workers/ServiceWorkerClients.cpp b/dom/workers/ServiceWorkerClients.cpp index 97477368fc83..0b3345a07b6e 100644 --- a/dom/workers/ServiceWorkerClients.cpp +++ b/dom/workers/ServiceWorkerClients.cpp @@ -132,9 +132,7 @@ public: rv.StealNSResult()); rv.SuppressException(); - AutoJSAPI jsapi; - jsapi.Init(); - r->Dispatch(jsapi.cx()); + r->Dispatch(); return NS_OK; } }; @@ -212,9 +210,7 @@ public: new ResolvePromiseWorkerRunnable(mPromiseProxy->GetWorkerPrivate(), mPromiseProxy, result); - AutoJSAPI jsapi; - jsapi.Init(); - r->Dispatch(jsapi.cx()); + r->Dispatch(); return NS_OK; } }; @@ -292,9 +288,7 @@ public: RefPtr r = new ResolveClaimRunnable(workerPrivate, mPromiseProxy, rv); - AutoJSAPI jsapi; - jsapi.Init(); - r->Dispatch(jsapi.cx()); + r->Dispatch(); return NS_OK; } }; @@ -405,10 +399,7 @@ public: new ResolveOpenWindowRunnable(mPromiseProxy, Move(clientInfo), NS_OK); - AutoJSAPI jsapi; - jsapi.Init(); - JSContext* cx = jsapi.cx(); - r->Dispatch(cx); + r->Dispatch(); return NS_OK; } @@ -553,9 +544,7 @@ public: RefPtr resolveRunnable = new ResolveOpenWindowRunnable(mPromiseProxy, nullptr, rv); - AutoJSAPI jsapi; - jsapi.Init(); - NS_WARN_IF(!resolveRunnable->Dispatch(jsapi.cx())); + NS_WARN_IF(!resolveRunnable->Dispatch()); return NS_OK; } diff --git a/dom/workers/ServiceWorkerPrivate.cpp b/dom/workers/ServiceWorkerPrivate.cpp index 510772344412..52b2c39ff402 100644 --- a/dom/workers/ServiceWorkerPrivate.cpp +++ b/dom/workers/ServiceWorkerPrivate.cpp @@ -163,9 +163,7 @@ ServiceWorkerPrivate::CheckScriptEvaluation(LifeCycleEventCallback* aCallback) RefPtr r = new CheckScriptEvaluationWithCallback(mWorkerPrivate, mKeepAliveToken, aCallback); - AutoJSAPI jsapi; - jsapi.Init(); - if (NS_WARN_IF(!r->Dispatch(jsapi.cx()))) { + if (NS_WARN_IF(!r->Dispatch())) { return NS_ERROR_FAILURE; } @@ -548,9 +546,7 @@ ServiceWorkerPrivate::SendLifeCycleEvent(const nsAString& aEventType, mKeepAliveToken, aEventType, aCallback); - AutoJSAPI jsapi; - jsapi.Init(); - if (NS_WARN_IF(!r->Dispatch(jsapi.cx()))) { + if (NS_WARN_IF(!r->Dispatch())) { return NS_ERROR_FAILURE; } @@ -680,9 +676,7 @@ ServiceWorkerPrivate::SendPushEvent(const Maybe>& aData, MOZ_ASSERT(mInfo->State() == ServiceWorkerState::Activated); - AutoJSAPI jsapi; - jsapi.Init(); - if (NS_WARN_IF(!r->Dispatch(jsapi.cx()))) { + if (NS_WARN_IF(!r->Dispatch())) { return NS_ERROR_FAILURE; } @@ -702,9 +696,7 @@ ServiceWorkerPrivate::SendPushSubscriptionChangeEvent() MOZ_ASSERT(mKeepAliveToken); RefPtr r = new SendPushSubscriptionChangeEventRunnable(mWorkerPrivate, mKeepAliveToken); - AutoJSAPI jsapi; - jsapi.Init(); - if (NS_WARN_IF(!r->Dispatch(jsapi.cx()))) { + if (NS_WARN_IF(!r->Dispatch())) { return NS_ERROR_FAILURE; } @@ -976,9 +968,7 @@ ServiceWorkerPrivate::SendNotificationClickEvent(const nsAString& aID, aID, aTitle, aDir, aLang, aBody, aTag, aIcon, aData, aBehavior, aScope); - AutoJSAPI jsapi; - jsapi.Init(); - if (NS_WARN_IF(!r->Dispatch(jsapi.cx()))) { + if (NS_WARN_IF(!r->Dispatch())) { return NS_ERROR_FAILURE; } @@ -1351,9 +1341,7 @@ ServiceWorkerPrivate::SendFetchEvent(nsIInterceptedChannel* aChannel, MOZ_ASSERT(mInfo->State() == ServiceWorkerState::Activated); - AutoJSAPI jsapi; - jsapi.Init(); - if (NS_WARN_IF(!r->Dispatch(jsapi.cx()))) { + if (NS_WARN_IF(!r->Dispatch())) { return NS_ERROR_FAILURE; } @@ -1543,9 +1531,7 @@ ServiceWorkerPrivate::Activated() for (uint32_t i = 0; i < pendingEvents.Length(); ++i) { RefPtr r = pendingEvents[i].forget(); - AutoJSAPI jsapi; - jsapi.Init(); - if (NS_WARN_IF(!r->Dispatch(jsapi.cx()))) { + if (NS_WARN_IF(!r->Dispatch())) { NS_WARNING("Failed to dispatch pending functional event!"); } } diff --git a/dom/workers/ServiceWorkerRegistration.cpp b/dom/workers/ServiceWorkerRegistration.cpp index 49419263da57..d5afaa34e8e0 100644 --- a/dom/workers/ServiceWorkerRegistration.cpp +++ b/dom/workers/ServiceWorkerRegistration.cpp @@ -388,12 +388,9 @@ public: return; } - AutoJSAPI jsapi; - jsapi.Init(); - RefPtr r = new UpdateResultRunnable(proxy, aStatus); - r->Dispatch(jsapi.cx()); + r->Dispatch(); } }; @@ -555,9 +552,7 @@ private: RefPtr r = new FulfillUnregisterPromiseRunnable(proxy, aState); - AutoJSAPI jsapi; - jsapi.Init(); - r->Dispatch(jsapi.cx()); + r->Dispatch(); } }; @@ -1201,10 +1196,7 @@ WorkerListener::UpdateFound() if (mWorkerPrivate) { RefPtr r = new FireUpdateFoundRunnable(mWorkerPrivate, this); - AutoJSAPI jsapi; - jsapi.Init(); - if (NS_WARN_IF(!r->Dispatch(jsapi.cx()))) { - } + NS_WARN_IF(!r->Dispatch()); } } diff --git a/dom/workers/ServiceWorkerWindowClient.cpp b/dom/workers/ServiceWorkerWindowClient.cpp index a1b2c3e4629b..a5e3e0f9e2f4 100644 --- a/dom/workers/ServiceWorkerWindowClient.cpp +++ b/dom/workers/ServiceWorkerWindowClient.cpp @@ -118,9 +118,7 @@ private: new ResolveOrRejectPromiseRunnable(mPromiseProxy->GetWorkerPrivate(), mPromiseProxy, Move(aClientInfo)); - AutoJSAPI jsapi; - jsapi.Init(); - resolveRunnable->Dispatch(jsapi.cx()); + resolveRunnable->Dispatch(); } }; diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index cbd115477c9d..3a950ab70867 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -466,14 +466,6 @@ public: mIncrease(aIncrease) { } - // We don't need a JSContext to dispatch, since we know our PreDispatch and - // DispatchInternal don't throw any exceptions. - bool - Dispatch() - { - return WorkerControlRunnable::Dispatch(nullptr); - } - private: virtual bool WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override @@ -853,14 +845,6 @@ public: aStatus == Canceling || aStatus == Killing); } - // We can be dispatched without a JSContext, because all we do with the - // JSContext passed to Dispatch() normally for worker runnables is call - // ModifyBusyCount... but that doesn't actually use its JSContext argument. - bool Dispatch() - { - return WorkerControlRunnable::Dispatch(nullptr); - } - private: virtual bool PreDispatch(WorkerPrivate* aWorkerPrivate) override @@ -1070,7 +1054,7 @@ public: new ReportErrorRunnable(aWorkerPrivate, aMessage, aFilename, aLine, aLineNumber, aColumnNumber, aFlags, aErrorNumber, aExnType, aMutedError); - return runnable->Dispatch(aCx); + return runnable->Dispatch(); } // Otherwise log an error to the error console. @@ -1755,7 +1739,7 @@ TimerThreadEventTarget::Dispatch(already_AddRefed&& aRunnable, uint // This can fail if we're racing to terminate or cancel, should be handled // by the terminate or cancel code. - mWorkerRunnable->Dispatch(nullptr); + mWorkerRunnable->Dispatch(); return NS_OK; } @@ -2633,7 +2617,7 @@ WorkerPrivateParent::Freeze(JSContext* aCx, RefPtr runnable = new FreezeRunnable(ParentAsWorkerPrivate()); - if (!runnable->Dispatch(aCx)) { + if (!runnable->Dispatch()) { return false; } @@ -2715,7 +2699,7 @@ WorkerPrivateParent::Thaw(JSContext* aCx, nsPIDOMWindowInner* aWindow) RefPtr runnable = new ThawRunnable(ParentAsWorkerPrivate()); - if (!runnable->Dispatch(aCx)) { + if (!runnable->Dispatch()) { return false; } @@ -2927,7 +2911,7 @@ WorkerPrivateParent::PostMessageInternal( runnable->SetMessageSource(Move(aClientInfo)); - if (!runnable->Dispatch(aCx)) { + if (!runnable->Dispatch()) { aRv.Throw(NS_ERROR_FAILURE); } } @@ -2969,9 +2953,8 @@ WorkerPrivateParent::UpdateRuntimeOptions( RefPtr runnable = new UpdateRuntimeOptionsRunnable(ParentAsWorkerPrivate(), aRuntimeOptions); - if (!runnable->Dispatch(aCx)) { + if (!runnable->Dispatch()) { NS_WARNING("Failed to update worker context options!"); - JS_ClearPendingException(aCx); } } @@ -2984,9 +2967,8 @@ WorkerPrivateParent::UpdatePreference(JSContext* aCx, WorkerPreference RefPtr runnable = new UpdatePreferenceRunnable(ParentAsWorkerPrivate(), aPref, aValue); - if (!runnable->Dispatch(aCx)) { + if (!runnable->Dispatch()) { NS_WARNING("Failed to update worker preferences!"); - JS_ClearPendingException(aCx); } } @@ -2999,9 +2981,8 @@ WorkerPrivateParent::UpdateLanguages(JSContext* aCx, RefPtr runnable = new UpdateLanguagesRunnable(ParentAsWorkerPrivate(), aLanguages); - if (!runnable->Dispatch(aCx)) { + if (!runnable->Dispatch()) { NS_WARNING("Failed to update worker languages!"); - JS_ClearPendingException(aCx); } } @@ -3024,9 +3005,8 @@ WorkerPrivateParent::UpdateJSWorkerMemoryParameter(JSContext* aCx, RefPtr runnable = new UpdateJSWorkerMemoryParameterRunnable(ParentAsWorkerPrivate(), aKey, aValue); - if (!runnable->Dispatch(aCx)) { + if (!runnable->Dispatch()) { NS_WARNING("Failed to update memory parameter!"); - JS_ClearPendingException(aCx); } } } @@ -3047,9 +3027,8 @@ WorkerPrivateParent::UpdateGCZeal(JSContext* aCx, uint8_t aGCZeal, RefPtr runnable = new UpdateGCZealRunnable(ParentAsWorkerPrivate(), aGCZeal, aFrequency); - if (!runnable->Dispatch(aCx)) { + if (!runnable->Dispatch()) { NS_WARNING("Failed to update worker gczeal!"); - JS_ClearPendingException(aCx); } } #endif @@ -3063,9 +3042,8 @@ WorkerPrivateParent::GarbageCollect(JSContext* aCx, bool aShrinking) RefPtr runnable = new GarbageCollectRunnable(ParentAsWorkerPrivate(), aShrinking, /* collectChildren = */ true); - if (!runnable->Dispatch(aCx)) { + if (!runnable->Dispatch()) { NS_WARNING("Failed to GC worker!"); - JS_ClearPendingException(aCx); } } @@ -3078,9 +3056,8 @@ WorkerPrivateParent::CycleCollect(JSContext* aCx, bool aDummy) RefPtr runnable = new CycleCollectRunnable(ParentAsWorkerPrivate(), /* collectChildren = */ true); - if (!runnable->Dispatch(aCx)) { + if (!runnable->Dispatch()) { NS_WARNING("Failed to CC worker!"); - JS_ClearPendingException(aCx); } } @@ -3092,9 +3069,8 @@ WorkerPrivateParent::OfflineStatusChangeEvent(JSContext* aCx, bool aIsO RefPtr runnable = new OfflineStatusChangeRunnable(ParentAsWorkerPrivate(), aIsOffline); - if (!runnable->Dispatch(aCx)) { + if (!runnable->Dispatch()) { NS_WARNING("Failed to dispatch offline status change event!"); - JS_ClearPendingException(aCx); } } @@ -3148,7 +3124,7 @@ WorkerPrivateParent::RegisterSharedWorker(JSContext* aCx, if (IsSharedWorker()) { RefPtr runnable = new MessagePortRunnable(ParentAsWorkerPrivate(), aPort); - if (!runnable->Dispatch(aCx)) { + if (!runnable->Dispatch()) { return false; } } @@ -3810,7 +3786,7 @@ WorkerDebugger::Initialize(const nsAString& aURL, JSContext* aCx) if (!mIsInitialized) { RefPtr runnable = new CompileDebuggerScriptRunnable(mWorkerPrivate, aURL); - if (!runnable->Dispatch(aCx)) { + if (!runnable->Dispatch()) { return NS_ERROR_FAILURE; } @@ -3831,7 +3807,7 @@ WorkerDebugger::PostMessageMoz(const nsAString& aMessage, JSContext* aCx) RefPtr runnable = new DebuggerMessageEventRunnable(mWorkerPrivate, aMessage); - if (!runnable->Dispatch(aCx)) { + if (!runnable->Dispatch()) { return NS_ERROR_FAILURE; } @@ -4118,7 +4094,7 @@ WorkerPrivate::Constructor(JSContext* aCx, RefPtr compiler = new CompileScriptRunnable(worker, aScriptURL); - if (!compiler->Dispatch(aCx)) { + if (!compiler->Dispatch()) { aRv.Throw(NS_ERROR_UNEXPECTED); return nullptr; } @@ -4778,7 +4754,7 @@ WorkerPrivate::ScheduleDeletion(WorkerRanOrNot aRanOrNot) if (WorkerPrivate* parent = GetParent()) { RefPtr runnable = new WorkerFinishedRunnable(parent, this); - if (!runnable->Dispatch(nullptr)) { + if (!runnable->Dispatch()) { NS_WARNING("Failed to dispatch runnable!"); } } @@ -5504,7 +5480,7 @@ WorkerPrivate::PostMessageToParentInternal( return; } - if (!runnable->Dispatch(aCx)) { + if (!runnable->Dispatch()) { aRv = NS_ERROR_FAILURE; } } @@ -5595,7 +5571,7 @@ WorkerPrivate::SetDebuggerImmediate(JSContext* aCx, dom::Function& aHandler, RefPtr runnable = new DebuggerImmediateRunnable(this, aHandler); - if (!runnable->Dispatch(aCx)) { + if (!runnable->Dispatch()) { aRv.Throw(NS_ERROR_FAILURE); } } @@ -5697,7 +5673,7 @@ WorkerPrivate::NotifyInternal(JSContext* aCx, Status aStatus) if (aStatus == Closing) { // Notify parent to stop sending us messages and balance our busy count. RefPtr runnable = new CloseRunnable(this); - if (!runnable->Dispatch(aCx)) { + if (!runnable->Dispatch()) { return false; } diff --git a/dom/workers/WorkerRunnable.cpp b/dom/workers/WorkerRunnable.cpp index baaaf8b69e27..411f34e1b7b8 100644 --- a/dom/workers/WorkerRunnable.cpp +++ b/dom/workers/WorkerRunnable.cpp @@ -87,41 +87,13 @@ WorkerRunnable::PreDispatch(WorkerPrivate* aWorkerPrivate) } bool -WorkerRunnable::Dispatch(JSContext* aCx) +WorkerRunnable::Dispatch() { - bool ok; - - if (!aCx) { - ok = PreDispatch(mWorkerPrivate); - if (ok) { - ok = DispatchInternal(); - } - PostDispatch(mWorkerPrivate, ok); - return ok; + bool ok = PreDispatch(mWorkerPrivate); + if (ok) { + ok = DispatchInternal(); } - - JSAutoRequest ar(aCx); - - JS::Rooted global(aCx, JS::CurrentGlobalOrNull(aCx)); - - Maybe ac; - if (global) { - ac.emplace(aCx, global); - } - - MOZ_ASSERT(!JS_IsExceptionPending(aCx)); - - ok = PreDispatch(mWorkerPrivate); - MOZ_ASSERT(!JS_IsExceptionPending(aCx)); - - if (ok && !DispatchInternal()) { - ok = false; - } - MOZ_ASSERT(!JS_IsExceptionPending(aCx)); - PostDispatch(mWorkerPrivate, ok); - MOZ_ASSERT(!JS_IsExceptionPending(aCx)); - return ok; } @@ -599,7 +571,7 @@ WorkerMainThreadRunnable::Run() mSyncLoopTarget.forget(), runResult); - MOZ_ALWAYS_TRUE(response->Dispatch(nullptr)); + MOZ_ALWAYS_TRUE(response->Dispatch()); return NS_OK; } diff --git a/dom/workers/WorkerRunnable.h b/dom/workers/WorkerRunnable.h index 189e372710ff..860df2b9f59f 100644 --- a/dom/workers/WorkerRunnable.h +++ b/dom/workers/WorkerRunnable.h @@ -73,12 +73,10 @@ public: // appropriately. NS_DECL_NSICANCELABLERUNNABLE - // Passing a JSContext here is required for the WorkerThreadModifyBusyCount - // behavior. It also guarantees that any failure (false return) will throw an - // exception on the given context. If a context is not passed then failures - // must be dealt with by the caller. + // The return value is true if and only if both PreDispatch and + // DispatchInternal return true. bool - Dispatch(JSContext* aCx); + Dispatch(); // See above note about Cancel(). virtual bool diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp index 746ac3af9294..de6ffcc33715 100644 --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -599,9 +599,7 @@ public: RefPtr runnable = new SkipWaitingResultRunnable(workerPrivate, mPromiseProxy); - AutoJSAPI jsapi; - jsapi.Init(); - if (!runnable->Dispatch(jsapi.cx())) { + if (!runnable->Dispatch()) { NS_WARNING("Failed to dispatch SkipWaitingResultRunnable to the worker."); } return NS_OK; diff --git a/dom/workers/XMLHttpRequest.cpp b/dom/workers/XMLHttpRequest.cpp index 8ff06e0c7959..2a1b5e62575d 100644 --- a/dom/workers/XMLHttpRequest.cpp +++ b/dom/workers/XMLHttpRequest.cpp @@ -223,7 +223,7 @@ public: NS_DECL_ISUPPORTS_INHERITED bool - Dispatch(JSContext* aCx) + Dispatch() { mWorkerPrivate->AssertIsOnWorkerThread(); @@ -231,7 +231,6 @@ public: mSyncLoopTarget = syncLoop.EventTarget(); if (NS_FAILED(NS_DispatchToMainThread(this))) { - JS_ReportError(aCx, "Failed to dispatch to main thread!"); return false; } @@ -595,10 +594,6 @@ public: mScopeObj(nsContentUtils::RootingCxForThread(), aScopeObj) { } - void Dispatch() - { - MainThreadProxyRunnable::Dispatch(nullptr); - } private: ~EventRunnable() { } @@ -974,7 +969,7 @@ Proxy::Teardown(bool aSendUnpin) if (aSendUnpin) { RefPtr runnable = new XHRUnpinRunnable(mWorkerPrivate, mXMLHttpRequestPrivate); - if (!runnable->Dispatch(nullptr)) { + if (!runnable->Dispatch()) { NS_RUNTIMEABORT("We're going to hang at shutdown anyways."); } } @@ -985,7 +980,7 @@ Proxy::Teardown(bool aSendUnpin) new MainThreadStopSyncLoopRunnable(mWorkerPrivate, mSyncLoopTarget.forget(), false); - if (!runnable->Dispatch(nullptr)) { + if (!runnable->Dispatch()) { NS_RUNTIMEABORT("We're going to hang at shutdown anyways."); } } @@ -1146,7 +1141,7 @@ LoadStartDetectionRunnable::Run() RefPtr runnable = new ProxyCompleteRunnable(mWorkerPrivate, mProxy, mXMLHttpRequestPrivate, mChannelId); - if (runnable->Dispatch(nullptr)) { + if (runnable->Dispatch()) { mProxy->mWorkerPrivate = nullptr; mProxy->mSyncLoopTarget = nullptr; mProxy->mOutstandingSendCount--; @@ -1447,7 +1442,7 @@ WorkerThreadProxySyncRunnable::Run() RefPtr response = new ResponseRunnable(mWorkerPrivate, mProxy, rv); - if (!response->Dispatch(nullptr)) { + if (!response->Dispatch()) { MOZ_ASSERT(false, "Failed to dispatch response!"); } @@ -1692,7 +1687,7 @@ XMLHttpRequest::ReleaseProxy(ReleaseType aType) new SyncTeardownRunnable(mWorkerPrivate, mProxy); mProxy = nullptr; - if (!runnable->Dispatch(nullptr)) { + if (!runnable->Dispatch()) { NS_ERROR("Failed to dispatch teardown runnable!"); } } @@ -1869,12 +1864,10 @@ XMLHttpRequest::SendInternal(SendRunnable* aRunnable, mProxy->mOuterChannelId++; - JSContext* cx = mWorkerPrivate->GetJSContext(); - aRunnable->SetSyncLoopTarget(syncLoopTarget); aRunnable->SetHaveUploadListeners(hasUploadListeners); - if (!aRunnable->Dispatch(cx)) { + if (!aRunnable->Dispatch()) { // Dispatch() may have spun the event loop and we may have already unrooted. // If so we don't want autoUnpin to try again. if (!mRooted) { @@ -1941,7 +1934,7 @@ XMLHttpRequest::Open(const nsACString& aMethod, const nsAString& aUrl, mTimeout); ++mProxy->mOpenCount; - if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) { + if (!runnable->Dispatch()) { if (!--mProxy->mOpenCount) { ReleaseProxy(); } @@ -1978,7 +1971,7 @@ XMLHttpRequest::SetRequestHeader(const nsACString& aHeader, RefPtr runnable = new SetRequestHeaderRunnable(mWorkerPrivate, mProxy, aHeader, aValue); - if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) { + if (!runnable->Dispatch()) { aRv.Throw(NS_ERROR_FAILURE); return; } @@ -2004,7 +1997,7 @@ XMLHttpRequest::SetTimeout(uint32_t aTimeout, ErrorResult& aRv) RefPtr runnable = new SetTimeoutRunnable(mWorkerPrivate, mProxy, aTimeout); - if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) { + if (!runnable->Dispatch()) { aRv.Throw(NS_ERROR_FAILURE); return; } @@ -2030,7 +2023,7 @@ XMLHttpRequest::SetWithCredentials(bool aWithCredentials, ErrorResult& aRv) RefPtr runnable = new SetWithCredentialsRunnable(mWorkerPrivate, mProxy, aWithCredentials); - if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) { + if (!runnable->Dispatch()) { aRv.Throw(NS_ERROR_FAILURE); return; } @@ -2058,7 +2051,7 @@ XMLHttpRequest::SetMozBackgroundRequest(bool aBackgroundRequest, RefPtr runnable = new SetBackgroundRequestRunnable(mWorkerPrivate, mProxy, aBackgroundRequest); - if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) { + if (!runnable->Dispatch()) { aRv.Throw(NS_ERROR_FAILURE); return; } @@ -2290,7 +2283,7 @@ XMLHttpRequest::Abort(ErrorResult& aRv) mProxy->mOuterEventStreamId++; RefPtr runnable = new AbortRunnable(mWorkerPrivate, mProxy); - if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) { + if (!runnable->Dispatch()) { aRv.Throw(NS_ERROR_FAILURE); return; } @@ -2316,7 +2309,7 @@ XMLHttpRequest::GetResponseHeader(const nsACString& aHeader, RefPtr runnable = new GetResponseHeaderRunnable(mWorkerPrivate, mProxy, aHeader, responseHeader); - if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) { + if (!runnable->Dispatch()) { aRv.Throw(NS_ERROR_FAILURE); return; } @@ -2342,7 +2335,7 @@ XMLHttpRequest::GetAllResponseHeaders(nsACString& aResponseHeaders, nsCString responseHeaders; RefPtr runnable = new GetAllResponseHeadersRunnable(mWorkerPrivate, mProxy, responseHeaders); - if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) { + if (!runnable->Dispatch()) { aRv.Throw(NS_ERROR_FAILURE); return; } @@ -2374,7 +2367,7 @@ XMLHttpRequest::OverrideMimeType(const nsAString& aMimeType, ErrorResult& aRv) RefPtr runnable = new OverrideMimeTypeRunnable(mWorkerPrivate, mProxy, aMimeType); - if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) { + if (!runnable->Dispatch()) { aRv.Throw(NS_ERROR_FAILURE); return; } @@ -2409,7 +2402,7 @@ XMLHttpRequest::SetResponseType(XMLHttpRequestResponseType aResponseType, RefPtr runnable = new SetResponseTypeRunnable(mWorkerPrivate, mProxy, responseType); - if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) { + if (!runnable->Dispatch()) { aRv.Throw(NS_ERROR_FAILURE); return; }