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:
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@211018
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
2017-01-21 Yusuke Suzuki <utatane.tea@gmail.com>
+ [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:
+
+2017-01-21 Yusuke Suzuki <utatane.tea@gmail.com>
+
dynamic import is ambiguous with import declaration at module code
https://bugs.webkit.org/show_bug.cgi?id=167098
macro(stringSubstrInternal) \
macro(makeBoundFunction) \
macro(hasOwnLengthProperty) \
+ macro(importModule) \
macro(WebAssembly) \
macro(Module) \
macro(Instance) \
return satisfyPromise;
}
-function requestInstantiateAll(key, fetcher)
-{
- // https://whatwg.github.io/loader/#request-instantiate-all
-
- "use strict";
-
- return this.requestSatisfy(key, fetcher);
-}
-
function requestLink(key, fetcher)
{
// https://whatwg.github.io/loader/#request-link
return deferred.@promise;
}
- return this.requestInstantiateAll(key, fetcher).then((entry) => {
+ return this.requestSatisfy(key, fetcher).then((entry) => {
this.link(entry, fetcher);
return entry;
});
// Take the name and resolve it to the unique identifier for the resource location.
// For example, take the "jquery" and return the URL for the resource.
return this.resolve(moduleName, referrer, fetcher).then((key) => {
- return this.requestInstantiateAll(key, fetcher);
+ return this.requestSatisfy(key, fetcher);
}).then((entry) => {
return entry.key;
});
return this.moduleEvaluation(entry.module, fetcher);
}
-function importModule(moduleName, referrer, fetcher)
+function requestImportModule(key, fetcher)
{
"use strict";
- // Loader.resolve hook point.
- // resolve: moduleName => Promise(moduleKey)
- // Take the name and resolve it to the unique identifier for the resource location.
- // For example, take the "jquery" and return the URL for the resource.
- return this.resolve(moduleName, referrer, fetcher).then((key) => {
- return this.requestInstantiateAll(key, fetcher);
- }).then((entry) => {
+ return this.requestSatisfy(key, fetcher).then((entry) => {
this.linkAndEvaluateModule(entry.key, fetcher);
return this.getModuleNamespaceObject(entry.module);
});
return resolvePath(directoryName.value(), ModuleName(fileName.impl()));
}
-JSInternalPromise* GlobalObject::moduleLoaderImportModule(JSGlobalObject*, ExecState* exec, JSModuleLoader* moduleLoader, JSString* moduleName, const SourceOrigin& sourceOrigin)
+JSInternalPromise* GlobalObject::moduleLoaderImportModule(JSGlobalObject* globalObject, ExecState* exec, JSModuleLoader*, JSString* moduleNameValue, const SourceOrigin& sourceOrigin)
{
- auto* function = jsCast<JSObject*>(moduleLoader->get(exec, exec->propertyNames().builtinNames().importModulePublicName()));
- CallData callData;
- auto callType = JSC::getCallData(function, callData);
- ASSERT(callType != CallType::None);
+ VM& vm = globalObject->vm();
+ auto scope = DECLARE_CATCH_SCOPE(vm);
+
+ auto rejectPromise = [&] (JSValue error) {
+ return JSInternalPromiseDeferred::create(exec, globalObject)->reject(exec, error);
+ };
- MarkedArgumentBuffer arguments;
- arguments.append(moduleName);
- arguments.append(jsString(exec, sourceOrigin.string()));
- arguments.append(jsUndefined());
+ auto referrer = sourceOrigin.string();
+ auto moduleName = moduleNameValue->value(exec);
+ if (UNLIKELY(scope.exception())) {
+ JSValue exception = scope.exception();
+ scope.clearException();
+ return rejectPromise(exception);
+ }
+
+ auto directoryName = extractDirectoryName(referrer.impl());
+ if (!directoryName)
+ return rejectPromise(createError(exec, makeString("Could not resolve the referrer name '", String(referrer.impl()), "'.")));
- return jsCast<JSInternalPromise*>(call(exec, function, callType, callData, moduleLoader, arguments));
+ return JSC::importModule(exec, Identifier::fromString(&vm, resolvePath(directoryName.value(), ModuleName(moduleName))), jsUndefined());
}
JSInternalPromise* GlobalObject::moduleLoaderResolve(JSGlobalObject* globalObject, ExecState* exec, JSModuleLoader*, JSValue keyValue, JSValue referrerValue, JSValue)
return globalObject->moduleLoader()->linkAndEvaluateModule(exec, identifierToJSValue(exec->vm(), moduleKey), scriptFetcher);
}
+JSInternalPromise* importModule(ExecState* exec, const Identifier& moduleKey, JSValue scriptFetcher)
+{
+ JSLockHolder lock(exec);
+ RELEASE_ASSERT(exec->vm().atomicStringTable() == wtfThreadData().atomicStringTable());
+ RELEASE_ASSERT(!exec->vm().isCollectorBusyOnCurrentThread());
+
+ return exec->vmEntryGlobalObject()->moduleLoader()->requestImportModule(exec, moduleKey, scriptFetcher);
+}
+
} // namespace JSC
// Link and evaluate the already linked module. This function is called in a sync manner.
JS_EXPORT_PRIVATE JSValue linkAndEvaluateModule(ExecState*, const Identifier& moduleKey, JSValue scriptFetcher = jsUndefined());
+JS_EXPORT_PRIVATE JSInternalPromise* importModule(ExecState*, const Identifier& moduleKey, JSValue scriptFetcher);
+
} // namespace JSC
return call(exec, function, callType, callData, this, arguments);
}
+JSInternalPromise* JSModuleLoader::requestImportModule(ExecState* exec, const Identifier& moduleKey, JSValue scriptFetcher)
+{
+ auto* function = jsCast<JSObject*>(get(exec, exec->propertyNames().builtinNames().requestImportModulePublicName()));
+ CallData callData;
+ auto callType = JSC::getCallData(function, callData);
+ ASSERT(callType != CallType::None);
+
+ MarkedArgumentBuffer arguments;
+ arguments.append(jsString(exec, moduleKey.impl()));
+ arguments.append(scriptFetcher);
+
+ return jsCast<JSInternalPromise*>(call(exec, function, callType, callData, this, arguments));
+}
+
JSInternalPromise* JSModuleLoader::importModule(ExecState* exec, JSString* moduleName, const SourceOrigin& referrer)
{
if (Options::dumpModuleLoadingState())
JSInternalPromise* loadAndEvaluateModule(ExecState*, JSValue moduleName, JSValue referrer, JSValue scriptFetcher);
JSInternalPromise* loadModule(ExecState*, JSValue moduleName, JSValue referrer, JSValue scriptFetcher);
JSValue linkAndEvaluateModule(ExecState*, JSValue moduleKey, JSValue scriptFetcher);
+ JSInternalPromise* requestImportModule(ExecState*, const Identifier&, JSValue scriptFetcher);
// Platform dependent hooked APIs.
JSInternalPromise* importModule(ExecState*, JSString* moduleName, const SourceOrigin& referrer);
requestFetch JSBuiltin DontEnum|Function 2
requestInstantiate JSBuiltin DontEnum|Function 2
requestSatisfy JSBuiltin DontEnum|Function 2
- requestInstantiateAll JSBuiltin DontEnum|Function 2
requestLink JSBuiltin DontEnum|Function 2
requestReady JSBuiltin DontEnum|Function 2
link JSBuiltin DontEnum|Function 2
loadAndEvaluateModule JSBuiltin DontEnum|Function 3
loadModule JSBuiltin DontEnum|Function 3
linkAndEvaluateModule JSBuiltin DontEnum|Function 2
- importModule JSBuiltin DontEnum|Function 3
+ requestImportModule JSBuiltin DontEnum|Function 2
getModuleNamespaceObject moduleLoaderPrototypeGetModuleNamespaceObject DontEnum|Function 1
parseModule moduleLoaderPrototypeParseModule DontEnum|Function 2
requestedModules moduleLoaderPrototypeRequestedModules DontEnum|Function 1