Bug 1523897 - Only initialize debugger data for modules the first time they are executed r=smaug

This commit is contained in:
Jon Coppeard 2019-02-01 10:26:14 +00:00
Родитель f5918e13c5
Коммит 9972b41fd8
4 изменённых файлов: 19 добавлений и 20 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -64,7 +64,7 @@ class ModuleScript final : public LoadedScript {
JS::Heap<JSObject*> mModuleRecord;
JS::Heap<JS::Value> mParseError;
JS::Heap<JS::Value> mErrorToRethrow;
bool mSourceElementAssociated;
bool mDebuggerDataInitialized;
~ModuleScript();
@ -78,7 +78,7 @@ class ModuleScript final : public LoadedScript {
void SetModuleRecord(JS::Handle<JSObject*> 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();

Просмотреть файл

@ -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<JSScript*> 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<JSObject*> 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());

Просмотреть файл

@ -524,8 +524,8 @@ class ScriptLoader final : public nsISupports {
RefPtr<mozilla::GenericPromise> StartFetchingModuleAndDependencies(
ModuleLoadRequest* aParent, nsIURI* aURI);
nsresult AssociateSourceElementsForModuleTree(JSContext* aCx,
ModuleLoadRequest* aRequest);
nsresult InitDebuggerDataForModuleTree(JSContext* aCx,
ModuleLoadRequest* aRequest);
void RunScriptWhenSafe(ScriptLoadRequest* aRequest);