Bug 1211970 - "Muted errors in workers are not correctly reported to the console". r=bz

This commit is contained in:
Andrea Marchesini 2015-10-15 05:05:00 +02:00
parent 997d15355c
commit a9dd4a35aa

View File

@ -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<JS::Value> 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<xpc::ErrorReport> xpcReport = new xpc::ErrorReport();
xpcReport->Init(report.report(), report.message(),
aWorkerPrivate->IsChromeWorker(), aWorkerPrivate->WindowID());
nsRefPtr<AsyncErrorReporter> r = new AsyncErrorReporter(xpcReport);
NS_DispatchToMainThread(r);
}
void
LoadAllScripts(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
nsTArray<ScriptLoadInfo>& aLoadInfos, bool aIsMainScript,