From 3bd23b408727fe4991922081c9cf43d6ad594105 Mon Sep 17 00:00:00 2001 From: Kouhei Ueno Date: Sat, 1 Jul 2017 05:27:23 +0000 Subject: [PATCH] [ES6 modules] Implement ModuleScript::RecordStatus() This CL implements ModuleScript::RecordStatus(), which returns module script's record's [[Status]]. Which will replace usage of ModuleScript::state_ after we switch to the new #internal-module-script-graph-fetching procedure proposed in the linked PRs. The call to ScriptModule::Status routed via Modulator to allow mock implementation in Modulator infra unit tests. This codepath will be tested in modulator infra unit tests after the #internal-module-script-graph-fetching update. Bug: 594639, 727299, https://github.com/whatwg/html/pull/2674 , https://github.com/tc39/ecma262/pull/916 Change-Id: I2ca193a8c779945c9ae9b08c2b5f55de41fb1a3c Reviewed-on: https://chromium-review.googlesource.com/558724 Commit-Queue: Kouhei Ueno Reviewed-by: Kinuko Yasuda Cr-Commit-Position: refs/heads/master@{#483902} --- third_party/WebKit/Source/core/dom/Modulator.h | 4 +++- third_party/WebKit/Source/core/dom/ModulatorImpl.cpp | 5 +++++ third_party/WebKit/Source/core/dom/ModulatorImpl.h | 1 + third_party/WebKit/Source/core/dom/ModuleScript.cpp | 5 +++++ third_party/WebKit/Source/core/dom/ModuleScript.h | 3 +++ third_party/WebKit/Source/core/testing/DummyModulator.cpp | 5 +++++ third_party/WebKit/Source/core/testing/DummyModulator.h | 1 + 7 files changed, 23 insertions(+), 1 deletion(-) diff --git a/third_party/WebKit/Source/core/dom/Modulator.h b/third_party/WebKit/Source/core/dom/Modulator.h index 4aa36b128f267..ef910f6632d96 100644 --- a/third_party/WebKit/Source/core/dom/Modulator.h +++ b/third_party/WebKit/Source/core/dom/Modulator.h @@ -5,6 +5,7 @@ #ifndef Modulator_h #define Modulator_h +#include "bindings/core/v8/ScriptModule.h" #include "core/CoreExport.h" #include "core/dom/AncestorList.h" #include "platform/bindings/ScriptWrappable.h" @@ -22,7 +23,6 @@ class ExceptionState; class ModuleScript; class ModuleScriptFetchRequest; class ModuleScriptLoaderClient; -class ScriptModule; class ScriptModuleResolver; class ScriptState; class ScriptValue; @@ -123,6 +123,8 @@ class CORE_EXPORT Modulator : public GarbageCollectedFinalized, virtual ScriptValue InstantiateModule(ScriptModule) = 0; + virtual ScriptModuleState GetRecordStatus(ScriptModule) = 0; + // https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-script-error virtual ScriptValue GetError(const ModuleScript*) = 0; diff --git a/third_party/WebKit/Source/core/dom/ModulatorImpl.cpp b/third_party/WebKit/Source/core/dom/ModulatorImpl.cpp index 0f916e5b35d9e..68efcd0012564 100644 --- a/third_party/WebKit/Source/core/dom/ModulatorImpl.cpp +++ b/third_party/WebKit/Source/core/dom/ModulatorImpl.cpp @@ -148,6 +148,11 @@ ScriptValue ModulatorImpl::InstantiateModule(ScriptModule script_module) { return script_module.Instantiate(script_state_.Get()); } +ScriptModuleState ModulatorImpl::GetRecordStatus(ScriptModule script_module) { + ScriptState::Scope scope(script_state_.Get()); + return script_module.Status(script_state_.Get()); +} + ScriptValue ModulatorImpl::GetError(const ModuleScript* module_script) { DCHECK(module_script); ScriptState::Scope scope(script_state_.Get()); diff --git a/third_party/WebKit/Source/core/dom/ModulatorImpl.h b/third_party/WebKit/Source/core/dom/ModulatorImpl.h index e60b02ea4d50c..9a87c580499e0 100644 --- a/third_party/WebKit/Source/core/dom/ModulatorImpl.h +++ b/third_party/WebKit/Source/core/dom/ModulatorImpl.h @@ -66,6 +66,7 @@ class ModulatorImpl final : public Modulator { const TextPosition&, ExceptionState&) override; ScriptValue InstantiateModule(ScriptModule) override; + ScriptModuleState GetRecordStatus(ScriptModule) override; ScriptValue GetError(const ModuleScript*) override; Vector ModuleRequestsFromScriptModule(ScriptModule) override; void ExecuteModule(const ModuleScript*) override; diff --git a/third_party/WebKit/Source/core/dom/ModuleScript.cpp b/third_party/WebKit/Source/core/dom/ModuleScript.cpp index b17da72e20c97..58a363de710bc 100644 --- a/third_party/WebKit/Source/core/dom/ModuleScript.cpp +++ b/third_party/WebKit/Source/core/dom/ModuleScript.cpp @@ -184,6 +184,11 @@ bool ModuleScript::HasEmptyRecord() const { return record_.IsEmpty(); } +ScriptModuleState ModuleScript::RecordStatus() const { + DCHECK(!record_.IsEmpty()); + return settings_object_->GetRecordStatus(Record()); +} + void ModuleScript::SetErrorAndClearRecord(ScriptValue error) { DVLOG(1) << "ModuleScript[" << this << "]::SetErrorAndClearRecord()"; diff --git a/third_party/WebKit/Source/core/dom/ModuleScript.h b/third_party/WebKit/Source/core/dom/ModuleScript.h index 0bbea7c41cffe..d047289ed6e5c 100644 --- a/third_party/WebKit/Source/core/dom/ModuleScript.h +++ b/third_party/WebKit/Source/core/dom/ModuleScript.h @@ -61,6 +61,9 @@ class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase { ModuleInstantiationState State() const { return state_; } + // Corresponds to spec concept: module script's record's [[Status]] + ScriptModuleState RecordStatus() const; + // https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-script-is-errored bool IsErrored() const { return record_.IsEmpty(); } diff --git a/third_party/WebKit/Source/core/testing/DummyModulator.cpp b/third_party/WebKit/Source/core/testing/DummyModulator.cpp index f2dbd09b4b978..ac51a15fa0085 100644 --- a/third_party/WebKit/Source/core/testing/DummyModulator.cpp +++ b/third_party/WebKit/Source/core/testing/DummyModulator.cpp @@ -115,6 +115,11 @@ ScriptValue DummyModulator::InstantiateModule(ScriptModule) { return ScriptValue(); } +ScriptModuleState DummyModulator::GetRecordStatus(ScriptModule) { + NOTREACHED(); + return ScriptModuleState::kErrored; +} + ScriptValue DummyModulator::GetError(const ModuleScript*) { NOTREACHED(); return ScriptValue(); diff --git a/third_party/WebKit/Source/core/testing/DummyModulator.h b/third_party/WebKit/Source/core/testing/DummyModulator.h index 6059718b773a0..e7f123a0ae4da 100644 --- a/third_party/WebKit/Source/core/testing/DummyModulator.h +++ b/third_party/WebKit/Source/core/testing/DummyModulator.h @@ -58,6 +58,7 @@ class DummyModulator : public Modulator { const TextPosition&, ExceptionState&) override; ScriptValue InstantiateModule(ScriptModule) override; + ScriptModuleState GetRecordStatus(ScriptModule) override; ScriptValue GetError(const ModuleScript*) override; Vector ModuleRequestsFromScriptModule(ScriptModule) override; void ExecuteModule(const ModuleScript*) override;