Ignore:
Timestamp:
Aug 4, 2015, 2:26:49 PM (10 years ago)
Author:
Yusuke Suzuki
Message:

[ES6] Support Module Syntax
https://bugs.webkit.org/show_bug.cgi?id=147422

Reviewed by Saam Barati.

Source/JavaScriptCore:

This patch introduces ES6 Modules syntax parsing part.
In this patch, ASTBuilder just produces the corresponding nodes to the ES6 Modules syntax,
and this patch does not include the code generator part.

Modules require 2 phase parsing. In the first pass, we just analyze the dependent modules
and do not execute the body or construct the AST. And after analyzing all the dependent
modules, we will parse the dependent modules next.
After all analyzing part is done, we will start the second pass. In the second pass, we
will parse the module, produce the AST, and execute the body.
If we don't do so, we need to create all the ASTs in the module's dependent graph at first
because the given module can be executed after the all dependent modules are executed. It
means that we need to hold so many parser arenas. To avoid this, the first pass only extracts
the dependent modules' information.

In this patch, we don't add this analyzing part yet. This patch only implements the second pass.
This patch aims at just implementing the syntax parsing functionality correctly.
After this patch is landed, we will create the ModuleDependencyAnalyzer that inherits SyntaxChecker
to collect the dependent modules fast[1].

To test the parsing, we added the "checkModuleSyntax" function into jsc shell.
By using this, we can parse the given string as the module.

[1]: https://bugs.webkit.org/show_bug.cgi?id=147353

  • bytecompiler/NodesCodegen.cpp:

(JSC::ModuleProgramNode::emitBytecode):
(JSC::ImportDeclarationNode::emitBytecode):
(JSC::ExportAllDeclarationNode::emitBytecode):
(JSC::ExportDefaultDeclarationNode::emitBytecode):
(JSC::ExportLocalDeclarationNode::emitBytecode):
(JSC::ExportNamedDeclarationNode::emitBytecode):

  • jsc.cpp:

(GlobalObject::finishCreation):
(functionCheckModuleSyntax):

  • parser/ASTBuilder.h:

(JSC::ASTBuilder::createModuleSpecifier):
(JSC::ASTBuilder::createImportSpecifier):
(JSC::ASTBuilder::createImportSpecifierList):
(JSC::ASTBuilder::appendImportSpecifier):
(JSC::ASTBuilder::createImportDeclaration):
(JSC::ASTBuilder::createExportAllDeclaration):
(JSC::ASTBuilder::createExportDefaultDeclaration):
(JSC::ASTBuilder::createExportLocalDeclaration):
(JSC::ASTBuilder::createExportNamedDeclaration):
(JSC::ASTBuilder::createExportSpecifier):
(JSC::ASTBuilder::createExportSpecifierList):
(JSC::ASTBuilder::appendExportSpecifier):

  • parser/Keywords.table:
  • parser/NodeConstructors.h:

(JSC::ModuleSpecifierNode::ModuleSpecifierNode):
(JSC::ImportSpecifierNode::ImportSpecifierNode):
(JSC::ImportDeclarationNode::ImportDeclarationNode):
(JSC::ExportAllDeclarationNode::ExportAllDeclarationNode):
(JSC::ExportDefaultDeclarationNode::ExportDefaultDeclarationNode):
(JSC::ExportLocalDeclarationNode::ExportLocalDeclarationNode):
(JSC::ExportNamedDeclarationNode::ExportNamedDeclarationNode):
(JSC::ExportSpecifierNode::ExportSpecifierNode):

  • parser/Nodes.cpp:

(JSC::ModuleProgramNode::ModuleProgramNode):

  • parser/Nodes.h:

