Propagate networking errors correctly for import() operator
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Feb 2017 10:00:32 +0000 (10:00 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Feb 2017 10:00:32 +0000 (10:00 +0000)
commit379f793a46c3b7f31e13137c6f2130e98741b6c0
tree7fc6e9eca55e37c68760219cf3cf8b0aa7930bcb
parentc23270cccf43ac74d6ad052a2d886aafb910a98b
Propagate networking errors correctly for import() operator
https://bugs.webkit.org/show_bug.cgi?id=167501

Reviewed by Ryosuke Niwa.

.:

* Source/ModuleFetchFailureKind.h: Added.

Source/WebCore:

We use the promise chain inside the module loader pipeline.
The problem is that,

1. The errors of loading module scripts are propagated through the promise's rejection.
2. Some module related errors like syntax error (when scanning module dependencies) are
   reported at loading time (evaluating time). These errors are propagated through the
   promise rejections and dumped to the console. LoadableModuleScript set catch handler
   for that and print these errors to the console for ScriptElement.
3. Some of errors are already reported to the console. For example, networking errors
   are reported by the CachedModuleLoader.
4. But there is no way to distinguish between (2) and (3) at the catch handler.

Previously, we propagate the special symbol for the already reported errors to distinguish
that. This was OK because these errors cannot be catched by the user code. However,
recent `import()` call needs to expose these errors to the user code. So now, accidentally,
the special purpose symbol is exposed.

Instead of propagating the special symbol, this patch just propagates the errors. But these
error objects are annotated with the private symbol. So these errors can be distinguished
from the other ones.

Currently, we do not have the way to expose the error details to the client of the
CachedScript. So we just report the error with the failed / canceled. This should be
more descriptive error messages in the separate patch[1].

[1]: https://bugs.webkit.org/show_bug.cgi?id=167553

Tests: http/tests/security/mixedContent/import-insecure-script-in-iframe.html
       js/dom/modules/import-not-found-error.html

* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSDOMPromise.h:
(WebCore::DeferredPromise::resolveWithCallback):
(WebCore::DeferredPromise::rejectWithCallback):
* bindings/js/ScriptController.cpp:
(WebCore::ScriptController::setupModuleScriptHandlers):
* bindings/js/ScriptController.h:
(WebCore::ScriptController::moduleLoaderAlreadyReportedErrorSymbol): Deleted.
(WebCore::ScriptController::moduleLoaderFetchingIsCanceledSymbol): Deleted.
* bindings/js/ScriptModuleLoader.cpp:
(WebCore::rejectToPropagateNetworkError):
(WebCore::ScriptModuleLoader::fetch):
(WebCore::ScriptModuleLoader::notifyFinished):
* bindings/js/WebCoreBuiltinNames.h:

LayoutTests:

* http/tests/security/mixedContent/import-insecure-script-in-iframe-expected.txt: Added.
* http/tests/security/mixedContent/import-insecure-script-in-iframe.html: Added.
* http/tests/security/mixedContent/resources/frame-with-insecure-import.html: Added.
* js/dom/modules/import-not-found-error-expected.txt: Added.
* js/dom/modules/import-not-found-error.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@211473 268f45cc-cd09-0410-ab3c-d52691b4dbfc
15 files changed:
ChangeLog
LayoutTests/ChangeLog
LayoutTests/http/tests/security/mixedContent/import-insecure-script-in-iframe-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/security/mixedContent/import-insecure-script-in-iframe.html [new file with mode: 0644]
LayoutTests/http/tests/security/mixedContent/resources/frame-with-insecure-import.html [new file with mode: 0644]
LayoutTests/js/dom/modules/import-not-found-error-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/modules/import-not-found-error.html [new file with mode: 0644]
Source/ModuleFetchFailureKind.h [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSDOMPromise.h
Source/WebCore/bindings/js/ScriptController.cpp
Source/WebCore/bindings/js/ScriptController.h
Source/WebCore/bindings/js/ScriptModuleLoader.cpp
Source/WebCore/bindings/js/WebCoreBuiltinNames.h