From 9571910e5c25fad0bef8d865b6680f6ac3f2b290 Mon Sep 17 00:00:00 2001 From: Tooru Fujisawa Date: Sat, 27 Sep 2025 23:33:54 +0000 Subject: [PATCH] Bug 1990116 - Use the error report to detect warnings in workers and worklets. a=RyanVM Original Revision: https://phabricator.services.mozilla.com/D265768 Differential Revision: https://phabricator.services.mozilla.com/D266292 --- dom/workers/WorkerPrivate.cpp | 10 +++++----- dom/worklet/WorkletThread.cpp | 6 +++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 01d7c8f63ad1..edd2960b9097 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -5927,7 +5927,11 @@ void WorkerPrivate::ReportError(JSContext* aCx, } JS::ExceptionStack exnStack(aCx); - if (JS_IsExceptionPending(aCx)) { + // NOTE: This function is used both for errors and warnings, and warnings + // can be reported while there's a pending exception. + // Warnings are always reported with non-null JSErrorReport. + if (!aReport || !aReport->isWarning()) { + MOZ_ASSERT(JS_IsExceptionPending(aCx)); if (!JS::StealPendingExceptionStack(aCx, &exnStack)) { JS_ClearPendingException(aCx); return; @@ -5941,10 +5945,6 @@ void WorkerPrivate::ReportError(JSContext* aCx, JSAutoRealm ar(aCx, stackGlobal); report->SerializeWorkerStack(aCx, this, stack); } - } else { - // ReportError is also used for reporting warnings, - // so there won't be a pending exception. - MOZ_ASSERT(aReport && aReport->isWarning()); } if (report->mMessage.IsEmpty() && aToStringResult) { diff --git a/dom/worklet/WorkletThread.cpp b/dom/worklet/WorkletThread.cpp index f9452e7ec69e..bcddeeebe455 100644 --- a/dom/worklet/WorkletThread.cpp +++ b/dom/worklet/WorkletThread.cpp @@ -199,7 +199,11 @@ void WorkletJSContext::ReportError(JSErrorReport* aReport, RefPtr reporter = new AsyncErrorReporter(xpcReport); JSContext* cx = Context(); - if (JS_IsExceptionPending(cx)) { + // NOTE: This function is used both for errors and warnings, and warnings + // can be reported while there's a pending exception. + // Warnings are always reported with non-null JSErrorReport. + if (!aReport || !aReport->isWarning()) { + MOZ_ASSERT(JS_IsExceptionPending(cx)); JS::ExceptionStack exnStack(cx); if (JS::StealPendingExceptionStack(cx, &exnStack)) { JS::Rooted stack(cx);