mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-01 13:57:32 +00:00
Bug 1247687 - Handle cancellation of long running modules; r=jonco
This is a slightly annoying thing that can happen. When we abruptly cancel (such as an infinitely running script being forcibly terminated) we will be in a state where the EvaluateModule call will finish _after_ the loader is destroyed. So, instead we track if there has been a forcible cancelation, and exit early. Depends on D155690 Differential Revision: https://phabricator.services.mozilla.com/D155568
This commit is contained in:
parent
e35e35d3c0
commit
ef3c7012f8
@ -755,7 +755,9 @@ bool WorkerScriptLoader::ProcessPendingRequests(JSContext* aCx) {
|
||||
MOZ_ASSERT(global);
|
||||
|
||||
while (!mLoadedRequests.isEmpty()) {
|
||||
RefPtr<ScriptLoadRequest> req = mLoadedRequests.StealFirst();
|
||||
// Take a reference, but do not remove it from the list yet. There is a
|
||||
// possibility that this will need to be cancelled.
|
||||
RefPtr<ScriptLoadRequest> req = mLoadedRequests.getFirst();
|
||||
// We don't have a ProcessRequest method (like we do on the DOM), as there
|
||||
// isn't much processing that we need to do per request that isn't related
|
||||
// to evaluation (the processsing done for the DOM is handled in
|
||||
@ -769,6 +771,8 @@ bool WorkerScriptLoader::ProcessPendingRequests(JSContext* aCx) {
|
||||
mLoadedRequests.CancelRequestsAndClear();
|
||||
break;
|
||||
}
|
||||
// remove the element from the list.
|
||||
mLoadedRequests.Remove(req);
|
||||
}
|
||||
|
||||
TryShutdown();
|
||||
@ -1073,6 +1077,9 @@ bool WorkerScriptLoader::EvaluateScript(JSContext* aCx,
|
||||
: EvaluateSourceBuffer(aCx, options,
|
||||
maybeSource.ref<JS::SourceText<char16_t>>());
|
||||
|
||||
if (aRequest->IsCanceled()) {
|
||||
return false;
|
||||
}
|
||||
if (!successfullyEvaluated) {
|
||||
mRv.StealExceptionFromJSContext(aCx);
|
||||
return false;
|
||||
|
@ -1213,6 +1213,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.
|
||||
if (request->IsCanceled() || !mLoader) {
|
||||
return NS_ERROR_ABORT;
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
LOG(("ScriptLoadRequest (%p): evaluation failed", aRequest));
|
||||
// For a dynamic import, the promise is rejected. Otherwise an error is
|
||||
|
Loading…
x
Reference in New Issue
Block a user