importScripts() should throw exception with a reason when it fails to load a script...
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Apr 2018 19:12:28 +0000 (19:12 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Apr 2018 19:12:28 +0000 (19:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184345

Reviewed by Alexey Proskuryakov.

Source/WebCore:

Currently importScripts() throws a NetworkError exception without a reason when
it fails to load a script from the network. It is ambiguous whether the load failed
due to an access control failure or some other error. Instead we should include
the reason the load failed in the thrown exception.

* workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::importScripts):

LayoutTests:

Update expected results.

* http/tests/security/contentSecurityPolicy/worker-blob-inherits-csp-importScripts-redirect-cross-origin-blocked-expected.txt:
* http/tests/security/contentSecurityPolicy/worker-csp-importScripts-redirect-cross-origin-blocked-expected.txt:
* http/tests/workers/worker-importScripts-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230345 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/security/contentSecurityPolicy/worker-blob-inherits-csp-importScripts-redirect-cross-origin-blocked-expected.txt
LayoutTests/http/tests/security/contentSecurityPolicy/worker-csp-importScripts-redirect-cross-origin-blocked-expected.txt
LayoutTests/http/tests/workers/worker-importScripts-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/workers/WorkerGlobalScope.cpp

index fc7ec5c..d0399c7 100644 (file)
@@ -1,3 +1,16 @@
+2018-04-06  Daniel Bates  <dabates@apple.com>
+
+        importScripts() should throw exception with a reason when it fails to load a script from the network
+        https://bugs.webkit.org/show_bug.cgi?id=184345
+
+        Reviewed by Alexey Proskuryakov.
+
+        Update expected results.
+
+        * http/tests/security/contentSecurityPolicy/worker-blob-inherits-csp-importScripts-redirect-cross-origin-blocked-expected.txt:
+        * http/tests/security/contentSecurityPolicy/worker-csp-importScripts-redirect-cross-origin-blocked-expected.txt:
+        * http/tests/workers/worker-importScripts-expected.txt:
+
 2018-04-06  Ryan Haddad  <ryanhaddad@apple.com>
 
         Remove pass expectation for LayoutTest imported/w3c/web-platform-tests/FileAPI/url/sandboxed-iframe.html
index 263732c..35ffae8 100644 (file)
@@ -1,3 +1,3 @@
 This tests that the Content Security Policy of the parent origin (this page) blocks a Web Worker from importing a script from a different origin, not listed in script-src, through a redirect.
 
-PASS threw exception NetworkError:  A network error occurred..
+PASS threw exception NetworkError: Cross-origin redirection denied by Content Security Policy..
index bcdc120..9154893 100644 (file)
@@ -1,3 +1,3 @@
 This tests a Web Worker with Content Security Policy "script-src 'self'" blocks the import of a script from a different origin through a redirect.
 
-PASS threw exception NetworkError:  A network error occurred..
+PASS threw exception NetworkError: Cross-origin redirection denied by Content Security Policy..
index 5593c3f..3171db8 100644 (file)
@@ -24,7 +24,7 @@ Loaded message from different origin
 Loaded resource 2
 PASS: all resources executed.
 Loaded resource 1
-PASS: Threw NetworkError: A network error occurred. when load failed
+PASS: Threw NetworkError: Failed to load script when load failed
 PASS: some resources were loaded despite the network error
 Loaded resource 1
 PASS: Threw SyntaxError: Unexpected identifier 'syntax' when encountering a syntax error in imported script
index 2722be1..e676fc5 100644 (file)
@@ -1,5 +1,20 @@
 2018-04-06  Daniel Bates  <dabates@apple.com>
 
+        importScripts() should throw exception with a reason when it fails to load a script from the network
+        https://bugs.webkit.org/show_bug.cgi?id=184345
+
+        Reviewed by Alexey Proskuryakov.
+
+        Currently importScripts() throws a NetworkError exception without a reason when
+        it fails to load a script from the network. It is ambiguous whether the load failed
+        due to an access control failure or some other error. Instead we should include
+        the reason the load failed in the thrown exception.
+
+        * workers/WorkerGlobalScope.cpp:
+        (WebCore::WorkerGlobalScope::importScripts):
+
+2018-04-06  Daniel Bates  <dabates@apple.com>
+
         Attempt to fix the build after <https://trac.webkit.org/changeset/230338>
         (https://bugs.webkit.org/show_bug.cgi?id=184360)
 
index 3dc5631..ce125b7 100644 (file)
@@ -289,7 +289,7 @@ ExceptionOr<void> WorkerGlobalScope::importScripts(const Vector<String>& urls)
 
         // If the fetching attempt failed, throw a NetworkError exception and abort all these steps.
         if (scriptLoader->failed())
-            return Exception { NetworkError };
+            return Exception { NetworkError, scriptLoader->error().localizedDescription() };
 
 #if ENABLE(SERVICE_WORKER)
         if (isServiceWorkerGlobalScope && !MIMETypeRegistry::isSupportedJavaScriptMIMEType(scriptLoader->responseMIMEType()))