Ignore:
Timestamp:
Aug 25, 2015, 12:10:29 PM (10 years ago)
Author:
[email protected]
Message:

Function.prototype.toString is incorrect for ArrowFunction
https://bugs.webkit.org/show_bug.cgi?id=148148

Source/JavaScriptCore:

Patch by Aleksandr Skachkov <[email protected]> on 2015-08-25
Reviewed by Saam Barati.

Added correct support of toString() method for arrow function.

  • parser/ASTBuilder.h:

(JSC::ASTBuilder::createFunctionMetadata):
(JSC::ASTBuilder::createArrowFunctionExpr):

  • parser/Nodes.cpp:

(JSC::FunctionMetadataNode::FunctionMetadataNode):

  • parser/Nodes.h:
  • parser/Parser.cpp:

(JSC::Parser<LexerType>::parseFunctionBody):
(JSC::Parser<LexerType>::parseFunctionInfo):

  • parser/SyntaxChecker.h:

(JSC::SyntaxChecker::createFunctionMetadata):

  • runtime/FunctionPrototype.cpp:

(JSC::functionProtoFuncToString):

  • tests/stress/arrowfunction-tostring.js: Added.

LayoutTests:

Patch by Skachkov Oleksandr <[email protected]> on 2015-08-25
Reviewed by Saam Barati.

Added test of toString() method.

  • js/arrowfunction-tostring-expected.txt: Added.
  • js/arrowfunction-tostring.html: Added.
  • js/script-tests/arrowfunction-tostring.js: Added.
File:
1 edited

Legend:

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

    r188545 r188928  
    362362        unsigned startColumn, unsigned endColumn, int functionKeywordStart,
    363363        int functionNameStart, int parametersStart, bool inStrictContext,
    364         ConstructorKind constructorKind, unsigned parameterCount, SourceParseMode mode, bool isArrowFunction)
     364        ConstructorKind constructorKind, unsigned parameterCount, SourceParseMode mode, bool isArrowFunction, bool isArrowFunctionBodyExpression)
    365365    {
    366366        return new (m_parserArena) FunctionMetadataNode(
    367367            m_parserArena, startLocation, endLocation, startColumn, endColumn,
    368368            functionKeywordStart, functionNameStart, parametersStart,
    369             inStrictContext, constructorKind, parameterCount, mode, isArrowFunction);
     369            inStrictContext, constructorKind, parameterCount, mode, isArrowFunction, isArrowFunctionBodyExpression);
    370370    }
    371371
     
    373373    {
    374374        usesThis();
    375         SourceCode source = m_sourceCode->subExpression(functionInfo.startOffset, functionInfo.endOffset, functionInfo.startLine, functionInfo.bodyStartColumn);
     375        SourceCode source = m_sourceCode->subExpression(functionInfo.startOffset, functionInfo.body->isArrowFunctionBodyExpression() ? functionInfo.endOffset - 1 : functionInfo.endOffset, functionInfo.startLine, functionInfo.bodyStartColumn);
    376376        ArrowFuncExprNode* result = new (m_parserArena) ArrowFuncExprNode(location, *functionInfo.name, functionInfo.body, source);
    377377        functionInfo.body->setLoc(functionInfo.startLine, functionInfo.endLine, location.startOffset, location.lineStartOffset);
Note: See TracChangeset for help on using the changeset viewer.