Skip to content

Commit fb77eef

Browse files
nyaxtCommit Bot
authored and
Commit Bot
committed
[ES6 modules] Update ModuleScript::IsErrored to match latest spec.
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 <[email protected]> Reviewed-by: Kinuko Yasuda <[email protected]> Reviewed-by: Kentaro Hara <[email protected]> Cr-Commit-Position: refs/heads/master@{#483945}
1 parent 8b0ad01 commit fb77eef

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

third_party/WebKit/Source/core/dom/ModuleScript.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,19 @@ bool ModuleScript::HasInstantiated() const {
205205
status == ScriptModuleState::kEvaluated;
206206
}
207207

208+
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-script-is-errored
209+
bool ModuleScript::IsErrored() const {
210+
// "We say that a module script is errored ..." [spec text]
211+
212+
// "if either its module record is null, ..." [spec text]
213+
if (record_.IsEmpty())
214+
return true;
215+
216+
// "or its module record's [[Status]] field has the value "errored"." [spec
217+
// text]
218+
return RecordStatus() == ScriptModuleState::kErrored;
219+
}
220+
208221
void ModuleScript::SetErrorAndClearRecord(ScriptValue error) {
209222
DVLOG(1) << *this << "::SetErrorAndClearRecord()";
210223

third_party/WebKit/Source/core/dom/ModuleScript.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase {
6868
bool HasInstantiated() const;
6969

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

7373
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-script-set-pre-instantiation-error
7474
void SetErrorAndClearRecord(ScriptValue error);

third_party/WebKit/Source/core/loader/modulescript/ModuleTreeLinkerTest.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,26 @@ class ModuleTreeLinkerTestModulator final : public DummyModulator {
189189
return it->value;
190190
}
191191

192-
ScriptValue InstantiateModule(ScriptModule) override {
192+
ScriptValue InstantiateModule(ScriptModule record) override {
193193
if (instantiate_should_fail_) {
194194
ScriptState::Scope scope(script_state_.Get());
195195
v8::Local<v8::Value> error = V8ThrowException::CreateError(
196196
script_state_->GetIsolate(), "Instantiation failure.");
197+
errored_records_.insert(record);
197198
return ScriptValue(script_state_.Get(), error);
198199
}
200+
instantiated_records_.insert(record);
199201
return ScriptValue();
200202
}
201203

204+
ScriptModuleState GetRecordStatus(ScriptModule record) override {
205+
if (instantiated_records_.Contains(record))
206+
return ScriptModuleState::kInstantiated;
207+
if (errored_records_.Contains(record))
208+
return ScriptModuleState::kErrored;
209+
return ScriptModuleState::kUninstantiated;
210+
}
211+
202212
ScriptValue GetError(const ModuleScript* module_script) override {
203213
ScriptState::Scope scope(script_state_.Get());
204214
return ScriptValue(script_state_.Get(), module_script->CreateErrorInternal(
@@ -224,6 +234,8 @@ class ModuleTreeLinkerTestModulator final : public DummyModulator {
224234
HeapHashMap<KURL, Member<ModuleScript>> module_map_;
225235
HeapHashMap<KURL, Member<ModuleTreeClient>> pending_tree_client_map_;
226236
HashMap<KURL, AncestorList> pending_tree_ancestor_list_;
237+
HashSet<ScriptModule> instantiated_records_;
238+
HashSet<ScriptModule> errored_records_;
227239
bool instantiate_should_fail_ = false;
228240
};
229241

0 commit comments

Comments
 (0)