Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit 86fe7b0

Browse files
[JSC] Drop translate phase in module loader
https://bugs.webkit.org/show_bug.cgi?id=164861 Reviewed by Saam Barati. Source/JavaScriptCore: Originally, this "translate" phase was introduced to the module loader. However, recent rework discussion[1] starts dropping this phase. And this "translate" phase is meaningless in the browser side module loader since this phase originally mimics the node.js's translation hook (like, transpiling CoffeeScript source to JavaScript). This "translate" phase is not necessary for the exposed HTML5 <script type="module"> tag right now. Once the module loader pipeline is redefined and specified, we need to update the current loader anyway. So dropping "translate" phase right now is OK. This a bit simplifies the current module loader pipeline. [1]: whatwg/loader#147 * builtins/ModuleLoaderPrototype.js: (newRegistryEntry): (fulfillFetch): (requestFetch): (requestInstantiate): (provide): (fulfillTranslate): Deleted. (requestTranslate): Deleted. * bytecode/BytecodeIntrinsicRegistry.cpp: (JSC::BytecodeIntrinsicRegistry::BytecodeIntrinsicRegistry): * jsc.cpp: * runtime/JSGlobalObject.cpp: * runtime/JSGlobalObject.h: * runtime/JSModuleLoader.cpp: (JSC::JSModuleLoader::translate): Deleted. * runtime/JSModuleLoader.h: * runtime/ModuleLoaderPrototype.cpp: (JSC::moduleLoaderPrototypeInstantiate): (JSC::moduleLoaderPrototypeTranslate): Deleted. Source/WebCore: * bindings/js/JSDOMWindowBase.cpp: * bindings/js/JSWorkerGlobalScopeBase.cpp: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@209500 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent f25ea0c commit 86fe7b0

12 files changed

+118
-113
lines changed

Source/JavaScriptCore/ChangeLog

+42
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,45 @@
1+
2016-12-07 Yusuke Suzuki <[email protected]>
2+
3+
[JSC] Drop translate phase in module loader
4+
https://bugs.webkit.org/show_bug.cgi?id=164861
5+
6+
Reviewed by Saam Barati.
7+
8+
Originally, this "translate" phase was introduced to the module loader.
9+
However, recent rework discussion[1] starts dropping this phase.
10+
And this "translate" phase is meaningless in the browser side module loader
11+
since this phase originally mimics the node.js's translation hook (like,
12+
transpiling CoffeeScript source to JavaScript).
13+
14+
This "translate" phase is not necessary for the exposed HTML5
15+
<script type="module"> tag right now. Once the module loader pipeline is
16+
redefined and specified, we need to update the current loader anyway.
17+
So dropping "translate" phase right now is OK.
18+
19+
This a bit simplifies the current module loader pipeline.
20+
21+
[1]: https://github.com/whatwg/loader/issues/147
22+
23+
* builtins/ModuleLoaderPrototype.js:
24+
(newRegistryEntry):
25+
(fulfillFetch):
26+
(requestFetch):
27+
(requestInstantiate):
28+
(provide):
29+
(fulfillTranslate): Deleted.
30+
(requestTranslate): Deleted.
31+
* bytecode/BytecodeIntrinsicRegistry.cpp:
32+
(JSC::BytecodeIntrinsicRegistry::BytecodeIntrinsicRegistry):
33+
* jsc.cpp:
34+
* runtime/JSGlobalObject.cpp:
35+
* runtime/JSGlobalObject.h:
36+
* runtime/JSModuleLoader.cpp:
37+
(JSC::JSModuleLoader::translate): Deleted.
38+
* runtime/JSModuleLoader.h:
39+
* runtime/ModuleLoaderPrototype.cpp:
40+
(JSC::moduleLoaderPrototypeInstantiate):
41+
(JSC::moduleLoaderPrototypeTranslate): Deleted.
42+
143
2016-12-07 Joseph Pecoraro <[email protected]>
244

345
Web Inspector: Add ability to distinguish if a Script was parsed as a module

Source/JavaScriptCore/builtins/ModuleLoaderPrototype.js

+13-68
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
// Currently, there are 4 hooks.
3131
// 1. Loader.resolve
3232
// 2. Loader.fetch
33-
// 3. Loader.translate
34-
// 4. Loader.instantiate
33+
// 3. Loader.instantiate
3534

