Title: [288820] trunk
Revision
288820
Author
[email protected]
Date
2022-01-31 11:04:30 -0800 (Mon, 31 Jan 2022)

Log Message

Fix handling of module script errors in WebCore
https://bugs.webkit.org/show_bug.cgi?id=218284

Patch by Asumu Takikawa <[email protected]> on 2022-01-31
Reviewed by Yusuke Suzuki.

LayoutTests/imported/w3c:

Set test expectations to PASS for fixed behavior in module tests.
For import assertion tests, set different error behavior from
load errors getting dispatched.

* web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/content-type-checking-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/cors-crossorigin-requests-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/import-css-module-basic-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/integrity-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/load-error-events-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/empty-assertion-clause-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/invalid-type-assertion-error-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/unsupported-assertion-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/charset-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/cors-crossorigin-requests-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/integrity-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/load-error-events-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/module-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/valid-content-type-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/module/compilation-error-1-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/module/compilation-error-2-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/module/errorhandling-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/module/specifier-error-expected.txt:

Source/WebCore:

According to the HTML spec, script fetch errors get dispatched to the
script (with no error value), but load errors should get reported to
the global object and dispatched with an error value included.
This patch implements that behavior for module scripts.

In addition, reported errors from module scripts are never expected to
be muted. To implement this, we add a fromModule flag to suppress the
error muting in canIncludeErrorDetails.

* bindings/js/JSDOMExceptionHandling.cpp:
(WebCore::reportException):
* bindings/js/JSDOMExceptionHandling.h:
* bindings/js/ModuleFetchFailureKind.h:
* bindings/js/ScriptController.cpp:
(WebCore::ScriptController::evaluateInWorld):
(WebCore::ScriptController::setupModuleScriptHandlers):
(WebCore::ScriptController::callInWorld):
(WebCore::ScriptController::reportExceptionFromScriptError):
* bindings/js/ScriptController.h:
* bindings/js/ScriptModuleLoader.cpp:
(WebCore::rejectWithFetchError):
(WebCore::ScriptModuleLoader::fetch):
(WebCore::rejectPromise):
(WebCore::ScriptModuleLoader::notifyFinished):
* dom/LoadableClassicScript.cpp:
(WebCore::LoadableClassicScript::error const):
(WebCore::LoadableClassicScript::notifyFinished):
* dom/LoadableScript.h:
* dom/ScriptElement.cpp:
(WebCore::ScriptElement::executeScriptAndDispatchEvent):
* dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::canIncludeErrorDetails):
(WebCore::ScriptExecutionContext::reportException):
(WebCore::ScriptExecutionContext::dispatchErrorEvent):
* dom/ScriptExecutionContext.h:
* workers/WorkerOrWorkletScriptController.cpp:
(WebCore::WorkerOrWorkletScriptController::loadModuleSynchronously):
(WebCore::WorkerOrWorkletScriptController::loadAndEvaluateModule):

LayoutTests:

Adjust tests expectations to match fixed script loading behvior.
Also add DumpJSConsoleLogInStdErr for flaky test (see bug 182177).
Changed a JS DOM test to match spec behavior.

* TestExpectations:
* js/dom/modules/module-incorrect-relative-specifier-expected.txt:
* js/dom/modules/module-incorrect-relative-specifier.html:
* platform/gtk/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/errorhandling-expected.txt: Removed.

Modified Paths

Removed Paths

  • trunk/LayoutTests/platform/gtk/imported/w3c/web-platform-tests/html/semantics/scripting-1/

Diff

Modified: trunk/LayoutTests/ChangeLog (288819 => 288820)


--- trunk/LayoutTests/ChangeLog	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/ChangeLog	2022-01-31 19:04:30 UTC (rev 288820)
@@ -1,3 +1,19 @@
+2022-01-31  Asumu Takikawa  <[email protected]>
+
+        Fix handling of module script errors in WebCore
+        https://bugs.webkit.org/show_bug.cgi?id=218284
+
+        Reviewed by Yusuke Suzuki.
+
+        Adjust tests expectations to match fixed script loading behvior.
+        Also add DumpJSConsoleLogInStdErr for flaky test (see bug 182177).
+        Changed a JS DOM test to match spec behavior.
+
+        * TestExpectations:
+        * js/dom/modules/module-incorrect-relative-specifier-expected.txt:
+        * js/dom/modules/module-incorrect-relative-specifier.html:
+        * platform/gtk/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/errorhandling-expected.txt: Removed.
+
 2022-01-31  Antti Koivisto  <[email protected]>
 
         [CSS Container Queries] Check for query containers when matching rules

Modified: trunk/LayoutTests/TestExpectations (288819 => 288820)


--- trunk/LayoutTests/TestExpectations	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/TestExpectations	2022-01-31 19:04:30 UTC (rev 288820)
@@ -858,6 +858,7 @@
 imported/w3c/web-platform-tests/html/semantics/document-metadata/the-link-element/link-style-error-quirks.html [ DumpJSConsoleLogInStdErr ]
 [ Release ] imported/w3c/web-platform-tests/html/dom/idlharness.https.html [ DumpJSConsoleLogInStdErr ]
 [ Release ] imported/w3c/web-platform-tests/html/dom/idlharness.worker.html [ DumpJSConsoleLogInStdErr ]
+imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/errorhandling.html [ DumpJSConsoleLogInStdErr ]
 imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/error-type-1.html [ DumpJSConsoleLogInStdErr ]
 imported/w3c/web-platform-tests/html/cross-origin-embedder-policy/sandbox.https.html [ DumpJSConsoleLogInStdErr ]
 imported/w3c/web-platform-tests/IndexedDB/fire-error-event-exception.html [ DumpJSConsoleLogInStdErr ]
@@ -2507,8 +2508,6 @@
 webkit.org/b/165764 http/tests/misc/module-script-async.html [ Pass Timeout ]
 
 # After rebasing WPT, we should investigate deterministic error handling, which is the updated spec.
-imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/compilation-error-1.html [ Pass Failure ]
-imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/compilation-error-2.html [ Pass Failure ]
 imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/crossorigin.html [ Pass Failure ]
 imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/instantiation-error-8.html [ Skip ]
 
@@ -3012,8 +3011,6 @@
 
 webkit.org/b/183390 http/wpt/html/browsers/history/the-location-interface/location-protocol-setter-non-broken-async-delegate.html [ Pass Failure ]
 
