Changeset 211018 in webkit


Ignore:
Timestamp:
Jan 21, 2017 2:22:54 PM (7 years ago)
Author:
Yusuke Suzuki
Message:

[JSC] export JSC::importModule API for WebCore dynamic import
https://bugs.webkit.org/show_bug.cgi?id=167099

Reviewed by Darin Adler.

We newly expose JSC::importModule API. This can be used later
from WebCore to implement WebCore side dynamic import.
And JSC shell also uses this API.

And this patch also cleans up module loader a bit:
Dropping requestInstantiateAll.

  • builtins/BuiltinNames.h:
  • builtins/ModuleLoaderPrototype.js:

(requestLink):
(requestImportModule):
(requestInstantiateAll): Deleted.
(importModule): Deleted.

  • jsc.cpp:

(GlobalObject::moduleLoaderImportModule):

  • runtime/Completion.cpp:

(JSC::importModule):

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

(JSC::JSModuleLoader::requestImportModule):

  • runtime/JSModuleLoader.h:
  • runtime/ModuleLoaderPrototype.cpp:
Location:
trunk/Source/JavaScriptCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r211017 r211018  
     12017-01-21  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [JSC] export JSC::importModule API for WebCore dynamic import
     4        https://bugs.webkit.org/show_bug.cgi?id=167099
     5
     6        Reviewed by Darin Adler.
     7
     8        We newly expose JSC::importModule API. This can be used later
     9        from WebCore to implement WebCore side dynamic import.
     10        And JSC shell also uses this API.
     11
     12        And this patch also cleans up module loader a bit:
     13        Dropping requestInstantiateAll.
     14
     15        * builtins/BuiltinNames.h:
     16        * builtins/ModuleLoaderPrototype.js:
     17        (requestLink):
     18        (requestImportModule):
     19        (requestInstantiateAll): Deleted.
     20        (importModule): Deleted.
     21        * jsc.cpp:
     22        (GlobalObject::moduleLoaderImportModule):
     23        * runtime/Completion.cpp:
     24        (JSC::importModule):
     25        * runtime/Completion.h:
     26        * runtime/JSModuleLoader.cpp:
     27        (JSC::JSModuleLoader::requestImportModule):
     28        * runtime/JSModuleLoader.h:
     29        * runtime/ModuleLoaderPrototype.cpp:
     30
    1312017-01-21  Yusuke Suzuki  <utatane.tea@gmail.com>
    232
  • trunk/Source/JavaScriptCore/builtins/BuiltinNames.h

    r210028 r211018  
    161161    macro(makeBoundFunction) \
    162162    macro(hasOwnLengthProperty) \
     163    macro(importModule) \
    163164    macro(WebAssembly) \
    164165    macro(Module) \
  • trunk/Source/JavaScriptCore/builtins/ModuleLoaderPrototype.js

    r210585 r211018  
    313313}
    314314
    315 function requestInstantiateAll(key, fetcher)
    316 {
    317     // https://whatwg.github.io/loader/#request-instantiate-all
    318 
    319     "use strict";
    320 
    321     return this.requestSatisfy(key, fetcher);
    322 }
    323 
    324315function requestLink(key, fetcher)
    325316{
     
    335326    }
    336327
    337     return this.requestInstantiateAll(key, fetcher).then((entry) => {
     328    return this.requestSatisfy(key, fetcher).then((entry) => {
    338329        this.link(entry, fetcher);
    339330        return entry;
     
    454445    // For example, take the "jquery" and return the URL for the resource.
    455446    return this.resolve(moduleName, referrer, fetcher).then((key) => {
    456         return this.requestInstantiateAll(key, fetcher);
     447        return this.requestSatisfy(key, fetcher);
    457448    }).then((entry) => {
    458449        return entry.key;
     
    472463}
    473464
    474 function importModule(moduleName, referrer, fetcher)
    475 {
    476     "use strict";
    477 
    478     // Loader.resolve hook point.
    479     // resolve: moduleName => Promise(moduleKey)
    480     // Take the name and resolve it to the unique identifier for the resource location.
    481     // For example, take the "jquery" and return the URL for the resource.
    482     return this.resolve(moduleName, referrer, fetcher).then((key) => {
    483         return this.requestInstantiateAll(key, fetcher);
    484     }).then((entry) => {
     465function requestImportModule(key, fetcher)
     466{
     467    "use strict";
     468
     469    return this.requestSatisfy(key, fetcher).then((entry) => {
    485470        this.linkAndEvaluateModule(entry.key, fetcher);
    486471        return this.getModuleNamespaceObject(entry.module);
  • trunk/Source/JavaScriptCore/jsc.cpp

    r210912 r211018  
    14311431}
    14321432
    1433 JSInternalPromise* GlobalObject::moduleLoaderImportModule(JSGlobalObject*, ExecState* exec, JSModuleLoader* moduleLoader, JSString* moduleName, const SourceOrigin& sourceOrigin)
    1434 {
    1435     auto* function = jsCast<JSObject*>(moduleLoader->get(exec, exec->propertyNames().builtinNames().importModulePublicName()));
    1436     CallData callData;
    1437     auto callType = JSC::getCallData(function, callData);
    1438     ASSERT(callType != CallType::None);
    1439 
    1440     MarkedArgumentBuffer arguments;
    1441     arguments.append(moduleName);
    1442     arguments.append(jsString(exec, sourceOrigin.string()));
    1443     arguments.append(jsUndefined());
    1444 
    1445     return jsCast<JSInternalPromise*>(call(exec, function, callType, callData, moduleLoader, arguments));
     1433JSInternalPromise* GlobalObject::moduleLoaderImportModule(JSGlobalObject* globalObject, ExecState* exec, JSModuleLoader*, JSString* moduleNameValue, const SourceOrigin& sourceOrigin)
     1434{
     1435    VM& vm = globalObject->vm();
     1436    auto scope = DECLARE_CATCH_SCOPE(vm);
     1437
     1438    auto rejectPromise = [&] (JSValue error) {
     1439        return JSInternalPromiseDeferred::create(exec, globalObject)->reject(exec, error);
     1440    };
     1441
     1442    auto referrer = sourceOrigin.string();
     1443    auto moduleName = moduleNameValue->value(exec);
     1444    if (UNLIKELY(scope.exception())) {
     1445        JSValue exception = scope.exception();
     1446        scope.clearException();
     1447        return rejectPromise(exception);
     1448    }
     1449
     1450    auto directoryName = extractDirectoryName(referrer.impl());
     1451    if (!directoryName)
     1452        return rejectPromise(createError(exec, makeString("Could not resolve the referrer name '", String(referrer.impl()), "'.")));
     1453
     1454    return JSC::importModule(exec, Identifier::fromString(&vm, resolvePath(directoryName.value(), ModuleName(moduleName))), jsUndefined());
    14461455}
    14471456
  • trunk/Source/JavaScriptCore/runtime/Completion.cpp

    r210585 r211018  
    249249}
    250250
     251JSInternalPromise* importModule(ExecState* exec, const Identifier& moduleKey, JSValue scriptFetcher)
     252{
     253    JSLockHolder lock(exec);
     254    RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable());
     255    RELEASE_ASSERT(!exec->vm().isCollectorBusyOnCurrentThread());
     256
     257    return exec->vmEntryGlobalObject()->moduleLoader()->requestImportModule(exec, moduleKey, scriptFetcher);
     258}
     259
    251260} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/Completion.h

    r210585 r211018  
    6868JS_EXPORT_PRIVATE JSValue linkAndEvaluateModule(ExecState*, const Identifier& moduleKey, JSValue scriptFetcher = jsUndefined());
    6969
     70JS_EXPORT_PRIVATE JSInternalPromise* importModule(ExecState*, const Identifier& moduleKey, JSValue scriptFetcher);
     71
    7072} // namespace JSC
  • trunk/Source/JavaScriptCore/runtime/JSModuleLoader.cpp

    r210585 r211018  
    138138}
    139139
     140JSInternalPromise* JSModuleLoader::requestImportModule(ExecState* exec, const Identifier& moduleKey, JSValue scriptFetcher)
     141{
     142    auto* function = jsCast<JSObject*>(get(exec, exec->propertyNames().builtinNames().requestImportModulePublicName()));
     143    CallData callData;
     144    auto callType = JSC::getCallData(function, callData);
     145    ASSERT(callType != CallType::None);
     146
     147    MarkedArgumentBuffer arguments;
     148    arguments.append(jsString(exec, moduleKey.impl()));
     149    arguments.append(scriptFetcher);
     150
     151    return jsCast<JSInternalPromise*>(call(exec, function, callType, callData, this, arguments));
     152}
     153
    140154JSInternalPromise* JSModuleLoader::importModule(ExecState* exec, JSString* moduleName, const SourceOrigin& referrer)
    141155{
  • trunk/Source/JavaScriptCore/runtime/JSModuleLoader.h

    r210585 r211018  
    6868    JSInternalPromise* loadModule(ExecState*, JSValue moduleName, JSValue referrer, JSValue scriptFetcher);
    6969    JSValue linkAndEvaluateModule(ExecState*, JSValue moduleKey, JSValue scriptFetcher);
     70    JSInternalPromise* requestImportModule(ExecState*, const Identifier&, JSValue scriptFetcher);
    7071
    7172    // Platform dependent hooked APIs.
  • trunk/Source/JavaScriptCore/runtime/ModuleLoaderPrototype.cpp

    r210573 r211018  
    7878    requestInstantiate             JSBuiltin                                           DontEnum|Function 2
    7979    requestSatisfy                 JSBuiltin                                           DontEnum|Function 2
    80     requestInstantiateAll          JSBuiltin                                           DontEnum|Function 2
    8180    requestLink                    JSBuiltin                                           DontEnum|Function 2
    8281    requestReady                   JSBuiltin                                           DontEnum|Function 2
     
    8988    loadModule                     JSBuiltin                                           DontEnum|Function 3
    9089    linkAndEvaluateModule          JSBuiltin                                           DontEnum|Function 2
    91     importModule                   JSBuiltin                                           DontEnum|Function 3
     90    requestImportModule            JSBuiltin                                           DontEnum|Function 2
    9291    getModuleNamespaceObject       moduleLoaderPrototypeGetModuleNamespaceObject       DontEnum|Function 1
    9392    parseModule                    moduleLoaderPrototypeParseModule                    DontEnum|Function 2
Note: See TracChangeset for help on using the changeset viewer.