3635
function setStateToMax(entry, newState)
3736
{
@@ -54,36 +53,29 @@ function newRegistryEntry(key)
5453
// a. If the status is Fetch and there is no entry.fetch promise, the entry is ready to fetch.
5554
// b. If the status is Fetch and there is the entry.fetch promise, the entry is just fetching the resource.
5655
//
57-
// 2. Translate
58-
// Ready to translate (or now translating) the raw fetched resource to the ECMAScript source code.
59-
// We can insert the hook that translates the resources e.g. transpilers.
60-
// a. If the status is Translate and there is no entry.translate promise, the entry is ready to translate.
61-
// b. If the status is Translate and there is the entry.translate promise, the entry is just translating
62-
// the payload to the source code.
63-
//
64-
// 3. Instantiate (AnalyzeModule)
65-
// Ready to instantiate (or now instantiating) the module record from the fetched (and translated)
56+
// 2. Instantiate (AnalyzeModule)
57+
// Ready to instantiate (or now instantiating) the module record from the fetched
6658
// source code.
6759
// Typically, we parse the module code, extract the dependencies and binding information.
6860
// a. If the status is Instantiate and there is no entry.instantiate promise, the entry is ready to instantiate.
69-
// b. If the status is Instantiate and there is the entry.translate promise, the entry is just instantiating
61+
// b. If the status is Instantiate and there is the entry.fetch promise, the entry is just instantiating
7062
// the module record.
7163
//
72-
// 4. Satisfy
64+
// 3. Satisfy
7365
// Ready to request the dependent modules (or now requesting & resolving).
7466
// Without this state, the current draft causes infinite recursion when there is circular dependency.
7567
// a. If the status is Satisfy and there is no entry.satisfy promise, the entry is ready to resolve the dependencies.
7668
// b. If the status is Satisfy and there is the entry.satisfy promise, the entry is just resolving
7769
// the dependencies.
7870
//
79-
// 5. Link
71+
// 4. Link
8072
// Ready to link the module with the other modules.
8173
// Linking means that the module imports and exports the bindings from/to the other modules.
8274
//
83-
// 6. Ready
75+
// 5. Ready
8476
// The module is linked, so the module is ready to be executed.
8577
//
86-
// Each registry entry has the 4 promises; "fetch", "translate", "instantiate" and "satisfy".
78+
// Each registry entry has the 4 promises; "fetch", "instantiate" and "satisfy".
8779
// They are assigned when starting the each phase. And they are fulfilled when the each phase is completed.
8880
//
8981
// In the current module draft, linking will be performed after the whole modules are instantiated and the dependencies are resolved.
@@ -100,7 +92,6 @@ function newRegistryEntry(key)
10092
state: @ModuleFetch,
10193
metadata: @undefined,
10294
fetch: @undefined,
103-
translate: @undefined,
10495
instantiate: @undefined,
10596
satisfy: @undefined,
10697
dependencies: [], // To keep the module order, we store the module keys in the array.
@@ -143,18 +134,6 @@ function fulfillFetch(entry, payload)
143134
if (!entry.fetch)
144135
entry.fetch = @newPromiseCapability(@InternalPromise).@promise;
145136
this.forceFulfillPromise(entry.fetch, payload);
146-
this.setStateToMax(entry, @ModuleTranslate);
147-
}
148-
149-
function fulfillTranslate(entry, source)
150-
{
151-
// https://whatwg.github.io/loader/#fulfill-translate
152-
153-
"use strict";
154-
155-
if (!entry.translate)
156-
entry.translate = @newPromiseCapability(@InternalPromise).@promise;
157-
this.forceFulfillPromise(entry.translate, source);
158137
this.setStateToMax(entry, @ModuleInstantiate);
159138
}
160139

@@ -240,38 +219,13 @@ function requestFetch(key, initiator)
240219
// For example, JavaScriptCore shell can provide the hook fetching the resource
241220
// from the local file system.
242221
var fetchPromise = this.fetch(key, initiator).then((payload) => {
243-
this.setStateToMax(entry, @ModuleTranslate);
222+
this.setStateToMax(entry, @ModuleInstantiate);
244223
return payload;
245224
});
246225
entry.fetch = fetchPromise;
247226
return fetchPromise;
248227
}
249228