-webkit.org/b/182177 imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/errorhandling.html [ Pass Failure ]
-
 # This fails with Legacy WebKit, and the symptom is a hang so we need to skip it. Skipped here and un-skipped in platform/wk2/TestExpectations.
 imported/w3c/web-platform-tests/service-workers/service-worker/svg-target-reftest.https.html [ Skip ]
 

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (288819 => 288820)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-01-31 19:04:30 UTC (rev 288820)
@@ -1,3 +1,34 @@
+2022-01-31  Asumu Takikawa  <[email protected]>
+
+        Fix handling of module script errors in WebCore
+        https://bugs.webkit.org/show_bug.cgi?id=218284
+
+        Reviewed by Yusuke Suzuki.
+
+        Set test expectations to PASS for fixed behavior in module tests.
+        For import assertion tests, set different error behavior from
+        load errors getting dispatched.
+
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset-expected.txt:
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/content-type-checking-expected.txt:
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/cors-crossorigin-requests-expected.txt:
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/import-css-module-basic-expected.txt:
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/integrity-expected.txt:
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/load-error-events-expected.txt:
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/empty-assertion-clause-expected.txt:
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/invalid-type-assertion-error-expected.txt:
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/unsupported-assertion-expected.txt:
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/charset-expected.txt:
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/cors-crossorigin-requests-expected.txt:
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/integrity-expected.txt:
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/load-error-events-expected.txt:
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/module-expected.txt:
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/valid-content-type-expected.txt:
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/module/compilation-error-1-expected.txt:
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/module/compilation-error-2-expected.txt:
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/module/errorhandling-expected.txt:
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/module/specifier-error-expected.txt:
+
 2022-01-31  Antti Koivisto  <[email protected]>
 
         [CSS Container Queries] Check for query containers when matching rules

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset-expected.txt (288819 => 288820)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset-expected.txt	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset-expected.txt	2022-01-31 19:04:30 UTC (rev 288820)
@@ -1,14 +1,9 @@
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
-CONSOLE MESSAGE: ReferenceError: Can't find variable: unreachable
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
-CONSOLE MESSAGE: ReferenceError: Can't find variable: unreachable
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
-CONSOLE MESSAGE: ReferenceError: Can't find variable: unreachable
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
-CONSOLE MESSAGE: ReferenceError: Can't find variable: unreachable
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
-CONSOLE MESSAGE: ReferenceError: Can't find variable: unreachable
 
-Harness Error (FAIL), message = ReferenceError: Can't find variable: unreachable
+Harness Error (FAIL), message = SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/content-type-checking-expected.txt (288819 => 288820)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/content-type-checking-expected.txt	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/content-type-checking-expected.txt	2022-01-31 19:04:30 UTC (rev 288820)
@@ -4,9 +4,11 @@
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 
-FAIL text/css assert_unreached: Reached unreachable code
-PASS application/css
-PASS text/html+css
-FAIL text/css;boundary=something assert_unreached: Reached unreachable code
-FAIL text/css;foo=bar assert_unreached: Reached unreachable code
+Harness Error (FAIL), message = SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 
+NOTRUN text/css
+NOTRUN application/css
+NOTRUN text/html+css
+NOTRUN text/css;boundary=something
+NOTRUN text/css;foo=bar
+

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/cors-crossorigin-requests-expected.txt (288819 => 288820)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/cors-crossorigin-requests-expected.txt	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/cors-crossorigin-requests-expected.txt	2022-01-31 19:04:30 UTC (rev 288820)
@@ -5,7 +5,7 @@
 
 
 
-FAIL Imported CSS module, cross-origin with CORS assert_equals: Unexpected _log value expected "imported CSS: #test { background-color: rgb(255, 0, 0); }" but got ""
-PASS Imported CSS module, cross-origin, missing CORS ACAO header
-FAIL Imported CSS module with parse error, cross-origin, with CORS assert_equals: Unexpected _log value expected "imported CSS rules count: 0" but got ""
+FAIL Imported CSS module, cross-origin with CORS assert_equals: Unexpected _log value expected "imported CSS: #test { background-color: rgb(255, 0, 0); }" but got "10-0"
+FAIL Imported CSS module, cross-origin, missing CORS ACAO header assert_equals: Unexpected _log value expected "error" but got "10-0"
+FAIL Imported CSS module with parse error, cross-origin, with CORS assert_equals: Unexpected _log value expected "imported CSS rules count: 0" but got "10-0"
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/import-css-module-basic-expected.txt (288819 => 288820)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/import-css-module-basic-expected.txt	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/import-css-module-basic-expected.txt	2022-01-31 19:04:30 UTC (rev 288820)
@@ -5,6 +5,6 @@
 I am a test div.
 I am a test div.
 
-Harness Error (FAIL), message = ReferenceError: Can't find variable: unreachable
+Harness Error (FAIL), message = SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/integrity-expected.txt (288819 => 288820)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/integrity-expected.txt	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/integrity-expected.txt	2022-01-31 19:04:30 UTC (rev 288820)
@@ -1,4 +1,4 @@
 
-FAIL The integrity attribute must be verified on the top-level of a module loading a CSS module and allow it to execute when it matches assert_array_equals: The module and its dependency must have executed lengths differ, expected array ["integrity-matches,css:#test { background-color: rgb(255, 0, 0); }"] length 1, got [] length 0
-PASS The integrity attribute must be verified on the top-level of a module loading a CSS module and not allow it to execute when there's a mismatch
+Harness Error (FAIL), message = SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 
+

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/load-error-events-expected.txt (288819 => 288820)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/load-error-events-expected.txt	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/load-error-events-expected.txt	2022-01-31 19:04:30 UTC (rev 288820)
@@ -7,12 +7,14 @@
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 
-FAIL inline, 200, parser-inserted assert_unreached: Error event should not be fired. Reached unreachable code
-PASS inline, 404, parser-inserted
-FAIL src, 200, parser-inserted assert_unreached: Error event should not be fired. Reached unreachable code
-PASS src, 404, parser-inserted
-FAIL src, 200, not parser-inserted assert_unreached: Error event should not be fired. Reached unreachable code
-PASS src, 404, not parser-inserted
-FAIL inline, 200, not parser-inserted assert_unreached: Error event should not be fired. Reached unreachable code
-PASS inline, 404, not parser-inserted
+Harness Error (FAIL), message = SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 
+NOTRUN inline, 200, parser-inserted
+NOTRUN inline, 404, parser-inserted
+NOTRUN src, 200, parser-inserted
+NOTRUN src, 404, parser-inserted
+NOTRUN src, 200, not parser-inserted
+NOTRUN src, 404, not parser-inserted
+NOTRUN inline, 200, not parser-inserted
+NOTRUN inline, 404, not parser-inserted
+

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/empty-assertion-clause-expected.txt (288819 => 288820)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/empty-assertion-clause-expected.txt	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/empty-assertion-clause-expected.txt	2022-01-31 19:04:30 UTC (rev 288820)
@@ -1,4 +1,6 @@
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 
-FAIL Test that no error occurs when an empty import assertion clause is provided. assert_array_equals: lengths differ, expected array ["hello", "empty-assertion-clause"] length 2, got ["unexpected"] length 1
+Harness Error (FAIL), message = SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 
+FAIL Test that no error occurs when an empty import assertion clause is provided. assert_array_equals: lengths differ, expected array ["hello", "empty-assertion-clause"] length 2, got [object "SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration."] length 1
+

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/invalid-type-assertion-error-expected.txt (288819 => 288820)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/invalid-type-assertion-error-expected.txt	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/invalid-type-assertion-error-expected.txt	2022-01-31 19:04:30 UTC (rev 288820)
@@ -5,7 +5,7 @@
 
 FAIL Test that invalid module type assertion leads to TypeError on window. assert_equals: expected function "function TypeError() {
     [native code]
