From 98752af13349e2da56b5ed1219cae30008ef250a Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 1 Jul 2020 21:12:49 +0000 Subject: Issue #618 - Add clarifying code comments. --- dom/script/ModuleLoadRequest.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'dom/script/ModuleLoadRequest.cpp') diff --git a/dom/script/ModuleLoadRequest.cpp b/dom/script/ModuleLoadRequest.cpp index e72edca2e..98106df1b 100644 --- a/dom/script/ModuleLoadRequest.cpp +++ b/dom/script/ModuleLoadRequest.cpp @@ -52,6 +52,14 @@ void ModuleLoadRequest::Cancel() void ModuleLoadRequest::SetReady() { + // Mark a module as ready to execute. This means that this module and all it + // dependencies have had their source loaded, parsed as a module and the + // modules instantiated. + // + // The mReady promise is used to ensure that when all dependencies of a module + // have become ready, DependenciesLoaded is called on that module + // request. This is set up in StartFetchingModuleDependencies. + #ifdef DEBUG for (size_t i = 0; i < mImports.Length(); i++) { MOZ_ASSERT(mImports[i]->IsReadyToRun()); -- cgit v1.2.3 From 046534432d2914c80bcab36797fe0a43ff332a98 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sat, 4 Jul 2020 10:35:22 +0000 Subject: Issue #618 - Remove eager instantiation This backs out the stuff added in Bug 1295978. Ref: BZ 1295978, 1388728 --- dom/script/ModuleLoadRequest.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'dom/script/ModuleLoadRequest.cpp') diff --git a/dom/script/ModuleLoadRequest.cpp b/dom/script/ModuleLoadRequest.cpp index 98106df1b..8871dcdab 100644 --- a/dom/script/ModuleLoadRequest.cpp +++ b/dom/script/ModuleLoadRequest.cpp @@ -86,11 +86,6 @@ ModuleLoadRequest::DependenciesLoaded() // The module and all of its dependencies have been successfully fetched and // compiled. - if (!mLoader->InstantiateModuleTree(this)) { - LoadFailed(); - return; - } - SetReady(); mLoader->ProcessLoadedModuleTree(this); mLoader = nullptr; -- cgit v1.2.3 From 66bf3a2279891ed621738fe988359758df881e41 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sat, 4 Jul 2020 16:28:30 +0000 Subject: Issue #618 - Further align error handling for module scripts with the spec Ref: BZ 1388728 --- dom/script/ModuleLoadRequest.cpp | 42 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'dom/script/ModuleLoadRequest.cpp') diff --git a/dom/script/ModuleLoadRequest.cpp b/dom/script/ModuleLoadRequest.cpp index 8871dcdab..d62214304 100644 --- a/dom/script/ModuleLoadRequest.cpp +++ b/dom/script/ModuleLoadRequest.cpp @@ -43,10 +43,16 @@ void ModuleLoadRequest::Cancel() ScriptLoadRequest::Cancel(); mModuleScript = nullptr; mProgress = ScriptLoadRequest::Progress::Ready; + CancelImports(); + mReady.RejectIfExists(NS_ERROR_DOM_ABORT_ERR, __func__); +} + +void +ModuleLoadRequest::CancelImports() +{ for (size_t i = 0; i < mImports.Length(); i++) { mImports[i]->Cancel(); } - mReady.RejectIfExists(NS_ERROR_FAILURE, __func__); } void @@ -77,25 +83,53 @@ ModuleLoadRequest::ModuleLoaded() // been loaded. mModuleScript = mLoader->GetFetchedModule(mURI); + if (!mModuleScript || mModuleScript->IsErrored()) { + ModuleErrored(); + return; + } + mLoader->StartFetchingModuleDependencies(this); } +void +ModuleLoadRequest::ModuleErrored() +{ + mLoader->CheckModuleDependenciesLoaded(this); + MOZ_ASSERT(!mModuleScript || mModuleScript->IsErrored()); + + CancelImports(); + SetReady(); + LoadFinished(); +} + void ModuleLoadRequest::DependenciesLoaded() { // The module and all of its dependencies have been successfully fetched and // compiled. + MOZ_ASSERT(mModuleScript); + + mLoader->CheckModuleDependenciesLoaded(this); SetReady(); - mLoader->ProcessLoadedModuleTree(this); - mLoader = nullptr; - mParent = nullptr; + LoadFinished(); } void ModuleLoadRequest::LoadFailed() { + // We failed to load the source text or an error occurred unrelated to the + // content of the module (e.g. OOM). + + MOZ_ASSERT(!mModuleScript); + Cancel(); + LoadFinished(); +} + +void +ModuleLoadRequest::LoadFinished() +{ mLoader->ProcessLoadedModuleTree(this); mLoader = nullptr; mParent = nullptr; -- cgit v1.2.3