250-
function requestTranslate(key, initiator)
251-
{
252-
// https://whatwg.github.io/loader/#request-translate
253-
254-
"use strict";
255-
256-
var entry = this.ensureRegistered(key);
257-
if (entry.translate)
258-
return entry.translate;
259-
260-
var translatePromise = this.requestFetch(key, initiator).then((payload) => {
261-
// Hook point.
262-
// 3. Loader.translate
263-
// https://whatwg.github.io/loader/#browser-translate
264-
// Take the key and the fetched source code and translate it to the ES6 source code.
265-
// Typically it is used by the transpilers.
266-
return this.translate(key, payload, initiator).then((source) => {
267-
this.setStateToMax(entry, @ModuleInstantiate);
268-
return source;
269-
});
270-
});
271-
entry.translate = translatePromise;
272-
return translatePromise;
273-
}
274-
275229
function requestInstantiate(key, initiator)
276230
{
277231
// https://whatwg.github.io/loader/#request-instantiate
@@ -282,11 +236,11 @@ function requestInstantiate(key, initiator)
282236
if (entry.instantiate)
283237
return entry.instantiate;
284238

285-
var instantiatePromise = this.requestTranslate(key, initiator).then((source) => {
239+
var instantiatePromise = this.requestFetch(key, initiator).then((source) => {
286240
// Hook point.
287-
// 4. Loader.instantiate
241+
// 3. Loader.instantiate
288242
// https://whatwg.github.io/loader/#browser-instantiate
289-
// Take the key and the translated source code, and instantiate the module record
243+
// Take the key and the fetched source code, and instantiate the module record
290244
// by parsing the module source code.
291245
// It has the chance to provide the optional module instance that is different from
292246
// the ordinary one.
@@ -462,20 +416,11 @@ function provide(key, stage, value)
462416
return;
463417
}
464418

465-
if (stage === @ModuleTranslate) {
466-
if (entry.state > @ModuleTranslate)
467-
@throwTypeError("Requested module is already translated.");
468-
this.fulfillFetch(entry, @undefined);
469-
this.fulfillTranslate(entry, value);
470-
return;
471-
}
472-
473419
if (stage === @ModuleInstantiate) {
474420
if (entry.state > @ModuleInstantiate)
475421
@throwTypeError("Requested module is already instantiated.");
476422
this.fulfillFetch(entry, @undefined);
477-
this.fulfillTranslate(entry, value);
478-
entry.translate.then((source) => {
423+
entry.fetch.then((source) => {
479424
this.fulfillInstantiate(entry, value, source);
480425
});
481426
return;

Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ BytecodeIntrinsicRegistry::BytecodeIntrinsicRegistry(VM& vm)
5656
m_MAX_STRING_LENGTH.set(m_vm, jsNumber(JSString::MaxLength));
5757
m_MAX_SAFE_INTEGER.set(m_vm, jsDoubleNumber(maxSafeInteger()));
5858
m_ModuleFetch.set(m_vm, jsNumber(static_cast<unsigned>(JSModuleLoader::Status::Fetch)));
59-
m_ModuleTranslate.set(m_vm, jsNumber(static_cast<unsigned>(JSModuleLoader::Status::Translate)));
6059
m_ModuleInstantiate.set(m_vm, jsNumber(static_cast<unsigned>(JSModuleLoader::Status::Instantiate)));
6160
m_ModuleSatisfy.set(m_vm, jsNumber(static_cast<unsigned>(JSModuleLoader::Status::Satisfy)));
6261
m_ModuleLink.set(m_vm, jsNumber(static_cast<unsigned>(JSModuleLoader::Status::Link)));

Source/JavaScriptCore/jsc.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -1279,8 +1279,18 @@ class GlobalObject : public JSGlobalObject {
12791279
};
12801280

12811281
const ClassInfo GlobalObject::s_info = { "global", &JSGlobalObject::s_info, nullptr, CREATE_METHOD_TABLE(GlobalObject) };
1282-
const GlobalObjectMethodTable GlobalObject::s_globalObjectMethodTable = { &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptRuntimeFlags, 0, &shouldInterruptScriptBeforeTimeout, &moduleLoaderResolve, &moduleLoaderFetch, nullptr, nullptr, nullptr, nullptr };
1283-
1282+
const GlobalObjectMethodTable GlobalObject::s_globalObjectMethodTable = {
1283+
&supportsRichSourceInfo,
1284+
&shouldInterruptScript,
1285+
&javaScriptRuntimeFlags,
1286+
nullptr,
1287+
&shouldInterruptScriptBeforeTimeout,
1288+
&moduleLoaderResolve,
1289+
&moduleLoaderFetch,
1290+
nullptr,
1291+
nullptr,
1292+
nullptr
1293+
};
12841294

12851295
GlobalObject::GlobalObject(VM& vm, Structure* structure)
12861296
: JSGlobalObject(vm, structure, &s_globalObjectMethodTable)

Source/JavaScriptCore/runtime/JSGlobalObject.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,18 @@ namespace JSC {
246246

247247
const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &Base::s_info, &globalObjectTable, CREATE_METHOD_TABLE(JSGlobalObject) };
248248

249-
const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = { &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptRuntimeFlags, nullptr, &shouldInterruptScriptBeforeTimeout, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
249+
const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = {
250+
&supportsRichSourceInfo,
251+
&shouldInterruptScript,
252+
&javaScriptRuntimeFlags,
253+
nullptr,
254+
&shouldInterruptScriptBeforeTimeout,
255+
nullptr,
256+
nullptr,
257+
nullptr,
258+
nullptr,
259+
nullptr
260+
};
250261

251262
/* Source for JSGlobalObject.lut.h
252263
@begin globalObjectTable

Source/JavaScriptCore/runtime/JSGlobalObject.h

-3
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,6 @@ struct GlobalObjectMethodTable {
189189
typedef JSInternalPromise* (*ModuleLoaderFetchPtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue);
190190
ModuleLoaderFetchPtr moduleLoaderFetch;
191191

192-
typedef JSInternalPromise* (*ModuleLoaderTranslatePtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue);
193-
ModuleLoaderTranslatePtr moduleLoaderTranslate;
194-
195192
typedef JSInternalPromise* (*ModuleLoaderInstantiatePtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue);
196193
ModuleLoaderInstantiatePtr moduleLoaderInstantiate;
197194

Source/JavaScriptCore/runtime/JSModuleLoader.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,6 @@ JSInternalPromise* JSModuleLoader::fetch(ExecState* exec, JSValue key, JSValue i
169169
return deferred->promise();
170170
}
171171

172-
JSInternalPromise* JSModuleLoader::translate(ExecState* exec, JSValue key, JSValue payload, JSValue initiator)
173-
{
174-
if (Options::dumpModuleLoadingState())
175-
dataLog("Loader [translate] ", printableModuleKey(exec, key), "\n");
176-
177-
JSGlobalObject* globalObject = exec->lexicalGlobalObject();
178-
if (globalObject->globalObjectMethodTable()->moduleLoaderTranslate)
179-
return globalObject->globalObjectMethodTable()->moduleLoaderTranslate(globalObject, exec, this, key, payload, initiator);
180-
JSInternalPromiseDeferred* deferred = JSInternalPromiseDeferred::create(exec, globalObject);
181-
deferred->resolve(exec, payload);
182-
return deferred->promise();
183-
}
184-
185172
JSInternalPromise* JSModuleLoader::instantiate(ExecState* exec, JSValue key, JSValue source, JSValue initiator)
186173
{
187174
if (Options::dumpModuleLoadingState())

Source/JavaScriptCore/runtime/JSModuleLoader.h

+4-6
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ class JSModuleLoader : public JSNonFinalObject {
4040

4141
enum Status {
4242
Fetch = 1,
43-
Translate = 2,
44-
Instantiate = 3,
45-
Satisfy = 4,
46-
Link = 5,
47-
Ready = 6,
43+
Instantiate,
44+
Satisfy,
45+
Link,
46+
Ready,
4847
};
4948

5049
static JSModuleLoader* create(ExecState* exec, VM& vm, JSGlobalObject* globalObject, Structure* structure)
@@ -70,7 +69,6 @@ class JSModuleLoader : public JSNonFinalObject {
7069
// Platform dependent hooked APIs.
7170
JSInternalPromise* resolve(ExecState*, JSValue name, JSValue referrer, JSValue initiator);
7271
JSInternalPromise* fetch(ExecState*, JSValue key, JSValue initiator);
73-
JSInternalPromise* translate(ExecState*, JSValue key, JSValue payload, JSValue initiator);
7472
JSInternalPromise* instantiate(ExecState*, JSValue key, JSValue source, JSValue initiator);
7573

7674
// Additional platform dependent hooked APIs.

Source/JavaScriptCore/runtime/ModuleLoaderPrototype.cpp

+1-17
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeEvaluate(ExecState*);
5151
static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeModuleDeclarationInstantiation(ExecState*);
5252
static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeResolve(ExecState*);
5353
static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeFetch(ExecState*);
54-
static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeTranslate(ExecState*);
5554
static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeInstantiate(ExecState*);
5655

5756
}
@@ -71,12 +70,10 @@ const ClassInfo ModuleLoaderPrototype::s_info = { "ModuleLoader", &Base::s_info,
7170
ensureRegistered JSBuiltin DontEnum|Function 1
7271
forceFulfillPromise JSBuiltin DontEnum|Function 2
7372
fulfillFetch JSBuiltin DontEnum|Function 2
74-
fulfillTranslate JSBuiltin DontEnum|Function 2
7573
fulfillInstantiate JSBuiltin DontEnum|Function 2
7674
commitInstantiated JSBuiltin DontEnum|Function 3
7775
instantiation JSBuiltin DontEnum|Function 3
7876
requestFetch JSBuiltin DontEnum|Function 2
79-
requestTranslate JSBuiltin DontEnum|Function 2
8077
requestInstantiate JSBuiltin DontEnum|Function 2
8178
requestSatisfy JSBuiltin DontEnum|Function 2
8279
requestInstantiateAll JSBuiltin DontEnum|Function 2
@@ -94,7 +91,6 @@ const ClassInfo ModuleLoaderPrototype::s_info = { "ModuleLoader", &Base::s_info,
9491
requestedModules moduleLoaderPrototypeRequestedModules DontEnum|Function 1
9592
resolve moduleLoaderPrototypeResolve DontEnum|Function 2
9693
fetch moduleLoaderPrototypeFetch DontEnum|Function 2
97-
translate moduleLoaderPrototypeTranslate DontEnum|Function 3
9894
instantiate moduleLoaderPrototypeInstantiate DontEnum|Function 3
9995
@end
10096
*/
@@ -203,23 +199,11 @@ EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeFetch(ExecState* exec)
203199
return JSValue::encode(loader->fetch(exec, exec->argument(0), exec->argument(1)));
204200
}
205201

206-
EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeTranslate(ExecState* exec)
207-
{
208-
// Hook point, Loader.translate
209-
// https://whatwg.github.io/loader/#browser-translate
210-
// Take the key and the fetched source code and translate it to the ES6 source code.
211-
// Typically it is used by the transpilers.
212-
JSModuleLoader* loader = jsDynamicCast<JSModuleLoader*>(exec->thisValue());
213-
if (!loader)
214-
return JSValue::encode(jsUndefined());
215-
return JSValue::encode(loader->translate(exec, exec->argument(0), exec->argument(1), exec->argument(2)));
216-
}
217-
218202
EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeInstantiate(ExecState* exec)
219203
{
220204
// Hook point, Loader.instantiate
221205
// https://whatwg.github.io/loader/#browser-instantiate
222-
// Take the key and the translated source code, and instantiate the module record
206+
// Take the key and the fetched source code, and instantiate the module record
223207
// by parsing the module source code.
224208
// It has the chance to provide the optional module instance that is different from
225209
// the ordinary one.

Source/WebCore/ChangeLog

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2016-12-07 Yusuke Suzuki <[email protected]>
2+
3+
[JSC] Drop translate phase in module loader
4+
https://bugs.webkit.org/show_bug.cgi?id=164861
5+
6+
Reviewed by Saam Barati.
7+
8+
* bindings/js/JSDOMWindowBase.cpp:
9+
* bindings/js/JSWorkerGlobalScopeBase.cpp:
10+
111
2016-12-07 Keith Rollin <[email protected]>
212

313
Network event record/replay

Source/WebCore/bindings/js/JSDOMWindowBase.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,18 @@ namespace WebCore {
5757

5858
const ClassInfo JSDOMWindowBase::s_info = { "Window", &JSDOMGlobalObject::s_info, 0, CREATE_METHOD_TABLE(JSDOMWindowBase) };
5959

60-
const GlobalObjectMethodTable JSDOMWindowBase::s_globalObjectMethodTable = { &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptRuntimeFlags, &queueTaskToEventLoop, &shouldInterruptScriptBeforeTimeout, &moduleLoaderResolve, &moduleLoaderFetch, nullptr, nullptr, &moduleLoaderEvaluate, &defaultLanguage };
60+
const GlobalObjectMethodTable JSDOMWindowBase::s_globalObjectMethodTable = {
61+
&supportsRichSourceInfo,
62+
&shouldInterruptScript,
63+
&javaScriptRuntimeFlags,
64+
&queueTaskToEventLoop,
65+
&shouldInterruptScriptBeforeTimeout,
66+
&moduleLoaderResolve,
67+
&moduleLoaderFetch,
68+
nullptr,
69+
&moduleLoaderEvaluate,
70+
&defaultLanguage
71+
};
6172

6273
JSDOMWindowBase::JSDOMWindowBase(VM& vm, Structure* structure, RefPtr<DOMWindow>&& window, JSDOMWindowShell* shell)
6374
: JSDOMGlobalObject(vm, structure, shell->world(), &s_globalObjectMethodTable)

0 commit comments

Comments
 (0)