Bug 1681046: fix non-js occuring error throw order for async modules; r=mgaudet

Differential Revision: https://phabricator.services.mozilla.com/D110961
This commit is contained in:
Yulia Startsev
2021-04-08 08:21:57 +00:00
parent 11030852f5
commit 6a8f0293f9

View File

@@ -3132,29 +3132,16 @@ nsresult ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest) {
LOG(("ScriptLoadRequest (%p): module has error to rethrow",
aRequest));
JS::Rooted<JS::Value> error(cx, moduleScript->ErrorToRethrow());
JS_SetPendingException(cx, error);
// For a dynamic import, the promise is rejected. Otherwise an error
// is either reported by AutoEntryScript.
if (!JS::ContextOptionsRef(cx).topLevelAwait()) {
JS_SetPendingException(cx, error);
// For a dynamic import, the promise is rejected. Otherwise an error
// is either reported by AutoEntryScript.
if (request->IsDynamicImport()) {
FinishDynamicImport_NoTLA(cx, request, NS_OK);
}
} else {
ErrorResult err;
RefPtr<Promise> aPromise = Promise::Create(globalObject, err);
if (NS_WARN_IF(err.Failed())) {
return err.StealNSResult();
}
aPromise->MaybeReject(error);
JS::Rooted<JSObject*> aEvaluationPromise(cx, aPromise->PromiseObj());
if (request->IsDynamicImport()) {
FinishDynamicImport(cx, request, NS_OK, aEvaluationPromise);
} else {
if (!JS::ThrowOnModuleEvaluationFailure(cx, aEvaluationPromise)) {
LOG(("ScriptLoadRequest (%p): evaluation failed", aRequest));
// For a dynamic import, the promise is rejected. Otherwise an
// error is either reported by AutoEntryScript.
}
FinishDynamicImport(cx, request, NS_OK, nullptr);
}
}
return NS_OK;