-}" but got function "function String() {
+}" but got function "function SyntaxError() {
     [native code]
 }"
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/unsupported-assertion-expected.txt (288819 => 288820)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/unsupported-assertion-expected.txt	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/import-assertions/unsupported-assertion-expected.txt	2022-01-31 19:04:30 UTC (rev 288820)
@@ -1,4 +1,6 @@
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 
-FAIL Test that no error occurs when an unsupported import assertion is provided. assert_array_equals: lengths differ, expected array ["hello", "unsupported-assertion"] length 2, got ["unexpected"] length 1
+Harness Error (FAIL), message = SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 
+FAIL Test that no error occurs when an unsupported import assertion is provided. assert_array_equals: lengths differ, expected array ["hello", "unsupported-assertion"] length 2, got [object "SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration."] length 1
+

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/charset-expected.txt (288819 => 288820)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/charset-expected.txt	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/charset-expected.txt	2022-01-31 19:04:30 UTC (rev 288820)
@@ -1,14 +1,9 @@
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
-CONSOLE MESSAGE: ReferenceError: Can't find variable: unreachable
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
-CONSOLE MESSAGE: ReferenceError: Can't find variable: unreachable
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
-CONSOLE MESSAGE: ReferenceError: Can't find variable: unreachable
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
-CONSOLE MESSAGE: ReferenceError: Can't find variable: unreachable
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
-CONSOLE MESSAGE: ReferenceError: Can't find variable: unreachable
 
-Harness Error (FAIL), message = ReferenceError: Can't find variable: unreachable
+Harness Error (FAIL), message = SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/cors-crossorigin-requests-expected.txt (288819 => 288820)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/cors-crossorigin-requests-expected.txt	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/cors-crossorigin-requests-expected.txt	2022-01-31 19:04:30 UTC (rev 288820)
@@ -5,7 +5,7 @@
 
 
 
-FAIL Imported JSON module, cross-origin with CORS assert_equals: Unexpected _log value expected "imported JSON: 42" but got ""
-PASS Imported JSON module, cross-origin, missing CORS ACAO header
-FAIL Imported JSON module with parse error, cross-origin, with CORS assert_equals: Unexpected _log value expected "0-0" but got ""
+FAIL Imported JSON module, cross-origin with CORS assert_equals: Unexpected _log value expected "imported JSON: 42" but got "10-0"
+FAIL Imported JSON module, cross-origin, missing CORS ACAO header assert_equals: Unexpected _log value expected "error" but got "10-0"
+FAIL Imported JSON module with parse error, cross-origin, with CORS assert_equals: Unexpected _log value expected "0-0" but got "10-0"
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/integrity-expected.txt (288819 => 288820)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/integrity-expected.txt	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/integrity-expected.txt	2022-01-31 19:04:30 UTC (rev 288820)
@@ -1,4 +1,4 @@
 
-FAIL The integrity attribute must be verified on the top-level of a module loading a JSON module and allow it to execute when it matches assert_array_equals: The module and its dependency must have executed lengths differ, expected array ["integrity-matches,json:42"] length 1, got [] length 0
-PASS The integrity attribute must be verified on the top-level of a module loading a JSON module and not allow it to execute when there's a mismatch
+Harness Error (FAIL), message = SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 
+

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/load-error-events-expected.txt (288819 => 288820)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/load-error-events-expected.txt	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/load-error-events-expected.txt	2022-01-31 19:04:30 UTC (rev 288820)
@@ -7,12 +7,14 @@
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 
-FAIL inline, 200, parser-inserted assert_unreached: Error event should not be fired. Reached unreachable code
-PASS inline, 404, parser-inserted
-FAIL src, 200, parser-inserted assert_unreached: Error event should not be fired. Reached unreachable code
-PASS src, 404, parser-inserted
-FAIL src, 200, not parser-inserted assert_unreached: Error event should not be fired. Reached unreachable code
-PASS src, 404, not parser-inserted
-FAIL inline, 200, not parser-inserted assert_unreached: Error event should not be fired. Reached unreachable code
-PASS inline, 404, not parser-inserted
+Harness Error (FAIL), message = SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 
+NOTRUN inline, 200, parser-inserted
+NOTRUN inline, 404, parser-inserted
+NOTRUN src, 200, parser-inserted
+NOTRUN src, 404, parser-inserted
+NOTRUN src, 200, not parser-inserted
+NOTRUN src, 404, not parser-inserted
+NOTRUN inline, 200, not parser-inserted
+NOTRUN inline, 404, not parser-inserted
+

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/module-expected.txt (288819 => 288820)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/module-expected.txt	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/module-expected.txt	2022-01-31 19:04:30 UTC (rev 288820)
@@ -1,4 +1,6 @@
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 
-FAIL JSON modules assert_unreached: [object Event] Reached unreachable code
+Harness Error (FAIL), message = SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 
+NOTRUN JSON modules
+

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/valid-content-type-expected.txt (288819 => 288820)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/valid-content-type-expected.txt	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/json-module/valid-content-type-expected.txt	2022-01-31 19:04:30 UTC (rev 288820)
@@ -5,10 +5,12 @@
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 CONSOLE MESSAGE: SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 
-FAIL text/json assert_unreached: [object Event] Reached unreachable code
-FAIL application/json assert_unreached: [object Event] Reached unreachable code
-FAIL text/html+json assert_unreached: [object Event] Reached unreachable code
-FAIL image/svg+json assert_unreached: [object Event] Reached unreachable code
-FAIL text/json;boundary=something assert_unreached: [object Event] Reached unreachable code
-FAIL text/json;foo=bar assert_unreached: [object Event] Reached unreachable code
+Harness Error (FAIL), message = SyntaxError: Unexpected identifier 'assert'. Expected a ';' following a targeted import declaration.
 
+NOTRUN text/json
+NOTRUN application/json
+NOTRUN text/html+json
+NOTRUN image/svg+json
+NOTRUN text/json;boundary=something
+NOTRUN text/json;foo=bar
+

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/compilation-error-1-expected.txt (288819 => 288820)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/compilation-error-1-expected.txt	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/compilation-error-1-expected.txt	2022-01-31 19:04:30 UTC (rev 288820)
@@ -4,9 +4,5 @@
 CONSOLE MESSAGE: SyntaxError: Unexpected token '%'
 CONSOLE MESSAGE: SyntaxError: Unexpected token '%'
 
-FAIL Test that syntax errors lead to SyntaxError events on window, and that exceptions are remembered. assert_equals: expected function "function SyntaxError() {
-    [native code]
-}" but got function "function String() {
-    [native code]
-}"
+PASS Test that syntax errors lead to SyntaxError events on window, and that exceptions are remembered.
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/compilation-error-2-expected.txt (288819 => 288820)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/compilation-error-2-expected.txt	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/compilation-error-2-expected.txt	2022-01-31 19:04:30 UTC (rev 288820)
@@ -4,9 +4,5 @@
 CONSOLE MESSAGE: SyntaxError: Unexpected token '%'
 CONSOLE MESSAGE: SyntaxError: Unexpected token '%'
 
-FAIL Test that syntax errors lead to SyntaxError events on window, and that exceptions are remembered. assert_equals: expected function "function SyntaxError() {
-    [native code]
-}" but got function "function String() {
-    [native code]
-}"
+PASS Test that syntax errors lead to SyntaxError events on window, and that exceptions are remembered.
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/errorhandling-expected.txt (288819 => 288820)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/errorhandling-expected.txt	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/errorhandling-expected.txt	2022-01-31 19:04:30 UTC (rev 288820)
@@ -1,13 +1,7 @@
-CONSOLE MESSAGE: TypeError: 'text/plain' is not a valid _javascript_ MIME type.
-CONSOLE MESSAGE: TypeError: 'text/plain' is not a valid _javascript_ MIME type.
-CONSOLE MESSAGE: SyntaxError: No identifiers allowed directly after numeric literal
-CONSOLE MESSAGE: SyntaxError: No identifiers allowed directly after numeric literal
-CONSOLE MESSAGE: SyntaxError: No identifiers allowed directly after numeric literal
-CONSOLE MESSAGE: SyntaxError: No identifiers allowed directly after numeric literal
 html-script-module-errorHandling
 
 
