Bug 986459. The error event in a worker (firing at the worker's global) should have the original exception value in its .error property. r=baku

This commit is contained in:
Boris Zbarsky 2016-08-29 12:30:51 -04:00
Родитель 4cf9d87ff1
Коммит 29cf04bde6
4 изменённых файлов: 54 добавлений и 2 удалений

Просмотреть файл

@ -1050,7 +1050,8 @@ public:
const nsString& aLine, uint32_t aLineNumber,
uint32_t aColumnNumber, uint32_t aFlags,
uint32_t aErrorNumber, JSExnType aExnType,
bool aMutedError, uint64_t aInnerWindowId)
bool aMutedError, uint64_t aInnerWindowId,
JS::Handle<JS::Value> aException = JS::NullHandleValue)
{
if (aWorkerPrivate) {
aWorkerPrivate->AssertIsOnWorkerThread();
@ -1070,6 +1071,7 @@ public:
init.mMessage = aMessage;
init.mFilename = aFilename;
init.mLineno = aLineNumber;
init.mError = aException;
}
init.mCancelable = true;
@ -5919,6 +5921,12 @@ WorkerPrivate::ReportError(JSContext* aCx, const char* aFallbackMessage,
mErrorHandlerRecursionCount == 1,
"Bad recursion logic!");
JS::Rooted<JS::Value> exn(aCx);
if (!JS_GetPendingException(aCx, &exn)) {
// Probably shouldn't actually happen? But let's go ahead and just use null
// for lack of anything better.
exn.setNull();
}
JS_ClearPendingException(aCx);
nsString message, filename, line;
@ -5966,7 +5974,7 @@ WorkerPrivate::ReportError(JSContext* aCx, const char* aFallbackMessage,
ReportErrorRunnable::ReportError(aCx, this, fireAtScope, nullptr, message,
filename, line, lineNumber,
columnNumber, flags, errorNumber, exnType,
mutedError, 0);
mutedError, 0, exn);
mErrorHandlerRecursionCount--;
}

Просмотреть файл

@ -37705,6 +37705,12 @@
"path": "web-animations/timing-model/animations/updating-the-finished-state.html",
"url": "/web-animations/timing-model/animations/updating-the-finished-state.html"
}
],
"workers/Worker_ErrorEvent_error.htm": [
{
"path": "workers/Worker_ErrorEvent_error.htm",
"url": "/workers/Worker_ErrorEvent_error.htm"
}
]
}
},

Просмотреть файл

@ -0,0 +1,29 @@
<!doctype html>
<meta charset=utf-8>
<title></title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
var t1 = async_test("Error handler outside the worker should not see the error value");
var t2 = async_test("Error handlers inside a worker should see the error value");
test(function() {
var worker = new Worker("support/ErrorEvent-error.js");
worker.onerror = t1.step_func_done(function(e) {
assert_true(/hello/.test(e.message));
assert_equals(e.error, null);
});
var messages = 0;
worker.onmessage = t2.step_func(function(e) {
++messages;
var data = e.data;
assert_true(data.source == "onerror" ||
data.source == "event listener");
assert_equals(data.value, "hello");
if (messages == 2) {
t2.done();
}
});
});
</script>

Просмотреть файл

@ -0,0 +1,9 @@
onerror = function(message, location, line, col, error) {
postMessage({ source: "onerror", value: error });
}
addEventListener("error", function(e) {
postMessage({ source: "event listener", value: e.error });
});
throw "hello";