Ignore:
Timestamp:
Jun 25, 2015, 11:49:20 PM (10 years ago)
Author:
[email protected]
Message:

Source/JavaScriptCore:

[ES6] Implement ES6 arrow function syntax. Parser of arrow function with execution as common function.
https://bugs.webkit.org/show_bug.cgi?id=144955

Reviewed by Yusuke Suzuki.

Added support of ES6 arrow function. Changes were made according to following spec http://wiki.ecmascript.org/doku.php?id=harmony:arrow_function_syntax. Patch does not include any arrow function specific behavior e.g. lexical bind this, arguments and etc.

This patch implements the simplest cases of arrow function declaration:

parameters () => 10 + 20
parameter x => x + 20
parameters (x, y) => x + y
function with block x => { return x*10; }

Not implemented:

bind of the this, arguments, super and etc.
exception in case of trying to use 'new' with arrow function

Patch by Aleksandr Skachkov <[email protected]> on 2015-06-26

  • parser/ASTBuilder.h:

(JSC::ASTBuilder::createFunctionExpr):
(JSC::ASTBuilder::createArrowFunctionExpr):
(JSC::ASTBuilder::createGetterOrSetterProperty):
(JSC::ASTBuilder::createFuncDeclStatement):

  • parser/Lexer.cpp:

(JSC::Lexer<T>::setTokenPosition):
(JSC::Lexer<T>::lex):

  • parser/Lexer.h:

(JSC::Lexer::lastTokenLocation):
(JSC::Lexer::setTerminator):

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::parseInner):
(JSC::Parser<LexerType>::parseSourceElements):
(JSC::Parser<LexerType>::parseArrowFunctionSingleExpressionBody):
(JSC::Parser<LexerType>::parseSwitchClauses):
(JSC::Parser<LexerType>::parseSwitchDefaultClause):
(JSC::Parser<LexerType>::parseBlockStatement):
(JSC::Parser<LexerType>::parseFunctionBody):
(JSC::stringForFunctionMode):
(JSC::Parser<LexerType>::parseFunctionParameters):
(JSC::Parser<LexerType>::parseFunctionInfo):
(JSC::Parser<LexerType>::parseFunctionDeclaration):
(JSC::Parser<LexerType>::parseClass):
(JSC::Parser<LexerType>::parseAssignmentExpression):
(JSC::Parser<LexerType>::parsePropertyMethod):
(JSC::Parser<LexerType>::parseGetterSetter):
(JSC::Parser<LexerType>::parseArrowFunctionExpression):

  • parser/Parser.h:

(JSC::Parser::locationBeforeLastToken):
(JSC::Parser::isEndOfArrowFunction):
(JSC::Parser::isArrowFunctionParamters):
(JSC::Parser::setEndOfStatement):

  • parser/ParserFunctionInfo.h:
  • parser/ParserTokens.h:
  • parser/SourceCode.h:

(JSC::SourceCode::subArrowExpression):

  • parser/SourceProviderCacheItem.h:

(JSC::SourceProviderCacheItem::endFunctionToken):
(JSC::SourceProviderCacheItem::SourceProviderCacheItem):

  • parser/SyntaxChecker.h:

(JSC::SyntaxChecker::createArrowFunctionExpr):
(JSC::SyntaxChecker::setFunctionNameStart):

LayoutTests:

[ES6] Implement ES6 arrow function syntax. Parser of arrow function with execution as common function
https://bugs.webkit.org/show_bug.cgi?id=144955

Reviewed by Yusuke Suzuki.

Added arrow function tests