-FAIL IFrame test: 'iframe_parseError_Root' assert_equals: Unexpected _errorReported value expected "error" but got ""
+PASS IFrame test: 'iframe_parseError_Root'
 PASS IFrame test: 'iframe_parseError_Dependent'
 PASS IFrame test: 'iframe_parseError_DependentMultiple'
 PASS External root module with non-script mimetype

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/specifier-error-expected.txt (288819 => 288820)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/specifier-error-expected.txt	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/module/specifier-error-expected.txt	2022-01-31 19:04:30 UTC (rev 288820)
@@ -1,8 +1,4 @@
 CONSOLE MESSAGE: TypeError: Module specifier, 'string-without-dot-slash-prefix' does not start with "/", "./", or "../". Referenced from http://localhost:8800/html/semantics/scripting-1/the-script-element/module/bad-module-specifier.js
 
-FAIL Test that invalid module specifier leads to TypeError on window. assert_equals: expected function "function TypeError() {
-    [native code]
-}" but got function "function String() {
-    [native code]
-}"
+PASS Test that invalid module specifier leads to TypeError on window.
 

Modified: trunk/LayoutTests/js/dom/modules/module-incorrect-relative-specifier-expected.txt (288819 => 288820)


--- trunk/LayoutTests/js/dom/modules/module-incorrect-relative-specifier-expected.txt	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/js/dom/modules/module-incorrect-relative-specifier-expected.txt	2022-01-31 19:04:30 UTC (rev 288820)
@@ -10,9 +10,10 @@
 0
 1
 2
-PASS scripts.has(document.getElementById("s0")) is true
-PASS scripts.has(document.getElementById("s1")) is true
-PASS scripts.has(document.getElementById("s2")) is true
+PASS errors.some(e => e.match(/incorrect/)) is true
+PASS errors.some(e => e.match(/hello/)) is true
+PASS errors.some(e => e.match(/test/)) is true
+PASS Got expected error: 'TypeError'
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/js/dom/modules/module-incorrect-relative-specifier.html (288819 => 288820)


--- trunk/LayoutTests/js/dom/modules/module-incorrect-relative-specifier.html	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/LayoutTests/js/dom/modules/module-incorrect-relative-specifier.html	2022-01-31 19:04:30 UTC (rev 288820)
@@ -10,30 +10,31 @@
 window.jsTestIsAsync = true;
 debug('Module is not executed yet.');
 var count = 0;
-var scripts = new Set();
-function errorHandler(script) {
+var errors = [];
+window.addEventListener("error", ev => {
     var current = count++;
     debug(`${current}`);
-    scripts.add(script);
+    errors.push(ev.message);
     if (count === 3) {
-        shouldBeTrue(`scripts.has(document.getElementById("s0"))`);
-        shouldBeTrue(`scripts.has(document.getElementById("s1"))`);
-        shouldBeTrue(`scripts.has(document.getElementById("s2"))`);
+        shouldBeTrue(`errors.some(e => e.match(/incorrect/))`);
+        shouldBeTrue(`errors.some(e => e.match(/hello/))`);
+        shouldBeTrue(`errors.some(e => e.match(/test/))`);
+        shouldHaveHadError("TypeError");
         finishJSTest();
     }
-}
+});
 </script>
 <script src=""
 
-<script type="module" id="s0" _onerror_="errorHandler(this)">
+<script type="module" id="s0">
 import Incorrect from "incorrect"
 </script>
 
-<script type="module" id="s1" _onerror_="errorHandler(this)">
+<script type="module" id="s1">
 import Incorrect from "$hello"
 </script>
 
-<script type="module" id="s2" _onerror_="errorHandler(this)">
+<script type="module" id="s2">
 import Incorrect from ".../test"
 </script>
 

Modified: trunk/Source/WebCore/ChangeLog (288819 => 288820)


--- trunk/Source/WebCore/ChangeLog	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/Source/WebCore/ChangeLog	2022-01-31 19:04:30 UTC (rev 288820)
@@ -1,3 +1,49 @@
+2022-01-31  Asumu Takikawa  <[email protected]>
+
+        Fix handling of module script errors in WebCore
+        https://bugs.webkit.org/show_bug.cgi?id=218284
+
+        Reviewed by Yusuke Suzuki.
+
+        According to the HTML spec, script fetch errors get dispatched to the
+        script (with no error value), but load errors should get reported to
+        the global object and dispatched with an error value included.
+        This patch implements that behavior for module scripts.
+
+        In addition, reported errors from module scripts are never expected to
+        be muted. To implement this, we add a fromModule flag to suppress the
+        error muting in canIncludeErrorDetails.
+
+        * bindings/js/JSDOMExceptionHandling.cpp:
+        (WebCore::reportException):
+        * bindings/js/JSDOMExceptionHandling.h:
+        * bindings/js/ModuleFetchFailureKind.h:
+        * bindings/js/ScriptController.cpp:
+        (WebCore::ScriptController::evaluateInWorld):
+        (WebCore::ScriptController::setupModuleScriptHandlers):
+        (WebCore::ScriptController::callInWorld):
+        (WebCore::ScriptController::reportExceptionFromScriptError):
+        * bindings/js/ScriptController.h:
+        * bindings/js/ScriptModuleLoader.cpp:
+        (WebCore::rejectWithFetchError):
+        (WebCore::ScriptModuleLoader::fetch):
+        (WebCore::rejectPromise):
+        (WebCore::ScriptModuleLoader::notifyFinished):
+        * dom/LoadableClassicScript.cpp:
+        (WebCore::LoadableClassicScript::error const):
+        (WebCore::LoadableClassicScript::notifyFinished):
+        * dom/LoadableScript.h:
+        * dom/ScriptElement.cpp:
+        (WebCore::ScriptElement::executeScriptAndDispatchEvent):
+        * dom/ScriptExecutionContext.cpp:
+        (WebCore::ScriptExecutionContext::canIncludeErrorDetails):
+        (WebCore::ScriptExecutionContext::reportException):
+        (WebCore::ScriptExecutionContext::dispatchErrorEvent):
+        * dom/ScriptExecutionContext.h:
+        * workers/WorkerOrWorkletScriptController.cpp:
+        (WebCore::WorkerOrWorkletScriptController::loadModuleSynchronously):
+        (WebCore::WorkerOrWorkletScriptController::loadAndEvaluateModule):
+
 2022-01-31  Per Arne Vollan  <[email protected]>
 
         [iOS][WP] Restrict image decoders

Modified: trunk/Source/WebCore/bindings/js/JSDOMExceptionHandling.cpp (288819 => 288820)


