Bug 1681046: fixup worklet error messages for async modules; r=mgaudet

Differential Revision: https://phabricator.services.mozilla.com/D110561
This commit is contained in:
Yulia Startsev 2021-04-07 08:45:38 +00:00
Родитель 2b2111b9b2
Коммит 880461bcf7
1 изменённых файлов: 14 добавлений и 2 удалений

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

@ -406,8 +406,20 @@ void ExecutionRunnable::RunOnWorkletThread() {
// https://html.spec.whatwg.org/multipage/webappapis.html#run-a-module-script
// without /rethrow errors/ and so unhandled exceptions do not cause the
// promise to be rejected.
JS::Rooted<JS::Value> ignored(cx);
JS::ModuleEvaluate(cx, module, &ignored);
JS::Rooted<JS::Value> rval(cx);
JS::ModuleEvaluate(cx, module, &rval);
// With top-level await, we need to unwrap the module promise, or we end up
// with less helpfull error messages. A modules return value can either be a
// promise or undefined. If the value is defined, we have an async module and
// can unwrap it.
if (!rval.isUndefined() && rval.isObject()) {
JS::Rooted<JSObject*> aEvaluationPromise(cx);
aEvaluationPromise.set(&rval.toObject());
if (!JS::ThrowOnModuleEvaluationFailure(cx, aEvaluationPromise)) {
mResult = NS_ERROR_DOM_ABORT_ERR;
return;
}
}
// All done.
mResult = NS_OK;