tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit c141abb081a2a3d2ef3b4aeb70b9476a6b84677e
parent 35055c39b060b8014a4dd74b2e97acdf2abd46ac
Author: Matthew Gaudet <mgaudet@mozilla.com>
Date:   Mon, 20 Oct 2025 17:56:01 +0000

Bug 1990930 - Clarify and validate OOM (crashing) in Gecko use of JS microtask queue r=smaug,arai,dom-worker-reviewers,edenchuang

Differential Revision: https://phabricator.services.mozilla.com/D268619

Diffstat:
Mdom/workers/RuntimeService.cpp | 8++++----
Mjs/public/friend/MicroTask.h | 4+++-
Mxpcom/base/CycleCollectedJSContext.cpp | 7+++----
3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp @@ -1015,16 +1015,16 @@ class WorkerJSContext final : public mozilla::CycleCollectedJSContext { if (IsWorkerGlobal(global) || IsShadowRealmGlobal(global)) { if (!EnqueueMicroTask(cx, runnable.forget())) { // This should never fail, but if it does, we have no choice but to - // crash. - MOZ_CRASH("Failed to enqueue micro task from worker."); + // crash. This is always an OOM. + NS_ABORT_OOM(0); } } else { MOZ_ASSERT(IsWorkerDebuggerGlobal(global) || IsWorkerDebuggerSandbox(global)); if (!EnqueueDebugMicroTask(cx, runnable.forget())) { // This should never fail, but if it does, we have no choice but to - // crash. - MOZ_CRASH("Failed to enqueue debugger micro task from worker."); + // crash. This is always an OOM. + NS_ABORT_OOM(0); } } } else { diff --git a/js/public/friend/MicroTask.h b/js/public/friend/MicroTask.h @@ -66,7 +66,7 @@ JS_PUBLIC_API bool IsJSMicroTask(const JS::Value& hv); // Run a MicroTask that is known to be a JS MicroTask. This will crash // if provided an invalid task kind. // -// This will return true except on OOM. +// This will return false if an exception is thrown while processing. JS_PUBLIC_API bool RunJSMicroTask(JSContext* cx, Handle<MicroTask> entry); // Queue Management. This is done per-JSContext. @@ -81,6 +81,8 @@ JS_PUBLIC_API bool RunJSMicroTask(JSContext* cx, Handle<MicroTask> entry); // In general, we highly recommend that most embeddings use only the regular // microtask queue. The debugger microtask queue mostly exists to support // patterns used by Gecko. +// +// These methods only fail for OOM. JS_PUBLIC_API bool EnqueueMicroTask(JSContext* cx, const MicroTask& entry); JS_PUBLIC_API bool EnqueueDebugMicroTask(JSContext* cx, const MicroTask& entry); JS_PUBLIC_API bool PrependMicroTask(JSContext* cx, const MicroTask& entry); diff --git a/xpcom/base/CycleCollectedJSContext.cpp b/xpcom/base/CycleCollectedJSContext.cpp @@ -1212,10 +1212,9 @@ bool CycleCollectedJSContext::PerformMicroTaskCheckPoint(bool aForce) { } didProcess = true; - // Note: We're dropping the return value on the floor here. This is - // consistent with the previous implementation, which left the - // exception if it was there pending on the context, but likely should - // be changed. + // Note: We're dropping the return value on the floor here, however + // cleanup and exception handling are done as part of the CallSetup + // destructor if necessary. (void)RunMicroTask(cx, &job); } }