--- trunk/Source/WebCore/bindings/js/JSDOMExceptionHandling.cpp	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/Source/WebCore/bindings/js/JSDOMExceptionHandling.cpp	2022-01-31 19:04:30 UTC (rev 288820)
@@ -38,7 +38,7 @@
 namespace WebCore {
 using namespace JSC;
 
-void reportException(JSGlobalObject* lexicalGlobalObject, JSValue exceptionValue, CachedScript* cachedScript)
+void reportException(JSGlobalObject* lexicalGlobalObject, JSValue exceptionValue, CachedScript* cachedScript, bool fromModule)
 {
     VM& vm = lexicalGlobalObject->vm();
     RELEASE_ASSERT(vm.currentThreadIsHoldingAPILock());
@@ -49,7 +49,7 @@
             exception = JSC::Exception::create(lexicalGlobalObject->vm(), exceptionValue, JSC::Exception::DoNotCaptureStack);
     }
 
-    reportException(lexicalGlobalObject, exception, cachedScript);
+    reportException(lexicalGlobalObject, exception, cachedScript, fromModule);
 }
 
 String retrieveErrorMessageWithoutName(JSGlobalObject& lexicalGlobalObject, VM& vm, JSValue exception, CatchScope& catchScope)
@@ -88,7 +88,7 @@
     return errorMessage;
 }
 
-void reportException(JSGlobalObject* lexicalGlobalObject, JSC::Exception* exception, CachedScript* cachedScript, ExceptionDetails* exceptionDetails)
+void reportException(JSGlobalObject* lexicalGlobalObject, JSC::Exception* exception, CachedScript* cachedScript, bool fromModule, ExceptionDetails* exceptionDetails)
 {
     VM& vm = lexicalGlobalObject->vm();
     auto scope = DECLARE_CATCH_SCOPE(vm);
@@ -119,7 +119,7 @@
     }
 
     auto errorMessage = retrieveErrorMessage(*lexicalGlobalObject, vm, exception->value(), scope);
-    globalObject->scriptExecutionContext()->reportException(errorMessage, lineNumber, columnNumber, exceptionSourceURL, exception, callStack->size() ? callStack.ptr() : nullptr, cachedScript);
+    globalObject->scriptExecutionContext()->reportException(errorMessage, lineNumber, columnNumber, exceptionSourceURL, exception, callStack->size() ? callStack.ptr() : nullptr, cachedScript, fromModule);
 
     if (exceptionDetails) {
         exceptionDetails->message = errorMessage;

Modified: trunk/Source/WebCore/bindings/js/JSDOMExceptionHandling.h (288819 => 288820)


--- trunk/Source/WebCore/bindings/js/JSDOMExceptionHandling.h	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/Source/WebCore/bindings/js/JSDOMExceptionHandling.h	2022-01-31 19:04:30 UTC (rev 288820)
@@ -65,8 +65,8 @@
 
 String retrieveErrorMessageWithoutName(JSC::JSGlobalObject&, JSC::VM&, JSC::JSValue exception, JSC::CatchScope&);
 String retrieveErrorMessage(JSC::JSGlobalObject&, JSC::VM&, JSC::JSValue exception, JSC::CatchScope&);
-WEBCORE_EXPORT void reportException(JSC::JSGlobalObject*, JSC::JSValue exception, CachedScript* = nullptr);
-WEBCORE_EXPORT void reportException(JSC::JSGlobalObject*, JSC::Exception*, CachedScript* = nullptr, ExceptionDetails* = nullptr);
+WEBCORE_EXPORT void reportException(JSC::JSGlobalObject*, JSC::JSValue exception, CachedScript* = nullptr, bool = false);
+WEBCORE_EXPORT void reportException(JSC::JSGlobalObject*, JSC::Exception*, CachedScript* = nullptr, bool = false, ExceptionDetails* = nullptr);
 void reportCurrentException(JSC::JSGlobalObject*);
 
 JSC::JSValue createDOMException(JSC::JSGlobalObject&, Exception&&);

Modified: trunk/Source/WebCore/bindings/js/ModuleFetchFailureKind.h (288819 => 288820)


--- trunk/Source/WebCore/bindings/js/ModuleFetchFailureKind.h	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/Source/WebCore/bindings/js/ModuleFetchFailureKind.h	2022-01-31 19:04:30 UTC (rev 288820)
@@ -28,8 +28,9 @@
 namespace WebCore {
 
 enum class ModuleFetchFailureKind {
-    WasErrored,
+    WasPropagatedError,
     WasCanceled,
+    WasFetchError,
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/js/ScriptController.cpp (288819 => 288820)


--- trunk/Source/WebCore/bindings/js/ScriptController.cpp	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/Source/WebCore/bindings/js/ScriptController.cpp	2022-01-31 19:04:30 UTC (rev 288820)
@@ -148,7 +148,7 @@
     std::optional<ExceptionDetails> optionalDetails;
     if (evaluationException) {
         ExceptionDetails details;
-        reportException(&globalObject, evaluationException, sourceCode.cachedScript(), &details);
+        reportException(&globalObject, evaluationException, sourceCode.cachedScript(), false, &details);
         optionalDetails = WTFMove(details);
     }
 
@@ -309,17 +309,33 @@
     auto& rejectHandler = *JSNativeStdFunction::create(lexicalGlobalObject.vm(), proxy.window(), 1, String(), [moduleScript](JSGlobalObject* globalObject, CallFrame* callFrame) {
         VM& vm = globalObject->vm();
         JSValue errorValue = callFrame->argument(0);
+        auto scope = DECLARE_CATCH_SCOPE(vm);
         if (errorValue.isObject()) {
             auto* object = JSC::asObject(errorValue);
             if (JSValue failureKindValue = object->getDirect(vm, static_cast<JSVMClientData&>(*vm.clientData).builtinNames().failureKindPrivateName())) {
                 // This is host propagated error in the module loader pipeline.
                 switch (static_cast<ModuleFetchFailureKind>(failureKindValue.asInt32())) {
-                case ModuleFetchFailureKind::WasErrored:
+                case ModuleFetchFailureKind::WasPropagatedError:
                     moduleScript->notifyLoadFailed(LoadableScript::Error {
                         LoadableScript::ErrorType::CachedScript,
+                        std::nullopt,
                         std::nullopt
                     });
                     break;
+                // For a fetch error that was not propagated from further in the
+                // pipeline, we include the console error message but do not
+                // include an error value as it should not be reported.
+                case ModuleFetchFailureKind::WasFetchError:
+                    moduleScript->notifyLoadFailed(LoadableScript::Error {
+                        LoadableScript::ErrorType::CachedScript,
+                        LoadableScript::ConsoleMessage {
+                            MessageSource::JS,
+                            MessageLevel::Error,
+                            retrieveErrorMessage(*globalObject, vm, errorValue, scope),
+                        },
+                        std::nullopt
+                    });
+                    break;
                 case ModuleFetchFailureKind::WasCanceled:
                     moduleScript->notifyLoadWasCanceled();
                     break;
@@ -328,7 +344,6 @@
             }
         }
 
-        auto scope = DECLARE_CATCH_SCOPE(vm);
         moduleScript->notifyLoadFailed(LoadableScript::Error {
             LoadableScript::ErrorType::CachedScript,
             LoadableScript::ConsoleMessage {
@@ -335,7 +350,10 @@
                 MessageSource::JS,
                 MessageLevel::Error,
                 retrieveErrorMessage(*globalObject, vm, errorValue, scope),
-            }
+            },
+            // The error value is included so that it can be reported to the
+            // appropriate global object.
+            errorValue
         });
         return JSValue::encode(jsUndefined());
     });
@@ -650,7 +668,7 @@
 
     if (evaluationException && !optionalDetails) {
         ExceptionDetails details;
-        reportException(&globalObject, evaluationException, sourceCode.cachedScript(), &details);
+        reportException(&globalObject, evaluationException, sourceCode.cachedScript(), false, &details);
         optionalDetails = WTFMove(details);
     }
 
@@ -831,6 +849,18 @@
     }
 }
 
+void ScriptController::reportExceptionFromScriptError(LoadableScript::Error error, bool isModule)
+{
+    auto& world = mainThreadNormalWorld();
+    JSC::VM& vm = world.vm();
+    JSLockHolder lock(vm);
+
+    auto& proxy = jsWindowProxy(world);
+    auto& lexicalGlobalObject = *proxy.window();
+
+    reportException(&lexicalGlobalObject, error.errorValue.value(), nullptr, isModule);
+}
+
 } // namespace WebCore
 
 #undef SCRIPTCONTROLLER_RELEASE_LOG_ERROR

