Skip to content

Commit

Permalink
[ES6 modules] Update ModuleScript::IsErrored to match latest spec.
Browse files Browse the repository at this point in the history
This CL updates ModuleScript::IsErrored so that it would also consider
its record's [[Status]].

This behavior change will be tested in
wpt/html/semantics/scripting-1/the-script-element/module/evaluation-error-*.html
once we update ModuleTreeLinker to latest #internal-module-script-graph-fetching
procedure

Bug: 594639, 727299, whatwg/html#2674 , tc39/ecma262#916
Change-Id: I575001a44ca1cc2ad5c9208c93c0b628a09086dd
Reviewed-on: https://chromium-review.googlesource.com/558825
Commit-Queue: Kouhei Ueno <kouhei@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#483945}
  • Loading branch information
nyaxt authored and Commit Bot committed Jul 3, 2017
1 parent 8b0ad01 commit fb77eef
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
13 changes: 13 additions & 0 deletions third_party/WebKit/Source/core/dom/ModuleScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,19 @@ bool ModuleScript::HasInstantiated() const {
status == ScriptModuleState::kEvaluated;
}

// https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-script-is-errored
bool ModuleScript::IsErrored() const {
// "We say that a module script is errored ..." [spec text]

// "if either its module record is null, ..." [spec text]
if (record_.IsEmpty())
return true;

// "or its module record's [[Status]] field has the value "errored"." [spec
// text]
return RecordStatus() == ScriptModuleState::kErrored;
}

void ModuleScript::SetErrorAndClearRecord(ScriptValue error) {
DVLOG(1) << *this << "::SetErrorAndClearRecord()";

Expand Down
2 changes: 1 addition & 1 deletion third_party/WebKit/Source/core/dom/ModuleScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase {
bool HasInstantiated() const;

// https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-script-is-errored
bool IsErrored() const { return record_.IsEmpty(); }
bool IsErrored() const;

// https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-script-set-pre-instantiation-error
void SetErrorAndClearRecord(ScriptValue error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,26 @@ class ModuleTreeLinkerTestModulator final : public DummyModulator {
return it->value;
}

ScriptValue InstantiateModule(ScriptModule) override {
ScriptValue InstantiateModule(ScriptModule record) override {
if (instantiate_should_fail_) {
ScriptState::Scope scope(script_state_.Get());
v8::Local<v8::Value> error = V8ThrowException::CreateError(
script_state_->GetIsolate(), "Instantiation failure.");
errored_records_.insert(record);
return ScriptValue(script_state_.Get(), error);
}
instantiated_records_.insert(record);
return ScriptValue();
}

ScriptModuleState GetRecordStatus(ScriptModule record) override {
if (instantiated_records_.Contains(record))
return ScriptModuleState::kInstantiated;
if (errored_records_.Contains(record))
return ScriptModuleState::kErrored;
return ScriptModuleState::kUninstantiated;
}

ScriptValue GetError(const ModuleScript* module_script) override {
ScriptState::Scope scope(script_state_.Get());
return ScriptValue(script_state_.Get(), module_script->CreateErrorInternal(
Expand All @@ -224,6 +234,8 @@ class ModuleTreeLinkerTestModulator final : public DummyModulator {
HeapHashMap<KURL, Member<ModuleScript>> module_map_;
HeapHashMap<KURL, Member<ModuleTreeClient>> pending_tree_client_map_;
HashMap<KURL, AncestorList> pending_tree_ancestor_list_;
HashSet<ScriptModule> instantiated_records_;
HashSet<ScriptModule> errored_records_;
bool instantiate_should_fail_ = false;
};

Expand Down

0 comments on commit fb77eef

Please sign in to comment.