Skip to content
This repository has been archived by the owner on Jul 18, 2018. It is now read-only.

Commit

Permalink
[ES6 modules] Implement ModuleScript::RecordStatus()
Browse files Browse the repository at this point in the history
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, whatwg/html#2674 , tc39/ecma262#916
Change-Id: I2ca193a8c779945c9ae9b08c2b5f55de41fb1a3c
Reviewed-on: https://chromium-review.googlesource.com/558724
Commit-Queue: Kouhei Ueno <kouhei@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#483902}
  • Loading branch information
nyaxt authored and Commit Bot committed Jul 1, 2017
1 parent aa841d0 commit 3bd23b4
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion third_party/WebKit/Source/core/dom/Modulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -22,7 +23,6 @@ class ExceptionState;
class ModuleScript;
class ModuleScriptFetchRequest;
class ModuleScriptLoaderClient;
class ScriptModule;
class ScriptModuleResolver;
class ScriptState;
class ScriptValue;
Expand Down Expand Up @@ -123,6 +123,8 @@ class CORE_EXPORT Modulator : public GarbageCollectedFinalized<Modulator>,

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;

Expand Down
5 changes: 5 additions & 0 deletions third_party/WebKit/Source/core/dom/ModulatorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions third_party/WebKit/Source/core/dom/ModulatorImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ModuleRequest> ModuleRequestsFromScriptModule(ScriptModule) override;
void ExecuteModule(const ModuleScript*) override;
Expand Down
5 changes: 5 additions & 0 deletions third_party/WebKit/Source/core/dom/ModuleScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()";

Expand Down
3 changes: 3 additions & 0 deletions third_party/WebKit/Source/core/dom/ModuleScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }

Expand Down
5 changes: 5 additions & 0 deletions third_party/WebKit/Source/core/testing/DummyModulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions third_party/WebKit/Source/core/testing/DummyModulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ModuleRequest> ModuleRequestsFromScriptModule(ScriptModule) override;
void ExecuteModule(const ModuleScript*) override;
Expand Down

0 comments on commit 3bd23b4

Please sign in to comment.