Modified: trunk/Source/WebCore/bindings/js/ScriptController.h (288819 => 288820)


--- trunk/Source/WebCore/bindings/js/ScriptController.h	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/Source/WebCore/bindings/js/ScriptController.h	2022-01-31 19:04:30 UTC (rev 288820)
@@ -23,6 +23,7 @@
 
 #include "FrameLoaderTypes.h"
 #include "JSWindowProxy.h"
+#include "LoadableScript.h"
 #include "SerializedScriptValue.h"
 #include "WindowProxy.h"
 #include <_javascript_Core/JSBase.h>
@@ -168,6 +169,8 @@
 
     bool willReplaceWithResultOfExecutingJavascriptURL() const { return m_willReplaceWithResultOfExecutingJavascriptURL; }
 
+    void reportExceptionFromScriptError(LoadableScript::Error, bool);
+
 private:
     ValueOrException executeUserAgentScriptInWorldInternal(DOMWrapperWorld&, RunJavaScriptParameters&&);
     ValueOrException executeScriptInWorld(DOMWrapperWorld&, RunJavaScriptParameters&&);

Modified: trunk/Source/WebCore/bindings/js/ScriptModuleLoader.cpp (288819 => 288820)


--- trunk/Source/WebCore/bindings/js/ScriptModuleLoader.cpp	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/Source/WebCore/bindings/js/ScriptModuleLoader.cpp	2022-01-31 19:04:30 UTC (rev 288820)
@@ -154,6 +154,18 @@
     });
 }
 
+static void rejectWithFetchError(DeferredPromise& deferred, ExceptionCode ec, const String& message)
+{
+    // Used to signal to the promise client that the failure was from a fetch, but not one that was propagated from another context.
+    deferred.rejectWithCallback([&] (JSDOMGlobalObject& jsGlobalObject) {
+        JSC::VM& vm = jsGlobalObject.vm();
+        JSC::JSObject* error = jsCast<JSObject*>(createDOMException(&jsGlobalObject, ec, message));
+        ASSERT(error);
+        error->putDirect(vm, static_cast<JSVMClientData&>(*vm.clientData).builtinNames().failureKindPrivateName(), JSC::jsNumber(static_cast<int32_t>(ModuleFetchFailureKind::WasFetchError)));
+        return error;
+    });
+}
+
 JSC::JSInternalPromise* ScriptModuleLoader::fetch(JSC::JSGlobalObject* jsGlobalObject, JSC::JSModuleLoader*, JSC::JSValue moduleKeyValue, JSC::JSValue parameters, JSC::JSValue scriptFetcher)
 {
     JSC::VM& vm = jsGlobalObject->vm();
@@ -164,12 +176,12 @@
     RELEASE_ASSERT(jsPromise);
     auto deferred = DeferredPromise::create(globalObject, *jsPromise);
     if (moduleKeyValue.isSymbol()) {
-        deferred->reject(TypeError, "Symbol module key should be already fulfilled with the inlined resource."_s);
+        rejectWithFetchError(deferred.get(), TypeError, "Symbol module key should be already fulfilled with the inlined resource."_s);
         return jsPromise;
     }
 
     if (!moduleKeyValue.isString()) {
-        deferred->reject(TypeError, "Module key is not Symbol or String."_s);
+        rejectWithFetchError(deferred.get(), TypeError, "Module key is not Symbol or String."_s);
         return jsPromise;
     }
 
@@ -177,7 +189,7 @@
 
     URL completedURL(URL(), asString(moduleKeyValue)->value(jsGlobalObject));
     if (!completedURL.isValid()) {
-        deferred->reject(TypeError, "Module key is a valid URL."_s);
+        rejectWithFetchError(deferred.get(), TypeError, "Module key is a valid URL."_s);
         return jsPromise;
     }
 
@@ -191,7 +203,7 @@
         if (!loader->load(downcast<Document>(m_context), WTFMove(completedURL))) {
             loader->clearClient();
             m_loaders.remove(WTFMove(loader));
-            rejectToPropagateNetworkError(deferred.get(), ModuleFetchFailureKind::WasErrored, "Importing a module script failed."_s);
+            rejectToPropagateNetworkError(deferred.get(), ModuleFetchFailureKind::WasPropagatedError, "Importing a module script failed."_s);
             return jsPromise;
         }
     } else {
@@ -270,7 +282,7 @@
     auto* jsPromise = JSC::JSInternalPromise::create(globalObject.vm(), globalObject.internalPromiseStructure());
     RELEASE_ASSERT(jsPromise);
     auto deferred = DeferredPromise::create(globalObject, *jsPromise);
-    deferred->reject(ec, WTFMove(message));
+    rejectWithFetchError(deferred.get(), ec, WTFMove(message));
     return jsPromise;
 }
 
@@ -388,12 +400,12 @@
         auto& cachedScript = *loader.cachedScript();
 
         if (cachedScript.resourceError().isAccessControl()) {
-            rejectToPropagateNetworkError(promise.get(), ModuleFetchFailureKind::WasErrored, "Cross-origin script load denied by Cross-Origin Resource Sharing policy."_s);
+            rejectToPropagateNetworkError(promise.get(), ModuleFetchFailureKind::WasPropagatedError, "Cross-origin script load denied by Cross-Origin Resource Sharing policy."_s);
             return;
         }
 
         if (cachedScript.errorOccurred()) {
-            rejectToPropagateNetworkError(promise.get(), ModuleFetchFailureKind::WasErrored, "Importing a module script failed."_s);
+            rejectToPropagateNetworkError(promise.get(), ModuleFetchFailureKind::WasPropagatedError, "Importing a module script failed."_s);
             return;
         }
 
@@ -406,7 +418,7 @@
             // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script
             // The result of extracting a MIME type from response's header list (ignoring parameters) is not a _javascript_ MIME type.
             // For historical reasons, fetching a classic script does not include MIME type checking. In contrast, module scripts will fail to load if they are not of a correct MIME type.
-            promise->reject(TypeError, makeString("'", cachedScript.response().mimeType(), "' is not a valid _javascript_ MIME type."));
+            rejectWithFetchError(promise.get(), TypeError, makeString("'", cachedScript.response().mimeType(), "' is not a valid _javascript_ MIME type."));
             return;
         }
 
@@ -413,7 +425,7 @@
         if (auto* parameters = loader.parameters()) {
             if (!matchIntegrityMetadata(cachedScript, parameters->integrity())) {
                 m_context.addConsoleMessage(MessageSource::Security, MessageLevel::Error, makeString("Cannot load script ", integrityMismatchDescription(cachedScript, parameters->integrity())));
-                promise->reject(TypeError, "Cannot load script due to integrity mismatch"_s);
+                rejectWithFetchError(promise.get(), TypeError, "Cannot load script due to integrity mismatch"_s);
                 return;
             }
         }
