<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[211018] trunk/Source/JavaScriptCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/211018">211018</a></dd>
<dt>Author</dt> <dd>utatane.tea@gmail.com</dd>
<dt>Date</dt> <dd>2017-01-21 14:22:54 -0800 (Sat, 21 Jan 2017)</dd>
</dl>
<h3>Log Message</h3>
<pre>[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:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorebuiltinsBuiltinNamesh">trunk/Source/JavaScriptCore/builtins/BuiltinNames.h</a></li>
<li><a href="#trunkSourceJavaScriptCorebuiltinsModuleLoaderPrototypejs">trunk/Source/JavaScriptCore/builtins/ModuleLoaderPrototype.js</a></li>
<li><a href="#trunkSourceJavaScriptCorejsccpp">trunk/Source/JavaScriptCore/jsc.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeCompletioncpp">trunk/Source/JavaScriptCore/runtime/Completion.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeCompletionh">trunk/Source/JavaScriptCore/runtime/Completion.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSModuleLoadercpp">trunk/Source/JavaScriptCore/runtime/JSModuleLoader.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSModuleLoaderh">trunk/Source/JavaScriptCore/runtime/JSModuleLoader.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeModuleLoaderPrototypecpp">trunk/Source/JavaScriptCore/runtime/ModuleLoaderPrototype.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (211017 => 211018)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2017-01-21 22:10:54 UTC (rev 211017)
+++ trunk/Source/JavaScriptCore/ChangeLog        2017-01-21 22:22:54 UTC (rev 211018)
</span><span class="lines">@@ -1,5 +1,35 @@
</span><span class="cx"> 2017-01-21 Yusuke Suzuki <utatane.tea@gmail.com>
</span><span class="cx">
</span><ins>+ [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>
+
</ins><span class="cx"> dynamic import is ambiguous with import declaration at module code
</span><span class="cx"> https://bugs.webkit.org/show_bug.cgi?id=167098
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebuiltinsBuiltinNamesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/builtins/BuiltinNames.h (211017 => 211018)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/builtins/BuiltinNames.h        2017-01-21 22:10:54 UTC (rev 211017)
+++ trunk/Source/JavaScriptCore/builtins/BuiltinNames.h        2017-01-21 22:22:54 UTC (rev 211018)
</span><span class="lines">@@ -160,6 +160,7 @@
</span><span class="cx"> macro(stringSubstrInternal) \
</span><span class="cx"> macro(makeBoundFunction) \
</span><span class="cx"> macro(hasOwnLengthProperty) \
</span><ins>+ macro(importModule) \
</ins><span class="cx"> macro(WebAssembly) \
</span><span class="cx"> macro(Module) \
</span><span class="cx"> macro(Instance) \
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebuiltinsModuleLoaderPrototypejs"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/builtins/ModuleLoaderPrototype.js (211017 => 211018)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/builtins/ModuleLoaderPrototype.js        2017-01-21 22:10:54 UTC (rev 211017)
+++ trunk/Source/JavaScriptCore/builtins/ModuleLoaderPrototype.js        2017-01-21 22:22:54 UTC (rev 211018)
</span><span class="lines">@@ -312,15 +312,6 @@
</span><span class="cx"> return satisfyPromise;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-function requestInstantiateAll(key, fetcher)
-{
- // https://whatwg.github.io/loader/#request-instantiate-all
-
- "use strict";
-
- return this.requestSatisfy(key, fetcher);
-}
-
</del><span class="cx"> function requestLink(key, fetcher)
</span><span class="cx"> {
</span><span class="cx"> // https://whatwg.github.io/loader/#request-link
</span><span class="lines">@@ -334,7 +325,7 @@
</span><span class="cx"> return deferred.@promise;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- return this.requestInstantiateAll(key, fetcher).then((entry) => {
</del><ins>+ return this.requestSatisfy(key, fetcher).then((entry) => {
</ins><span class="cx"> this.link(entry, fetcher);
</span><span class="cx"> return entry;
</span><span class="cx"> });
</span><span class="lines">@@ -453,7 +444,7 @@
</span><span class="cx"> // Take the name and resolve it to the unique identifier for the resource location.
</span><span class="cx"> // For example, take the "jquery" and return the URL for the resource.
</span><span class="cx"> return this.resolve(moduleName, referrer, fetcher).then((key) => {
</span><del>- return this.requestInstantiateAll(key, fetcher);
</del><ins>+ return this.requestSatisfy(key, fetcher);
</ins><span class="cx"> }).then((entry) => {
</span><span class="cx"> return entry.key;
</span><span class="cx"> });
</span><span class="lines">@@ -471,17 +462,11 @@
</span><span class="cx"> return this.moduleEvaluation(entry.module, fetcher);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-function importModule(moduleName, referrer, fetcher)
</del><ins>+function requestImportModule(key, fetcher)
</ins><span class="cx"> {
</span><span class="cx"> "use strict";
</span><span class="cx">
</span><del>- // 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) => {
</del><ins>+ return this.requestSatisfy(key, fetcher).then((entry) => {
</ins><span class="cx"> this.linkAndEvaluateModule(entry.key, fetcher);
</span><span class="cx"> return this.getModuleNamespaceObject(entry.module);
</span><span class="cx"> });
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorejsccpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/jsc.cpp (211017 => 211018)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/jsc.cpp        2017-01-21 22:10:54 UTC (rev 211017)
+++ trunk/Source/JavaScriptCore/jsc.cpp        2017-01-21 22:22:54 UTC (rev 211018)
</span><span class="lines">@@ -1430,19 +1430,28 @@
</span><span class="cx"> return resolvePath(directoryName.value(), ModuleName(fileName.impl()));
</span><span class="cx"> }
</span><span class="cx">
</span><del>-JSInternalPromise* GlobalObject::moduleLoaderImportModule(JSGlobalObject*, ExecState* exec, JSModuleLoader* moduleLoader, JSString* moduleName, const SourceOrigin& sourceOrigin)
</del><ins>+JSInternalPromise* GlobalObject::moduleLoaderImportModule(JSGlobalObject* globalObject, ExecState* exec, JSModuleLoader*, JSString* moduleNameValue, const SourceOrigin& sourceOrigin)
</ins><span class="cx"> {
</span><del>- auto* function = jsCast<JSObject*>(moduleLoader->get(exec, exec->propertyNames().builtinNames().importModulePublicName()));
- CallData callData;
- auto callType = JSC::getCallData(function, callData);
- ASSERT(callType != CallType::None);
</del><ins>+ VM& vm = globalObject->vm();
+ auto scope = DECLARE_CATCH_SCOPE(vm);
</ins><span class="cx">
</span><del>- MarkedArgumentBuffer arguments;
- arguments.append(moduleName);
- arguments.append(jsString(exec, sourceOrigin.string()));
- arguments.append(jsUndefined());
</del><ins>+ auto rejectPromise = [&] (JSValue error) {
+ return JSInternalPromiseDeferred::create(exec, globalObject)->reject(exec, error);
+ };
</ins><span class="cx">
</span><del>- return jsCast<JSInternalPromise*>(call(exec, function, callType, callData, moduleLoader, arguments));
</del><ins>+ 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());
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> JSInternalPromise* GlobalObject::moduleLoaderResolve(JSGlobalObject* globalObject, ExecState* exec, JSModuleLoader*, JSValue keyValue, JSValue referrerValue, JSValue)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeCompletioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/Completion.cpp (211017 => 211018)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/Completion.cpp        2017-01-21 22:10:54 UTC (rev 211017)
+++ trunk/Source/JavaScriptCore/runtime/Completion.cpp        2017-01-21 22:22:54 UTC (rev 211018)
</span><span class="lines">@@ -248,4 +248,13 @@
</span><span class="cx"> return globalObject->moduleLoader()->linkAndEvaluateModule(exec, identifierToJSValue(exec->vm(), moduleKey), scriptFetcher);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+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);
+}
+
</ins><span class="cx"> } // namespace JSC
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeCompletionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/Completion.h (211017 => 211018)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/Completion.h        2017-01-21 22:10:54 UTC (rev 211017)
+++ trunk/Source/JavaScriptCore/runtime/Completion.h        2017-01-21 22:22:54 UTC (rev 211018)
</span><span class="lines">@@ -67,4 +67,6 @@
</span><span class="cx"> // Link and evaluate the already linked module. This function is called in a sync manner.
</span><span class="cx"> JS_EXPORT_PRIVATE JSValue linkAndEvaluateModule(ExecState*, const Identifier& moduleKey, JSValue scriptFetcher = jsUndefined());
</span><span class="cx">
</span><ins>+JS_EXPORT_PRIVATE JSInternalPromise* importModule(ExecState*, const Identifier& moduleKey, JSValue scriptFetcher);
+
</ins><span class="cx"> } // namespace JSC
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSModuleLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSModuleLoader.cpp (211017 => 211018)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSModuleLoader.cpp        2017-01-21 22:10:54 UTC (rev 211017)
+++ trunk/Source/JavaScriptCore/runtime/JSModuleLoader.cpp        2017-01-21 22:22:54 UTC (rev 211018)
</span><span class="lines">@@ -137,6 +137,20 @@
</span><span class="cx"> return call(exec, function, callType, callData, this, arguments);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+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));
+}
+
</ins><span class="cx"> JSInternalPromise* JSModuleLoader::importModule(ExecState* exec, JSString* moduleName, const SourceOrigin& referrer)
</span><span class="cx"> {
</span><span class="cx"> if (Options::dumpModuleLoadingState())
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSModuleLoaderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSModuleLoader.h (211017 => 211018)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSModuleLoader.h        2017-01-21 22:10:54 UTC (rev 211017)
+++ trunk/Source/JavaScriptCore/runtime/JSModuleLoader.h        2017-01-21 22:22:54 UTC (rev 211018)
</span><span class="lines">@@ -67,6 +67,7 @@
</span><span class="cx"> JSInternalPromise* loadAndEvaluateModule(ExecState*, JSValue moduleName, JSValue referrer, JSValue scriptFetcher);
</span><span class="cx"> JSInternalPromise* loadModule(ExecState*, JSValue moduleName, JSValue referrer, JSValue scriptFetcher);
</span><span class="cx"> JSValue linkAndEvaluateModule(ExecState*, JSValue moduleKey, JSValue scriptFetcher);
</span><ins>+ JSInternalPromise* requestImportModule(ExecState*, const Identifier&, JSValue scriptFetcher);
</ins><span class="cx">
</span><span class="cx"> // Platform dependent hooked APIs.
</span><span class="cx"> JSInternalPromise* importModule(ExecState*, JSString* moduleName, const SourceOrigin& referrer);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeModuleLoaderPrototypecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/ModuleLoaderPrototype.cpp (211017 => 211018)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/ModuleLoaderPrototype.cpp        2017-01-21 22:10:54 UTC (rev 211017)
+++ trunk/Source/JavaScriptCore/runtime/ModuleLoaderPrototype.cpp        2017-01-21 22:22:54 UTC (rev 211018)
</span><span class="lines">@@ -77,7 +77,6 @@
</span><span class="cx"> requestFetch JSBuiltin DontEnum|Function 2
</span><span class="cx"> requestInstantiate JSBuiltin DontEnum|Function 2
</span><span class="cx"> requestSatisfy JSBuiltin DontEnum|Function 2
</span><del>- requestInstantiateAll JSBuiltin DontEnum|Function 2
</del><span class="cx"> requestLink JSBuiltin DontEnum|Function 2
</span><span class="cx"> requestReady JSBuiltin DontEnum|Function 2
</span><span class="cx"> link JSBuiltin DontEnum|Function 2
</span><span class="lines">@@ -88,7 +87,7 @@
</span><span class="cx"> loadAndEvaluateModule JSBuiltin DontEnum|Function 3
</span><span class="cx"> loadModule JSBuiltin DontEnum|Function 3
</span><span class="cx"> linkAndEvaluateModule JSBuiltin DontEnum|Function 2
</span><del>- importModule JSBuiltin DontEnum|Function 3
</del><ins>+ requestImportModule JSBuiltin DontEnum|Function 2
</ins><span class="cx"> getModuleNamespaceObject moduleLoaderPrototypeGetModuleNamespaceObject DontEnum|Function 1
</span><span class="cx"> parseModule moduleLoaderPrototypeParseModule DontEnum|Function 2
</span><span class="cx"> requestedModules moduleLoaderPrototypeRequestedModules DontEnum|Function 1
</span></span></pre>
</div>
</div>
</body>
</html>