Patch by Aleksandr Skachkov <[email protected]> on 2015-06-26

  • js/arrowfunction-asparamter-1-expected.txt: Added.
  • js/arrowfunction-asparamter-1.html: Added.
  • js/arrowfunction-asparamter-2-expected.txt: Added.
  • js/arrowfunction-asparamter-2.html: Added.
  • js/arrowfunction-associativity-1-expected.txt: Added.
  • js/arrowfunction-associativity-1.html: Added.
  • js/arrowfunction-associativity-2-expected.txt: Added.
  • js/arrowfunction-associativity-2.html: Added.
  • js/arrowfunction-block-1-expected.txt: Added.
  • js/arrowfunction-block-1.html: Added.
  • js/arrowfunction-block-2-expected.txt: Added.
  • js/arrowfunction-block-2.html: Added.
  • js/arrowfunction-syntax-endings-expected.txt: Added.
  • js/arrowfunction-syntax-endings.html: Added.
  • js/arrowfunction-syntax-errors-expected.txt: Added.
  • js/arrowfunction-syntax-errors.html: Added.
  • js/arrowfunction-syntax-expected.txt: Added.
  • js/arrowfunction-syntax.html: Added.
  • js/script-tests/arrowfunction-asparamter-1.js: Added.
  • js/script-tests/arrowfunction-asparamter-2.js: Added.
  • js/script-tests/arrowfunction-associativity-1.js: Added.
  • js/script-tests/arrowfunction-associativity-2.js: Added.
  • js/script-tests/arrowfunction-block-1.js: Added.
  • js/script-tests/arrowfunction-block-2.js: Added.
  • js/script-tests/arrowfunction-syntax-endings.js: Added.
  • js/script-tests/arrowfunction-syntax-errors.js: Added.
  • js/script-tests/arrowfunction-syntax.js: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/SourceProviderCacheItem.h

    r184828 r185989  
    3636struct SourceProviderCacheItemCreationParameters {
    3737    unsigned functionNameStart;
    38     unsigned closeBraceLine;
    39     unsigned closeBraceOffset;
    40     unsigned closeBraceLineStartOffset;
     38    unsigned lastTockenLine;
     39    unsigned lastTockenStartOffset;
     40    unsigned lastTockenEndOffset;
     41    unsigned lastTockenLineStartOffset;
     42    unsigned endFunctionOffset;
    4143    bool needsFullActivation;
    4244    bool usesEval;
     
    4446    Vector<RefPtr<UniquedStringImpl>> usedVariables;
    4547    Vector<RefPtr<UniquedStringImpl>> writtenVariables;
     48#if ENABLE(ES6_ARROWFUNCTION_SYNTAX)
     49    bool isBodyArrowExpression { false };
     50    JSTokenType tokenType { CLOSEBRACE };
     51#endif
    4652};
    4753
     
    5763    ~SourceProviderCacheItem();
    5864
    59     JSToken closeBraceToken() const
     65    JSToken endFunctionToken() const
    6066    {
    6167        JSToken token;
     68#if ENABLE(ES6_ARROWFUNCTION_SYNTAX)
     69        token.m_type = isBodyArrowExpression ? tokenType : CLOSEBRACE;
     70#else
    6271        token.m_type = CLOSEBRACE;
    63         token.m_data.offset = closeBraceOffset;
    64         token.m_location.startOffset = closeBraceOffset;
    65         token.m_location.endOffset = closeBraceOffset + 1;
    66         token.m_location.line = closeBraceLine;
    67         token.m_location.lineStartOffset = closeBraceLineStartOffset;
     72#endif
     73        token.m_data.offset = lastTockenStartOffset;
     74        token.m_location.startOffset = lastTockenStartOffset;
     75        token.m_location.endOffset = lastTockenEndOffset;
     76        token.m_location.line = lastTockenLine;
     77        token.m_location.lineStartOffset = lastTockenLineStartOffset;
    6878        // token.m_location.sourceOffset is initialized once by the client. So,
    6979        // we do not need to set it here.
     
    7383    unsigned functionNameStart : 31;
    7484    bool needsFullActivation : 1;
     85
     86    unsigned endFunctionOffset : 31;
     87    unsigned lastTockenLine : 31;
     88    unsigned lastTockenStartOffset : 31;
     89    unsigned lastTockenEndOffset: 31;
    7590   
    76     unsigned closeBraceLine : 31;
    7791    bool usesEval : 1;
    7892
    79     unsigned closeBraceOffset : 31;
    8093    bool strictMode : 1;
    8194
    82     unsigned closeBraceLineStartOffset;
     95    unsigned lastTockenLineStartOffset;
    8396    unsigned usedVariablesCount;
    8497    unsigned writtenVariablesCount;
     
    8699    UniquedStringImpl** usedVariables() const { return const_cast<UniquedStringImpl**>(m_variables); }
    87100    UniquedStringImpl** writtenVariables() const { return const_cast<UniquedStringImpl**>(&m_variables[usedVariablesCount]); }
     101#if ENABLE(ES6_ARROWFUNCTION_SYNTAX)
     102    bool isBodyArrowExpression;
     103    JSTokenType tokenType;
     104#endif
    88105
    89106private:
     
    110127    : functionNameStart(parameters.functionNameStart)
    111128    , needsFullActivation(parameters.needsFullActivation)
    112     , closeBraceLine(parameters.closeBraceLine)
     129    , endFunctionOffset(parameters.endFunctionOffset)
     130    , lastTockenLine(parameters.lastTockenLine)
     131    , lastTockenStartOffset(parameters.lastTockenStartOffset)
     132    , lastTockenEndOffset(parameters.lastTockenEndOffset)
    113133    , usesEval(parameters.usesEval)
    114     , closeBraceOffset(parameters.closeBraceOffset)
    115134    , strictMode(parameters.strictMode)
    116     , closeBraceLineStartOffset(parameters.closeBraceLineStartOffset)
     135    , lastTockenLineStartOffset(parameters.lastTockenLineStartOffset)
    117136    , usedVariablesCount(parameters.usedVariables.size())
    118137    , writtenVariablesCount(parameters.writtenVariables.size())
     138#if ENABLE(ES6_ARROWFUNCTION_SYNTAX)
     139    , isBodyArrowExpression(parameters.isBodyArrowExpression)
     140    , tokenType(parameters.tokenType)
     141#endif
    119142{
    120143    unsigned j = 0;
Note: See TracChangeset for help on using the changeset viewer.