diff --git a/dom/script/LoadedScript.cpp b/dom/script/LoadedScript.cpp index 5e396ed08b20..8b9b686182b5 100644 --- a/dom/script/LoadedScript.cpp +++ b/dom/script/LoadedScript.cpp @@ -123,7 +123,7 @@ NS_IMPL_RELEASE_INHERITED(ModuleScript, LoadedScript) ModuleScript::ModuleScript(ScriptFetchOptions* aFetchOptions, nsIURI* aBaseURL) : LoadedScript(ScriptKind::eModule, aFetchOptions, aBaseURL), - mSourceElementAssociated(false) { + mDebuggerDataInitialized(false) { MOZ_ASSERT(!ModuleRecord()); MOZ_ASSERT(!HasParseError()); MOZ_ASSERT(!HasErrorToRethrow()); @@ -182,11 +182,11 @@ void ModuleScript::SetErrorToRethrow(const JS::Value& aError) { mErrorToRethrow = aError; } -void ModuleScript::SetSourceElementAssociated() { +void ModuleScript::SetDebuggerDataInitialized() { MOZ_ASSERT(ModuleRecord()); - MOZ_ASSERT(!mSourceElementAssociated); + MOZ_ASSERT(!mDebuggerDataInitialized); - mSourceElementAssociated = true; + mDebuggerDataInitialized = true; } } // namespace dom diff --git a/dom/script/LoadedScript.h b/dom/script/LoadedScript.h index 04c7765ba349..10f32ed43113 100644 --- a/dom/script/LoadedScript.h +++ b/dom/script/LoadedScript.h @@ -64,7 +64,7 @@ class ModuleScript final : public LoadedScript { JS::Heap mModuleRecord; JS::Heap mParseError; JS::Heap mErrorToRethrow; - bool mSourceElementAssociated; + bool mDebuggerDataInitialized; ~ModuleScript(); @@ -78,7 +78,7 @@ class ModuleScript final : public LoadedScript { void SetModuleRecord(JS::Handle aModuleRecord); void SetParseError(const JS::Value& aError); void SetErrorToRethrow(const JS::Value& aError); - void SetSourceElementAssociated(); + void SetDebuggerDataInitialized(); JSObject* ModuleRecord() const { return mModuleRecord; } @@ -86,7 +86,7 @@ class ModuleScript final : public LoadedScript { JS::Value ErrorToRethrow() const { return mErrorToRethrow; } bool HasParseError() const { return !mParseError.isUndefined(); } bool HasErrorToRethrow() const { return !mErrorToRethrow.isUndefined(); } - bool SourceElementAssociated() const { return mSourceElementAssociated; } + bool DebuggerDataInitialized() const { return mDebuggerDataInitialized; } void UnlinkModuleRecord(); diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index 206a9619e219..74d8f6601db6 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -1108,21 +1108,22 @@ bool ScriptLoader::InstantiateModuleTree(ModuleLoadRequest* aRequest) { return true; } -nsresult ScriptLoader::AssociateSourceElementsForModuleTree( +nsresult ScriptLoader::InitDebuggerDataForModuleTree( JSContext* aCx, ModuleLoadRequest* aRequest) { - // Preloading can cause JS scripts to be compiled before DOM script element - // nodes have been created. This method ensures compiled scripts are - // associated with DOM element nodes before execution. + // JS scripts can be associated with a DOM element for use by the debugger, + // but preloading can cause scripts to be compiled before DOM script element + // nodes have been created. This method ensures that this association takes + // place before the first time a module script is run. MOZ_ASSERT(aRequest); ModuleScript* moduleScript = aRequest->mModuleScript; - if (moduleScript->SourceElementAssociated()) { + if (moduleScript->DebuggerDataInitialized()) { return NS_OK; } for (ModuleLoadRequest* childRequest : aRequest->mImports) { - nsresult rv = AssociateSourceElementsForModuleTree(aCx, childRequest); + nsresult rv = InitDebuggerDataForModuleTree(aCx, childRequest); NS_ENSURE_SUCCESS(rv, rv); } @@ -1133,13 +1134,13 @@ nsresult ScriptLoader::AssociateSourceElementsForModuleTree( if (element) { nsresult rv = nsJSUtils::InitModuleSourceElement(aCx, module, element); NS_ENSURE_SUCCESS(rv, rv); - moduleScript->SetSourceElementAssociated(); } // The script is now ready to be exposed to the debugger. JS::Rooted script(aCx, JS::GetModuleScript(module)); JS::ExposeScriptToDebugger(aCx, script); + moduleScript->SetDebuggerDataInitialized(); return NS_OK; } @@ -2576,10 +2577,8 @@ nsresult ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest) { JS::Rooted module(cx, moduleScript->ModuleRecord()); MOZ_ASSERT(module); - if (!moduleScript->SourceElementAssociated()) { - rv = AssociateSourceElementsForModuleTree(cx, request); - NS_ENSURE_SUCCESS(rv, rv); - } + rv = InitDebuggerDataForModuleTree(cx, request); + NS_ENSURE_SUCCESS(rv, rv); rv = nsJSUtils::ModuleEvaluate(cx, module); MOZ_ASSERT(NS_FAILED(rv) == aes.HasException()); diff --git a/dom/script/ScriptLoader.h b/dom/script/ScriptLoader.h index 8a1f7b29aac7..6459daac8d72 100644 --- a/dom/script/ScriptLoader.h +++ b/dom/script/ScriptLoader.h @@ -524,8 +524,8 @@ class ScriptLoader final : public nsISupports { RefPtr StartFetchingModuleAndDependencies( ModuleLoadRequest* aParent, nsIURI* aURI); - nsresult AssociateSourceElementsForModuleTree(JSContext* aCx, - ModuleLoadRequest* aRequest); + nsresult InitDebuggerDataForModuleTree(JSContext* aCx, + ModuleLoadRequest* aRequest); void RunScriptWhenSafe(ScriptLoadRequest* aRequest);