Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (211017 => 211018)
--- trunk/Source/_javascript_Core/ChangeLog 2017-01-21 22:10:54 UTC (rev 211017)
+++ trunk/Source/_javascript_Core/ChangeLog 2017-01-21 22:22:54 UTC (rev 211018)
@@ -1,5 +1,35 @@
2017-01-21 Yusuke Suzuki <[email protected]>
+ [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 <[email protected]>
+
dynamic import is ambiguous with import declaration at module code
https://bugs.webkit.org/show_bug.cgi?id=167098
Modified: trunk/Source/_javascript_Core/builtins/BuiltinNames.h (211017 => 211018)
--- trunk/Source/_javascript_Core/builtins/BuiltinNames.h 2017-01-21 22:10:54 UTC (rev 211017)
+++ trunk/Source/_javascript_Core/builtins/BuiltinNames.h 2017-01-21 22:22:54 UTC (rev 211018)
@@ -160,6 +160,7 @@
macro(stringSubstrInternal) \
macro(makeBoundFunction) \
macro(hasOwnLengthProperty) \
+ macro(importModule) \
macro(WebAssembly) \
macro(Module) \
macro(Instance) \
Modified: trunk/Source/_javascript_Core/builtins/ModuleLoaderPrototype.js (211017 => 211018)
--- trunk/Source/_javascript_Core/builtins/ModuleLoaderPrototype.js 2017-01-21 22:10:54 UTC (rev 211017)
+++ trunk/Source/_javascript_Core/builtins/ModuleLoaderPrototype.js 2017-01-21 22:22:54 UTC (rev 211018)
@@ -312,15 +312,6 @@
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
@@ -334,7 +325,7 @@
return deferred.@promise;
}
- return this.requestInstantiateAll(key, fetcher).then((entry) => {
+ return this.requestSatisfy(key, fetcher).then((entry) => {
this.link(entry, fetcher);
return entry;
});
@@ -453,7 +444,7 @@
// 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;
});
@@ -471,17 +462,11 @@
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);
});
Modified: trunk/Source/_javascript_Core/jsc.cpp (211017 => 211018)
--- trunk/Source/_javascript_Core/jsc.cpp 2017-01-21 22:10:54 UTC (rev 211017)
+++ trunk/Source/_javascript_Core/jsc.cpp 2017-01-21 22:22:54 UTC (rev 211018)
@@ -1430,19 +1430,28 @@
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);
- MarkedArgumentBuffer arguments;
- arguments.append(moduleName);
- arguments.append(jsString(exec, sourceOrigin.string()));
- arguments.append(jsUndefined());
+ auto rejectPromise = [&] (JSValue error) {
+ return JSInternalPromiseDeferred::create(exec, globalObject)->reject(exec, error);
+ };
- return jsCast<JSInternalPromise*>(call(exec, function, callType, callData, moduleLoader, arguments));
+ 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 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)
Modified: trunk/Source/_javascript_Core/runtime/Completion.cpp (211017 => 211018)
--- trunk/Source/_javascript_Core/runtime/Completion.cpp 2017-01-21 22:10:54 UTC (rev 211017)
+++ trunk/Source/_javascript_Core/runtime/Completion.cpp 2017-01-21 22:22:54 UTC (rev 211018)
@@ -248,4 +248,13 @@
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
Modified: trunk/Source/_javascript_Core/runtime/Completion.h (211017 => 211018)
--- trunk/Source/_javascript_Core/runtime/Completion.h 2017-01-21 22:10:54 UTC (rev 211017)
+++ trunk/Source/_javascript_Core/runtime/Completion.h 2017-01-21 22:22:54 UTC (rev 211018)
@@ -67,4 +67,6 @@
// 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
Modified: trunk/Source/_javascript_Core/runtime/JSModuleLoader.cpp (211017 => 211018)
--- trunk/Source/_javascript_Core/runtime/JSModuleLoader.cpp 2017-01-21 22:10:54 UTC (rev 211017)
+++ trunk/Source/_javascript_Core/runtime/JSModuleLoader.cpp 2017-01-21 22:22:54 UTC (rev 211018)
@@ -137,6 +137,20 @@
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())
Modified: trunk/Source/_javascript_Core/runtime/JSModuleLoader.h (211017 => 211018)
--- trunk/Source/_javascript_Core/runtime/JSModuleLoader.h 2017-01-21 22:10:54 UTC (rev 211017)
+++ trunk/Source/_javascript_Core/runtime/JSModuleLoader.h 2017-01-21 22:22:54 UTC (rev 211018)
@@ -67,6 +67,7 @@
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);
Modified: trunk/Source/_javascript_Core/runtime/ModuleLoaderPrototype.cpp (211017 => 211018)
--- trunk/Source/_javascript_Core/runtime/ModuleLoaderPrototype.cpp 2017-01-21 22:10:54 UTC (rev 211017)
+++ trunk/Source/_javascript_Core/runtime/ModuleLoaderPrototype.cpp 2017-01-21 22:22:54 UTC (rev 211018)
@@ -77,7 +77,6 @@
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
@@ -88,7 +87,7 @@
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