Changeset 223237 in webkit


Ignore:
Timestamp:
Oct 12, 2017 6:12:48 AM (7 years ago)
Author:
Yusuke Suzuki
Message:

Support integrity="" on module scripts
https://bugs.webkit.org/show_bug.cgi?id=177959

Reviewed by Sam Weinig.

Source/JavaScriptCore:

This patch adds Subresource Integrity check for module scripts. Currently,
only top-level module can be verified with integrity parameter since there
is no way to perform integrity check onto the imported modules.

In JSC side, we add parameters to the entry point of the module loader
pipeline. This is fetching parameters and used when fetching modules.

We separately pass this parameters to the pipeline along with the script fetcher.
The script fetcher is only one for module graph since this is the initiator of
this module graph loading. On the other hand, this parameters is for each
module fetching. While setting "integrity" parameters to this script fetcher is
sufficient to pass parameters to top-level-module's fetching, it is not enough
for the future extension.

In the future, we will investigate a way to pass parameters to each non-top-level
module. At that time, this parameters should be per-module. This is because
"integrity" value should be different for each module. For example, we will accept
some form of syntax to add parameters to import. Some proposed syntax is like
https://discourse.wicg.io/t/specifying-nonce-or-integrity-when-importing-modules/1861

import "./xxx.js" integrity "xxxxxxx"

In this case, this parameters will be passed to "./xxx.js" module fetching. This
parameters should be different from the one of top-level-module's one. That's why
we need per-module parameters and why this patch adds parameters to the module pipeline.

On the other hand, we also want to keep script fetcher. This per-module-graph thing
is important to offer module-graph-wide information. For example, import.meta would
have import.meta.scriptElement, which is the script element fetching the module graph
including this. So, we keep the both, script fetcher and parameters.
https://github.com/tc39/proposal-import-meta

This parameters will be finally used by pipeline's fetch hook, and WebCore side
can use this parameters to fetch modules.

We also further clean up the module pipeline by dropping unnecessary features.

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • Sources.txt:
  • builtins/ModuleLoaderPrototype.js:

(requestFetch):
(requestInstantiate):
(requestSatisfy):
(loadModule):
(loadAndEvaluateModule):
This loadAndEvaluateModule should be implemented by just calling loadModule and
linkAndEvaluateModule. We can drop requestReady and requestLink.

(requestLink): Deleted.
(requestImportModule): Deleted.

  • jsc.cpp:

(GlobalObject::moduleLoaderImportModule):
(GlobalObject::moduleLoaderFetch):
import and fetch hook takes parameters. Currently, we always pass undefined for
import hook. When dynamic import() is extended to accept additional parameters
like integrity, this parameters will be replaced with the actual value.

(functionLoadModule):
(runWithOptions):

  • runtime/Completion.cpp:

(JSC::loadAndEvaluateModule):
(JSC::loadModule):
(JSC::importModule):

  • runtime/Completion.h:
  • runtime/JSGlobalObject.h:
  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::globalFuncImportModule):

  • runtime/JSModuleLoader.cpp:

(JSC::JSModuleLoader::loadAndEvaluateModule):
(JSC::JSModuleLoader::loadModule):
(JSC::JSModuleLoader::requestImportModule):
(JSC::JSModuleLoader::importModule):
(JSC::JSModuleLoader::fetch):

  • runtime/JSModuleLoader.h:
  • runtime/JSScriptFetchParameters.cpp: Added.

(JSC::JSScriptFetchParameters::destroy):

  • runtime/JSScriptFetchParameters.h: Added.

(JSC::JSScriptFetchParameters::createStructure):
(JSC::JSScriptFetchParameters::create):
(JSC::JSScriptFetchParameters::parameters const):
(JSC::JSScriptFetchParameters::JSScriptFetchParameters):
Add ScriptFetchParameters' JSCell wrapper, JSScriptFetchParameters.
It is used in the module pipeline.

  • runtime/JSType.h:
  • runtime/ModuleLoaderPrototype.cpp:

(JSC::moduleLoaderPrototypeFetch):

  • runtime/ScriptFetchParameters.h: Added.

(JSC::ScriptFetchParameters::~ScriptFetchParameters):
Add ScriptFetchParameters. We can define our own custom ScriptFetchParameters
by inheriting this class. WebCore creates ModuleFetchParameters by inheriting
this.

  • runtime/VM.cpp:

(JSC::VM::VM):

  • runtime/VM.h:

Source/WebCore:

This patch extends module hooks to accept fetching parameters.
When starting fetching modules, WebCore creates ModuleFetchParameters.
And this parameters is propagated to the fetch hook. Then, fetch
hook can use this parameters to fetch modules.

This parameters only contains integrity field. This "integrity" is
used to perform subresource integrity check in module loader pipeline.
And this error is just proparaged as errors in module pipeline, which
is the same to the other types of errors in module pipeline.

Test: http/tests/subresource-integrity/sri-module.html

  • ForwardingHeaders/runtime/JSScriptFetchParameters.h: Added.
  • ForwardingHeaders/runtime/ScriptFetchParameters.h: Added.
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/CachedModuleScriptLoader.cpp:

(WebCore::CachedModuleScriptLoader::create):
(WebCore::CachedModuleScriptLoader::CachedModuleScriptLoader):
Take parameters, which includes "integrity".

  • bindings/js/CachedModuleScriptLoader.h:
  • bindings/js/JSDOMWindowBase.cpp:

(WebCore::JSDOMWindowBase::moduleLoaderFetch):
(WebCore::JSDOMWindowBase::moduleLoaderImportModule):
import and fetch hooks take parameters.

  • bindings/js/JSDOMWindowBase.h:
  • bindings/js/JSMainThreadExecState.h:

(WebCore::JSMainThreadExecState::loadModule):

  • bindings/js/ScriptController.cpp:

(WebCore::ScriptController::loadModuleScriptInWorld):
(WebCore::ScriptController::loadModuleScript):
Pass parameters to the entry point of the module pipeline.

  • bindings/js/ScriptController.h:
  • bindings/js/ScriptModuleLoader.cpp:

(WebCore::ScriptModuleLoader::fetch):
If parameters are passed, we set them to CachedModuleScriptLoader.

(WebCore::ScriptModuleLoader::importModule):
Pass parameters to the entry point of dynamic import.

(WebCore::ScriptModuleLoader::notifyFinished):
If script loader has parameters, we perform subresource integrity check here.

  • bindings/js/ScriptModuleLoader.h:
  • dom/LoadableModuleScript.cpp:

(WebCore::LoadableModuleScript::create):
(WebCore::LoadableModuleScript::LoadableModuleScript):
(WebCore::LoadableModuleScript::load):
Create ModuleFetchParameters with "integrity" value.

  • dom/LoadableModuleScript.h:
  • dom/ModuleFetchParameters.h: Copied from Source/WebCore/bindings/js/CachedModuleScriptLoader.h.

(WebCore::ModuleFetchParameters::create):
(WebCore::ModuleFetchParameters::integrity const):
(WebCore::ModuleFetchParameters::ModuleFetchParameters):

  • dom/ScriptElement.cpp:

(WebCore::ScriptElement::requestModuleScript):
Pass "integrity" value to the module script.

LayoutTests:

  • http/tests/subresource-integrity/resources/crossorigin-anon-script-module.js: Added.
  • http/tests/subresource-integrity/resources/crossorigin-creds-script-module.js: Added.
  • http/tests/subresource-integrity/resources/crossorigin-ineligible-script-module.js: Added.
  • http/tests/subresource-integrity/resources/matching-digest-module.js: Added.
  • http/tests/subresource-integrity/resources/non-matching-digest-module.js: Added.
  • http/tests/subresource-integrity/resources/sri-utilities.js:

(add_result_callback):
(SRIModuleTest):
(SRIModuleTest.prototype.execute):

  • http/tests/subresource-integrity/sri-module-expected.txt: Added.
  • http/tests/subresource-integrity/sri-module.html: Added.
  • js/dom/modules/module-inline-ignore-integrity-expected.txt: Added.
  • js/dom/modules/module-inline-ignore-integrity.html: Added.
  • js/dom/modules/module-integrity-non-top-level-expected.txt: Added.
  • js/dom/modules/module-integrity-non-top-level.html: Added.
  • js/dom/modules/script-tests/module-integrity-non-top-level-2.js: Added.
  • js/dom/modules/script-tests/module-integrity-non-top-level.js: Added.