@@ -432,7 +444,7 @@
             auto& workerScriptLoader = loader.scriptLoader();
             ASSERT(workerScriptLoader.failed());
             if (workerScriptLoader.error().isAccessControl()) {
-                rejectToPropagateNetworkError(promise.get(), ModuleFetchFailureKind::WasErrored, "Cross-origin script load denied by Cross-Origin Resource Sharing policy."_s);
+                rejectToPropagateNetworkError(promise.get(), ModuleFetchFailureKind::WasPropagatedError, "Cross-origin script load denied by Cross-Origin Resource Sharing policy."_s);
                 return;
             }
 
@@ -441,7 +453,7 @@
                 return;
             }
 
-            rejectToPropagateNetworkError(promise.get(), ModuleFetchFailureKind::WasErrored, "Importing a module script failed."_s);
+            rejectToPropagateNetworkError(promise.get(), ModuleFetchFailureKind::WasPropagatedError, "Importing a module script failed."_s);
             return;
         }
 
@@ -449,7 +461,7 @@
             // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script
             // The result of extracting a MIME type from response's header list (ignoring parameters) is not a _javascript_ MIME type.
             // For historical reasons, fetching a classic script does not include MIME type checking. In contrast, module scripts will fail to load if they are not of a correct MIME type.
-            promise->reject(TypeError, makeString("'", loader.responseMIMEType(), "' is not a valid _javascript_ MIME type."));
+            rejectWithFetchError(promise.get(), TypeError, makeString("'", loader.responseMIMEType(), "' is not a valid _javascript_ MIME type."));
             return;
         }
 

Modified: trunk/Source/WebCore/dom/LoadableClassicScript.cpp (288819 => 288820)


--- trunk/Source/WebCore/dom/LoadableClassicScript.cpp	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/Source/WebCore/dom/LoadableClassicScript.cpp	2022-01-31 19:04:30 UTC (rev 288820)
@@ -60,7 +60,7 @@
         return m_error;
 
     if (m_cachedScript->errorOccurred())
-        return Error { ErrorType::CachedScript, std::nullopt };
+        return Error { ErrorType::CachedScript, std::nullopt, std::nullopt };
 
     return std::nullopt;
 }
@@ -82,7 +82,8 @@
                 MessageSource::JS,
                 MessageLevel::Error,
                 consoleMessage
-            }
+            },
+            std::nullopt
         };
     }
 
@@ -93,7 +94,8 @@
                 MessageSource::Security,
                 MessageLevel::Error,
                 makeString("Refused to execute ", m_cachedScript->url().stringCenterEllipsizedToLength(), " as script because \"X-Content-Type-Options: nosniff\" was given and its Content-Type is not a script MIME type.")
-            }
+            },
+            std::nullopt
         };
     }
 
@@ -104,7 +106,8 @@
                 MessageSource::Security,
                 MessageLevel::Error,
                 makeString("Refused to execute ", m_cachedScript->url().stringCenterEllipsizedToLength(), " as script because ", m_cachedScript->response().mimeType(), " is not a script MIME type.")
-            }
+            },
+            std::nullopt
         };
     }
 
@@ -111,7 +114,8 @@
     if (!m_error && !resource.errorOccurred() && !matchIntegrityMetadata(resource, m_integrity)) {
         m_error = Error {
             ErrorType::FailedIntegrityCheck,
-            ConsoleMessage { MessageSource::Security, MessageLevel::Error, makeString("Cannot load script ", integrityMismatchDescription(resource, m_integrity)) }
+            ConsoleMessage { MessageSource::Security, MessageLevel::Error, makeString("Cannot load script ", integrityMismatchDescription(resource, m_integrity)) },
+            std::nullopt
         };
     }
 

Modified: trunk/Source/WebCore/dom/LoadableScript.h (288819 => 288820)


--- trunk/Source/WebCore/dom/LoadableScript.h	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/Source/WebCore/dom/LoadableScript.h	2022-01-31 19:04:30 UTC (rev 288820)
@@ -27,6 +27,7 @@
 
 #include "ScriptElementCachedScriptFetcher.h"
 #include <_javascript_Core/ConsoleTypes.h>
+#include <_javascript_Core/JSCJSValue.h>
 #include <wtf/HashCountedSet.h>
 #include <wtf/text/WTFString.h>
 
@@ -54,6 +55,7 @@
     struct Error {
         ErrorType type;
         std::optional<ConsoleMessage> consoleMessage;
+        std::optional<JSC::JSValue> errorValue;
     };
 
     virtual ~LoadableScript() = default;

Modified: trunk/Source/WebCore/dom/ScriptElement.cpp (288819 => 288820)