(JSC::ModuleProgramNode::startColumn):
(JSC::ModuleProgramNode::endColumn):
(JSC::ModuleSpecifierNode::moduleName):
(JSC::ImportSpecifierNode::importedName):
(JSC::ImportSpecifierNode::localName):
(JSC::ImportSpecifierListNode::specifiers):
(JSC::ImportSpecifierListNode::append):
(JSC::ImportDeclarationNode::specifierList):
(JSC::ImportDeclarationNode::moduleSpecifier):
(JSC::ExportAllDeclarationNode::moduleSpecifier):
(JSC::ExportDefaultDeclarationNode::declaration):
(JSC::ExportLocalDeclarationNode::declaration):
(JSC::ExportSpecifierNode::exportedName):
(JSC::ExportSpecifierNode::localName):
(JSC::ExportSpecifierListNode::specifiers):
(JSC::ExportSpecifierListNode::append):
(JSC::ExportNamedDeclarationNode::specifierList):
(JSC::ExportNamedDeclarationNode::moduleSpecifier):

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::Parser):
(JSC::Parser<LexerType>::parseInner):
(JSC::Parser<LexerType>::parseModuleSourceElements):
(JSC::Parser<LexerType>::parseVariableDeclaration):
(JSC::Parser<LexerType>::parseVariableDeclarationList):
(JSC::Parser<LexerType>::createBindingPattern):
(JSC::Parser<LexerType>::tryParseDestructuringPatternExpression):
(JSC::Parser<LexerType>::parseDestructuringPattern):
(JSC::Parser<LexerType>::parseForStatement):
(JSC::Parser<LexerType>::parseFormalParameters):
(JSC::Parser<LexerType>::parseFunctionParameters):
(JSC::Parser<LexerType>::parseFunctionDeclaration):
(JSC::Parser<LexerType>::parseClassDeclaration):
(JSC::Parser<LexerType>::parseModuleSpecifier):
(JSC::Parser<LexerType>::parseImportClauseItem):
(JSC::Parser<LexerType>::parseImportDeclaration):
(JSC::Parser<LexerType>::parseExportSpecifier):
(JSC::Parser<LexerType>::parseExportDeclaration):
(JSC::Parser<LexerType>::parseMemberExpression):

  • parser/Parser.h:

(JSC::isIdentifierOrKeyword):
(JSC::ModuleScopeData::create):
(JSC::ModuleScopeData::exportedBindings):
(JSC::ModuleScopeData::exportName):
(JSC::ModuleScopeData::exportBinding):
(JSC::Scope::Scope):
(JSC::Scope::setIsModule):
(JSC::Scope::moduleScopeData):
(JSC::Parser::matchContextualKeyword):
(JSC::Parser::matchIdentifierOrKeyword):
(JSC::Parser::isofToken): Deleted.

  • parser/ParserModes.h:
  • parser/ParserTokens.h:
  • parser/SyntaxChecker.h:

(JSC::SyntaxChecker::createModuleSpecifier):
(JSC::SyntaxChecker::createImportSpecifier):
(JSC::SyntaxChecker::createImportSpecifierList):
(JSC::SyntaxChecker::appendImportSpecifier):
(JSC::SyntaxChecker::createImportDeclaration):
(JSC::SyntaxChecker::createExportAllDeclaration):
(JSC::SyntaxChecker::createExportDefaultDeclaration):
(JSC::SyntaxChecker::createExportLocalDeclaration):
(JSC::SyntaxChecker::createExportNamedDeclaration):
(JSC::SyntaxChecker::createExportSpecifier):
(JSC::SyntaxChecker::createExportSpecifierList):
(JSC::SyntaxChecker::appendExportSpecifier):

  • runtime/CommonIdentifiers.cpp:

(JSC::CommonIdentifiers::CommonIdentifiers):

  • runtime/CommonIdentifiers.h:
  • runtime/Completion.cpp:

(JSC::checkModuleSyntax):

  • runtime/Completion.h:
  • tests/stress/modules-syntax-error-with-names.js: Added.

(shouldThrow):

  • tests/stress/modules-syntax-error.js: Added.

(shouldThrow):
(checkModuleSyntaxError.checkModuleSyntaxError.checkModuleSyntaxError):

  • tests/stress/modules-syntax.js: Added.

(prototype.checkModuleSyntax):
(checkModuleSyntax):

  • tests/stress/tagged-templates-syntax.js:

LayoutTests:

