diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp index fa2c4f187bb..a843e4c8ec9 100644 --- a/dom/workers/ScriptLoader.cpp +++ b/dom/workers/ScriptLoader.cpp @@ -22,6 +22,7 @@ #include "nsIURI.h" #include "jsapi.h" +#include "jsfriendapi.h" #include "nsError.h" #include "nsContentPolicyUtils.h" #include "nsContentUtils.h" @@ -318,6 +319,9 @@ private: WorkerPrivate* aWorkerPrivate, bool aResult, bool aMutedError); + + void LogExceptionToConsole(JSContext* aCx, + WorkerPrivate* WorkerPrivate); }; class CacheScriptLoader; @@ -1811,7 +1815,7 @@ ScriptExecutorRunnable::ShutdownScriptLoader(JSContext* aCx, // If this error has to be muted, we have to clear the pending exception, // if any, and use the ErrorResult object to throw a new exception. if (aMutedError && JS_IsExceptionPending(aCx)) { - JS_ClearPendingException(aCx); + LogExceptionToConsole(aCx, aWorkerPrivate); mScriptLoader.mRv.Throw(NS_ERROR_FAILURE); } else { mScriptLoader.mRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); @@ -1822,6 +1826,33 @@ ScriptExecutorRunnable::ShutdownScriptLoader(JSContext* aCx, aWorkerPrivate->StopSyncLoop(mSyncLoopTarget, aResult); } +void +ScriptExecutorRunnable::LogExceptionToConsole(JSContext* aCx, + WorkerPrivate* aWorkerPrivate) +{ + aWorkerPrivate->AssertIsOnWorkerThread(); + + JS::Rooted exn(aCx); + if (!JS_GetPendingException(aCx, &exn)) { + return; + } + + JS_ClearPendingException(aCx); + + js::ErrorReport report(aCx); + if (!report.init(aCx, exn)) { + JS_ClearPendingException(aCx); + return; + } + + nsRefPtr xpcReport = new xpc::ErrorReport(); + xpcReport->Init(report.report(), report.message(), + aWorkerPrivate->IsChromeWorker(), aWorkerPrivate->WindowID()); + + nsRefPtr r = new AsyncErrorReporter(xpcReport); + NS_DispatchToMainThread(r); +} + void LoadAllScripts(JSContext* aCx, WorkerPrivate* aWorkerPrivate, nsTArray& aLoadInfos, bool aIsMainScript,