Ignore:
Timestamp:
Oct 4, 2017, 8:57:38 PM (8 years ago)
Author:
Yusuke Suzuki
Message:

[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:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/jsc.cpp

    r222827 r222895  
    16611661    static JSInternalPromise* moduleLoaderResolve(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue, JSValue);
    16621662    static JSInternalPromise* moduleLoaderFetch(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSValue);
     1663    static JSObject* moduleLoaderCreateImportMetaProperties(JSGlobalObject*, ExecState*, JSModuleLoader*, JSValue, JSModuleRecord*, JSValue);
    16631664};
    16641665
     
    16741675    &moduleLoaderFetch,
    16751676    nullptr, // moduleLoaderInstantiate
     1677    &moduleLoaderCreateImportMetaProperties,
    16761678    nullptr, // moduleLoaderEvaluate
    16771679    nullptr, // promiseRejectionTracker
     
    20072009}
    20082010
     2011JSObject* GlobalObject::moduleLoaderCreateImportMetaProperties(JSGlobalObject* globalObject, ExecState* exec, JSModuleLoader*, JSValue key, JSModuleRecord*, JSValue)
     2012{
     2013    VM& vm = exec->vm();
     2014    auto scope = DECLARE_THROW_SCOPE(vm);
     2015
     2016    JSObject* metaProperties = constructEmptyObject(exec, globalObject->nullPrototypeObjectStructure());
     2017    RETURN_IF_EXCEPTION(scope, nullptr);
     2018
     2019    metaProperties->putDirect(vm, Identifier::fromString(&vm, "filename"), key);
     2020    RETURN_IF_EXCEPTION(scope, nullptr);
     2021
     2022    return metaProperties;
     2023}
    20092024
    20102025static EncodedJSValue printInternal(ExecState* exec, FILE* out)
Note: See TracChangeset for help on using the changeset viewer.