⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 223173 in webkit


Ignore:
Timestamp:
Oct 11, 2017, 5:30:37 AM (9 years ago)
Author:
Yusuke Suzuki
Message:

[JSC] Drop Instantiate hook in ES6 module loader
​https://bugs.webkit.org/show_bug.cgi?id=178162

Reviewed by Sam Weinig.

Source/JavaScriptCore:

This patch is a part of patch series for module loader refactoring to adopt
integrity="" parameters and introduce new whatwg module import mechanism.

In this patch, we drop instantiate hook in module loader. This hook is originally
introduced because it is defined in whatwg/loader spec. But this hook is not
used in our implementation, and this hook won't be used since (1) whatwg/loader
spec is abandoned, and (2) this type of hooks should be done in Service Workers.

In addition, this patch applies some cleaning up of our module loader JS code
to simplify things. This change paves the way to more efficient loader implementation
with great flexibility to adopt integrity="" parameters.

  • builtins/ModuleLoaderPrototype.js:

(requestInstantiate):
(provideFetch):
provide is changed to provideFetch since we only used this function with Fetch stage parameter.

(fulfillInstantiate): Deleted.
(commitInstantiated): Deleted.
(instantiation): Deleted.
They are merged into requestInstantiate code. This is simpler.

(provide): Deleted.

  • jsc.cpp:
  • runtime/Completion.cpp:

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

  • runtime/JSGlobalObject.cpp:
  • runtime/JSGlobalObject.h:
  • runtime/JSModuleLoader.cpp:

(JSC::JSModuleLoader::provideFetch):
(JSC::JSModuleLoader::provide): Deleted.
Changed to provideFetch.

(JSC::JSModuleLoader::instantiate): Deleted.
Drop this hook.

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

(JSC::moduleLoaderPrototypeInstantiate): Deleted.
Drop this hook.

Source/WebCore:

Drop instantiate hooks.
No behavior change.

  • bindings/js/JSDOMWindowBase.cpp:
  • bindings/js/JSWorkerGlobalScopeBase.cpp:
