forked from mirrors/gecko-dev
Bug 1880708 - Handle CC unlink when destroying ScriptLoader/ModuleLoader. r=jonco
Differential Revision: https://phabricator.services.mozilla.com/D202080
This commit is contained in:
parent
3bf0a840e4
commit
7533056300
3 changed files with 25 additions and 2 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -125,6 +125,8 @@ class ModuleLoadRequest final : public ScriptLoadRequest {
|
|||
void CancelImports();
|
||||
void CheckModuleDependenciesLoaded();
|
||||
|
||||
void ChildModuleUnlinked();
|
||||
|
||||
void AssertAllImportsFinished() const;
|
||||
void AssertAllImportsCancelled() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -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()) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue