Ignore:
Timestamp:
Sep 17, 2020, 3:30:19 AM (5 years ago)
Author:
[email protected]
Message:

Support export namespace export * as ns
https://bugs.webkit.org/show_bug.cgi?id=214379

Reviewed by Ross Kirsling.

JSTests:

  • stress/modules-syntax-error.js:
  • stress/modules-syntax.js:
  • test262/expectations.yaml:

Source/JavaScriptCore:

This patch supports export * as ns from "module" syntax. If it is used, we expose "module"'s namespace object as "ns".
For each module environment, we create *namespace* (starNamespace) private symbol scope variable. And we fill it later
with module namespace object. This way allows us to use module namespace object IC and super fast imported module binding
lookup though environment variable lookup mechanism.

  • builtins/BuiltinNames.h:
  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::BytecodeGenerator):

  • parser/NodesAnalyzeModule.cpp:

(JSC::ExportNamedDeclarationNode::analyzeModule):

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::parseExportDeclaration):

  • runtime/AbstractModuleRecord.cpp:

(JSC::AbstractModuleRecord::ExportEntry::createNamespace):
(JSC::AbstractModuleRecord::resolveExportImpl):
(JSC::AbstractModuleRecord::getModuleNamespace):
(JSC::AbstractModuleRecord::setModuleEnvironment):
(JSC::AbstractModuleRecord::dump):

  • runtime/AbstractModuleRecord.h:
  • runtime/CommonIdentifiers.h:
  • runtime/JSFunction.cpp:

(JSC::JSFunction::name):
(JSC::JSFunction::reifyName):

  • runtime/JSModuleNamespaceObject.cpp:

(JSC::JSModuleNamespaceObject::getOwnPropertySlotCommon):

  • runtime/JSModuleRecord.cpp:

(JSC::JSModuleRecord::instantiateDeclarations):
(JSC::JSModuleRecord::evaluate):

  • wasm/js/JSWebAssemblyModule.cpp:

(JSC::JSWebAssemblyModule::finishCreation):

  • wasm/js/WebAssemblyModuleRecord.cpp:

(JSC::WebAssemblyModuleRecord::link):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r266340 r267186  
    35323532    case TIMES: {
    35333533        // export * FromClause ;
    3534         next();
     3534        // export * as IdentifierName FromClause ;
     3535        next();
     3536
     3537        const Identifier* exportedName = nullptr;
     3538        JSTokenLocation specifierLocation;
     3539        if (matchContextualKeyword(m_vm.propertyNames->as)) {
     3540            next();
     3541            specifierLocation = JSTokenLocation(tokenLocation());
     3542            failIfFalse(matchIdentifierOrKeyword(), "Expected an exported name for the export declaration");
     3543            exportedName = m_token.m_data.ident;
     3544            next();
     3545        }
    35353546
    35363547        failIfFalse(matchContextualKeyword(m_vm.propertyNames->from), "Expected 'from' before exported module name");
     
    35393550        failIfFalse(moduleName, "Cannot parse the 'from' clause");
    35403551        failIfFalse(autoSemiColon(), "Expected a ';' following a targeted export declaration");
     3552
     3553        if (exportedName) {
     3554            semanticFailIfFalse(exportName(*exportedName), "Cannot export a duplicate name '", exportedName->impl(), "'");
     3555            auto specifierList = context.createExportSpecifierList();
     3556            auto localName = &m_vm.propertyNames->starNamespacePrivateName;
     3557            auto specifier = context.createExportSpecifier(specifierLocation, *localName, *exportedName);
     3558            context.appendExportSpecifier(specifierList, specifier);
     3559            return context.createExportNamedDeclaration(exportLocation, specifierList, moduleName);
     3560        }
    35413561
    35423562        return context.createExportAllDeclaration(exportLocation, moduleName);
Note: See TracChangeset for help on using the changeset viewer.