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);