summaryrefslogtreecommitdiffstats
path: root/js/loader
diff options
context:
space:
mode:
Diffstat (limited to 'js/loader')
-rw-r--r--js/loader/ModuleLoadRequest.cpp15
-rw-r--r--js/loader/ModuleLoadRequest.h2
-rw-r--r--js/loader/ModuleLoaderBase.cpp10
3 files changed, 25 insertions, 2 deletions
diff --git a/js/loader/ModuleLoadRequest.cpp b/js/loader/ModuleLoadRequest.cpp
index d90d41da58..7e188160fc 100644
--- a/js/loader/ModuleLoadRequest.cpp
+++ b/js/loader/ModuleLoadRequest.cpp
@@ -27,6 +27,9 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(ModuleLoadRequest)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(ModuleLoadRequest,
ScriptLoadRequest)
+ if (tmp->mWaitingParentRequest) {
+ tmp->mWaitingParentRequest->ChildModuleUnlinked();
+ }
NS_IMPL_CYCLE_COLLECTION_UNLINK(mLoader, mRootModule, mModuleScript, mImports,
mWaitingParentRequest,
mDynamicReferencingScript)
@@ -230,6 +233,18 @@ void ModuleLoadRequest::LoadFinished() {
mLoader->OnModuleLoadComplete(request);
}
+void ModuleLoadRequest::ChildModuleUnlinked() {
+ // This module was waiting for a child request, but the child reqeust
+ // got unlinked by CC and will never complete.
+ // It also means this module itself is also in the cycle, and will be
+ // unlinked or has already been unlinked, and will be collected.
+ // There's no need to normally finish the module request.
+ // Just reflect the awaiting imports count, so that the assertion in the
+ // destructor passes.
+ MOZ_ASSERT(mAwaitingImports > 0);
+ mAwaitingImports--;
+}
+
void ModuleLoadRequest::SetDynamicImport(LoadedScript* aReferencingScript,
JS::Handle<JSString*> aSpecifier,
JS::Handle<JSObject*> aPromise) {
diff --git a/js/loader/ModuleLoadRequest.h b/js/loader/ModuleLoadRequest.h
index cb33c532fc..4a2eeadf43 100644
--- a/js/loader/ModuleLoadRequest.h
+++ b/js/loader/ModuleLoadRequest.h
@@ -125,6 +125,8 @@ class ModuleLoadRequest final : public ScriptLoadRequest {
void CancelImports();
void CheckModuleDependenciesLoaded();
+ void ChildModuleUnlinked();
+
void AssertAllImportsFinished() const;
void AssertAllImportsCancelled() const;
diff --git a/js/loader/ModuleLoaderBase.cpp b/js/loader/ModuleLoaderBase.cpp
index 59e77b2d9c..228c96ad69 100644
--- a/js/loader/ModuleLoaderBase.cpp
+++ b/js/loader/ModuleLoaderBase.cpp
@@ -969,7 +969,12 @@ void ModuleLoaderBase::FinishDynamicImport(
LOG(("ScriptLoadRequest (%p): Finish dynamic import %x %d", aRequest,
unsigned(aResult), JS_IsExceptionPending(aCx)));
- MOZ_ASSERT(GetCurrentModuleLoader(aCx) == aRequest->mLoader);
+ MOZ_ASSERT_IF(NS_SUCCEEDED(aResult),
+ GetCurrentModuleLoader(aCx) == aRequest->mLoader);
+ // For failure case, aRequest may have already been unlinked by CC.
+ MOZ_ASSERT_IF(
+ NS_FAILED(aResult),
+ GetCurrentModuleLoader(aCx) == aRequest->mLoader || !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
@@ -1057,7 +1062,8 @@ bool ModuleLoaderBase::HasPendingDynamicImports() const {
void ModuleLoaderBase::CancelDynamicImport(ModuleLoadRequest* aRequest,
nsresult aResult) {
- MOZ_ASSERT(aRequest->mLoader == this);
+ // aRequest may have already been unlinked by CC.
+ MOZ_ASSERT(aRequest->mLoader == this || !aRequest->mLoader);
RefPtr<ScriptLoadRequest> req = mDynamicImportRequests.Steal(aRequest);
if (!aRequest->IsCanceled()) {