Location:
trunk
Files:
18 added
31 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r223227 r223237  
     12017-10-12  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Support integrity="" on module scripts
     4        https://bugs.webkit.org/show_bug.cgi?id=177959
     5
     6        Reviewed by Sam Weinig.
     7
     8        * http/tests/subresource-integrity/resources/crossorigin-anon-script-module.js: Added.
     9        * http/tests/subresource-integrity/resources/crossorigin-creds-script-module.js: Added.
     10        * http/tests/subresource-integrity/resources/crossorigin-ineligible-script-module.js: Added.
     11        * http/tests/subresource-integrity/resources/matching-digest-module.js: Added.
     12        * http/tests/subresource-integrity/resources/non-matching-digest-module.js: Added.
     13        * http/tests/subresource-integrity/resources/sri-utilities.js:
     14        (add_result_callback):
     15        (SRIModuleTest):
     16        (SRIModuleTest.prototype.execute):
     17        * http/tests/subresource-integrity/sri-module-expected.txt: Added.
     18        * http/tests/subresource-integrity/sri-module.html: Added.
     19        * js/dom/modules/module-inline-ignore-integrity-expected.txt: Added.
     20        * js/dom/modules/module-inline-ignore-integrity.html: Added.
     21        * js/dom/modules/module-integrity-non-top-level-expected.txt: Added.
     22        * js/dom/modules/module-integrity-non-top-level.html: Added.
     23        * js/dom/modules/script-tests/module-integrity-non-top-level-2.js: Added.
     24        * js/dom/modules/script-tests/module-integrity-non-top-level.js: Added.
     25
    1262017-10-11  Per Arne Vollan  <pvollan@apple.com>
    227
  • trunk/LayoutTests/http/tests/subresource-integrity/resources/sri-utilities.js

    r216347 r223237  
    77
    88add_result_callback(function(res) {
    9     if (res.name.startsWith("Script: ") || res.name.startsWith("Style: ")) {
     9    if (res.name.startsWith("Script: ") || res.name.startsWith("Style: ") || res.name.startsWith("Module: ")) {
    1010      SRITests.execute();
    1111    }
     
    108108    this.customCallback(e, container);
    109109};
     110
     111var SRIModuleURLCounter = 0;
     112var SRIModuleTest = function(pass, name, src, integrityValue, crossoriginValue) {
     113    this.pass = pass;
     114    this.name = "Module: " + name;
     115    this.src = src;
     116    this.integrityValue = integrityValue;
     117    this.crossoriginValue = crossoriginValue;
     118
     119    this.test = async_test(this.name);
     120
     121    this.queue = SRITests;
     122    this.queue.push(this);
     123}
     124
     125SRIModuleTest.prototype.execute = function() {
     126    var test = this.test;
     127    var e = document.createElement("script");
     128    e.type = "module";
     129    e.src = this.src + "#" + (SRIModuleURLCounter++);
     130    e.setAttribute("integrity", this.integrityValue);
     131    if(this.crossoriginValue) {
     132        e.setAttribute("crossorigin", this.crossoriginValue);
     133    }
     134    if(this.pass) {
     135        e.addEventListener("load", function() {test.done()});
     136        e.addEventListener("error", function() {
     137            test.step(function(){ assert_unreached("Good load fired error handler.") })
     138        });
     139    } else {
     140       e.addEventListener("load", function() {
     141            test.step(function() { assert_unreached("Bad load succeeded.") })
     142        });
     143       e.addEventListener("error", function() {test.done()});
     144    }
     145    document.body.appendChild(e);
     146};
  • trunk/Source/JavaScriptCore/ChangeLog

    r223232 r223237  
     12017-10-12  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Support integrity="" on module scripts
     4        https://bugs.webkit.org/show_bug.cgi?id=177959
     5
     6        Reviewed by Sam Weinig.
     7
     8        This patch adds Subresource Integrity check for module scripts. Currently,
     9        only top-level module can be verified with integrity parameter since there
     10        is no way to perform integrity check onto the imported modules.
     11
     12        In JSC side, we add `parameters` to the entry point of the module loader
     13        pipeline. This is fetching parameters and used when fetching modules.
     14
     15        We separately pass this parameters to the pipeline along with the script fetcher.
     16        The script fetcher is only one for module graph since this is the initiator of
     17        this module graph loading. On the other hand, this parameters is for each
     18        module fetching. While setting "integrity" parameters to this script fetcher is
     19        sufficient to pass parameters to top-level-module's fetching, it is not enough
     20        for the future extension.
     21
     22        In the future, we will investigate a way to pass parameters to each non-top-level
     23        module. At that time, this `parameters` should be per-module. This is because
     24        "integrity" value should be different for each module. For example, we will accept
     25        some form of syntax to add parameters to `import`. Some proposed syntax is like
     26        https://discourse.wicg.io/t/specifying-nonce-or-integrity-when-importing-modules/1861
     27
     28        import "./xxx.js" integrity "xxxxxxx"
     29
     30        In this case, this `parameters` will be passed to "./xxx.js" module fetching. This
     31        `parameters` should be different from the one of top-level-module's one. That's why
     32        we need per-module `parameters` and why this patch adds `parameters` to the module pipeline.
     33
     34        On the other hand, we also want to keep script fetcher. This `per-module-graph` thing
     35        is important to offer module-graph-wide information. For example, import.meta would
     36        have `import.meta.scriptElement`, which is the script element fetching the module graph
     37        including this. So, we keep the both, script fetcher and parameters.
     38        https://github.com/tc39/proposal-import-meta
     39
     40        This parameters will be finally used by pipeline's fetch hook, and WebCore side
     41        can use this parameters to fetch modules.
     42
     43        We also further clean up the module pipeline by dropping unnecessary features.
     44
     45        * JavaScriptCore.xcodeproj/project.pbxproj:
     46        * Sources.txt:
     47        * builtins/ModuleLoaderPrototype.js:
     48        (requestFetch):
     49        (requestInstantiate):
     50        (requestSatisfy):
     51        (loadModule):
     52        (loadAndEvaluateModule):
     53        This loadAndEvaluateModule should be implemented by just calling loadModule and
     54        linkAndEvaluateModule. We can drop requestReady and requestLink.
     55
     56        (requestLink): Deleted.
     57        (requestImportModule): Deleted.
     58        * jsc.cpp:
     59        (GlobalObject::moduleLoaderImportModule):
     60        (GlobalObject::moduleLoaderFetch):
     61        import and fetch hook takes parameters. Currently, we always pass `undefined` for
     62        import hook. When dynamic `import()` is extended to accept additional parameters
     63        like integrity, this parameters will be replaced with the actual value.
     64
     65        (functionLoadModule):
     66        (runWithOptions):
     67        * runtime/Completion.cpp:
     68        (JSC::loadAndEvaluateModule):
     69        (JSC::loadModule):
     70        (JSC::importModule):
     71        * runtime/Completion.h:
     72        * runtime/JSGlobalObject.h:
     73        * runtime/JSGlobalObjectFunctions.cpp:
     74        (JSC::globalFuncImportModule):
     75        * runtime/JSModuleLoader.cpp:
     76        (JSC::JSModuleLoader::loadAndEvaluateModule):
     77        (JSC::JSModuleLoader::loadModule):
     78        (JSC::JSModuleLoader::requestImportModule):
     79        (JSC::JSModuleLoader::importModule):
     80        (JSC::JSModuleLoader::fetch):
     81        * runtime/JSModuleLoader.h:
     82        * runtime/JSScriptFetchParameters.cpp: Added.
     83        (JSC::JSScriptFetchParameters::destroy):
     84        * runtime/JSScriptFetchParameters.h: Added.
     85        (JSC::JSScriptFetchParameters::createStructure):
     86        (JSC::JSScriptFetchParameters::create):
     87        (JSC::JSScriptFetchParameters::parameters const):
     88        (JSC::JSScriptFetchParameters::JSScriptFetchParameters):
     89        Add ScriptFetchParameters' JSCell wrapper, JSScriptFetchParameters.
     90        It is used in the module pipeline.
     91
     92        * runtime/JSType.h:
     93        * runtime/ModuleLoaderPrototype.cpp:
     94        (JSC::moduleLoaderPrototypeFetch):
     95        * runtime/ScriptFetchParameters.h: Added.
     96        (JSC::ScriptFetchParameters::~ScriptFetchParameters):
     97        Add ScriptFetchParameters. We can define our own custom ScriptFetchParameters
     98        by inheriting this class. WebCore creates ModuleFetchParameters by inheriting
     99        this.
     100
     101        * runtime/VM.cpp:
     102        (JSC::VM::VM):
     103        * runtime/VM.h:
     104
    11052017-10-11  Yusuke Suzuki  <utatane.tea@gmail.com>
    2106
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r223125 r223237  
    16331633                E31618151EC5FE270006A218 /* DOMAttributeGetterSetter.h in Headers */ = {isa = PBXBuildFile; fileRef = E31618121EC5FE080006A218 /* DOMAttributeGetterSetter.h */; settings = {ATTRIBUTES = (Private, ); }; };
    16341634                E318CBC11B8AEF5100A2929D /* JSModuleNamespaceObject.h in Headers */ = {isa = PBXBuildFile; fileRef = E318CBBF1B8AEF5100A2929D /* JSModuleNamespaceObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1635                E3201C1D1F8E82360076A032 /* JSScriptFetchParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = E38D060B1F8E814100649CF2 /* JSScriptFetchParameters.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1636                E3201C1E1F8E824C0076A032 /* ScriptFetchParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = E38D060C1F8E814100649CF2 /* ScriptFetchParameters.h */; settings = {ATTRIBUTES = (Private, ); }; };
    16351637                E322E5A31DA64439006E7709 /* DFGSnippetParams.h in Headers */ = {isa = PBXBuildFile; fileRef = E322E5A11DA64435006E7709 /* DFGSnippetParams.h */; };
    16361638                E322E5A71DA644A8006E7709 /* FTLSnippetParams.h in Headers */ = {isa = PBXBuildFile; fileRef = E322E5A51DA644A4006E7709 /* FTLSnippetParams.h */; };
     
    44204422                E380A76B1DCD7195000F89E6 /* MacroAssemblerHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MacroAssemblerHelpers.h; sourceTree = "<group>"; };
    44214423                E380D66B1F19249D00A59095 /* BuiltinNames.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BuiltinNames.cpp; sourceTree = "<group>"; };
     4424                E38D060B1F8E814100649CF2 /* JSScriptFetchParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSScriptFetchParameters.h; sourceTree = "<group>"; };
     4425                E38D060C1F8E814100649CF2 /* ScriptFetchParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptFetchParameters.h; sourceTree = "<group>"; };
     4426                E38D060D1F8E814100649CF2 /* JSScriptFetchParameters.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSScriptFetchParameters.cpp; sourceTree = "<group>"; };
    44224427                E3963CEC1B73F75000EB4CE5 /* NodesAnalyzeModule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NodesAnalyzeModule.cpp; sourceTree = "<group>"; };
    44234428                E39D9D841D39000600667282 /* InterpreterInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InterpreterInlines.h; sourceTree = "<group>"; };
     
    64806485                                11C197C2624848EDA84CED7F /* JSScriptFetcher.cpp */,
    64816486                                6BA93C9590484C5BAD9316EA /* JSScriptFetcher.h */,
     6487                                E38D060D1F8E814100649CF2 /* JSScriptFetchParameters.cpp */,
     6488                                E38D060B1F8E814100649CF2 /* JSScriptFetchParameters.h */,
    64826489                                0F919D0E157F3327004A4E7D /* JSSegmentedVariableObject.cpp */,
    64836490                                0F919D0F157F3327004A4E7D /* JSSegmentedVariableObject.h */,
     
    66506657                                147341CD1DC02D7900AA29BA /* ScriptExecutable.h */,
    66516658                                8852151A9C3842389B3215B7 /* ScriptFetcher.h */,
     6659                                E38D060C1F8E814100649CF2 /* ScriptFetchParameters.h */,
    66526660                                A7299DA317D12858005F5FF9 /* SetConstructor.cpp */,
    66536661                                A7299DA417D12858005F5FF9 /* SetConstructor.h */,
     
    87338741                                14874AE615EBDE4A002E3587 /* JSScope.h in Headers */,
    87348742                                9064337DD4B0402BAF34A592 /* JSScriptFetcher.h in Headers */,
     8743                                E3201C1D1F8E82360076A032 /* JSScriptFetchParameters.h in Headers */,
    87358744                                A7C0C4AC168103020017011D /* JSScriptRefPrivate.h in Headers */,
    87368745                                0F919D11157F332C004A4E7D /* JSSegmentedVariableObject.h in Headers */,
     
    89568965                                147B84630E6DE6B1004775A4 /* PutPropertySlot.h in Headers */,
    89578966                                0FF60AC216740F8300029779 /* ReduceWhitespace.h in Headers */,
    8958                                 7986943B1F8C0ACC009232AE /* StructureCache.h in Headers */,
    89598967                                E33637A61B63220200EE0840 /* ReflectObject.h in Headers */,
    89608968                                996B73231BDA08EF00331B84 /* ReflectObject.lut.h in Headers */,
     
    90059013                                147341CE1DC02D7900AA29BA /* ScriptExecutable.h in Headers */,
    90069014                                CEAE7D7B889B477BA93ABA6C /* ScriptFetcher.h in Headers */,
     9015                                E3201C1E1F8E824C0076A032 /* ScriptFetchParameters.h in Headers */,
    90079016                                A55D93A6185012A800400DED /* ScriptFunctionCall.h in Headers */,
    90089017                                A54CF2FA184EAEDA00237F19 /* ScriptObject.h in Headers */,
     
    90569065                                145722861437E140005FDE26 /* StrongInlines.h in Headers */,
    90579066                                BCDE3AB80E6C82F5001453A7 /* Structure.h in Headers */,
     9067                                7986943B1F8C0ACC009232AE /* StructureCache.h in Headers */,
    90589068                                7E4EE7090EBB7963005934AA /* StructureChain.h in Headers */,
    90599069                                2AAAA31218BD49D100394CC8 /* StructureIDBlob.h in Headers */,
  • trunk/Source/JavaScriptCore/Sources.txt

    r223125 r223237  
    808808runtime/JSScope.cpp
    809809runtime/JSScriptFetcher.cpp
     810runtime/JSScriptFetchParameters.cpp
    810811runtime/JSSegmentedVariableObject.cpp
    811812runtime/JSSegmentedVariableObjectSubspace.cpp
  • trunk/Source/JavaScriptCore/builtins/ModuleLoaderPrototype.js

    r223173 r223237  
    141141// Loader.
    142142
    143 function requestFetch(key, fetcher)
     143function requestFetch(key, parameters, fetcher)
    144144{
    145145    // https://whatwg.github.io/loader/#request-fetch
     
    157157    //     For example, JavaScriptCore shell can provide the hook fetching the resource
    158158    //     from the local file system.
    159     var fetchPromise = this.fetch(key, fetcher).then((source) => {
     159    var fetchPromise = this.fetch(key, parameters, fetcher).then((source) => {
    160160        @setStateToMax(entry, @ModuleInstantiate);
    161161        return source;
     
    165165}
    166166
    167 function requestInstantiate(key, fetcher)
     167function requestInstantiate(key, parameters, fetcher)
    168168{
    169169    // https://whatwg.github.io/loader/#request-instantiate
     
    175175        return entry.instantiate;
    176176
    177     var instantiatePromise = this.requestFetch(key, fetcher).then((source) => {
     177    var instantiatePromise = this.requestFetch(key, parameters, fetcher).then((source) => {
    178178        var moduleRecord = this.parseModule(entry.key, source);
    179179
     
    208208}
    209209
    210 function requestSatisfy(key, fetcher)
     210function requestSatisfy(key, parameters, fetcher)
    211211{
    212212    // https://whatwg.github.io/loader/#satisfy-instance
     
    218218        return entry.satisfy;
    219219
    220     var satisfyPromise = this.requestInstantiate(key, fetcher).then((entry) => {
     220    var satisfyPromise = this.requestInstantiate(key, parameters, fetcher).then((entry) => {
    221221        var depLoads = [];
    222222        for (var i = 0, length = entry.dependencies.length; i < length; ++i) {
     
    247247                }
    248248
    249                 return this.requestSatisfy(depKey, fetcher).then((entry) => {
     249                // Currently, module loader do not pass any information for non-top-level module fetching.
     250                return this.requestSatisfy(depKey, @undefined, fetcher).then((entry) => {
    250251                    pair.value = entry.module;
    251252                    return entry;
     
    263264    entry.satisfy = satisfyPromise;
    264265    return satisfyPromise;
    265 }
    266 
    267 function requestLink(key, fetcher)
    268 {
    269     // https://whatwg.github.io/loader/#request-link
    270 
    271     "use strict";
    272 
    273     var entry = this.ensureRegistered(key);
    274     if (entry.state > @ModuleLink) {
    275         var deferred = @newPromiseCapability(@InternalPromise);
    276         deferred.@resolve.@call(@undefined, entry);
    277         return deferred.@promise;
    278     }
    279 
    280     return this.requestSatisfy(key, fetcher).then((entry) => {
    281         this.link(entry, fetcher);
    282         return entry;
    283     });
    284 }
    285 
    286 function requestReady(key, fetcher)
    287 {
    288     // https://whatwg.github.io/loader/#request-ready
    289 
    290     "use strict";
    291 
    292     return this.requestLink(key, fetcher).then((entry) => {
    293         this.moduleEvaluation(entry.module, fetcher);
    294     });
    295266}
    296267
     
    364335}
    365336
    366 function loadAndEvaluateModule(moduleName, referrer, fetcher)
     337function loadModule(moduleName, parameters, fetcher)
    367338{
    368339    "use strict";
     
    372343    // Take the name and resolve it to the unique identifier for the resource location.
    373344    // For example, take the "jquery" and return the URL for the resource.
    374     return this.resolve(moduleName, referrer, fetcher).then((key) => {
    375         return this.requestReady(key, fetcher);
    376     });
    377 }
    378 
    379 function loadModule(moduleName, referrer, fetcher)
    380 {
    381     "use strict";
    382 
    383     // Loader.resolve hook point.
    384     // resolve: moduleName => Promise(moduleKey)
    385     // Take the name and resolve it to the unique identifier for the resource location.
    386     // For example, take the "jquery" and return the URL for the resource.
    387     return this.resolve(moduleName, referrer, fetcher).then((key) => {
    388         return this.requestSatisfy(key, fetcher);
     345    return this.resolve(moduleName, @undefined, fetcher).then((key) => {
     346        return this.requestSatisfy(key, parameters, fetcher);
    389347    }).then((entry) => {
    390348        return entry.key;
     
    404362}
    405363
    406 function requestImportModule(key, fetcher)
    407 {
    408     "use strict";
    409 
    410     return this.requestSatisfy(key, fetcher).then((entry) => {
     364function loadAndEvaluateModule(moduleName, parameters, fetcher)
     365{
     366    "use strict";
     367
     368    return this.loadModule(moduleName, parameters, fetcher).then((key) => {
     369        return this.linkAndEvaluateModule(key, fetcher);
     370    });
     371}
     372
     373function requestImportModule(key, parameters, fetcher)
     374{
     375    "use strict";
     376
     377    return this.requestSatisfy(key, parameters, fetcher).then((entry) => {
    411378        this.linkAndEvaluateModule(entry.key, fetcher);
    412379        return this.getModuleNamespaceObject(entry.module);
  • trunk/Source/JavaScriptCore/jsc.cpp

    r223173 r223237  
    16581658    }
    16591659
    1660     static JSInternalPromise* moduleLoaderImportModule(JSGlobalObject*, ExecState*, JSModuleLoader*, JSString*, const SourceOrigin&);
     1660    static JSInternalPromise* moduleLoaderImportModule(JSGlobalObject*, ExecState*, JSModuleLoader*, JSString*, JSValue, const SourceOrigin&);
    16611661    static JSInternalPromise* moduleLoaderResolve(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue);
    1662     static JSInternalPromise* moduleLoaderFetch(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue);
     1662    static JSInternalPromise* moduleLoaderFetch(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue);
    16631663    static JSObject* moduleLoaderCreateImportMetaProperties(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSModuleRecord*, JSValue);
    16641664};
     
    18121812}
    18131813
    1814 JSInternalPromise* GlobalObject::moduleLoaderImportModule(JSGlobalObject* globalObject, ExecState* exec, JSModuleLoader*, JSString* moduleNameValue, const SourceOrigin& sourceOrigin)
     1814JSInternalPromise* GlobalObject::moduleLoaderImportModule(JSGlobalObject* globalObject, ExecState* exec, JSModuleLoader*, JSString* moduleNameValue, JSValue parameters, const SourceOrigin& sourceOrigin)
    18151815{
    18161816    VM& vm = globalObject->vm();
     
    18361836        return rejectPromise(createError(exec, makeString("Could not resolve the referrer name '", String(referrer.impl()), "'.")));
    18371837
    1838     auto result = JSC::importModule(exec, Identifier::fromString(&vm, resolvePath(directoryName.value(), ModuleName(moduleName))), jsUndefined());
     1838    auto result = JSC::importModule(exec, Identifier::fromString(&vm, resolvePath(directoryName.value(), ModuleName(moduleName))), parameters, jsUndefined());
    18391839    scope.releaseAssertNoException();
    18401840    return result;
     
    19861986}
    19871987
    1988 JSInternalPromise* GlobalObject::moduleLoaderFetch(JSGlobalObject* globalObject, ExecState* exec, JSModuleLoader*, JSValue key, JSValue)
     1988JSInternalPromise* GlobalObject::moduleLoaderFetch(JSGlobalObject* globalObject, ExecState* exec, JSModuleLoader*, JSValue key, JSValue, JSValue)
    19891989{
    19901990    VM& vm = globalObject->vm();
     
    32743274        return JSValue::encode(throwException(exec, scope, createError(exec, ASCIILiteral("Could not open file."))));
    32753275
    3276     JSInternalPromise* promise = loadAndEvaluateModule(exec, fileName);
     3276    JSInternalPromise* promise = loadAndEvaluateModule(exec, fileName, jsUndefined(), jsUndefined());
    32773277    RETURN_IF_EXCEPTION(scope, encodedJSValue());
    32783278
     
    36613661
    36623662            if (isModule) {
    3663                 promise = loadAndEvaluateModule(globalObject->globalExec(), fileName);
     3663                promise = loadAndEvaluateModule(globalObject->globalExec(), fileName, jsUndefined(), jsUndefined());
    36643664                scope.releaseAssertNoException();
    36653665            } else {
     
    36773677        if (isModule) {
    36783678            if (!promise)
    3679                 promise = loadAndEvaluateModule(globalObject->globalExec(), makeSource(stringFromUTF(scriptBuffer), SourceOrigin { absolutePath(fileName) }, fileName, TextPosition(), SourceProviderSourceType::Module));
     3679                promise = loadAndEvaluateModule(globalObject->globalExec(), makeSource(stringFromUTF(scriptBuffer), SourceOrigin { absolutePath(fileName) }, fileName, TextPosition(), SourceProviderSourceType::Module), jsUndefined());
    36803680            scope.clearException();
    36813681
  • trunk/Source/JavaScriptCore/runtime/Completion.cpp

    r223173 r223237  
    155155}
    156156
    157 static JSInternalPromise* loadAndEvaluateModule(const JSLockHolder&, ExecState* exec, JSGlobalObject* globalObject, JSValue moduleName, JSValue referrer, JSValue scriptFetcher)
    158 {
    159     return globalObject->moduleLoader()->loadAndEvaluateModule(exec, moduleName, referrer, scriptFetcher);
    160 }
    161 
    162 static JSInternalPromise* loadAndEvaluateModule(const JSLockHolder& lock, ExecState* exec, JSGlobalObject* globalObject, const Identifier& moduleName, JSValue scriptFetcher)
    163 {
    164     return loadAndEvaluateModule(lock, exec, globalObject, identifierToJSValue(exec->vm(), moduleName), jsUndefined(), scriptFetcher);
    165 }
    166 
    167 JSInternalPromise* loadAndEvaluateModule(ExecState* exec, const String& moduleName, JSValue scriptFetcher)
    168 {
    169     VM& vm = exec->vm();
    170     JSLockHolder lock(vm);
    171     RELEASE_ASSERT(vm.atomicStringTable() == Thread::current().atomicStringTable());
    172     RELEASE_ASSERT(!vm.isCollectorBusyOnCurrentThread());
    173 
    174     return loadAndEvaluateModule(lock, exec, exec->vmEntryGlobalObject(), Identifier::fromString(exec, moduleName), scriptFetcher);
     157JSInternalPromise* loadAndEvaluateModule(ExecState* exec, const String& moduleName, JSValue parameters, JSValue scriptFetcher)
     158{
     159    VM& vm = exec->vm();
     160    JSLockHolder lock(vm);
     161    RELEASE_ASSERT(vm.atomicStringTable() == Thread::current().atomicStringTable());
     162    RELEASE_ASSERT(!vm.isCollectorBusyOnCurrentThread());
     163
     164    return exec->vmEntryGlobalObject()->moduleLoader()->loadAndEvaluateModule(exec, identifierToJSValue(vm, Identifier::fromString(exec, moduleName)), parameters, scriptFetcher);
    175165}
    176166
     
    191181    RETURN_IF_EXCEPTION(scope, rejectPromise(exec, globalObject));
    192182
    193     return loadAndEvaluateModule(lock, exec, globalObject, key, jsUndefined(), scriptFetcher);
    194 }
    195 
    196 static JSInternalPromise* loadModule(const JSLockHolder&, ExecState* exec, JSGlobalObject* globalObject, JSValue moduleName, JSValue referrer, JSValue scriptFetcher)
    197 {
    198     return globalObject->moduleLoader()->loadModule(exec, moduleName, referrer, scriptFetcher);
    199 }
    200 
    201 static JSInternalPromise* loadModule(const JSLockHolder& lock, ExecState* exec, JSGlobalObject* globalObject, const Identifier& moduleName, JSValue scriptFetcher)
    202 {
    203     return loadModule(lock, exec, globalObject, identifierToJSValue(exec->vm(), moduleName), jsUndefined(), scriptFetcher);
    204 }
    205 
    206 JSInternalPromise* loadModule(ExecState* exec, const String& moduleName, JSValue scriptFetcher)
    207 {
    208     VM& vm = exec->vm();
    209     JSLockHolder lock(vm);
    210     RELEASE_ASSERT(vm.atomicStringTable() == Thread::current().atomicStringTable());
    211     RELEASE_ASSERT(!vm.isCollectorBusyOnCurrentThread());
    212 
    213     return loadModule(lock, exec, exec->vmEntryGlobalObject(), Identifier::fromString(exec, moduleName), scriptFetcher);
     183    return globalObject->moduleLoader()->loadAndEvaluateModule(exec, key, jsUndefined(), scriptFetcher);
     184}
     185
     186JSInternalPromise* loadModule(ExecState* exec, const String& moduleName, JSValue parameters, JSValue scriptFetcher)
     187{
     188    VM& vm = exec->vm();
     189    JSLockHolder lock(vm);
     190    RELEASE_ASSERT(vm.atomicStringTable() == Thread::current().atomicStringTable());
     191    RELEASE_ASSERT(!vm.isCollectorBusyOnCurrentThread());
     192
     193    return exec->vmEntryGlobalObject()->moduleLoader()->loadModule(exec, identifierToJSValue(vm, Identifier::fromString(exec, moduleName)), parameters, scriptFetcher);
    214194}
    215195
     
    231211    RETURN_IF_EXCEPTION(scope, rejectPromise(exec, globalObject));
    232212
    233     return loadModule(lock, exec, globalObject, key, jsUndefined(), scriptFetcher);
     213    return globalObject->moduleLoader()->loadModule(exec, key, jsUndefined(), scriptFetcher);
    234214}
    235215
     
    245225}
    246226
    247 JSInternalPromise* importModule(ExecState* exec, const Identifier& moduleKey, JSValue scriptFetcher)
    248 {
    249     VM& vm = exec->vm();
    250     JSLockHolder lock(vm);
    251     RELEASE_ASSERT(vm.atomicStringTable() == Thread::current().atomicStringTable());
    252     RELEASE_ASSERT(!vm.isCollectorBusyOnCurrentThread());
    253 
    254     return exec->vmEntryGlobalObject()->moduleLoader()->requestImportModule(exec, moduleKey, scriptFetcher);
     227JSInternalPromise* importModule(ExecState* exec, const Identifier& moduleKey, JSValue parameters, JSValue scriptFetcher)
     228{
     229    VM& vm = exec->vm();
     230    JSLockHolder lock(vm);
     231    RELEASE_ASSERT(vm.atomicStringTable() == Thread::current().atomicStringTable());
     232    RELEASE_ASSERT(!vm.isCollectorBusyOnCurrentThread());
     233
     234    return exec->vmEntryGlobalObject()->moduleLoader()->requestImportModule(exec, moduleKey, parameters, scriptFetcher);
    255235}
    256236
  • trunk/Source/JavaScriptCore/runtime/Completion.h

    r211018 r223237  
    5858
    5959// Load the module source and evaluate it.
    60 JS_EXPORT_PRIVATE JSInternalPromise* loadAndEvaluateModule(ExecState*, const String& moduleName, JSValue scriptFetcher = jsUndefined());
    61 JS_EXPORT_PRIVATE JSInternalPromise* loadAndEvaluateModule(ExecState*, const SourceCode&, JSValue scriptFetcher = jsUndefined());
     60JS_EXPORT_PRIVATE JSInternalPromise* loadAndEvaluateModule(ExecState*, const String& moduleName, JSValue parameters, JSValue scriptFetcher);
     61JS_EXPORT_PRIVATE JSInternalPromise* loadAndEvaluateModule(ExecState*, const SourceCode&, JSValue scriptFetcher);
    6262
    6363// Fetch the module source, and instantiate the module record.
    64 JS_EXPORT_PRIVATE JSInternalPromise* loadModule(ExecState*, const String& moduleName, JSValue scriptFetcher = jsUndefined());
    65 JS_EXPORT_PRIVATE JSInternalPromise* loadModule(ExecState*, const SourceCode&, JSValue scriptFetcher = jsUndefined());
     64JS_EXPORT_PRIVATE JSInternalPromise* loadModule(ExecState*, const String& moduleName, JSValue parameters, JSValue scriptFetcher);
     65JS_EXPORT_PRIVATE JSInternalPromise* loadModule(ExecState*, const SourceCode&, JSValue scriptFetcher);
    6666
    6767// Link and evaluate the already linked module. This function is called in a sync manner.
    68 JS_EXPORT_PRIVATE JSValue linkAndEvaluateModule(ExecState*, const Identifier& moduleKey, JSValue scriptFetcher = jsUndefined());
     68JS_EXPORT_PRIVATE JSValue linkAndEvaluateModule(ExecState*, const Identifier& moduleKey, JSValue scriptFetcher);
    6969
    70 JS_EXPORT_PRIVATE JSInternalPromise* importModule(ExecState*, const Identifier& moduleKey, JSValue scriptFetcher);
     70JS_EXPORT_PRIVATE JSInternalPromise* importModule(ExecState*, const Identifier& moduleKey, JSValue parameters, JSValue scriptFetcher);
    7171
    7272} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h

    r223173 r223237  
    187187    ShouldInterruptScriptBeforeTimeoutPtr shouldInterruptScriptBeforeTimeout;
    188188
    189     typedef JSInternalPromise* (*ModuleLoaderImportModulePtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSString*, const SourceOrigin&);
     189    typedef JSInternalPromise* (*ModuleLoaderImportModulePtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSString*, JSValue, const SourceOrigin&);
    190190    ModuleLoaderImportModulePtr moduleLoaderImportModule;
    191191
     
    193193    ModuleLoaderResolvePtr moduleLoaderResolve;
    194194
    195     typedef JSInternalPromise* (*ModuleLoaderFetchPtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue);
     195    typedef JSInternalPromise* (*ModuleLoaderFetchPtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue);
    196196    ModuleLoaderFetchPtr moduleLoaderFetch;
    197197
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp

    r221849 r223237  
    798798    }
    799799
    800     auto* internalPromise = globalObject->moduleLoader()->importModule(exec, specifier, sourceOrigin);
     800    // We always specify parameters as undefined. Once dynamic import() starts accepting fetching parameters,
     801    // we should retrieve this from the arguments.
     802    JSValue parameters = jsUndefined();
     803    auto* internalPromise = globalObject->moduleLoader()->importModule(exec, specifier, parameters, sourceOrigin);
    801804    if (Exception* exception = catchScope.exception()) {
    802805        catchScope.clearException();
  • trunk/Source/JavaScriptCore/runtime/JSModuleLoader.cpp

    r223173 r223237  
    100100}
    101101
    102 JSInternalPromise* JSModuleLoader::loadAndEvaluateModule(ExecState* exec, JSValue moduleName, JSValue referrer, JSValue scriptFetcher)
     102JSInternalPromise* JSModuleLoader::loadAndEvaluateModule(ExecState* exec, JSValue moduleName, JSValue parameters, JSValue scriptFetcher)
    103103{
    104104    VM& vm = exec->vm();
     
    113113    MarkedArgumentBuffer arguments;
    114114    arguments.append(moduleName);
    115     arguments.append(referrer);
     115    arguments.append(parameters);
    116116    arguments.append(scriptFetcher);
    117117
     
    120120}
    121121
    122 JSInternalPromise* JSModuleLoader::loadModule(ExecState* exec, JSValue moduleName, JSValue referrer, JSValue scriptFetcher)
     122JSInternalPromise* JSModuleLoader::loadModule(ExecState* exec, JSValue moduleName, JSValue parameters, JSValue scriptFetcher)
    123123{
    124124    VM& vm = exec->vm();
     
    133133    MarkedArgumentBuffer arguments;
    134134    arguments.append(moduleName);
    135     arguments.append(referrer);
     135    arguments.append(parameters);
    136136    arguments.append(scriptFetcher);
    137137
     
    159159}
    160160
    161 JSInternalPromise* JSModuleLoader::requestImportModule(ExecState* exec, const Identifier& moduleKey, JSValue scriptFetcher)
     161JSInternalPromise* JSModuleLoader::requestImportModule(ExecState* exec, const Identifier& moduleKey, JSValue parameters, JSValue scriptFetcher)
    162162{
    163163    VM& vm = exec->vm();
     
    172172    MarkedArgumentBuffer arguments;
    173173    arguments.append(jsString(exec, moduleKey.impl()));
     174    arguments.append(parameters);
    174175    arguments.append(scriptFetcher);
    175176
     
    178179}
    179180
    180 JSInternalPromise* JSModuleLoader::importModule(ExecState* exec, JSString* moduleName, const SourceOrigin& referrer)
     181JSInternalPromise* JSModuleLoader::importModule(ExecState* exec, JSString* moduleName, JSValue parameters, const SourceOrigin& referrer)
    181182{
    182183    if (Options::dumpModuleLoadingState())
     
    188189
    189190    if (globalObject->globalObjectMethodTable()->moduleLoaderImportModule)
    190         return globalObject->globalObjectMethodTable()->moduleLoaderImportModule(globalObject, exec, this, moduleName, referrer);
     191        return globalObject->globalObjectMethodTable()->moduleLoaderImportModule(globalObject, exec, this, moduleName, parameters, referrer);
    191192
    192193    auto* deferred = JSInternalPromiseDeferred::create(exec, globalObject);
     
    215216}
    216217
    217 JSInternalPromise* JSModuleLoader::fetch(ExecState* exec, JSValue key, JSValue scriptFetcher)
     218JSInternalPromise* JSModuleLoader::fetch(ExecState* exec, JSValue key, JSValue parameters, JSValue scriptFetcher)
    218219{
    219220    if (Options::dumpModuleLoadingState())
     
    224225    auto scope = DECLARE_CATCH_SCOPE(vm);
    225226    if (globalObject->globalObjectMethodTable()->moduleLoaderFetch)
    226         return globalObject->globalObjectMethodTable()->moduleLoaderFetch(globalObject, exec, this, key, scriptFetcher);
     227        return globalObject->globalObjectMethodTable()->moduleLoaderFetch(globalObject, exec, this, key, parameters, scriptFetcher);
    227228    JSInternalPromiseDeferred* deferred = JSInternalPromiseDeferred::create(exec, globalObject);
    228229    String moduleKey = key.toWTFString(exec);
  • trunk/Source/JavaScriptCore/runtime/JSModuleLoader.h

    r223173 r223237  
    6565    // APIs to control the module loader.
    6666    JSValue provideFetch(ExecState*, JSValue key, const SourceCode&);
    67     JSInternalPromise* loadAndEvaluateModule(ExecState*, JSValue moduleName, JSValue referrer, JSValue scriptFetcher);
    68     JSInternalPromise* loadModule(ExecState*, JSValue moduleName, JSValue referrer, JSValue scriptFetcher);
     67    JSInternalPromise* loadAndEvaluateModule(ExecState*, JSValue moduleName, JSValue parameters, JSValue scriptFetcher);
     68    JSInternalPromise* loadModule(ExecState*, JSValue moduleName, JSValue parameters, JSValue scriptFetcher);
    6969    JSValue linkAndEvaluateModule(ExecState*, JSValue moduleKey, JSValue scriptFetcher);
    70     JSInternalPromise* requestImportModule(ExecState*, const Identifier&, JSValue scriptFetcher);
     70    JSInternalPromise* requestImportModule(ExecState*, const Identifier&, JSValue parameters, JSValue scriptFetcher);
    7171
    7272    // Platform dependent hooked APIs.
    73     JSInternalPromise* importModule(ExecState*, JSString* moduleName, const SourceOrigin& referrer);
     73    JSInternalPromise* importModule(ExecState*, JSString* moduleName, JSValue parameters, const SourceOrigin& referrer);
    7474    JSInternalPromise* resolve(ExecState*, JSValue name, JSValue referrer, JSValue scriptFetcher);
    75     JSInternalPromise* fetch(ExecState*, JSValue key, JSValue scriptFetcher);
     75    JSInternalPromise* fetch(ExecState*, JSValue key, JSValue parameters, JSValue scriptFetcher);
    7676    JSObject* createImportMetaProperties(ExecState*, JSValue key, JSModuleRecord*, JSValue scriptFetcher);
    7777
  • trunk/Source/JavaScriptCore/runtime/JSType.h

    r221959 r223237  
    5353    JSSourceCodeType,
    5454    JSScriptFetcherType,
     55    JSScriptFetchParametersType,
    5556
    5657    // The ObjectType value must come before any JSType that is a subclass of JSObject.
  • trunk/Source/JavaScriptCore/runtime/ModuleLoaderPrototype.cpp

    r223173 r223237  
    7171    forceFulfillPromise            JSBuiltin                                           DontEnum|Function 2
    7272    fulfillFetch                   JSBuiltin                                           DontEnum|Function 2
    73     requestFetch                   JSBuiltin                                           DontEnum|Function 2
    74     requestInstantiate             JSBuiltin                                           DontEnum|Function 2
    75     requestSatisfy                 JSBuiltin                                           DontEnum|Function 2
    76     requestLink                    JSBuiltin                                           DontEnum|Function 2
    77     requestReady                   JSBuiltin                                           DontEnum|Function 2
     73    requestFetch                   JSBuiltin                                           DontEnum|Function 3
     74    requestInstantiate             JSBuiltin                                           DontEnum|Function 3
     75    requestSatisfy                 JSBuiltin                                           DontEnum|Function 3
    7876    link                           JSBuiltin                                           DontEnum|Function 2
    7977    moduleDeclarationInstantiation moduleLoaderPrototypeModuleDeclarationInstantiation DontEnum|Function 3
     
    8482    loadModule                     JSBuiltin                                           DontEnum|Function 3
    8583    linkAndEvaluateModule          JSBuiltin                                           DontEnum|Function 2
    86     requestImportModule            JSBuiltin                                           DontEnum|Function 2
     84    requestImportModule            JSBuiltin                                           DontEnum|Function 3
    8785    getModuleNamespaceObject       moduleLoaderPrototypeGetModuleNamespaceObject       DontEnum|Function 1
    8886    parseModule                    moduleLoaderPrototypeParseModule                    DontEnum|Function 2
    8987    requestedModules               moduleLoaderPrototypeRequestedModules               DontEnum|Function 1
    9088    resolve                        moduleLoaderPrototypeResolve                        DontEnum|Function 2
    91     fetch                          moduleLoaderPrototypeFetch                          DontEnum|Function 2
     89    fetch                          moduleLoaderPrototypeFetch                          DontEnum|Function 3
    9290@end
    9391*/
     
    196194    if (!loader)
    197195        return JSValue::encode(jsUndefined());
    198     return JSValue::encode(loader->fetch(exec, exec->argument(0), exec->argument(1)));
     196    return JSValue::encode(loader->fetch(exec, exec->argument(0), exec->argument(1), exec->argument(2)));
    199197}
    200198
  • trunk/Source/JavaScriptCore/runtime/VM.cpp

    r223125 r223237  
    7474#include "JSPromiseDeferred.h"
    7575#include "JSPropertyNameEnumerator.h"
     76#include "JSScriptFetchParameters.h"
    7677#include "JSScriptFetcher.h"
    7778#include "JSSet.h"
     
    254255    sourceCodeStructure.set(*this, JSSourceCode::createStructure(*this, 0, jsNull()));
    255256    scriptFetcherStructure.set(*this, JSScriptFetcher::createStructure(*this, 0, jsNull()));
     257    scriptFetchParametersStructure.set(*this, JSScriptFetchParameters::createStructure(*this, 0, jsNull()));
    256258    structureChainStructure.set(*this, StructureChain::createStructure(*this, 0, jsNull()));
    257259    sparseArrayValueMapStructure.set(*this, SparseArrayValueMap::createStructure(*this, 0, jsNull()));
  • trunk/Source/JavaScriptCore/runtime/VM.h

    r223125 r223237  
    362362    Strong<Structure> sourceCodeStructure;
    363363    Strong<Structure> scriptFetcherStructure;
     364    Strong<Structure> scriptFetchParametersStructure;
    364365    Strong<Structure> structureChainStructure;
    365366    Strong<Structure> sparseArrayValueMapStructure;
  • trunk/Source/WebCore/ChangeLog

    r223235 r223237  
     12017-10-12  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        Support integrity="" on module scripts
     4        https://bugs.webkit.org/show_bug.cgi?id=177959
     5
     6        Reviewed by Sam Weinig.
     7
     8        This patch extends module hooks to accept fetching parameters.
     9        When starting fetching modules, WebCore creates ModuleFetchParameters.
     10        And this parameters is propagated to the fetch hook. Then, fetch
     11        hook can use this parameters to fetch modules.
     12
     13        This parameters only contains `integrity` field. This "integrity" is
     14        used to perform subresource integrity check in module loader pipeline.
     15        And this error is just proparaged as errors in module pipeline, which
     16        is the same to the other types of errors in module pipeline.
     17
     18        Test: http/tests/subresource-integrity/sri-module.html
     19
     20        * ForwardingHeaders/runtime/JSScriptFetchParameters.h: Added.
     21        * ForwardingHeaders/runtime/ScriptFetchParameters.h: Added.
     22        * WebCore.xcodeproj/project.pbxproj:
     23        * bindings/js/CachedModuleScriptLoader.cpp:
     24        (WebCore::CachedModuleScriptLoader::create):
     25        (WebCore::CachedModuleScriptLoader::CachedModuleScriptLoader):
     26        Take parameters, which includes "integrity".
     27
     28        * bindings/js/CachedModuleScriptLoader.h:
     29        * bindings/js/JSDOMWindowBase.cpp:
     30        (WebCore::JSDOMWindowBase::moduleLoaderFetch):
     31        (WebCore::JSDOMWindowBase::moduleLoaderImportModule):
     32        import and fetch hooks take parameters.
     33
     34        * bindings/js/JSDOMWindowBase.h:
     35        * bindings/js/JSMainThreadExecState.h:
     36        (WebCore::JSMainThreadExecState::loadModule):
     37        * bindings/js/ScriptController.cpp:
     38        (WebCore::ScriptController::loadModuleScriptInWorld):
     39        (WebCore::ScriptController::loadModuleScript):
     40        Pass parameters to the entry point of the module pipeline.
     41
     42        * bindings/js/ScriptController.h:
     43        * bindings/js/ScriptModuleLoader.cpp:
     44        (WebCore::ScriptModuleLoader::fetch):
     45        If parameters are passed, we set them to CachedModuleScriptLoader.
     46
     47        (WebCore::ScriptModuleLoader::importModule):
     48        Pass parameters to the entry point of dynamic import.
     49
     50        (WebCore::ScriptModuleLoader::notifyFinished):
     51        If script loader has parameters, we perform subresource integrity check here.
     52
     53        * bindings/js/ScriptModuleLoader.h:
     54        * dom/LoadableModuleScript.cpp:
     55        (WebCore::LoadableModuleScript::create):
     56        (WebCore::LoadableModuleScript::LoadableModuleScript):
     57        (WebCore::LoadableModuleScript::load):
     58        Create ModuleFetchParameters with "integrity" value.
     59
     60        * dom/LoadableModuleScript.h:
     61        * dom/ModuleFetchParameters.h: Copied from Source/WebCore/bindings/js/CachedModuleScriptLoader.h.
     62        (WebCore::ModuleFetchParameters::create):
     63        (WebCore::ModuleFetchParameters::integrity const):
     64        (WebCore::ModuleFetchParameters::ModuleFetchParameters):
     65        * dom/ScriptElement.cpp:
     66        (WebCore::ScriptElement::requestModuleScript):
     67        Pass "integrity" value to the module script.
     68
    1692017-10-12  Tomas Popela  <tpopela@redhat.com>
    270
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r223206 r223237  
    68306830                E3150EA71DA7219300194012 /* DOMJITHelpers.h in Headers */ = {isa = PBXBuildFile; fileRef = E3150EA51DA7218D00194012 /* DOMJITHelpers.h */; };
    68316831                E318039D1DC40099009932C2 /* JSDynamicDowncast.h in Headers */ = {isa = PBXBuildFile; fileRef = E3A5872E1DC3F52600F607A6 /* JSDynamicDowncast.h */; settings = {ATTRIBUTES = (Private, ); }; };
     6832                E3201C1A1F8E82130076A032 /* ModuleFetchParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = E38D06091F8E811900649CF2 /* ModuleFetchParameters.h */; settings = {ATTRIBUTES = (Private, ); }; };
    68326833                E323CFFA1E5AF6AF00F0B4A0 /* JSDOMConvertPromise.h in Headers */ = {isa = PBXBuildFile; fileRef = E323CFF91E5AF6A500F0B4A0 /* JSDOMConvertPromise.h */; settings = {ATTRIBUTES = (Private, ); }; };
    68336834                E3565B7B1DC2D6C900217DBD /* JSEventCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = E34EE49F1DC2D57500EAA9D3 /* JSEventCustom.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    1568815689                E38838941BAD145F00D62EE3 /* ScriptModuleLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptModuleLoader.cpp; sourceTree = "<group>"; };
    1568915690                E38838951BAD145F00D62EE3 /* ScriptModuleLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptModuleLoader.h; sourceTree = "<group>"; };
     15691                E38D06091F8E811900649CF2 /* ModuleFetchParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ModuleFetchParameters.h; sourceTree = "<group>"; };
    1569015692                E3975B761EC9AF3900847717 /* JSDocumentFragmentDOMJIT.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDocumentFragmentDOMJIT.cpp; sourceTree = "<group>"; };
    1569115693                E3975B771EC9AF3900847717 /* JSElementDOMJIT.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSElementDOMJIT.cpp; sourceTree = "<group>"; };
     
    2654126543                                CB8CF0151A934B43000D510B /* Microtasks.cpp */,
    2654226544                                53B895AD19DC7C37009CAA93 /* Microtasks.h */,
     26545                                E38D06091F8E811900649CF2 /* ModuleFetchParameters.h */,
    2654326546                                85031B2F0A44EFC700F992E0 /* MouseEvent.cpp */,
    2654426547                                85031B300A44EFC700F992E0 /* MouseEvent.h */,
     
    2952729530                                C6D74AD509AA282E000B0A52 /* ModifySelectionListLevel.h in Headers */,
    2952829531                                709A01FE1E3D0BDD006B0D4C /* ModuleFetchFailureKind.h in Headers */,
     29532                                E3201C1A1F8E82130076A032 /* ModuleFetchParameters.h in Headers */,
    2952929533                                F55B3DC61251F12D003EF269 /* MonthInputType.h in Headers */,
    2953029534                                85031B460A44EFC700F992E0 /* MouseEvent.h in Headers */,
  • trunk/Source/WebCore/bindings/js/CachedModuleScriptLoader.cpp

    r211280 r223237  
    3232#include "Frame.h"
    3333#include "JSDOMBinding.h"
     34#include "ModuleFetchParameters.h"
    3435#include "ResourceLoaderOptions.h"
    3536#include "ScriptController.h"
     
    3940namespace WebCore {
    4041
    41 Ref<CachedModuleScriptLoader> CachedModuleScriptLoader::create(CachedModuleScriptLoaderClient& client, DeferredPromise& promise, CachedScriptFetcher& scriptFetcher)
     42Ref<CachedModuleScriptLoader> CachedModuleScriptLoader::create(CachedModuleScriptLoaderClient& client, DeferredPromise& promise, CachedScriptFetcher& scriptFetcher, RefPtr<ModuleFetchParameters>&& parameters)
    4243{
    43     return adoptRef(*new CachedModuleScriptLoader(client, promise, scriptFetcher));
     44    return adoptRef(*new CachedModuleScriptLoader(client, promise, scriptFetcher, WTFMove(parameters)));
    4445}
    4546
    46 CachedModuleScriptLoader::CachedModuleScriptLoader(CachedModuleScriptLoaderClient& client, DeferredPromise& promise, CachedScriptFetcher& scriptFetcher)
     47CachedModuleScriptLoader::CachedModuleScriptLoader(CachedModuleScriptLoaderClient& client, DeferredPromise& promise, CachedScriptFetcher& scriptFetcher, RefPtr<ModuleFetchParameters>&& parameters)
    4748    : m_client(&client)
    4849    , m_promise(&promise)
    4950    , m_scriptFetcher(scriptFetcher)
     51    , m_parameters(WTFMove(parameters))
    5052{
    5153}
  • trunk/Source/WebCore/bindings/js/CachedModuleScriptLoader.h

    r210627 r223237  
    4040class Document;
    4141class JSDOMGlobalObject;
     42class ModuleFetchParameters;
    4243class URL;
    4344
    4445class CachedModuleScriptLoader final : public RefCounted<CachedModuleScriptLoader>, private CachedResourceClient {
    4546public:
    46     static Ref<CachedModuleScriptLoader> create(CachedModuleScriptLoaderClient&, DeferredPromise&, CachedScriptFetcher&);
     47    static Ref<CachedModuleScriptLoader> create(CachedModuleScriptLoaderClient&, DeferredPromise&, CachedScriptFetcher&, RefPtr<ModuleFetchParameters>&&);
    4748
    4849    virtual ~CachedModuleScriptLoader();
     
    5253    CachedScriptFetcher& scriptFetcher() { return m_scriptFetcher.get(); }
    5354    CachedScript* cachedScript() { return m_cachedScript.get(); }
     55    ModuleFetchParameters* parameters() { return m_parameters.get(); }
    5456
    5557    void clearClient()
     
    6062
    6163private:
    62     CachedModuleScriptLoader(CachedModuleScriptLoaderClient&, DeferredPromise&, CachedScriptFetcher&);
     64    CachedModuleScriptLoader(CachedModuleScriptLoaderClient&, DeferredPromise&, CachedScriptFetcher&, RefPtr<ModuleFetchParameters>&&);
    6365
    6466    void notifyFinished(CachedResource&) final;
     
    6769    RefPtr<DeferredPromise> m_promise;
    6870    Ref<CachedScriptFetcher> m_scriptFetcher;
     71    RefPtr<ModuleFetchParameters> m_parameters;
    6972    CachedResourceHandle<CachedScript> m_cachedScript;
    7073};
  • trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp

    r223173 r223237  
    374374}
    375375
    376 JSC::JSInternalPromise* JSDOMWindowBase::moduleLoaderFetch(JSC::JSGlobalObject* globalObject, JSC::ExecState* exec, JSC::JSModuleLoader* moduleLoader, JSC::JSValue moduleKey, JSC::JSValue scriptFetcher)
     376JSC::JSInternalPromise* JSDOMWindowBase::moduleLoaderFetch(JSC::JSGlobalObject* globalObject, JSC::ExecState* exec, JSC::JSModuleLoader* moduleLoader, JSC::JSValue moduleKey, JSC::JSValue parameters, JSC::JSValue scriptFetcher)
    377377{
    378378    JSDOMWindowBase* thisObject = JSC::jsCast<JSDOMWindowBase*>(globalObject);
    379379    if (RefPtr<Document> document = thisObject->wrapped().document())
    380         return document->moduleLoader()->fetch(globalObject, exec, moduleLoader, moduleKey, scriptFetcher);
     380        return document->moduleLoader()->fetch(globalObject, exec, moduleLoader, moduleKey, parameters, scriptFetcher);
    381381    JSC::JSInternalPromiseDeferred* deferred = JSC::JSInternalPromiseDeferred::create(exec, globalObject);
    382382    return deferred->reject(exec, jsUndefined());
     
    391391}
    392392
    393 JSC::JSInternalPromise* JSDOMWindowBase::moduleLoaderImportModule(JSC::JSGlobalObject* globalObject, JSC::ExecState* exec, JSC::JSModuleLoader* moduleLoader, JSC::JSString* moduleName, const JSC::SourceOrigin& sourceOrigin)
     393JSC::JSInternalPromise* JSDOMWindowBase::moduleLoaderImportModule(JSC::JSGlobalObject* globalObject, JSC::ExecState* exec, JSC::JSModuleLoader* moduleLoader, JSC::JSString* moduleName, JSC::JSValue parameters, const JSC::SourceOrigin& sourceOrigin)
    394394{
    395395    JSDOMWindowBase* thisObject = JSC::jsCast<JSDOMWindowBase*>(globalObject);
    396396    if (RefPtr<Document> document = thisObject->wrapped().document())
    397         return document->moduleLoader()->importModule(globalObject, exec, moduleLoader, moduleName, sourceOrigin);
     397        return document->moduleLoader()->importModule(globalObject, exec, moduleLoader, moduleName, parameters, sourceOrigin);
    398398    JSC::JSInternalPromiseDeferred* deferred = JSC::JSInternalPromiseDeferred::create(exec, globalObject);
    399399    return deferred->reject(exec, jsUndefined());
  • trunk/Source/WebCore/bindings/js/JSDOMWindowBase.h

    r218437 r223237  
    7777private:
    7878    static JSC::JSInternalPromise* moduleLoaderResolve(JSC::JSGlobalObject*, JSC::ExecState*, JSC::JSModuleLoader*, JSC::JSValue, JSC::JSValue, JSC::JSValue);
    79     static JSC::JSInternalPromise* moduleLoaderFetch(JSC::JSGlobalObject*, JSC::ExecState*, JSC::JSModuleLoader*, JSC::JSValue, JSC::JSValue);
     79    static JSC::JSInternalPromise* moduleLoaderFetch(JSC::JSGlobalObject*, JSC::ExecState*, JSC::JSModuleLoader*, JSC::JSValue, JSC::JSValue, JSC::JSValue);
    8080    static JSC::JSValue moduleLoaderEvaluate(JSC::JSGlobalObject*, JSC::ExecState*, JSC::JSModuleLoader*, JSC::JSValue, JSC::JSValue, JSC::JSValue);
    81     static JSC::JSInternalPromise* moduleLoaderImportModule(JSC::JSGlobalObject*, JSC::ExecState*, JSC::JSModuleLoader*, JSC::JSString*, const JSC::SourceOrigin&);
     81    static JSC::JSInternalPromise* moduleLoaderImportModule(JSC::JSGlobalObject*, JSC::ExecState*, JSC::JSModuleLoader*, JSC::JSString*, JSC::JSValue, const JSC::SourceOrigin&);
    8282    static void promiseRejectionTracker(JSC::JSGlobalObject*, JSC::ExecState*, JSC::JSPromise*, JSC::JSPromiseRejectionOperation);
    8383
  • trunk/Source/WebCore/bindings/js/JSMainThreadExecState.h

    r218794 r223237  
    9191    }
    9292
    93     static JSC::JSInternalPromise& loadModule(JSC::ExecState& state, const String& moduleName, JSC::JSValue scriptFetcher)
     93    static JSC::JSInternalPromise& loadModule(JSC::ExecState& state, const String& moduleName, JSC::JSValue parameters, JSC::JSValue scriptFetcher)
    9494    {
    9595        JSMainThreadExecState currentState(&state);
    96         return *JSC::loadModule(&state, moduleName, scriptFetcher);
     96        return *JSC::loadModule(&state, moduleName, parameters, scriptFetcher);
    9797    }
    9898
  • trunk/Source/WebCore/bindings/js/ScriptController.cpp

    r223149 r223237  
    4242#include "MainFrame.h"
    4343#include "ModuleFetchFailureKind.h"
     44#include "ModuleFetchParameters.h"
    4445#include "NP_jsobject.h"
    4546#include "Page.h"
     
    6364#include <runtime/JSModuleRecord.h>
    6465#include <runtime/JSNativeStdFunction.h>
     66#include <runtime/JSScriptFetchParameters.h>
    6567#include <runtime/JSScriptFetcher.h>
    6668#include <wtf/MemoryPressureHandler.h>
     
    191193}
    192194
    193 void ScriptController::loadModuleScriptInWorld(LoadableModuleScript& moduleScript, const String& moduleName, DOMWrapperWorld& world)
     195void ScriptController::loadModuleScriptInWorld(LoadableModuleScript& moduleScript, const String& moduleName, Ref<ModuleFetchParameters>&& topLevelFetchParameters, DOMWrapperWorld& world)
    194196{
    195197    JSLockHolder lock(world.vm());
     
    198200    auto& state = *proxy.window()->globalExec();
    199201
    200     auto& promise = JSMainThreadExecState::loadModule(state, moduleName, JSC::JSScriptFetcher::create(state.vm(), { &moduleScript }));
     202    auto& promise = JSMainThreadExecState::loadModule(state, moduleName, JSC::JSScriptFetchParameters::create(state.vm(), WTFMove(topLevelFetchParameters)), JSC::JSScriptFetcher::create(state.vm(), { &moduleScript }));
    201203    setupModuleScriptHandlers(moduleScript, promise, world);
    202204}
    203205
    204 void ScriptController::loadModuleScript(LoadableModuleScript& moduleScript, const String& moduleName)
    205 {
    206     loadModuleScriptInWorld(moduleScript, moduleName, mainThreadNormalWorld());
     206void ScriptController::loadModuleScript(LoadableModuleScript& moduleScript, const String& moduleName, Ref<ModuleFetchParameters>&& topLevelFetchParameters)
     207{
     208    loadModuleScriptInWorld(moduleScript, moduleName, WTFMove(topLevelFetchParameters), mainThreadNormalWorld());
    207209}
    208210
  • trunk/Source/WebCore/bindings/js/ScriptController.h

    r218951 r223237  
    5757class HTMLPlugInElement;
    5858class LoadableModuleScript;
     59class ModuleFetchParameters;
    5960class ScriptSourceCode;
    6061class SecurityOrigin;
     
    116117    JSC::JSValue evaluateInWorld(const ScriptSourceCode&, DOMWrapperWorld&, ExceptionDetails* = nullptr);
    117118
    118     void loadModuleScriptInWorld(LoadableModuleScript&, const String& moduleName, DOMWrapperWorld&);
    119     void loadModuleScript(LoadableModuleScript&, const String& moduleName);
     119    void loadModuleScriptInWorld(LoadableModuleScript&, const String& moduleName, Ref<ModuleFetchParameters>&&, DOMWrapperWorld&);
     120    void loadModuleScript(LoadableModuleScript&, const String& moduleName, Ref<ModuleFetchParameters>&&);
    120121    void loadModuleScriptInWorld(LoadableModuleScript&, const ScriptSourceCode&, DOMWrapperWorld&);
    121122    void loadModuleScript(LoadableModuleScript&, const ScriptSourceCode&);
  • trunk/Source/WebCore/bindings/js/ScriptModuleLoader.cpp

    r212438 r223237  
    3636#include "MIMETypeRegistry.h"
    3737#include "ModuleFetchFailureKind.h"
     38#include "ModuleFetchParameters.h"
    3839#include "ScriptController.h"
    3940#include "ScriptSourceCode.h"
     41#include "SubresourceIntegrity.h"
    4042#include "WebCoreJSClientData.h"
    4143#include <runtime/Completion.h>
     
    4345#include <runtime/JSInternalPromiseDeferred.h>
    4446#include <runtime/JSModuleRecord.h>
     47#include <runtime/JSScriptFetchParameters.h>
    4548#include <runtime/JSScriptFetcher.h>
    4649#include <runtime/JSSourceCode.h>
     
    140143}
    141144
    142 JSC::JSInternalPromise* ScriptModuleLoader::fetch(JSC::JSGlobalObject* jsGlobalObject, JSC::ExecState* exec, JSC::JSModuleLoader*, JSC::JSValue moduleKeyValue, JSC::JSValue scriptFetcher)
    143 {
    144     ASSERT(JSC::jsDynamicCast<JSC::JSScriptFetcher*>(exec->vm(), scriptFetcher));
     145JSC::JSInternalPromise* ScriptModuleLoader::fetch(JSC::JSGlobalObject* jsGlobalObject, JSC::ExecState* exec, JSC::JSModuleLoader*, JSC::JSValue moduleKeyValue, JSC::JSValue parameters, JSC::JSValue scriptFetcher)
     146{
     147    JSC::VM& vm = exec->vm();
     148    ASSERT(JSC::jsDynamicCast<JSC::JSScriptFetcher*>(vm, scriptFetcher));
    145149
    146150    auto& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(jsGlobalObject);
     
    165169    }
    166170
    167     auto loader = CachedModuleScriptLoader::create(*this, deferred.get(), *static_cast<CachedScriptFetcher*>(JSC::jsCast<JSC::JSScriptFetcher*>(scriptFetcher)->fetcher()));
     171    RefPtr<ModuleFetchParameters> topLevelFetchParameters;
     172    if (auto* scriptFetchParameters = JSC::jsDynamicCast<JSC::JSScriptFetchParameters*>(vm, parameters))
     173        topLevelFetchParameters = static_cast<ModuleFetchParameters*>(&scriptFetchParameters->parameters());
     174
     175    auto loader = CachedModuleScriptLoader::create(*this, deferred.get(), *static_cast<CachedScriptFetcher*>(JSC::jsCast<JSC::JSScriptFetcher*>(scriptFetcher)->fetcher()), WTFMove(topLevelFetchParameters));
    168176    m_loaders.add(loader.copyRef());
    169177    if (!loader->load(m_document, completedURL)) {
     
    213221}
    214222
    215 JSC::JSInternalPromise* ScriptModuleLoader::importModule(JSC::JSGlobalObject* jsGlobalObject, JSC::ExecState* exec, JSC::JSModuleLoader*, JSC::JSString* moduleName, const JSC::SourceOrigin& sourceOrigin)
     223JSC::JSInternalPromise* ScriptModuleLoader::importModule(JSC::JSGlobalObject* jsGlobalObject, JSC::ExecState* exec, JSC::JSModuleLoader*, JSC::JSString* moduleName, JSC::JSValue parameters, const JSC::SourceOrigin& sourceOrigin)
    216224{
    217225    auto& state = *exec;
     
    249257        return rejectPromise(state, globalObject, TypeError, result.error());
    250258
    251     return JSC::importModule(exec, JSC::Identifier::fromString(&vm, result->string()), JSC::JSScriptFetcher::create(vm, WTFMove(scriptFetcher) ));
     259    return JSC::importModule(exec, JSC::Identifier::fromString(&vm, result->string()), parameters, JSC::JSScriptFetcher::create(vm, WTFMove(scriptFetcher) ));
    252260}
    253261
     
    285293    }
    286294
     295    if (auto* parameters = loader.parameters()) {
     296        if (!matchIntegrityMetadata(cachedScript, parameters->integrity())) {
     297            promise->reject(TypeError, makeString("Cannot load script ", cachedScript.url().stringCenterEllipsizedToLength(), ". Failed integrity metadata check."));
     298            return;
     299        }
     300    }
     301
    287302    m_requestURLToResponseURLMap.add(cachedScript.url(), cachedScript.response().url());
    288303    promise->resolveWithCallback([&] (JSC::ExecState& state, JSDOMGlobalObject&) {
  • trunk/Source/WebCore/bindings/js/ScriptModuleLoader.h

    r211280 r223237  
    5757
    5858    JSC::JSInternalPromise* resolve(JSC::JSGlobalObject*, JSC::ExecState*, JSC::JSModuleLoader*, JSC::JSValue moduleName, JSC::JSValue importerModuleKey, JSC::JSValue scriptFetcher);
    59     JSC::JSInternalPromise* fetch(JSC::JSGlobalObject*, JSC::ExecState*, JSC::JSModuleLoader*, JSC::JSValue moduleKey, JSC::JSValue scriptFetcher);
     59    JSC::JSInternalPromise* fetch(JSC::JSGlobalObject*, JSC::ExecState*, JSC::JSModuleLoader*, JSC::JSValue moduleKey, JSC::JSValue parameters, JSC::JSValue scriptFetcher);
    6060    JSC::JSValue evaluate(JSC::JSGlobalObject*, JSC::ExecState*, JSC::JSModuleLoader*, JSC::JSValue moduleKey, JSC::JSValue moduleRecord, JSC::JSValue scriptFetcher);
    61     JSC::JSInternalPromise* importModule(JSC::JSGlobalObject*, JSC::ExecState*, JSC::JSModuleLoader*, JSC::JSString*, const JSC::SourceOrigin&);
     61    JSC::JSInternalPromise* importModule(JSC::JSGlobalObject*, JSC::ExecState*, JSC::JSModuleLoader*, JSC::JSString*, JSC::JSValue parameters, const JSC::SourceOrigin&);
    6262
    6363private:
  • trunk/Source/WebCore/dom/LoadableModuleScript.cpp

    r211313 r223237  
    2929#include "Document.h"
    3030#include "Frame.h"
     31#include "ModuleFetchParameters.h"
    3132#include "ScriptController.h"
    3233#include "ScriptElement.h"
     
    3435namespace WebCore {
    3536
    36 Ref<LoadableModuleScript> LoadableModuleScript::create(const String& nonce, const String& crossOriginMode, const String& charset, const AtomicString& initiatorName, bool isInUserAgentShadowTree)
     37Ref<LoadableModuleScript> LoadableModuleScript::create(const String& nonce, const String& integrity, const String& crossOriginMode, const String& charset, const AtomicString& initiatorName, bool isInUserAgentShadowTree)
    3738{
    38     return adoptRef(*new LoadableModuleScript(nonce, crossOriginMode, charset, initiatorName, isInUserAgentShadowTree));
     39    return adoptRef(*new LoadableModuleScript(nonce, integrity, crossOriginMode, charset, initiatorName, isInUserAgentShadowTree));
    3940}
    4041
    41 LoadableModuleScript::LoadableModuleScript(const String& nonce, const String& crossOriginMode, const String& charset, const AtomicString& initiatorName, bool isInUserAgentShadowTree)
     42LoadableModuleScript::LoadableModuleScript(const String& nonce, const String& integrity, const String& crossOriginMode, const String& charset, const AtomicString& initiatorName, bool isInUserAgentShadowTree)
    4243    : LoadableScript(nonce, crossOriginMode, charset, initiatorName, isInUserAgentShadowTree)
     44    , m_parameters(ModuleFetchParameters::create(integrity))
    4345{
    4446}
     
    9294{
    9395    if (auto* frame = document.frame())
    94         frame->script().loadModuleScript(*this, rootURL.string());
     96        frame->script().loadModuleScript(*this, rootURL.string(), m_parameters.copyRef());
    9597}
    9698
  • trunk/Source/WebCore/dom/LoadableModuleScript.h

    r211313 r223237  
    3232
    3333class ScriptSourceCode;
     34class ModuleFetchParameters;
    3435
    3536class LoadableModuleScript final : public LoadableScript {
     
    3738    virtual ~LoadableModuleScript();
    3839
    39     static Ref<LoadableModuleScript> create(const String& nonce, const String& crossOriginMode, const String& charset, const AtomicString& initiatorName, bool isInUserAgentShadowTree);
     40    static Ref<LoadableModuleScript> create(const String& nonce, const String& integrity, const String& crossOriginMode, const String& charset, const AtomicString& initiatorName, bool isInUserAgentShadowTree);
    4041
    4142    bool isLoaded() const final;
     
    6061
    6162private:
    62     LoadableModuleScript(const String& nonce, const String& crossOriginMode, const String& charset, const AtomicString& initiatorName, bool isInUserAgentShadowTree);
     63    LoadableModuleScript(const String& nonce, const String& integrity, const String& crossOriginMode, const String& charset, const AtomicString& initiatorName, bool isInUserAgentShadowTree);
    6364
     65    Ref<ModuleFetchParameters> m_parameters;
    6466    RefPtr<UniquedStringImpl> m_moduleKey;
    6567    std::optional<LoadableScript::Error> m_error;
  • trunk/Source/WebCore/dom/ModuleFetchParameters.h

    r223236 r223237  
    11/*
    2  * Copyright (C) 2015, 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017 Yusuke Suzuki <utatane.tea@gmail.com>
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2626#pragma once
    2727
    28 #include "CachedResourceClient.h"
    29 #include "CachedResourceHandle.h"
    30 #include <wtf/Ref.h>
    31 #include <wtf/RefCounted.h>
    32 #include <wtf/RefPtr.h>
     28#include <runtime/ScriptFetchParameters.h>
    3329
    3430namespace WebCore {
    3531
    36 class CachedModuleScriptLoaderClient;
    37 class CachedScript;
    38 class CachedScriptFetcher;
    39 class DeferredPromise;
    40 class Document;
    41 class JSDOMGlobalObject;
    42 class URL;
    43 
    44 class CachedModuleScriptLoader final : public RefCounted<CachedModuleScriptLoader>, private CachedResourceClient {
     32class ModuleFetchParameters : public JSC::ScriptFetchParameters {
    4533public:
    46     static Ref<CachedModuleScriptLoader> create(CachedModuleScriptLoaderClient&, DeferredPromise&, CachedScriptFetcher&);
    47 
    48     virtual ~CachedModuleScriptLoader();
    49 
    50     bool load(Document&, const URL& sourceURL);
    51 
    52     CachedScriptFetcher& scriptFetcher() { return m_scriptFetcher.get(); }
    53     CachedScript* cachedScript() { return m_cachedScript.get(); }
    54 
    55     void clearClient()
     34    static Ref<ModuleFetchParameters> create(const String& integrity)
    5635    {
    57         ASSERT(m_client);
    58         m_client = nullptr;
     36        return adoptRef(*new ModuleFetchParameters(integrity));
    5937    }
    6038
     39    const String& integrity() const { return m_integrity; }
     40
    6141private:
    62     CachedModuleScriptLoader(CachedModuleScriptLoaderClient&, DeferredPromise&, CachedScriptFetcher&);
     42    ModuleFetchParameters(const String& integrity)
     43        : m_integrity(integrity)
     44    {
     45    }
    6346
    64     void notifyFinished(CachedResource&) final;
    65 
    66     CachedModuleScriptLoaderClient* m_client { nullptr };
    67     RefPtr<DeferredPromise> m_promise;
    68     Ref<CachedScriptFetcher> m_scriptFetcher;
    69     CachedResourceHandle<CachedScript> m_cachedScript;
     47    String m_integrity;
    7048};
    7149
  • trunk/Source/WebCore/dom/ScriptElement.cpp

    r220290 r223237  
    337337
    338338        m_isExternalScript = true;
    339         auto script = LoadableModuleScript::create(nonce, crossOriginMode, scriptCharset(), m_element.localName(), m_element.isInUserAgentShadowTree());
     339        auto script = LoadableModuleScript::create(
     340            nonce,
     341            m_element.document().settings().subresourceIntegrityEnabled() ? m_element.attributeWithoutSynchronization(HTMLNames::integrityAttr).string() : emptyString(),
     342            crossOriginMode,
     343            scriptCharset(),
     344            m_element.localName(),
     345            m_element.isInUserAgentShadowTree());
    340346        script->load(m_element.document(), moduleScriptRootURL);
    341347        m_loadableScript = WTFMove(script);
     
    343349    }
    344350
    345     auto script = LoadableModuleScript::create(nonce, crossOriginMode, scriptCharset(), m_element.localName(), m_element.isInUserAgentShadowTree());
     351    auto script = LoadableModuleScript::create(nonce, emptyString(), crossOriginMode, scriptCharset(), m_element.localName(), m_element.isInUserAgentShadowTree());
    346352
    347353    TextPosition position = m_element.document().isInDocumentWrite() ? TextPosition() : scriptStartPosition;
Note: See TracChangeset for help on using the changeset viewer.