Bug 1540913 - Part 3: Exit early if worker module evaluation is aborted; r=jonco
This change addresses the second issue around worker shutdown with infinitely running dynamic imports: As the event loop is prevented from running when the worker is dying, we do not want to delegate to the event loop in this case. This case always has a failing promise. Since this is a failure case related to the worker dying, we stop running code, rather than waiting for a tick (that never comes) from the event loop. Differential Revision: https://phabricator.services.mozilla.com/D171684
This commit is contained in:
@@ -1227,16 +1227,11 @@ nsresult ModuleLoaderBase::EvaluateModuleInContext(
|
||||
// unless the user cancels execution.
|
||||
MOZ_ASSERT_IF(ok, !JS_IsExceptionPending(aCx));
|
||||
|
||||
// For long running scripts, the request may be cancelled abruptly. This
|
||||
// may also happen if the loader is collected before we get here.
|
||||
if (request->IsCanceled() || !mLoader) {
|
||||
return NS_ERROR_ABORT;
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
if (!ok || IsModuleEvaluationAborted(request)) {
|
||||
LOG(("ScriptLoadRequest (%p): evaluation failed", aRequest));
|
||||
// For a dynamic import, the promise is rejected. Otherwise an error is
|
||||
// reported by AutoEntryScript.
|
||||
rv = NS_ERROR_ABORT;
|
||||
}
|
||||
|
||||
// ModuleEvaluate returns a promise unless the user cancels the execution in
|
||||
@@ -1248,7 +1243,11 @@ nsresult ModuleLoaderBase::EvaluateModuleInContext(
|
||||
}
|
||||
|
||||
if (request->IsDynamicImport()) {
|
||||
FinishDynamicImport(aCx, request, NS_OK, evaluationPromise);
|
||||
if (NS_FAILED(rv)) {
|
||||
FinishDynamicImportAndReject(request, rv);
|
||||
} else {
|
||||
FinishDynamicImport(aCx, request, NS_OK, evaluationPromise);
|
||||
}
|
||||
} else {
|
||||
// If this is not a dynamic import, and if the promise is rejected,
|
||||
// the value is unwrapped from the promise value.
|
||||
|
||||
Reference in New Issue
Block a user