Location:
trunk/Source
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r223161 r223173  
     12017-10-11  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [JSC] Drop Instantiate hook in ES6 module loader
     4        https://bugs.webkit.org/show_bug.cgi?id=178162
     5
     6        Reviewed by Sam Weinig.
     7
     8        This patch is a part of patch series for module loader refactoring to adopt
     9        integrity="" parameters and introduce new whatwg module import mechanism.
     10
     11        In this patch, we drop instantiate hook in module loader. This hook is originally
     12        introduced because it is defined in whatwg/loader spec. But this hook is not
     13        used in our implementation, and this hook won't be used since (1) whatwg/loader
     14        spec is abandoned, and (2) this type of hooks should be done in Service Workers.
     15
     16        In addition, this patch applies some cleaning up of our module loader JS code
     17        to simplify things. This change paves the way to more efficient loader implementation
     18        with great flexibility to adopt integrity="" parameters.
     19
     20        * builtins/ModuleLoaderPrototype.js:
     21        (requestInstantiate):
     22        (provideFetch):
     23        provide is changed to provideFetch since we only used this function with Fetch stage parameter.
     24
     25        (fulfillInstantiate): Deleted.
     26        (commitInstantiated): Deleted.
     27        (instantiation): Deleted.
     28        They are merged into requestInstantiate code. This is simpler.
     29
     30        (provide): Deleted.
     31        * jsc.cpp:
     32        * runtime/Completion.cpp:
     33        (JSC::loadAndEvaluateModule):
     34        (JSC::loadModule):
     35        * runtime/JSGlobalObject.cpp:
     36        * runtime/JSGlobalObject.h:
     37        * runtime/JSModuleLoader.cpp:
     38        (JSC::JSModuleLoader::provideFetch):
     39        (JSC::JSModuleLoader::provide): Deleted.
     40        Changed to provideFetch.
     41
     42        (JSC::JSModuleLoader::instantiate): Deleted.
     43        Drop this hook.
     44
     45        * runtime/JSModuleLoader.h:
     46        * runtime/ModuleLoaderPrototype.cpp:
     47        (JSC::moduleLoaderPrototypeInstantiate): Deleted.
     48        Drop this hook.
     49
    1502017-10-10  Saam Barati  <sbarati@apple.com>
    251
  • trunk/Source/JavaScriptCore/builtins/ModuleLoaderPrototype.js

    r222895 r223173  
    3131//    1. Loader.resolve
    3232//    2. Loader.fetch
    33 //    3. Loader.instantiate
    3433
    3534@globalPrivate
    … …  
    140139}
    141140
    142 function fulfillInstantiate(entry, optionalInstance, source)
    143 {
    144     // https://whatwg.github.io/loader/#fulfill-instantiate
    145 
    146     "use strict";
    147 
    148     if (!entry.instantiate)
    149         entry.instantiate = @newPromiseCapability(@InternalPromise).@promise;
    150     this.commitInstantiated(entry, optionalInstance, source);
    151 
    152     // FIXME: The draft fulfills the promise in the CommitInstantiated operation.
    153     // But it CommitInstantiated is also used in the requestInstantiate and
    154     // we should not "force fulfill" there.
    155     // So we separate "force fulfill" operation from the CommitInstantiated operation.
    156     // https://github.com/whatwg/loader/pull/67
    157     this.forceFulfillPromise(entry.instantiate, entry);
    158 }
    159 
    160 function commitInstantiated(entry, optionalInstance, source)
    161 {
    162     // https://whatwg.github.io/loader/#commit-instantiated
    163 
    164     "use strict";
    165 
    166     var moduleRecord = this.instantiation(optionalInstance, source, entry);
    167 
    168     // FIXME: Described in the draft,
    169     //   4. Fulfill entry.[[Instantiate]] with instance.
    170     // But, instantiate promise should be fulfilled with the entry.
    171     // We remove this statement because instantiate promise will be
    172     // fulfilled without this "force fulfill" operation.
    173     // https://github.com/whatwg/loader/pull/67
    174 
    175     var dependencies = [];
    176     var dependenciesMap = moduleRecord.dependenciesMap;
    177     moduleRecord.registryEntry = entry;
    178     var requestedModules = this.requestedModules(moduleRecord);
    179     for (var i = 0, length = requestedModules.length; i < length; ++i) {
    180         var depKey = requestedModules[i];
    181         var pair = {
    182             key: depKey,
    183             value: @undefined
    184         };
    185         @putByValDirect(dependencies, dependencies.length, pair);
    186         dependenciesMap.@set(depKey, pair);
    187     }
    188     entry.dependencies = dependencies;
    189     entry.dependenciesMap = dependenciesMap;
    190     entry.module = moduleRecord;
    191     @setStateToMax(entry, @ModuleSatisfy);
    192 }
    193 
    194 function instantiation(result, source, entry)
    195 {
    196     // https://whatwg.github.io/loader/#instantiation
    197     // FIXME: Current implementation does not support optionalInstance.
    198     // https://bugs.webkit.org/show_bug.cgi?id=148171
    199 
    200     "use strict";
    201 
    202     return this.parseModule(entry.key, source);
    203 }
    204 
    205141// Loader.
    206142
    … …  
    240176
    241177    var instantiatePromise = this.requestFetch(key, fetcher).then((source) => {
    242         // Hook point.
    243         // 3. Loader.instantiate
    244         //     https://whatwg.github.io/loader/#browser-instantiate
    245         //     Take the key and the fetched source code, and instantiate the module record
    246         //     by parsing the module source code.
    247         //     It has the chance to provide the optional module instance that is different from
    248         //     the ordinary one.
    249         return this.instantiate(key, source, fetcher).then((optionalInstance) => {
    250             this.commitInstantiated(entry, optionalInstance, source);
    251             return entry;
    252         });
     178        var moduleRecord = this.parseModule(entry.key, source);
     179
     180        // FIXME: Described in the draft,
     181        //   4. Fulfill entry.[[Instantiate]] with instance.
     182        // But, instantiate promise should be fulfilled with the entry.
     183        // We remove this statement because instantiate promise will be
     184        // fulfilled without this "force fulfill" operation.
     185        // https://github.com/whatwg/loader/pull/67
     186
     187        var dependencies = [];
     188        var dependenciesMap = moduleRecord.dependenciesMap;
     189        moduleRecord.registryEntry = entry;
     190        var requestedModules = this.requestedModules(moduleRecord);
     191        for (var i = 0, length = requestedModules.length; i < length; ++i) {
     192            var depKey = requestedModules[i];
     193            var pair = {
     194                key: depKey,
     195                value: @undefined
     196            };
     197            @putByValDirect(dependencies, dependencies.length, pair);
     198            dependenciesMap.@set(depKey, pair);
     199        }
     200        entry.dependencies = dependencies;
     201        entry.dependenciesMap = dependenciesMap;
     202        entry.module = moduleRecord;
     203        @setStateToMax(entry, @ModuleSatisfy);
     204        return entry;
    253205    });
    254206    entry.instantiate = instantiatePromise;
    … …  
    401353// APIs to control the module loader.
    402354
    403 function provide(key, stage, value)
    404 {
    405     "use strict";
    406 
    407     var entry = this.ensureRegistered(key);
    408 
    409     if (stage === @ModuleFetch) {
    410         if (entry.state > @ModuleFetch)
    411             @throwTypeError("Requested module is already fetched.");
    412         this.fulfillFetch(entry, value);
    413         return;
    414     }
    415 
    416     if (stage === @ModuleInstantiate) {
    417         if (entry.state > @ModuleInstantiate)
    418             @throwTypeError("Requested module is already instantiated.");
    419         this.fulfillFetch(entry, @undefined);
    420         entry.fetch.then((source) => {
    421             this.fulfillInstantiate(entry, value, source);
    422         });
    423         return;
    424     }
    425 
    426     @throwTypeError("Requested module is already ready to be executed.");
     355function provideFetch(key, value)
     356{
     357    "use strict";
     358
     359    var entry = this.ensureRegistered(key);
     360
     361    if (entry.state > @ModuleFetch)
     362        @throwTypeError("Requested module is already fetched.");
     363    this.fulfillFetch(entry, value);
    427364}
    428365
  • trunk/Source/JavaScriptCore/jsc.cpp

    r223002 r223173  
    16741674    &moduleLoaderResolve,
    16751675    &moduleLoaderFetch,
    1676     nullptr, // moduleLoaderInstantiate
    16771676    &moduleLoaderCreateImportMetaProperties,
    16781677    nullptr, // moduleLoaderEvaluate
  • trunk/Source/JavaScriptCore/runtime/Completion.cpp

    r221822 r223173  
    188188
    189189    // Insert the given source code to the ModuleLoader registry as the fetched registry entry.
    190     globalObject->moduleLoader()->provide(exec, key, JSModuleLoader::Status::Fetch, source);
     190    globalObject->moduleLoader()->provideFetch(exec, key, source);
    191191    RETURN_IF_EXCEPTION(scope, rejectPromise(exec, globalObject));
    192192
    … …  
    228228    // Insert the given source code to the ModuleLoader registry as the fetched registry entry.
    229229    // FIXME: Introduce JSSourceCode object to wrap around this source.
    230     globalObject->moduleLoader()->provide(exec, key, JSModuleLoader::Status::Fetch, source);
     230    globalObject->moduleLoader()->provideFetch(exec, key, source);
    231231    RETURN_IF_EXCEPTION(scope, rejectPromise(exec, globalObject));
    232232
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp

    r223125 r223173  
    255255    nullptr, // moduleLoaderResolve
    256256    nullptr, // moduleLoaderFetch
    257     nullptr, // moduleLoaderInstantiate
    258257    nullptr, // moduleLoaderCreateImportMetaProperties
    259258    nullptr, // moduleLoaderEvaluate
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h

    r222895 r223173  
    196196    ModuleLoaderFetchPtr moduleLoaderFetch;
    197197
    198     typedef JSInternalPromise* (*ModuleLoaderInstantiatePtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue);
    199     ModuleLoaderInstantiatePtr moduleLoaderInstantiate;
    200 
    201198    typedef JSObject* (*ModuleLoaderCreateImportMetaPropertiesPtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSModuleRecord*, JSValue);
    202199    ModuleLoaderCreateImportMetaPropertiesPtr moduleLoaderCreateImportMetaProperties;
  • trunk/Source/JavaScriptCore/runtime/JSModuleLoader.cpp

    r222895 r223173  
    8080}
    8181
    82 JSValue JSModuleLoader::provide(ExecState* exec, JSValue key, Status status, const SourceCode& sourceCode)
    83 {
    84     VM& vm = exec->vm();
    85     auto scope = DECLARE_THROW_SCOPE(vm);
    86 
    87     JSObject* function = jsCast<JSObject*>(get(exec, vm.propertyNames->builtinNames().providePublicName()));
     82JSValue JSModuleLoader::provideFetch(ExecState* exec, JSValue key, const SourceCode& sourceCode)
     83{
     84    VM& vm = exec->vm();
     85    auto scope = DECLARE_THROW_SCOPE(vm);
     86
     87    JSObject* function = jsCast<JSObject*>(get(exec, vm.propertyNames->builtinNames().provideFetchPublicName()));
    8888    RETURN_IF_EXCEPTION(scope, { });
    8989    CallData callData;
    … …  
    9494    MarkedArgumentBuffer arguments;
    9595    arguments.append(key);
    96     arguments.append(jsNumber(status));
    9796    arguments.append(JSSourceCode::create(vm, WTFMove(source)));
    9897
    … …  
    238237}
    239238
    240 JSInternalPromise* JSModuleLoader::instantiate(ExecState* exec, JSValue key, JSValue source, JSValue scriptFetcher)
    241 {
    242     if (Options::dumpModuleLoadingState())
    243         dataLog("Loader [instantiate] ", printableModuleKey(exec, key), "\n");
    244 
    245     JSGlobalObject* globalObject = exec->lexicalGlobalObject();
    246     if (globalObject->globalObjectMethodTable()->moduleLoaderInstantiate)
    247         return globalObject->globalObjectMethodTable()->moduleLoaderInstantiate(globalObject, exec, this, key, source, scriptFetcher);
    248     JSInternalPromiseDeferred* deferred = JSInternalPromiseDeferred::create(exec, globalObject);
    249     deferred->resolve(exec, jsUndefined());
    250     return deferred->promise();
    251 }
    252 
    253239JSObject* JSModuleLoader::createImportMetaProperties(ExecState* exec, JSValue key, JSModuleRecord* moduleRecord, JSValue scriptFetcher)
    254240{
  • trunk/Source/JavaScriptCore/runtime/JSModuleLoader.h

    r222895 r223173  
    6464
    6565    // APIs to control the module loader.
    66     JSValue provide(ExecState*, JSValue key, Status, const SourceCode&);
     66    JSValue provideFetch(ExecState*, JSValue key, const SourceCode&);
    6767    JSInternalPromise* loadAndEvaluateModule(ExecState*, JSValue moduleName, JSValue referrer, JSValue scriptFetcher);
    6868    JSInternalPromise* loadModule(ExecState*, JSValue moduleName, JSValue referrer, JSValue scriptFetcher);
    … …  
    7474    JSInternalPromise* resolve(ExecState*, JSValue name, JSValue referrer, JSValue scriptFetcher);
    7575    JSInternalPromise* fetch(ExecState*, JSValue key, JSValue scriptFetcher);
    76     JSInternalPromise* instantiate(ExecState*, JSValue key, JSValue source, JSValue scriptFetcher);
    7776    JSObject* createImportMetaProperties(ExecState*, JSValue key, JSModuleRecord*, JSValue scriptFetcher);
    7877
  • trunk/Source/JavaScriptCore/runtime/ModuleLoaderPrototype.cpp

    r222895 r223173  
    5454static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeResolve(ExecState*);
    5555static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeFetch(ExecState*);
    56 static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeInstantiate(ExecState*);
    5756static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeGetModuleNamespaceObject(ExecState*);
    5857
    … …  
    7271    forceFulfillPromise            JSBuiltin                                           DontEnum|Function 2
    7372    fulfillFetch                   JSBuiltin                                           DontEnum|Function 2
    74     fulfillInstantiate             JSBuiltin                                           DontEnum|Function 2
    75     commitInstantiated             JSBuiltin                                           DontEnum|Function 3
    76     instantiation                  JSBuiltin                                           DontEnum|Function 3
    7773    requestFetch                   JSBuiltin                                           DontEnum|Function 2
    7874    requestInstantiate             JSBuiltin                                           DontEnum|Function 2
    … …  
    8480    moduleEvaluation               JSBuiltin                                           DontEnum|Function 2
    8581    evaluate                       moduleLoaderPrototypeEvaluate                       DontEnum|Function 3
    86     provide                        JSBuiltin                                           DontEnum|Function 3
     82    provideFetch                   JSBuiltin                                           DontEnum|Function 2
    8783    loadAndEvaluateModule          JSBuiltin                                           DontEnum|Function 3
    8884    loadModule                     JSBuiltin                                           DontEnum|Function 3
    … …  
    9490    resolve                        moduleLoaderPrototypeResolve                        DontEnum|Function 2
    9591    fetch                          moduleLoaderPrototypeFetch                          DontEnum|Function 2
    96     instantiate                    moduleLoaderPrototypeInstantiate                    DontEnum|Function 3
    9792@end
    9893*/
    … …  
    204199}
    205200
    206 EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeInstantiate(ExecState* exec)
    207 {
    208     VM& vm = exec->vm();
    209     // Hook point, Loader.instantiate
    210     // https://whatwg.github.io/loader/#browser-instantiate
    211     // Take the key and the fetched source code, and instantiate the module record
    212     // by parsing the module source code.
    213     // It has the chance to provide the optional module instance that is different from
    214     // the ordinary one.
    215     JSModuleLoader* loader = jsDynamicCast<JSModuleLoader*>(vm, exec->thisValue());
    216     if (!loader)
    217         return JSValue::encode(jsUndefined());
    218     return JSValue::encode(loader->instantiate(exec, exec->argument(0), exec->argument(1), exec->argument(2)));
    219 }
    220 
    221201EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeGetModuleNamespaceObject(ExecState* exec)
    222202{
  • trunk/Source/WebCore/ChangeLog

    r223172 r223173  
     12017-10-11  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [JSC] Drop Instantiate hook in ES6 module loader
     4        https://bugs.webkit.org/show_bug.cgi?id=178162
     5
     6        Reviewed by Sam Weinig.
     7
     8        Drop instantiate hooks.
     9        No behavior change.
     10
     11        * bindings/js/JSDOMWindowBase.cpp:
     12        * bindings/js/JSWorkerGlobalScopeBase.cpp:
     13
    1142017-10-11  Alicia Boya García  <aboya@igalia.com>
    215
  • trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp

    r222895 r223173  
    7373    &moduleLoaderResolve,
    7474    &moduleLoaderFetch,
    75     nullptr, // moduleLoaderInstantiate
    7675    nullptr, // moduleLoaderCreateImportMetaProperties
    7776    &moduleLoaderEvaluate,
  • trunk/Source/WebCore/bindings/js/JSWorkerGlobalScopeBase.cpp

    r222895 r223173  
    6060    nullptr, // moduleLoaderResolve
    6161    nullptr, // moduleLoaderFetch
    62     nullptr, // moduleLoaderInstantiate
    6362    nullptr, // moduleLoaderCreateImportMetaProperties
    6463    nullptr, // moduleLoaderEvaluate
Note: See TracChangeset for help on using the changeset viewer.