Bug 1835886 - Cancel outstanding load requests when a document is detached from a global r=smaug

Also cancel module load requests when cancelling requests generally.

What was happening here was that a previous load was completing and calling
into the wrong module loader, because the loader to use is determined via the
current global, and this was now associated with a different document / script
loader / module loader.

Differential Revision: https://phabricator.services.mozilla.com/D179787
This commit is contained in:
Jon Coppeard
2023-06-13 08:46:26 +00:00
parent 456e1f00df
commit 5c50b911ed
2 changed files with 20 additions and 8 deletions

View File

@@ -934,15 +934,19 @@ void ModuleLoaderBase::FinishDynamicImportAndReject(ModuleLoadRequest* aRequest,
FinishDynamicImport(jsapi.cx(), aRequest, aResult, nullptr);
}
/* static */
void ModuleLoaderBase::FinishDynamicImport(
JSContext* aCx, ModuleLoadRequest* aRequest, nsresult aResult,
JS::Handle<JSObject*> aEvaluationPromise) {
LOG(("ScriptLoadRequest (%p): Finish dynamic import %x %d", aRequest,
unsigned(aResult), JS_IsExceptionPending(aCx)));
MOZ_ASSERT(GetCurrentModuleLoader(aCx) == aRequest->mLoader);
// If aResult is a failed result, we don't have an EvaluationPromise. If it
// succeeded, evaluationPromise may still be null, but in this case it will
// be handled by rejecting the dynamic module import promise in the JSAPI.
MOZ_ASSERT_IF(NS_FAILED(aResult), !aEvaluationPromise);
LOG(("ScriptLoadRequest (%p): Finish dynamic import %x %d", aRequest,
unsigned(aResult), JS_IsExceptionPending(aCx)));
// Complete the dynamic import, report failures indicated by aResult or as a
// pending exception on the context.
@@ -1182,6 +1186,7 @@ nsresult ModuleLoaderBase::EvaluateModuleInContext(
JSContext* aCx, ModuleLoadRequest* aRequest,
JS::ModuleErrorBehaviour errorBehaviour) {
MOZ_ASSERT(aRequest->mLoader == this);
MOZ_ASSERT(mGlobalObject->GetModuleLoader(aCx) == this);
AUTO_PROFILER_LABEL("ModuleLoaderBase::EvaluateModule", JS);
@@ -1215,6 +1220,7 @@ nsresult ModuleLoaderBase::EvaluateModuleInContext(
JS::Rooted<JSObject*> module(aCx, moduleScript->ModuleRecord());
MOZ_ASSERT(module);
MOZ_ASSERT(CurrentGlobalOrNull(aCx) == GetNonCCWObjectGlobal(module));
if (!xpc::Scriptability::AllowedIfExists(module)) {
return NS_OK;