[JSC] Retry module fetching if previous request fails
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Nov 2017 05:28:34 +0000 (05:28 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Nov 2017 05:28:34 +0000 (05:28 +0000)
commit35d7265aeafa27e2d092254b7f48542bf704f485
tree67cd30a2909ac41a3bb4d1a3253f4f5087c62d01
parentaf503c4885baf588fe3b88b8d95a08be8ed61788
[JSC] Retry module fetching if previous request fails
https://bugs.webkit.org/show_bug.cgi?id=178168

Reviewed by Saam Barati.

Source/JavaScriptCore:

According to the latest spec, the failed fetching operation can be retried if it is requested again.
For example,

    <script type="module" integrity="shaXXX-bad" src="./A.js"></script>
    <script type="module" integrity="shaXXX-correct" src="./A.js"></script>

When performing the first module fetching, integrity check fails, and the load of this module becomes failed.
But when loading the second module, we do not use the cached failure result in the first module loading.
We retry fetching for "./A.js". In this case, we have a correct integrity and module fetching succeeds.
This is specified in whatwg/HTML[1]. If the fetching fails, we do not cache it.

Interestingly, fetching result and instantiation result will be cached if they succeeds. This is because we would
like to cache modules based on their URLs. As a result,

    <script type="module" integrity="shaXXX-correct" src="./A.js"></script>
    <script type="module" integrity="shaXXX-bad" src="./A.js"></script>

In the above case, the first loading succeeds. And the second loading also succeeds since the succeeded fetching and
instantiation are cached in the module pipeline.

This patch implements the above semantics. Previously, our module pipeline always caches the result. If the fetching
failed, all the subsequent fetching for the same URL fails even if we have different integrity values. We retry fetching
if the previous one fails. As an overview of our change,

1. Fetching result should be cached only if it succeeds. Two or more on-the-fly fetching requests to the same URLs should
   be unified. But if currently executing one fails, other attempts should retry fetching.

2. Instantiation should be cached if fetching succeeds.

3. Satisfying should be cached if it succeeds.

[1]: https://html.spec.whatwg.org/#fetch-a-single-module-script

* builtins/ModuleLoaderPrototype.js:
(requestFetch):
(requestInstantiate):
(requestSatisfy):
(link):
(loadModule):
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):

LayoutTests:

* js/dom/modules/module-fetch-failure-not-cached-expected.txt: Added.
* js/dom/modules/module-fetch-failure-not-cached.html: Added.
* js/dom/modules/module-integrity-bad-value-success-with-cache-expected.txt: Added.
* js/dom/modules/module-integrity-bad-value-success-with-cache.html: Added.
* js/dom/modules/script-tests/module-fetch-failure-not-cached.js: Added.
* js/dom/modules/script-tests/module-integrity-bad-value-success-with-cache.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224662 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/js/dom/modules/module-fetch-failure-not-cached-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/modules/module-fetch-failure-not-cached.html [new file with mode: 0644]
LayoutTests/js/dom/modules/module-integrity-bad-value-success-with-cache-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/modules/module-integrity-bad-value-success-with-cache.html [new file with mode: 0644]
LayoutTests/js/dom/modules/script-tests/module-fetch-failure-not-cached.js [new file with mode: 0644]
LayoutTests/js/dom/modules/script-tests/module-integrity-bad-value-success-with-cache.js [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/builtins/ModuleLoaderPrototype.js
Source/JavaScriptCore/runtime/JSGlobalObject.cpp