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/SourceCode.h

    r182034 r185989  
    106106        SourceCode subExpression(unsigned openBrace, unsigned closeBrace, int firstLine, int startColumn);
    107107
     108#if ENABLE(ES6_ARROWFUNCTION_SYNTAX)
     109        SourceCode subArrowExpression(unsigned startArrowFunction, unsigned endArrowFunction, int firstLine, int startColumn);
     110#endif
    108111    private:
    109112        RefPtr<SourceProvider> m_provider;
     
    118121        return SourceCode(StringSourceProvider::create(source, url, startPosition), startPosition.m_line.oneBasedInt(), startPosition.m_column.oneBasedInt());
    119122    }
     123   
     124#if ENABLE(ES6_ARROWFUNCTION_SYNTAX)
     125    inline SourceCode SourceCode::subArrowExpression(unsigned startArrowFunction, unsigned endArrowFunction, int firstLine, int startColumn)
     126    {
     127        ASSERT(provider()->source()[startArrowFunction] == '=' && provider()->source()[startArrowFunction + 1] == '>');
     128
     129        startColumn += 1; // Convert to base 1.
     130        return SourceCode(provider(), startArrowFunction, endArrowFunction, firstLine, startColumn);
     131    }
     132#endif
    120133
    121134    inline SourceCode SourceCode::subExpression(unsigned openBrace, unsigned closeBrace, int firstLine, int startColumn)
Note: See TracChangeset for help on using the changeset viewer.