From 524cb8f30a3181feb9aaacee73fa8fc80a049e1b Mon Sep 17 00:00:00 2001 From: Eden Chuang Date: Thu, 26 Sep 2024 09:30:13 +0000 Subject: [PATCH] Bug 1904059 - Using DOM::Function::Call instead JS_CallFunctionValue in DebuggerImmediateRunnable::WorkerRun. r=asuth, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D222436 --- dom/workers/WorkerPrivate.cpp | 14 ++++++++------ .../WorkerDebugger.initialize_waiting_debugger.js | 4 +++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 8be2a8054cc4..0b54c34da13b 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -626,16 +626,18 @@ class DebuggerImmediateRunnable final : public WorkerThreadRunnable { // Silence bad assertions. } + // Make as MOZ_CAN_RUN_SCRIPT_BOUNDARY for calling mHandler->Call(); + // Since WorkerRunnable::WorkerRun has not to be MOZ_CAN_RUN_SCRIPT, but + // DebuggerImmediateRunnable is a special case that must to call the function + // defined in the debugger script. + MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual bool WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override { - JS::Rooted global(aCx, JS::CurrentGlobalOrNull(aCx)); - JS::Rooted callable( - aCx, JS::ObjectOrNullValue(mHandler->CallableOrNull())); - JS::HandleValueArray args = JS::HandleValueArray::empty(); JS::Rooted rval(aCx); + IgnoredErrorResult rv; + MOZ_KnownLive(mHandler)->Call({}, &rval, rv); - // WorkerRunnable::Run will report the exception if it happens. - return JS_CallFunctionValue(aCx, global, callable, args, &rval); + return !rv.Failed(); } }; diff --git a/dom/workers/test/WorkerDebugger.initialize_waiting_debugger.js b/dom/workers/test/WorkerDebugger.initialize_waiting_debugger.js index 1f82c9ffeec6..ee347de40336 100644 --- a/dom/workers/test/WorkerDebugger.initialize_waiting_debugger.js +++ b/dom/workers/test/WorkerDebugger.initialize_waiting_debugger.js @@ -2,4 +2,6 @@ dump(" Evaluated debugger script\n"); -postMessage("debugger script ran"); +setImmediate(function () { + postMessage("debugger script ran"); +});