Changeset 210522 in webkit
- Timestamp:
- Jan 9, 2017 2:02:47 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 8 added
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JSTests/ChangeLog
r210518 r210522 1 2017-01-09 Yusuke Suzuki <utatane.tea@gmail.com> 2 3 [JSC] Prototype dynamic-import 4 https://bugs.webkit.org/show_bug.cgi?id=165724 5 6 Reviewed by Saam Barati. 7 8 * stress/import-basic.js: Added. 9 (async.async.load): 10 (async): 11 (catch): 12 * stress/import-from-eval.js: Added. 13 (async): 14 (catch): 15 * stress/import-syntax.js: Added. 16 (testSyntaxError): 17 * stress/import-tests/cocoa.js: Added. 18 (export.Cocoa): 19 (export.hello): 20 * stress/import-tests/multiple.js: Added. 21 (export.result): 22 * stress/import-tests/multiple2.js: Added. 23 (export.ok): 24 * stress/import-tests/should.js: Added. 25 (export.shouldBe): 26 (export.shouldThrow): 27 * stress/modules-syntax-error.js: 28 1 29 2017-01-09 Commit Queue <commit-queue@webkit.org> 2 30 -
trunk/JSTests/stress/modules-syntax-error.js
r199927 r210522 108 108 import * as from from "Cocoa" 109 109 } 110 `, `SyntaxError: Unexpected keyword 'import':3`);110 `, `SyntaxError: Unexpected token '*'. import call expects exactly one argument.:3`); 111 111 112 112 checkModuleSyntaxError(String.raw` … … 114 114 import * as from from "Cocoa" 115 115 } 116 `, `SyntaxError: Unexpected keyword 'import':3`);116 `, `SyntaxError: Unexpected token '*'. import call expects exactly one argument.:3`); 117 117 118 118 checkModuleSyntaxError(String.raw` … … 120 120 import * as from from "Cocoa" 121 121 } 122 `, `SyntaxError: Unexpected keyword 'import':3`);122 `, `SyntaxError: Unexpected token '*'. import call expects exactly one argument.:3`); 123 123 124 124 checkModuleSyntaxError(String.raw` … … 126 126 import * as from from "Cocoa" 127 127 } 128 `, `SyntaxError: Unexpected keyword 'import':3`);128 `, `SyntaxError: Unexpected token '*'. import call expects exactly one argument.:3`); 129 129 130 130 checkModuleSyntaxError(String.raw` -
trunk/LayoutTests/ChangeLog
r210519 r210522 1 2017-01-09 Yusuke Suzuki <utatane.tea@gmail.com> 2 3 [JSC] Prototype dynamic-import 4 https://bugs.webkit.org/show_bug.cgi?id=165724 5 6 Reviewed by Saam Barati. 7 8 * sputnik/Conformance/07_Lexical_Conventions/7.5_Tokens/7.5.3_Future_Reserved_Words/S7.5.3_A1.16-expected.txt: 9 1 10 2017-01-09 Andy Estes <aestes@apple.com> 2 11 -
trunk/LayoutTests/sputnik/Conformance/07_Lexical_Conventions/7.5_Tokens/7.5.3_Future_Reserved_Words/S7.5.3_A1.16-expected.txt
r187890 r210522 1 CONSOLE MESSAGE: line 76: SyntaxError: Unexpected keyword 'import'1 CONSOLE MESSAGE: line 76: SyntaxError: Unexpected token '='. import call expects exactly one argument. 2 2 S7.5.3_A1.16 3 3 -
trunk/Source/JavaScriptCore/ChangeLog
r210521 r210522 1 2017-01-09 Yusuke Suzuki <utatane.tea@gmail.com> 2 3 [JSC] Prototype dynamic-import 4 https://bugs.webkit.org/show_bug.cgi?id=165724 5 6 Reviewed by Saam Barati. 7 8 In this patch, we implement stage3 dynamic-import proposal[1]. 9 This patch adds a new special operator `import`. And by using it, we can import 10 the module dynamically from modules and scripts. Before this feature, the module 11 is always imported statically and before executing the modules, importing the modules 12 needs to be done. And especially, the module can only be imported from the module. 13 So the classic script cannot import and use the modules. This dynamic-import relaxes 14 the above restrictions. 15 16 The typical dynamic-import form is the following. 17 18 import("...").then(function (namespace) { ... }); 19 20 You can pass any AssignmentExpression for the import operator. So you can determine 21 the importing modules dynamically. 22 23 import(value).then(function (namespace) { ... }); 24 25 And previously the module import declaration is only allowed in the top level statements. 26 But this import operator is just an expression. So you can use it in the function. 27 And you can use it conditionally. 28 29 async function go(cond) 30 { 31 if (cond) 32 return import("..."); 33 return undefined; 34 } 35 await go(true); 36 37 Currently, this patch just implements this feature only for the JSC shell. 38 JSC module loader requires a new hook, `importModule`. And the JSC shell implements 39 this hook. So, for now, this dynamic-import is not available in the browser side. 40 If you write this `import` call, it always returns the rejected promise. 41 42 import is implemented like a special operator similar to `super`. 43 This is because import is context-sensitive. If you call the `import`, the module 44 key resolution is done based on the caller's running context. 45 46 For example, if you are running the script which filename is "./ok/hello.js", the module 47 key for the call`import("./resource/syntax.js")` becomes `"./ok/resource/syntax.js"`. 48 But if you write the completely same import form in the script "./error/hello.js", the 49 key becomes "./error/resource/syntax.js". So exposing this feature as the `import` 50 function is misleading: this function becomes caller's context-sensitive. That's why 51 dynamic-import is specified as a special operator. 52 53 To resolve the module key, we need the caller's context information like the filename of 54 the caller. This is provided by the SourceOrigin implemented in r210149. 55 In the JSC shell implementation, this SourceOrigin holds the filename of the caller. So 56 based on this implementation, the module loader resolve the module key. 57 In the near future, we will extend this SourceOrigin to hold more information needed for 58 the browser-side import implementation. 59 60 [1]: https://tc39.github.io/proposal-dynamic-import/ 61 62 * builtins/ModuleLoaderPrototype.js: 63 (importModule): 64 * bytecompiler/BytecodeGenerator.cpp: 65 (JSC::BytecodeGenerator::emitGetTemplateObject): 66 (JSC::BytecodeGenerator::emitGetGlobalPrivate): 67 * bytecompiler/BytecodeGenerator.h: 68 * bytecompiler/NodesCodegen.cpp: 69 (JSC::ImportNode::emitBytecode): 70 * jsc.cpp: 71 (absolutePath): 72 (GlobalObject::moduleLoaderImportModule): 73 (functionRun): 74 (functionLoad): 75 (functionCheckSyntax): 76 (runWithScripts): 77 * parser/ASTBuilder.h: 78 (JSC::ASTBuilder::createImportExpr): 79 * parser/NodeConstructors.h: 80 (JSC::ImportNode::ImportNode): 81 * parser/Nodes.h: 82 (JSC::ExpressionNode::isImportNode): 83 * parser/Parser.cpp: 84 (JSC::Parser<LexerType>::parseMemberExpression): 85 * parser/SyntaxChecker.h: 86 (JSC::SyntaxChecker::createImportExpr): 87 * runtime/JSGlobalObject.cpp: 88 (JSC::JSGlobalObject::init): 89 * runtime/JSGlobalObject.h: 90 * runtime/JSGlobalObjectFunctions.cpp: 91 (JSC::globalFuncImportModule): 92 * runtime/JSGlobalObjectFunctions.h: 93 * runtime/JSModuleLoader.cpp: 94 (JSC::JSModuleLoader::importModule): 95 (JSC::JSModuleLoader::getModuleNamespaceObject): 96 * runtime/JSModuleLoader.h: 97 * runtime/ModuleLoaderPrototype.cpp: 98 (JSC::moduleLoaderPrototypeGetModuleNamespaceObject): 99 1 100 2017-01-08 Filip Pizlo <fpizlo@apple.com> 2 101 -
trunk/Source/JavaScriptCore/builtins/ModuleLoaderPrototype.js
r209848 r210522 471 471 return this.moduleEvaluation(entry.module, initiator); 472 472 } 473 474 function importModule(moduleName, referrer, initiator) 475 { 476 "use strict"; 477 478 // Loader.resolve hook point. 479 // resolve: moduleName => Promise(moduleKey) 480 // Take the name and resolve it to the unique identifier for the resource location. 481 // For example, take the "jquery" and return the URL for the resource. 482 return this.resolve(moduleName, referrer, initiator).then((key) => { 483 return this.requestInstantiateAll(key, initiator); 484 }).then((entry) => { 485 this.linkAndEvaluateModule(entry.key, initiator); 486 return this.getModuleNamespaceObject(entry.module); 487 }); 488 } -
trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
r210119 r210522 4262 4262 } 4263 4263 4264 RefPtr<RegisterID> getTemplateObject = nullptr; 4265 Variable var = variable(propertyNames().builtinNames().getTemplateObjectPrivateName()); 4266 if (RegisterID* local = var.local()) 4267 getTemplateObject = emitMove(newTemporary(), local); 4268 else { 4269 getTemplateObject = newTemporary(); 4270 RefPtr<RegisterID> scope = newTemporary(); 4271 moveToDestinationIfNeeded(scope.get(), emitResolveScope(scope.get(), var)); 4272 emitGetFromScope(getTemplateObject.get(), scope.get(), var, ThrowIfNotFound); 4273 } 4274 4264 RefPtr<RegisterID> getTemplateObject = emitGetGlobalPrivate(newTemporary(), propertyNames().builtinNames().getTemplateObjectPrivateName()); 4275 4265 CallArguments arguments(*this, nullptr); 4276 4266 emitLoad(arguments.thisRegister(), JSValue(addTemplateRegistryKeyConstant(m_vm->templateRegistryKeyTable().createKey(rawStrings, cookedStrings)))); 4277 4267 return emitCall(dst, getTemplateObject.get(), NoExpectedFunction, arguments, taggedTemplate->divot(), taggedTemplate->divotStart(), taggedTemplate->divotEnd(), DebuggableCall::No); 4268 } 4269 4270 RegisterID* BytecodeGenerator::emitGetGlobalPrivate(RegisterID* dst, const Identifier& property) 4271 { 4272 dst = tempDestination(dst); 4273 Variable var = variable(property); 4274 if (RegisterID* local = var.local()) 4275 return emitMove(dst, local); 4276 4277 RefPtr<RegisterID> scope = newTemporary(); 4278 moveToDestinationIfNeeded(scope.get(), emitResolveScope(scope.get(), var)); 4279 return emitGetFromScope(dst, scope.get(), var, ThrowIfNotFound); 4278 4280 } 4279 4281 -
trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
r210119 r210522 679 679 680 680 RegisterID* emitGetTemplateObject(RegisterID* dst, TaggedTemplateNode*); 681 RegisterID* emitGetGlobalPrivate(RegisterID* dst, const Identifier& property); 681 682 682 683 enum class ReturnFrom { Normal, Finally }; -
trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
r210116 r210522 189 189 RegisterID* result = emitSuperBaseForCallee(generator); 190 190 return generator.moveToDestinationIfNeeded(generator.finalDestination(dst), result); 191 } 192 193 // ------------------------------ ImportNode ------------------------------------- 194 195 RegisterID* ImportNode::emitBytecode(BytecodeGenerator& generator, RegisterID* dst) 196 { 197 RefPtr<RegisterID> importModule = generator.emitGetGlobalPrivate(generator.newTemporary(), generator.propertyNames().builtinNames().importModulePrivateName()); 198 CallArguments arguments(generator, nullptr, 1); 199 generator.emitLoad(arguments.thisRegister(), jsUndefined()); 200 generator.emitNode(arguments.argumentRegister(0), m_expr); 201 return generator.emitCall(generator.finalDestination(dst, importModule.get()), importModule.get(), NoExpectedFunction, arguments, divot(), divotStart(), divotEnd(), DebuggableCall::No); 191 202 } 192 203 -
trunk/Source/JavaScriptCore/jsc.cpp
r210229 r210522 26 26 #include "ArrayPrototype.h" 27 27 #include "BuiltinExecutableCreator.h" 28 #include "BuiltinNames.h" 28 29 #include "ButterflyInlines.h" 29 30 #include "CodeBlock.h" … … 49 50 #include "JSInternalPromiseDeferred.h" 50 51 #include "JSLock.h" 52 #include "JSModuleLoader.h" 51 53 #include "JSNativeStdFunction.h" 52 54 #include "JSONObject.h" … … 1102 1104 1103 1105 template<typename Vector> 1104 static inline SourceCode jscSource(const Vector& utf8, const S tring& filename)1106 static inline SourceCode jscSource(const Vector& utf8, const SourceOrigin& sourceOrigin, const String& filename) 1105 1107 { 1106 1108 String str = stringFromUTF(utf8); 1107 return makeSource(str, SourceOrigin { filename }, filename);1109 return makeSource(str, sourceOrigin, filename); 1108 1110 } 1109 1111 … … 1278 1280 } 1279 1281 1282 static JSInternalPromise* moduleLoaderImportModule(JSGlobalObject*, ExecState*, JSModuleLoader*, JSString*, const SourceOrigin&); 1280 1283 static JSInternalPromise* moduleLoaderResolve(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue); 1281 1284 static JSInternalPromise* moduleLoaderFetch(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue); … … 1289 1292 nullptr, 1290 1293 &shouldInterruptScriptBeforeTimeout, 1294 &moduleLoaderImportModule, 1291 1295 &moduleLoaderResolve, 1292 1296 &moduleLoaderFetch, … … 1421 1425 } 1422 1426 1427 static String absolutePath(const String& fileName) 1428 { 1429 auto directoryName = currentWorkingDirectory(); 1430 if (!directoryName) 1431 return fileName; 1432 return resolvePath(directoryName.value(), ModuleName(fileName.impl())); 1433 } 1434 1435 JSInternalPromise* GlobalObject::moduleLoaderImportModule(JSGlobalObject*, ExecState* exec, JSModuleLoader* moduleLoader, JSString* moduleName, const SourceOrigin& sourceOrigin) 1436 { 1437 auto* function = jsCast<JSObject*>(moduleLoader->get(exec, exec->propertyNames().builtinNames().importModulePublicName())); 1438 CallData callData; 1439 auto callType = JSC::getCallData(function, callData); 1440 ASSERT(callType != CallType::None); 1441 1442 MarkedArgumentBuffer arguments; 1443 arguments.append(moduleName); 1444 arguments.append(jsString(exec, sourceOrigin.string())); 1445 arguments.append(jsUndefined()); 1446 1447 return jsCast<JSInternalPromise*>(call(exec, function, callType, callData, moduleLoader, arguments)); 1448 } 1449 1423 1450 JSInternalPromise* GlobalObject::moduleLoaderResolve(JSGlobalObject* globalObject, ExecState* exec, JSModuleLoader*, JSValue keyValue, JSValue referrerValue, JSValue) 1424 1451 { … … 1925 1952 StopWatch stopWatch; 1926 1953 stopWatch.start(); 1927 evaluate(globalObject->globalExec(), jscSource(script, fileName), JSValue(), exception);1954 evaluate(globalObject->globalExec(), jscSource(script, SourceOrigin { absolutePath(fileName) }, fileName), JSValue(), exception); 1928 1955 stopWatch.stop(); 1929 1956 … … 1977 2004 1978 2005 NakedPtr<Exception> evaluationException; 1979 JSValue result = evaluate(globalObject->globalExec(), jscSource(script, fileName), JSValue(), evaluationException);2006 JSValue result = evaluate(globalObject->globalExec(), jscSource(script, SourceOrigin { absolutePath(fileName) }, fileName), JSValue(), evaluationException); 1980 2007 if (evaluationException) 1981 2008 throwException(exec, scope, evaluationException); … … 2048 2075 2049 2076 JSValue syntaxException; 2050 bool validSyntax = checkSyntax(globalObject->globalExec(), jscSource(script, fileName), &syntaxException);2077 bool validSyntax = checkSyntax(globalObject->globalExec(), jscSource(script, SourceOrigin { absolutePath(fileName) }, fileName), &syntaxException); 2051 2078 stopWatch.stop(); 2052 2079 … … 2910 2937 if (isModule) { 2911 2938 if (!promise) 2912 promise = loadAndEvaluateModule(globalObject->globalExec(), jscSource(scriptBuffer, fileName));2939 promise = loadAndEvaluateModule(globalObject->globalExec(), jscSource(scriptBuffer, SourceOrigin { absolutePath(fileName) }, fileName)); 2913 2940 scope.clearException(); 2914 2941 … … 2927 2954 } else { 2928 2955 NakedPtr<Exception> evaluationException; 2929 JSValue returnValue = evaluate(globalObject->globalExec(), jscSource(scriptBuffer, fileName), JSValue(), evaluationException);2956 JSValue returnValue = evaluate(globalObject->globalExec(), jscSource(scriptBuffer, SourceOrigin { absolutePath(fileName) }, fileName), JSValue(), evaluationException); 2930 2957 ASSERT(!scope.exception()); 2931 2958 if (evaluationException) … … 3000 3027 3001 3028 NakedPtr<Exception> evaluationException; 3002 JSValue returnValue = evaluate(globalObject->globalExec(), jscSource(line, sourceOrigin .string()), JSValue(), evaluationException);3029 JSValue returnValue = evaluate(globalObject->globalExec(), jscSource(line, sourceOrigin, sourceOrigin.string()), JSValue(), evaluationException); 3003 3030 #endif 3004 3031 if (evaluationException) -
trunk/Source/JavaScriptCore/parser/ASTBuilder.h
r208885 r210522 179 179 return new (m_parserArena) SuperNode(location); 180 180 } 181 ExpressionNode* createImportExpr(const JSTokenLocation& location, ExpressionNode* expr, const JSTextPosition& start, const JSTextPosition& divot, const JSTextPosition& end) 182 { 183 auto* node = new (m_parserArena) ImportNode(location, expr); 184 setExceptionLocation(node, start, divot, end); 185 return node; 186 } 181 187 ExpressionNode* createNewTargetExpr(const JSTokenLocation location) 182 188 { -
trunk/Source/JavaScriptCore/parser/NodeConstructors.h
r206525 r210522 168 168 } 169 169 170 inline ImportNode::ImportNode(const JSTokenLocation& location, ExpressionNode* expr) 171 : ExpressionNode(location) 172 , m_expr(expr) 173 { 174 } 175 170 176 inline NewTargetNode::NewTargetNode(const JSTokenLocation& location) 171 177 : ExpressionNode(location) -
trunk/Source/JavaScriptCore/parser/Nodes.h
r209871 r210522 187 187 virtual bool isSpreadExpression() const { return false; } 188 188 virtual bool isSuperNode() const { return false; } 189 virtual bool isImportNode() const { return false; } 189 190 virtual bool isNewTarget() const { return false; } 190 191 virtual bool isBytecodeIntrinsicNode() const { return false; } … … 569 570 bool isSuperNode() const override { return true; } 570 571 RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; 572 }; 573 574 class ImportNode : public ExpressionNode, public ThrowableExpressionData { 575 public: 576 ImportNode(const JSTokenLocation&, ExpressionNode*); 577 578 private: 579 bool isImportNode() const override { return true; } 580 RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) override; 581 582 ExpressionNode* m_expr; 571 583 }; 572 584 -
trunk/Source/JavaScriptCore/parser/Parser.cpp
r210151 r210522 4344 4344 4345 4345 bool baseIsSuper = match(SUPER); 4346 semanticFailIfTrue(baseIsSuper && newCount, "Cannot use new with super"); 4346 bool baseIsImport = match(IMPORT); 4347 semanticFailIfTrue((baseIsSuper || baseIsImport) && newCount, "Cannot use new with ", getToken()); 4347 4348 4348 4349 bool baseIsNewTarget = false; … … 4384 4385 } 4385 4386 } 4387 } else if (baseIsImport) { 4388 JSTextPosition expressionEnd = lastTokenEndPosition(); 4389 next(); 4390 consumeOrFail(OPENPAREN, "import call expects exactly one argument"); 4391 TreeExpression expr = parseAssignmentExpression(context); 4392 failIfFalse(expr, "Cannot parse expression"); 4393 consumeOrFail(CLOSEPAREN, "import call expects exactly one argument"); 4394 return context.createImportExpr(location, expr, expressionStart, expressionEnd, lastTokenEndPosition()); 4386 4395 } else if (!baseIsNewTarget) { 4387 4396 const bool isAsync = match(ASYNC); -
trunk/Source/JavaScriptCore/parser/SyntaxChecker.h
r208885 r210522 72 72 ResolveEvalExpr, ResolveExpr, IntegerExpr, DoubleExpr, StringExpr, 73 73 ThisExpr, NullExpr, BoolExpr, RegExpExpr, ObjectLiteralExpr, 74 FunctionExpr, ClassExpr, SuperExpr, BracketExpr, DotExpr, CallExpr,74 FunctionExpr, ClassExpr, SuperExpr, ImportExpr, BracketExpr, DotExpr, CallExpr, 75 75 NewExpr, PreExpr, PostExpr, UnaryExpr, BinaryExpr, 76 76 ConditionalExpr, AssignmentExpr, TypeofExpr, NewTargetExpr, … … 157 157 ExpressionType createUnaryPlus(const JSTokenLocation&, ExpressionType) { return UnaryExpr; } 158 158 ExpressionType createVoid(const JSTokenLocation&, ExpressionType) { return UnaryExpr; } 159 ExpressionType createImportExpr(const JSTokenLocation&, ExpressionType, int, int, int) { return ImportExpr; } 159 160 ExpressionType createThisExpr(const JSTokenLocation&) { return ThisExpr; } 160 161 ExpressionType createSuperExpr(const JSTokenLocation&) { return SuperExpr; } -
trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp
r210518 r210522 257 257 nullptr, 258 258 nullptr, 259 nullptr, 259 260 nullptr 260 261 }; … … 733 734 734 735 JSFunction* privateFuncGetTemplateObject = JSFunction::create(vm, this, 0, String(), getTemplateObject); 736 JSFunction* privateFuncImportModule = JSFunction::create(vm, this, 0, String(), globalFuncImportModule); 735 737 JSFunction* privateFuncTypedArrayLength = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncLength); 736 738 JSFunction* privateFuncTypedArrayGetOriginalConstructor = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncGetOriginalConstructor); … … 786 788 GlobalPropertyInfo(vm.propertyNames->builtinNames().ownEnumerablePropertyKeysPrivateName(), JSFunction::create(vm, this, 0, String(), ownEnumerablePropertyKeys), DontEnum | DontDelete | ReadOnly), 787 789 GlobalPropertyInfo(vm.propertyNames->builtinNames().getTemplateObjectPrivateName(), privateFuncGetTemplateObject, DontEnum | DontDelete | ReadOnly), 790 GlobalPropertyInfo(vm.propertyNames->builtinNames().importModulePrivateName(), privateFuncImportModule, DontEnum | DontDelete | ReadOnly), 788 791 GlobalPropertyInfo(vm.propertyNames->builtinNames().enqueueJobPrivateName(), JSFunction::create(vm, this, 0, String(), enqueueJob), DontEnum | DontDelete | ReadOnly), 789 792 GlobalPropertyInfo(vm.propertyNames->builtinNames().ErrorPrivateName(), m_errorConstructor.get(), DontEnum | DontDelete | ReadOnly), -
trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h
r210518 r210522 185 185 ShouldInterruptScriptBeforeTimeoutPtr shouldInterruptScriptBeforeTimeout; 186 186 187 typedef JSInternalPromise* (*ModuleLoaderImportModulePtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSString*, const SourceOrigin&); 188 ModuleLoaderImportModulePtr moduleLoaderImportModule; 189 187 190 typedef JSInternalPromise* (*ModuleLoaderResolvePtr)(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue); 188 191 ModuleLoaderResolvePtr moduleLoaderResolve; -
trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
r210149 r210522 28 28 #include "CallFrame.h" 29 29 #include "EvalExecutable.h" 30 #include "Exception.h" 30 31 #include "IndirectEvalExecutable.h" 31 32 #include "Interpreter.h" 32 33 #include "JSFunction.h" 33 34 #include "JSGlobalObject.h" 35 #include "JSInternalPromise.h" 36 #include "JSModuleLoader.h" 37 #include "JSPromiseDeferred.h" 34 38 #include "JSString.h" 35 39 #include "JSStringBuilder.h" … … 926 930 } 927 931 932 EncodedJSValue JSC_HOST_CALL globalFuncImportModule(ExecState* exec) 933 { 934 VM& vm = exec->vm(); 935 auto catchScope = DECLARE_CATCH_SCOPE(vm); 936 937 auto* globalObject = exec->lexicalGlobalObject(); 938 939 auto* promise = JSPromiseDeferred::create(exec, globalObject); 940 RETURN_IF_EXCEPTION(catchScope, { }); 941 942 auto sourceOrigin = exec->callerSourceOrigin(); 943 if (sourceOrigin.isNull()) { 944 promise->reject(exec, createError(exec, ASCIILiteral("Could not resolve the module specifier."))); 945 return JSValue::encode(promise->promise()); 946 } 947 948 RELEASE_ASSERT(exec->argumentCount() == 1); 949 auto* specifier = exec->uncheckedArgument(0).toString(exec); 950 if (Exception* exception = catchScope.exception()) { 951 catchScope.clearException(); 952 promise->reject(exec, exception); 953 return JSValue::encode(promise->promise()); 954 } 955 956 auto* internalPromise = globalObject->moduleLoader()->importModule(exec, specifier, sourceOrigin); 957 if (Exception* exception = catchScope.exception()) { 958 catchScope.clearException(); 959 promise->reject(exec, exception); 960 return JSValue::encode(promise->promise()); 961 } 962 promise->resolve(exec, internalPromise); 963 964 return JSValue::encode(promise->promise()); 965 } 966 928 967 } // namespace JSC -
trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.h
r206525 r210522 51 51 EncodedJSValue JSC_HOST_CALL globalFuncProtoSetter(ExecState*); 52 52 EncodedJSValue JSC_HOST_CALL globalFuncBuiltinLog(ExecState*); 53 EncodedJSValue JSC_HOST_CALL globalFuncImportModule(ExecState*); 53 54 54 55 static const double mantissaOverflowLowerBound = 9007199254740992.0; -
trunk/Source/JavaScriptCore/runtime/JSModuleLoader.cpp
r209801 r210522 135 135 } 136 136 137 JSInternalPromise* JSModuleLoader::importModule(ExecState* exec, JSString* moduleName, const SourceOrigin& referrer) 138 { 139 if (Options::dumpModuleLoadingState()) 140 dataLog("Loader [import] ", printableModuleKey(exec, moduleName), "\n"); 141 142 auto* globalObject = exec->lexicalGlobalObject(); 143 VM& vm = globalObject->vm(); 144 auto scope = DECLARE_CATCH_SCOPE(vm); 145 146 if (globalObject->globalObjectMethodTable()->moduleLoaderImportModule) 147 return globalObject->globalObjectMethodTable()->moduleLoaderImportModule(globalObject, exec, this, moduleName, referrer); 148 149 auto* deferred = JSInternalPromiseDeferred::create(exec, globalObject); 150 auto moduleNameString = moduleName->value(exec); 151 if (UNLIKELY(scope.exception())) { 152 JSValue exception = scope.exception()->value(); 153 scope.clearException(); 154 deferred->reject(exec, exception); 155 return deferred->promise(); 156 } 157 deferred->reject(exec, createError(exec, makeString("Could not import the module '", moduleNameString, "'."))); 158 return deferred->promise(); 159 } 160 137 161 JSInternalPromise* JSModuleLoader::resolve(ExecState* exec, JSValue name, JSValue referrer, JSValue initiator) 138 162 { … … 198 222 } 199 223 224 JSModuleNamespaceObject* JSModuleLoader::getModuleNamespaceObject(ExecState* exec, JSValue moduleRecordValue) 225 { 226 VM& vm = exec->vm(); 227 auto scope = DECLARE_THROW_SCOPE(vm); 228 229 auto* moduleRecord = jsDynamicCast<AbstractModuleRecord*>(moduleRecordValue); 230 if (!moduleRecord) { 231 throwTypeError(exec, scope); 232 return nullptr; 233 } 234 235 scope.release(); 236 return moduleRecord->getModuleNamespace(exec); 237 } 238 200 239 } // namespace JSC -
trunk/Source/JavaScriptCore/runtime/JSModuleLoader.h
r209500 r210522 32 32 33 33 class JSInternalPromise; 34 class JSModuleNamespaceObject; 34 35 35 36 class JSModuleLoader : public JSNonFinalObject { … … 68 69 69 70 // Platform dependent hooked APIs. 71 JSInternalPromise* importModule(ExecState*, JSString* moduleName, const SourceOrigin& referrer); 70 72 JSInternalPromise* resolve(ExecState*, JSValue name, JSValue referrer, JSValue initiator); 71 73 JSInternalPromise* fetch(ExecState*, JSValue key, JSValue initiator); … … 75 77 JSValue evaluate(ExecState*, JSValue key, JSValue moduleRecord, JSValue initiator); 76 78 79 // Utility functions. 80 JSModuleNamespaceObject* getModuleNamespaceObject(ExecState*, JSValue moduleRecord); 81 77 82 protected: 78 83 void finishCreation(ExecState*, VM&, JSGlobalObject*); -
trunk/Source/JavaScriptCore/runtime/ModuleLoaderPrototype.cpp
r210149 r210522 38 38 #include "JSModuleEnvironment.h" 39 39 #include "JSModuleLoader.h" 40 #include "JSModuleNamespaceObject.h" 40 41 #include "JSModuleRecord.h" 41 42 #include "ModuleAnalyzer.h" … … 53 54 static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeFetch(ExecState*); 54 55 static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeInstantiate(ExecState*); 56 static EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeGetModuleNamespaceObject(ExecState*); 55 57 56 58 } … … 86 88 loadModule JSBuiltin DontEnum|Function 3 87 89 linkAndEvaluateModule JSBuiltin DontEnum|Function 2 90 importModule JSBuiltin DontEnum|Function 3 91 getModuleNamespaceObject moduleLoaderPrototypeGetModuleNamespaceObject DontEnum|Function 1 88 92 parseModule moduleLoaderPrototypeParseModule DontEnum|Function 2 89 93 requestedModules moduleLoaderPrototypeRequestedModules DontEnum|Function 1 … … 212 216 } 213 217 218 EncodedJSValue JSC_HOST_CALL moduleLoaderPrototypeGetModuleNamespaceObject(ExecState* exec) 219 { 220 VM& vm = exec->vm(); 221 auto scope = DECLARE_THROW_SCOPE(vm); 222 223 auto* loader = jsDynamicCast<JSModuleLoader*>(exec->thisValue()); 224 if (!loader) 225 return JSValue::encode(jsUndefined()); 226 auto* moduleNamespaceObject = loader->getModuleNamespaceObject(exec, exec->argument(0)); 227 RETURN_IF_EXCEPTION(scope, encodedJSValue()); 228 return JSValue::encode(moduleNamespaceObject); 229 } 230 214 231 // ------------------- Additional Hook Functions --------------------------- 215 232 -
trunk/Source/WebCore/ChangeLog
r210514 r210522 1 2017-01-09 Yusuke Suzuki <utatane.tea@gmail.com> 2 3 [JSC] Prototype dynamic-import 4 https://bugs.webkit.org/show_bug.cgi?id=165724 5 6 Reviewed by Saam Barati. 7 8 We do not set a handler for import for now. 9 So dynamic import feature is only enabled in the JSC shell right now. 10 11 * bindings/js/JSDOMWindowBase.cpp: 12 * bindings/js/JSWorkerGlobalScopeBase.cpp: 13 1 14 2017-01-09 Youenn Fablet <youennf@gmail.com> 2 15 -
trunk/Source/WebCore/bindings/js/JSDOMWindowBase.cpp
r209683 r210522 65 65 &queueTaskToEventLoop, 66 66 &shouldInterruptScriptBeforeTimeout, 67 nullptr, 67 68 &moduleLoaderResolve, 68 69 &moduleLoaderFetch, -
trunk/Source/WebCore/bindings/js/JSWorkerGlobalScopeBase.cpp
r209897 r210522 54 54 &queueTaskToEventLoop, 55 55 &shouldInterruptScriptBeforeTimeout, 56 nullptr, 56 57 nullptr, 57 58 nullptr,
Note: See TracChangeset
for help on using the changeset viewer.