haikuwebkit/JSTests/modules/import-meta-syntax.js

26 lines
857 B
JavaScript
Raw Permalink Normal View History

[JSC] Introduce import.meta https://bugs.webkit.org/show_bug.cgi?id=177703 Reviewed by Filip Pizlo. JSTests: * modules/import-meta-syntax.js: Added. (shouldThrow): (shouldNotThrow): * modules/import-meta.js: Added. * modules/import-meta/cocoa.js: Added. * modules/resources/assert.js: (export.shouldNotThrow): * stress/import-syntax.js: Source/JavaScriptCore: This patch adds stage 3 `import.meta`[1]. We add a new hook function moduleLoaderCreateImportMetaProperties, which creates import meta properties object to this module. And we set this object as @meta private variable in module environments. So module code can access this by accessing @meta private variable. [1]: https://github.com/tc39/proposal-import-meta * builtins/BuiltinNames.h: * builtins/ModuleLoaderPrototype.js: * bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::BytecodeGenerator): * jsc.cpp: (GlobalObject::moduleLoaderCreateImportMetaProperties): * parser/Parser.cpp: (JSC::Parser<LexerType>::parseModuleSourceElements): (JSC::Parser<LexerType>::parseMemberExpression): * runtime/JSGlobalObject.cpp: * runtime/JSGlobalObject.h: * runtime/JSModuleLoader.cpp: (JSC::JSModuleLoader::createImportMetaProperties): * runtime/JSModuleLoader.h: * runtime/JSModuleRecord.cpp: (JSC::JSModuleRecord::link): (JSC::JSModuleRecord::instantiateDeclarations): * runtime/JSModuleRecord.h: * runtime/ModuleLoaderPrototype.cpp: (JSC::moduleLoaderPrototypeModuleDeclarationInstantiation): Source/WebCore: * bindings/js/JSDOMWindowBase.cpp: * bindings/js/JSWorkerGlobalScopeBase.cpp: Canonical link: https://commits.webkit.org/194170@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222895 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-05 03:57:38 +00:00
import { shouldThrow, shouldNotThrow } from "./resources/assert.js";
shouldThrow(() => {
new Function(`import.meta`);
}, `SyntaxError: import.meta is only valid inside modules.`);
shouldNotThrow(() => {
checkModuleSyntax(`import.meta`);
});
shouldThrow(() => {
checkModuleSyntax(`(import.cocoa)`);
}, `SyntaxError: Unexpected identifier 'cocoa'. "import." can only followed with meta.:1`);
shouldThrow(() => {
checkModuleSyntax(`(import["Cocoa"])`);
}, `SyntaxError: Unexpected token '['. import call expects exactly one argument.:1`);
shouldThrow(() => {
checkModuleSyntax(`import.cocoa`);
}, `SyntaxError: Unexpected identifier 'cocoa'. "import." can only followed with meta.:1`);
shouldThrow(() => {
checkModuleSyntax(`import["Cocoa"]`);
}, `SyntaxError: Unexpected token '['. Expected namespace import or import list.:1`);