Changeset 223173 in webkit
- Timestamp:
- Oct 11, 2017, 5:30:37 AM (9 years ago)
- Location:
- trunk/Source
- Files:
-
- 12 edited
-
JavaScriptCore/ChangeLog (modified) (1 diff)
-
JavaScriptCore/builtins/ModuleLoaderPrototype.js (modified) (4 diffs)
-
JavaScriptCore/jsc.cpp (modified) (1 diff)
-
JavaScriptCore/runtime/Completion.cpp (modified) (2 diffs)
-
JavaScriptCore/runtime/JSGlobalObject.cpp (modified) (1 diff)
-
JavaScriptCore/runtime/JSGlobalObject.h (modified) (1 diff)
-
JavaScriptCore/runtime/JSModuleLoader.cpp (modified) (3 diffs)
-
JavaScriptCore/runtime/JSModuleLoader.h (modified) (2 diffs)
-
JavaScriptCore/runtime/ModuleLoaderPrototype.cpp (modified) (5 diffs)
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/bindings/js/JSDOMWindowBase.cpp (modified) (1 diff)
-
WebCore/bindings/js/JSWorkerGlobalScopeBase.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r223161 r223173 1 2017-10-11 Yusuke Suzuki <utatane.tea@gmail.com> 2 3 [JSC] Drop Instantiate hook in ES6 module loader 4 https://bugs.webkit.org/show_bug.cgi?id=178162 5 6 Reviewed by Sam Weinig. 7 8 This patch is a part of patch series for module loader refactoring to adopt 9 integrity="" parameters and introduce new whatwg module import mechanism. 10 11 In this patch, we drop instantiate hook in module loader. This hook is originally 12 introduced because it is defined in whatwg/loader spec. But this hook is not 13 used in our implementation, and this hook won't be used since (1) whatwg/loader 14 spec is abandoned, and (2) this type of hooks should be done in Service Workers. 15 16 In addition, this patch applies some cleaning up of our module loader JS code 17 to simplify things. This change paves the way to more efficient loader implementation 18 with great flexibility to adopt integrity="" parameters. 19 20 * builtins/ModuleLoaderPrototype.js: 21 (requestInstantiate): 22 (provideFetch): 23 provide is changed to provideFetch since we only used this function with Fetch stage parameter. 24 25 (fulfillInstantiate): Deleted. 26 (commitInstantiated): Deleted. 27 (instantiation): Deleted. 28 They are merged into requestInstantiate code. This is simpler. 29 30 (provide): Deleted. 31 * jsc.cpp: 32 * runtime/Completion.cpp: 33 (JSC::loadAndEvaluateModule): 34 (JSC::loadModule): 35 * runtime/JSGlobalObject.cpp: 36 * runtime/JSGlobalObject.h: 37 * runtime/JSModuleLoader.cpp: 38 (JSC::JSModuleLoader::provideFetch): 39 (JSC::JSModuleLoader::provide): Deleted. 40 Changed to provideFetch. 41 42 (JSC::JSModuleLoader::instantiate): Deleted. 43 Drop this hook. 44 45 * runtime/JSModuleLoader.h: 46 * runtime/ModuleLoaderPrototype.cpp: 47 (JSC::moduleLoaderPrototypeInstantiate): Deleted. 48 Drop this hook. 49 1 50 2017-10-10 Saam Barati <sbarati@apple.com> 2 51 -
trunk/Source/JavaScriptCore/builtins/ModuleLoaderPrototype.js
r222895 r223173 31 31 // 1. Loader.resolve 32 32 // 2. Loader.fetch 33 // 3. Loader.instantiate34 33 35 34 @globalPrivate … … 140 139 } 141 140 142 function fulfillInstantiate(entry, optionalInstance, source)143 {144 // https://whatwg.github.io/loader/#fulfill-instantiate145 146 "use strict";147 148 if (!entry.instantiate)149 entry.instantiate = @newPromiseCapability(@InternalPromise).@promise;150 this.commitInstantiated(entry, optionalInstance, source);151 152 // FIXME: The draft fulfills the promise in the CommitInstantiated operation.153 // But it CommitInstantiated is also used in the requestInstantiate and154 // we should not "force fulfill" there.155 // So we separate "force fulfill" operation from the CommitInstantiated operation.156 // https://github.com/whatwg/loader/pull/67157 this.forceFulfillPromise(entry.instantiate, entry);158 }159 160 function commitInstantiated(entry, optionalInstance, source)161 {162 // https://whatwg.github.io/loader/#commit-instantiated163 164 "use strict";165 166 var moduleRecord = this.instantiation(optionalInstance, source, entry);167 168 // FIXME: Described in the draft,169 // 4. Fulfill entry.[[Instantiate]] with instance.170 // But, instantiate promise should be fulfilled with the entry.171 // We remove this statement because instantiate promise will be172 // fulfilled without this "force fulfill" operation.173 // https://github.com/whatwg/loader/pull/67174 175 var dependencies = [];176 var dependenciesMap = moduleRecord.dependenciesMap;177 moduleRecord.registryEntry = entry;178 var requestedModules = this.requestedModules(moduleRecord);179 for (var i = 0, length = requestedModules.length; i < length; ++i) {180 var depKey = requestedModules[i];181 var pair = {182 key: depKey,183 value: @undefined184 };185 @putByValDirect(dependencies, dependencies.length, pair);186 dependenciesMap.@set(depKey, pair);187 }188 entry.dependencies = dependencies;189 entry.dependenciesMap = dependenciesMap;190 entry.module = moduleRecord;191 @setStateToMax(entry, @ModuleSatisfy);192 }193 194 function instantiation(result, source, entry)195 {196 // https://whatwg.github.io/loader/#instantiation197 // FIXME: Current implementation does not support optionalInstance.198 // https://bugs.webkit.org/show_bug.cgi?id=148171199 200 "use strict";201 202 return this.parseModule(entry.key, source);203 }204 205 141 // Loader. 206 142 … … 240 176 241 177 var instantiatePromise = this.requestFetch(key, fetcher).then((source) => { 242 // Hook point. 243 // 3. Loader.instantiate 244 // https://whatwg.github.io/loader/#browser-instantiate 245 // Take the key and the fetched source code, and instantiate the module record 246 // by parsing the module source code. 247 // It has the chance to provide the optional module instance that is different from 248 // the ordinary one. 249 return this.instantiate(key, source, fetcher).then((optionalInstance) => { 250 this.commitInstantiated(entry, optionalInstance, source); 251 return entry; 252 }); 178 var moduleRecord = this.parseModule(entry.key, source); 179 180 // FIXME: Described in the draft, 181 // 4. Fulfill entry.[[Instantiate]] with instance. 182 // But, instantiate promise should be fulfilled with the entry. 183 // We remove this statement because instantiate promise will be 184 // fulfilled without this "force fulfill" operation. 185 // https://github.com/whatwg/loader/pull/67 186 187 var dependencies = []; 188 var dependenciesMap = moduleRecord.dependenciesMap; 189 moduleRecord.registryEntry = entry; 190 var requestedModules = this.requestedModules(moduleRecord); 191 for (var i = 0, length = requestedModules.length; i < length; ++i) { 192 var depKey = requestedModules[i]; 193 var pair = { 194 key: depKey, 195 value: @undefined 196 }; 197 @putByValDirect(dependencies, dependencies.length, pair); 198 dependenciesMap.@set(depKey, pair); 199 } 200 entry.dependencies = dependencies; 201 entry.dependenciesMap = dependenciesMap; 202 entry.module = moduleRecord; 203 @setStateToMax(entry, @ModuleSatisfy); 204 return entry; 253 205 }); 254 206 entry.instantiate = instantiatePromise; … … 401 353 // APIs to control the module loader. 402 354 403 function provide(key, stage, value) 404 { 405 "use strict"; 406 407 var entry = this.ensureRegistered(key); 408 409 if (stage === @ModuleFetch) { 410 if (entry.state > @ModuleFetch) 411 @throwTypeError("Requested module is already fetched."); 412 this.fulfillFetch(entry, value); 413 return; 414 } 415 416 if (stage === @ModuleInstantiate) { 417 if (entry.state > @ModuleInstantiate) 418 @throwTypeError("Requested module is already instantiated."); 419 this.fulfillFetch(entry, @undefined); 420 entry.fetch.then((source) => { 421 this.fulfillInstantiate(entry, value, source); 422 }); 423 return; 424 } 425 426 @throwTypeError("Requested module is already ready to be executed."); 355 function provideFetch(key, value) 356 { 357 "use strict"; 358 359 var entry = this.ensureRegistered(key); 360 361 if (entry.state > @ModuleFetch) 362 @throwTypeError("Requested module is already fetched."); 363 this.fulfillFetch(entry, value); 427 364 } 428 365 -
trunk/Source/JavaScriptCore/jsc.cpp
r223002 r223173 1674 1674 &moduleLoaderResolve, 1675 1675 &moduleLoaderFetch, 1676 nullptr, // moduleLoaderInstantiate1677 1676 &moduleLoaderCreateImportMetaProperties, 1678 1677 nullptr, // moduleLoaderEvaluate -
trunk/Source/JavaScriptCore/runtime/Completion.cpp
r221822 r223173 188 188 189 189 // Insert the given source code to the ModuleLoader registry as the fetched registry entry. 190 globalObject->moduleLoader()->provide (exec, key, JSModuleLoader::Status::Fetch, source);190 globalObject->moduleLoader()->provideFetch(exec, key, source); 191 191 RETURN_IF_EXCEPTION(scope, rejectPromise(exec, globalObject)); 192 192 … … 228 228 // Insert the given source code to the ModuleLoader registry as the fetched registry entry. 229 229 // FIXME: Introduce JSSourceCode object to wrap around this source. 230 globalObject->moduleLoader()->provide (exec, key, JSModuleLoader::Status::Fetch, source);230 globalObject->moduleLoader()->provideFetch(exec, key, source); 231 231 RETURN_IF_EXCEPTION(scope, rejectPromise(exec, globalObject)); 232 232 -
trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp
r223125 r223173 255 255 nullptr, // moduleLoaderResolve 256 256 nullptr, // moduleLoaderFetch 257 nullptr, // moduleLoaderInstantiate258 257 nullptr, // moduleLoaderCreateImportMetaProperties 259 258 nullptr, // moduleLoaderEvaluate -
trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h
r222895 r223173 196 196 ModuleLoaderFetchPtr moduleLoaderFetch; 197 197 198 typedef JSInternalPromise* (*ModuleLoaderInstantiatePtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue);199 ModuleLoaderInstantiatePtr moduleLoaderInstantiate;200 201 198 typedef JSObject* (*ModuleLoaderCreateImportMetaPropertiesPtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSModuleRecord*, JSValue); 202 199 ModuleLoaderCreateImportMetaPropertiesPtr moduleLoaderCreateImportMetaProperties; -
trunk/Source/JavaScriptCore/runtime/JSModuleLoader.cpp
r222895 r223173 80 80 } 81 81 82 JSValue JSModuleLoader::provide (ExecState* exec, JSValue key, Status status, const SourceCode& sourceCode)83 { 84 VM& vm = exec->vm(); 85 auto scope = DECLARE_THROW_SCOPE(vm); 86 87 JSObject* function = jsCast<JSObject*>(get(exec, vm.propertyNames->builtinNames().provide PublicName()));82 JSValue JSModuleLoader::provideFetch(ExecState* exec, JSValue key, const SourceCode& sourceCode) 83 { 84 VM& vm = exec->vm(); 85 auto scope = DECLARE_THROW_SCOPE(vm); 86 87 JSObject* function = jsCast<JSObject*>(get(exec, vm.propertyNames->builtinNames().provideFetchPublicName())); 88 88 RETURN_IF_EXCEPTION(scope, { }); 89 89 CallData callData; … … 94 94 MarkedArgumentBuffer arguments; 95 95 arguments.append(key); 96 arguments.append(jsNumber(status));97 96 arguments.append(JSSourceCode::create(vm, WTFMove(source))); 98 97 … … 238 237 } 239 238 240 JSInternalPromise* JSModuleLoader::instantiate(ExecState* exec, JSValue key, JSValue source, JSValue scriptFetcher)241 {242 if (Options::dumpModuleLoadingState())243 dataLog("Loader [instantiate] ", printableModuleKey(exec, key), "\n");244 245 JSGlobalObject* globalObject = exec->lexicalGlobalObject();246 if (globalObject->globalObjectMethodTable()->moduleLoaderInstantiate)247 return globalObject->globalObjectMethodTable()->moduleLoaderInstantiate(globalObject, exec, this, key, source, scriptFetcher);248 JSInternalPromiseDeferred* deferred = JSInternalPromiseDeferred::create(exec, globalObject);249 deferred->resolve(exec, jsUndefined());250 return deferred->promise();251 }252 253 239 JSObject* JSModuleLoader::createImportMetaProperties(ExecState* exec, JSValue key, JSModuleRecord* moduleRecord, JSValue scriptFetcher) 254 240 { -
trunk/Source/JavaScriptCore/runtime/JSModuleLoader.h
r222895 r223173 64 64 65 65 // APIs to control the module loader. 66 JSValue provide (ExecState*, JSValue key, Status, const SourceCode&);66 JSValue provideFetch(ExecState*, JSValue key, const SourceCode&); 67 67 JSInternalPromise* loadAndEvaluateModule(ExecState*, JSValue moduleName, JSValue referrer, JSValue scriptFetcher); 68 68 JSInternalPromise* loadModule(ExecState*, JSValue moduleName, JSValue referrer, JSValue scriptFetcher); … … 74 74 JSInternalPromise* resolve(ExecState*, JSValue name, JSValue referrer, JSValue scriptFetcher); 75 75 JSInternalPromise* fetch(ExecState*, JSValue key, JSValue scriptFetcher); 76 JSInternalPromise* instantiate(ExecState*, JSValue key, JSValue source, JSValue scriptFetcher);77 76 JSObject* createImportMetaProperties(ExecState*, JSValue key, JSModuleRecord*, JSValue scriptFetcher); 78 77 -
trunk/Source/JavaScriptCore/runtime/ModuleLoaderPrototype.cpp
r222895 r223173 54 54 static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeResolve(ExecState*); 55 55 static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeFetch(ExecState*); 56 static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeInstantiate(ExecState*);57 56 static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeGetModuleNamespaceObject(ExecState*); 58 57 … … 72 71 forceFulfillPromise JSBuiltin DontEnum|Function 2 73 72 fulfillFetch JSBuiltin DontEnum|Function 2 74 fulfillInstantiate JSBuiltin DontEnum|Function 275 commitInstantiated JSBuiltin DontEnum|Function 376 instantiation JSBuiltin DontEnum|Function 377 73 requestFetch JSBuiltin DontEnum|Function 2 78 74 requestInstantiate JSBuiltin DontEnum|Function 2 … … 84 80 moduleEvaluation JSBuiltin DontEnum|Function 2 85 81 evaluate moduleLoaderPrototypeEvaluate DontEnum|Function 3 86 provide JSBuiltin DontEnum|Function 382 provideFetch JSBuiltin DontEnum|Function 2 87 83 loadAndEvaluateModule JSBuiltin DontEnum|Function 3 88 84 loadModule JSBuiltin DontEnum|Function 3 … … 94 90 resolve moduleLoaderPrototypeResolve DontEnum|Function 2 95 91 fetch moduleLoaderPrototypeFetch DontEnum|Function 2 96 instantiate moduleLoaderPrototypeInstantiate DontEnum|Function 397 92 @end 98 93 */ … … 204 199 } 205 200 206 EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeInstantiate(ExecState* exec)207 {208 VM& vm = exec->vm();209 // Hook point, Loader.instantiate210 // https://whatwg.github.io/loader/#browser-instantiate211 // Take the key and the fetched source code, and instantiate the module record212 // by parsing the module source code.213 // It has the chance to provide the optional module instance that is different from214 // the ordinary one.215 JSModuleLoader* loader = jsDynamicCast<JSModuleLoader*>(vm, exec->thisValue());216 if (!loader)217 return JSValue::encode(jsUndefined());218 return JSValue::encode(loader->instantiate(exec, exec->argument(0), exec->argument(1), exec->argument(2)));219 }220 221 201 EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeGetModuleNamespaceObject(ExecState* exec) 222 202 { -
trunk/Source/WebCore/ChangeLog
r223172 r223173 1 2017-10-11 Yusuke Suzuki <utatane.tea@gmail.com> 2 3 [JSC] Drop Instantiate hook in ES6 module loader 4 https://bugs.webkit.org/show_bug.cgi?id=178162 5 6 Reviewed by Sam Weinig. 7 8 Drop instantiate hooks. 9 No behavior change. 10 11 * bindings/js/JSDOMWindowBase.cpp: 12 * bindings/js/JSWorkerGlobalScopeBase.cpp: 13 1 14 2017-10-11 Alicia Boya García <aboya@igalia.com> 2 15 -
trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp
r222895 r223173 73 73 &moduleLoaderResolve, 74 74 &moduleLoaderFetch, 75 nullptr, // moduleLoaderInstantiate76 75 nullptr, // moduleLoaderCreateImportMetaProperties 77 76 &moduleLoaderEvaluate, -
trunk/Source/WebCore/bindings/js/JSWorkerGlobalScopeBase.cpp
r222895 r223173 60 60 nullptr, // moduleLoaderResolve 61 61 nullptr, // moduleLoaderFetch 62 nullptr, // moduleLoaderInstantiate63 62 nullptr, // moduleLoaderCreateImportMetaProperties 64 63 nullptr, // moduleLoaderEvaluate
Note:
See TracChangeset
for help on using the changeset viewer.