'export' and 'import' are changed from FutureReservedWord to Keyword in ES6.
http://www.ecma-international.org/ecma-262/6.0/#sec-keywords
And restrict 'super' use under the Script / Module contexts.

  • js/dom/reserved-words-as-property-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.5_Tokens/7.5.3_Future_Reserved_Words/S7.5.3_A1.10-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.5_Tokens/7.5.3_Future_Reserved_Words/S7.5.3_A1.16-expected.txt:
  • sputnik/Conformance/07_Lexical_Conventions/7.5_Tokens/7.5.3_Future_Reserved_Words/S7.5.3_A1.27-expected.txt:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r187819 r187890  
     12015-08-04  Yusuke Suzuki  <[email protected]>
     2
     3        [ES6] Support Module Syntax
     4        https://bugs.webkit.org/show_bug.cgi?id=147422
     5
     6        Reviewed by Saam Barati.
     7
     8        This patch introduces ES6 Modules syntax parsing part.
     9        In this patch, ASTBuilder just produces the corresponding nodes to the ES6 Modules syntax,
     10        and this patch does not include the code generator part.
     11
     12        Modules require 2 phase parsing. In the first pass, we just analyze the dependent modules
     13        and do not execute the body or construct the AST. And after analyzing all the dependent
     14        modules, we will parse the dependent modules next.
     15        After all analyzing part is done, we will start the second pass. In the second pass, we
     16        will parse the module, produce the AST, and execute the body.
     17        If we don't do so, we need to create all the ASTs in the module's dependent graph at first
     18        because the given module can be executed after the all dependent modules are executed. It
     19        means that we need to hold so many parser arenas. To avoid this, the first pass only extracts
     20        the dependent modules' information.
     21
     22        In this patch, we don't add this analyzing part yet. This patch only implements the second pass.
     23        This patch aims at just implementing the syntax parsing functionality correctly.
     24        After this patch is landed, we will create the ModuleDependencyAnalyzer that inherits SyntaxChecker
     25        to collect the dependent modules fast[1].
     26
     27        To test the parsing, we added the "checkModuleSyntax" function into jsc shell.
     28        By using this, we can parse the given string as the module.
     29
     30        [1]: https://bugs.webkit.org/show_bug.cgi?id=147353
     31
     32        * bytecompiler/NodesCodegen.cpp:
     33        (JSC::ModuleProgramNode::emitBytecode):
     34        (JSC::ImportDeclarationNode::emitBytecode):
     35        (JSC::ExportAllDeclarationNode::emitBytecode):
     36        (JSC::ExportDefaultDeclarationNode::emitBytecode):
     37        (JSC::ExportLocalDeclarationNode::emitBytecode):
     38        (JSC::ExportNamedDeclarationNode::emitBytecode):
     39        * jsc.cpp:
     40        (GlobalObject::finishCreation):
     41        (functionCheckModuleSyntax):
     42        * parser/ASTBuilder.h:
     43        (JSC::ASTBuilder::createModuleSpecifier):
     44        (JSC::ASTBuilder::createImportSpecifier):
     45        (JSC::ASTBuilder::createImportSpecifierList):
     46        (JSC::ASTBuilder::appendImportSpecifier):
     47        (JSC::ASTBuilder::createImportDeclaration):
     48        (JSC::ASTBuilder::createExportAllDeclaration):
     49        (JSC::ASTBuilder::createExportDefaultDeclaration):
     50        (JSC::ASTBuilder::createExportLocalDeclaration):
     51        (JSC::ASTBuilder::createExportNamedDeclaration):
     52        (JSC::ASTBuilder::createExportSpecifier):
     53        (JSC::ASTBuilder::createExportSpecifierList):
     54        (JSC::ASTBuilder::appendExportSpecifier):
     55        * parser/Keywords.table:
     56        * parser/NodeConstructors.h:
     57        (JSC::ModuleSpecifierNode::ModuleSpecifierNode):
     58        (JSC::ImportSpecifierNode::ImportSpecifierNode):
     59        (JSC::ImportDeclarationNode::ImportDeclarationNode):
     60        (JSC::ExportAllDeclarationNode::ExportAllDeclarationNode):
     61        (JSC::ExportDefaultDeclarationNode::ExportDefaultDeclarationNode):
     62        (JSC::ExportLocalDeclarationNode::ExportLocalDeclarationNode):
     63        (JSC::ExportNamedDeclarationNode::ExportNamedDeclarationNode):
     64        (JSC::ExportSpecifierNode::ExportSpecifierNode):
     65        * parser/Nodes.cpp:
     66        (JSC::ModuleProgramNode::ModuleProgramNode):
     67        * parser/Nodes.h:
     68        (JSC::ModuleProgramNode::startColumn):
     69        (JSC::ModuleProgramNode::endColumn):
     70        (JSC::ModuleSpecifierNode::moduleName):
     71        (JSC::ImportSpecifierNode::importedName):
     72        (JSC::ImportSpecifierNode::localName):
     73        (JSC::ImportSpecifierListNode::specifiers):
     74        (JSC::ImportSpecifierListNode::append):
     75        (JSC::ImportDeclarationNode::specifierList):
     76        (JSC::ImportDeclarationNode::moduleSpecifier):
     77        (JSC::ExportAllDeclarationNode::moduleSpecifier):
     78        (JSC::ExportDefaultDeclarationNode::declaration):
     79        (JSC::ExportLocalDeclarationNode::declaration):
     80        (JSC::ExportSpecifierNode::exportedName):
     81        (JSC::ExportSpecifierNode::localName):
     82        (JSC::ExportSpecifierListNode::specifiers):
     83        (JSC::ExportSpecifierListNode::append):
     84        (JSC::ExportNamedDeclarationNode::specifierList):
     85        (JSC::ExportNamedDeclarationNode::moduleSpecifier):
     86        * parser/Parser.cpp:
     87        (JSC::Parser<LexerType>::Parser):
     88        (JSC::Parser<LexerType>::parseInner):
     89        (JSC::Parser<LexerType>::parseModuleSourceElements):
     90        (JSC::Parser<LexerType>::parseVariableDeclaration):
     91        (JSC::Parser<LexerType>::parseVariableDeclarationList):
     92        (JSC::Parser<LexerType>::createBindingPattern):
     93        (JSC::Parser<LexerType>::tryParseDestructuringPatternExpression):
     94        (JSC::Parser<LexerType>::parseDestructuringPattern):
     95        (JSC::Parser<LexerType>::parseForStatement):
     96        (JSC::Parser<LexerType>::parseFormalParameters):
     97        (JSC::Parser<LexerType>::parseFunctionParameters):
     98        (JSC::Parser<LexerType>::parseFunctionDeclaration):
     99        (JSC::Parser<LexerType>::parseClassDeclaration):
     100        (JSC::Parser<LexerType>::parseModuleSpecifier):
     101        (JSC::Parser<LexerType>::parseImportClauseItem):
     102        (JSC::Parser<LexerType>::parseImportDeclaration):
     103        (JSC::Parser<LexerType>::parseExportSpecifier):
     104        (JSC::Parser<LexerType>::parseExportDeclaration):
     105        (JSC::Parser<LexerType>::parseMemberExpression):
     106        * parser/Parser.h:
     107        (JSC::isIdentifierOrKeyword):
     108        (JSC::ModuleScopeData::create):
     109        (JSC::ModuleScopeData::exportedBindings):
     110        (JSC::ModuleScopeData::exportName):
     111        (JSC::ModuleScopeData::exportBinding):
     112        (JSC::Scope::Scope):
     113        (JSC::Scope::setIsModule):
     114        (JSC::Scope::moduleScopeData):
     115        (JSC::Parser::matchContextualKeyword):
     116        (JSC::Parser::matchIdentifierOrKeyword):
     117        (JSC::Parser::isofToken): Deleted.
     118        * parser/ParserModes.h:
     119        * parser/ParserTokens.h:
     120        * parser/SyntaxChecker.h:
     121        (JSC::SyntaxChecker::createModuleSpecifier):
     122        (JSC::SyntaxChecker::createImportSpecifier):
     123        (JSC::SyntaxChecker::createImportSpecifierList):
     124        (JSC::SyntaxChecker::appendImportSpecifier):
     125        (JSC::SyntaxChecker::createImportDeclaration):
     126        (JSC::SyntaxChecker::createExportAllDeclaration):
     127        (JSC::SyntaxChecker::createExportDefaultDeclaration):
     128        (JSC::SyntaxChecker::createExportLocalDeclaration):
     129        (JSC::SyntaxChecker::createExportNamedDeclaration):
     130        (JSC::SyntaxChecker::createExportSpecifier):
     131        (JSC::SyntaxChecker::createExportSpecifierList):
     132        (JSC::SyntaxChecker::appendExportSpecifier):
     133        * runtime/CommonIdentifiers.cpp:
     134        (JSC::CommonIdentifiers::CommonIdentifiers):
     135        * runtime/CommonIdentifiers.h:
     136        * runtime/Completion.cpp:
     137        (JSC::checkModuleSyntax):
     138        * runtime/Completion.h:
     139        * tests/stress/modules-syntax-error-with-names.js: Added.
     140        (shouldThrow):
     141        * tests/stress/modules-syntax-error.js: Added.
     142        (shouldThrow):
     143        (checkModuleSyntaxError.checkModuleSyntaxError.checkModuleSyntaxError):
     144        * tests/stress/modules-syntax.js: Added.
     145        (prototype.checkModuleSyntax):
     146        (checkModuleSyntax):
     147        * tests/stress/tagged-templates-syntax.js:
     148
    11492015-08-03  Csaba Osztrogonác  <[email protected]>
    2150
Note: See TracChangeset for help on using the changeset viewer.