--- trunk/Source/WebCore/dom/ScriptElement.cpp	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/Source/WebCore/dom/ScriptElement.cpp	2022-01-31 19:04:30 UTC (rev 288820)
@@ -444,9 +444,21 @@
 void ScriptElement::executeScriptAndDispatchEvent(LoadableScript& loadableScript)
 {
     if (std::optional<LoadableScript::Error> error = loadableScript.error()) {
-        if (std::optional<LoadableScript::ConsoleMessage> message = error->consoleMessage)
-            m_element.document().addConsoleMessage(message->source, message->level, message->message);
-        dispatchErrorEvent();
+        if (error->errorValue) {
+            // https://html.spec.whatwg.org/multipage/webappapis.html#report-the-exception
+            // An error value is present when there is a load failure that was
+            // not triggered during fetching. In this case, we need to report
+            // the exception to the global object.
+            if (auto* frame = m_element.document().frame())
+                frame->script().reportExceptionFromScriptError(error.value(), loadableScript.isModuleScript());
+        } else {
+            // https://html.spec.whatwg.org/multipage/scripting.html#execute-the-script-block
+            // When the script is "null" due to a fetch error, an error event
+            // should be dispatched for the script element.
+            if (std::optional<LoadableScript::ConsoleMessage> message = error->consoleMessage)
+                m_element.document().addConsoleMessage(message->source, message->level, message->message);
+            dispatchErrorEvent();
+        }
     } else if (!loadableScript.wasCanceled()) {
         ASSERT(!loadableScript.error());
         loadableScript.execute(*this);

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.cpp (288819 => 288820)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2022-01-31 19:04:30 UTC (rev 288820)
@@ -382,9 +382,12 @@
 }
 
 // FIXME: Should this function be in SecurityContext or SecurityOrigin instead?
-bool ScriptExecutionContext::canIncludeErrorDetails(CachedScript* script, const String& sourceURL)
+bool ScriptExecutionContext::canIncludeErrorDetails(CachedScript* script, const String& sourceURL, bool fromModule)
 {
     ASSERT(securityOrigin());
+    // Errors from module scripts are never muted.
+    if (fromModule)
+        return true;
     if (script) {
         ASSERT(script->origin());
         ASSERT(securityOrigin()->toString() == script->origin()->toString());
@@ -393,7 +396,7 @@
     return securityOrigin()->canRequest(completeURL(sourceURL));
 }
 
-void ScriptExecutionContext::reportException(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL, JSC::Exception* exception, RefPtr<ScriptCallStack>&& callStack, CachedScript* cachedScript)
+void ScriptExecutionContext::reportException(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL, JSC::Exception* exception, RefPtr<ScriptCallStack>&& callStack, CachedScript* cachedScript, bool fromModule)
 {
     if (m_inDispatchErrorEvent) {
         if (!m_pendingExceptions)
@@ -403,7 +406,7 @@
     }
 
     // First report the original exception and only then all the nested ones.
-    if (!dispatchErrorEvent(errorMessage, lineNumber, columnNumber, sourceURL, exception, cachedScript))
+    if (!dispatchErrorEvent(errorMessage, lineNumber, columnNumber, sourceURL, exception, cachedScript, fromModule))
         logExceptionToConsole(errorMessage, sourceURL, lineNumber, columnNumber, callStack.copyRef());
 
     if (!m_pendingExceptions)
@@ -459,7 +462,7 @@
     addMessage(source, level, message, sourceURL, lineNumber, columnNumber, nullptr, state, requestIdentifier);
 }
 
-bool ScriptExecutionContext::dispatchErrorEvent(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL, JSC::Exception* exception, CachedScript* cachedScript)
+bool ScriptExecutionContext::dispatchErrorEvent(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL, JSC::Exception* exception, CachedScript* cachedScript, bool fromModule)
 {
     auto* target = errorEventTarget();
     if (!target)
@@ -466,7 +469,7 @@
         return false;
 
     RefPtr<ErrorEvent> errorEvent;
-    if (canIncludeErrorDetails(cachedScript, sourceURL))
+    if (canIncludeErrorDetails(cachedScript, sourceURL, fromModule))
         errorEvent = ErrorEvent::create(errorMessage, sourceURL, lineNumber, columnNumber, { vm(), exception ? exception->value() : JSC::jsNull() });
     else
         errorEvent = ErrorEvent::create("Script error."_s, { }, 0, 0, { });

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (288819 => 288820)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.h	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h	2022-01-31 19:04:30 UTC (rev 288820)
@@ -124,8 +124,8 @@
 
     virtual String resourceRequestIdentifier() const { return String(); };
 
-    bool canIncludeErrorDetails(CachedScript*, const String& sourceURL);
-    void reportException(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL, JSC::Exception*, RefPtr<Inspector::ScriptCallStack>&&, CachedScript* = nullptr);
+    bool canIncludeErrorDetails(CachedScript*, const String& sourceURL, bool = false);
+    void reportException(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL, JSC::Exception*, RefPtr<Inspector::ScriptCallStack>&&, CachedScript* = nullptr, bool = false);
     void reportUnhandledPromiseRejection(JSC::JSGlobalObject&, JSC::JSPromise&, RefPtr<Inspector::ScriptCallStack>&&);
 
     virtual void addConsoleMessage(std::unique_ptr<Inspector::ConsoleMessage>&&) = 0;
@@ -315,7 +315,7 @@
     virtual void addMessage(MessageSource, MessageLevel, const String& message, const String& sourceURL, unsigned lineNumber, unsigned columnNumber, RefPtr<Inspector::ScriptCallStack>&&, JSC::JSGlobalObject* = nullptr, unsigned long requestIdentifier = 0) = 0;
     virtual void logExceptionToConsole(const String& errorMessage, const String& sourceURL, int lineNumber, int columnNumber, RefPtr<Inspector::ScriptCallStack>&&) = 0;
 
-    bool dispatchErrorEvent(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL, JSC::Exception*, CachedScript*);
+    bool dispatchErrorEvent(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL, JSC::Exception*, CachedScript*, bool);
 
     virtual void refScriptExecutionContext() = 0;
     virtual void derefScriptExecutionContext() = 0;

Modified: trunk/Source/WebCore/workers/WorkerOrWorkletScriptController.cpp (288819 => 288820)


--- trunk/Source/WebCore/workers/WorkerOrWorkletScriptController.cpp	2022-01-31 18:11:26 UTC (rev 288819)
+++ trunk/Source/WebCore/workers/WorkerOrWorkletScriptController.cpp	2022-01-31 19:04:30 UTC (rev 288820)
@@ -299,17 +299,33 @@
             VM& vm = globalObject->vm();
             JSLockHolder lock { vm };
             JSValue errorValue = callFrame->argument(0);
+            auto scope = DECLARE_CATCH_SCOPE(vm);
             if (errorValue.isObject()) {
                 auto* object = JSC::asObject(errorValue);
                 if (JSValue failureKindValue = object->getDirect(vm, static_cast<JSVMClientData&>(*vm.clientData).builtinNames().failureKindPrivateName())) {
                     // This is host propagated error in the module loader pipeline.
                     switch (static_cast<ModuleFetchFailureKind>(failureKindValue.asInt32())) {
-                    case ModuleFetchFailureKind::WasErrored:
+                    case ModuleFetchFailureKind::WasPropagatedError:
                         protector->notifyLoadFailed(LoadableScript::Error {
                             LoadableScript::ErrorType::CachedScript,
+                            std::nullopt,
                             std::nullopt
                         });
                         break;
+                    // For a fetch error that was not propagated from further in the
+                    // pipeline, we include the console error message but do not
+                    // include an error value as it should not be reported.
+                    case ModuleFetchFailureKind::WasFetchError:
+                        protector->notifyLoadFailed(LoadableScript::Error {
+                            LoadableScript::ErrorType::CachedScript,
+                            LoadableScript::ConsoleMessage {
+                                MessageSource::JS,
+                                MessageLevel::Error,
+                                retrieveErrorMessage(*globalObject, vm, errorValue, scope),
+                            },
+                            std::nullopt
+                        });
+                        break;
                     case ModuleFetchFailureKind::WasCanceled:
                         protector->notifyLoadWasCanceled();
                         break;
@@ -318,7 +334,6 @@
                 }
             }
 
-            auto scope = DECLARE_CATCH_SCOPE(vm);
             protector->notifyLoadFailed(LoadableScript::Error {
                 LoadableScript::ErrorType::CachedScript,
                 LoadableScript::ConsoleMessage {
@@ -325,7 +340,10 @@
                     MessageSource::JS,
                     MessageLevel::Error,
                     retrieveErrorMessage(*globalObject, vm, errorValue, scope),
-                }
+                },
+                // The error value may need to be propagated here as it is in
+                // ScriptController in the future.
+                std::nullopt
             });
             return JSValue::encode(jsUndefined());
         });
@@ -452,10 +470,18 @@
             JSValue errorValue = callFrame->argument(0);
             if (errorValue.isObject()) {
                 auto* object = JSC::asObject(errorValue);
-                if (object->getDirect(vm, static_cast<JSVMClientData&>(*vm.clientData).builtinNames().failureKindPrivateName())) {
+                if (JSValue failureKindValue = object->getDirect(vm, static_cast<JSVMClientData&>(*vm.clientData).builtinNames().failureKindPrivateName())) {
                     auto catchScope = DECLARE_CATCH_SCOPE(vm);
                     String message = retrieveErrorMessageWithoutName(*globalObject, vm, object, catchScope);
-                    task->run(Exception { AbortError, message });
+                    switch (static_cast<ModuleFetchFailureKind>(failureKindValue.asInt32())) {
+                    case ModuleFetchFailureKind::WasFetchError:
+                        task->run(Exception { TypeError, message });
+                        break;
+                    case ModuleFetchFailureKind::WasPropagatedError:
+                    case ModuleFetchFailureKind::WasCanceled:
+                        task->run(Exception { AbortError, message });
+                        break;
+                    }
                     return JSValue::encode(jsUndefined());
                 }
                 if (object->inherits<ErrorInstance>(vm)) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to