Changeset 223175 in webkit


Ignore:
Timestamp:
Oct 11, 2017 5:59:36 AM (7 years ago)
Author:
Caio Lima
Message:

Object properties are undefined in super.call() but not in this.call()
https://bugs.webkit.org/show_bug.cgi?id=177230

Reviewed by Saam Barati.

JSTests:

  • stress/super-call-function-subclass.js: Added.

(assert):
(A.prototype.t):
(A):

  • stress/super-dot-call-and-apply.js: Added.

(assert):
(A):
(A.prototype.call):
(A.prototype.apply):
(B.prototype.testSuper):
(B):
(const.obj.new.B.string_appeared_here.obj.testSuper.C):
(D.prototype.testSuper):
(D):

Source/JavaScriptCore:

Bytecode generation for "super.call(...)" or "super.apply(...)"
shouldn't be considered as CallFunctionCallDotNode or
ApplyFunctionCallDotNode because they should be considered as common
super property access as any other function. According to spec[1],
"super" is not refering to parent constructor.

[1] - https://tc39.github.io/ecma262/#sec-super-keyword-runtime-semantics-evaluation

  • parser/ASTBuilder.h:

(JSC::ASTBuilder::makeFunctionCallNode):

  • parser/Parser.cpp:

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

  • parser/SyntaxChecker.h:

(JSC::SyntaxChecker::makeFunctionCallNode):

Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r223125 r223175  
     12017-10-11  Caio Lima  <ticaiolima@gmail.com>
     2
     3        Object properties are undefined in super.call() but not in this.call()
     4        https://bugs.webkit.org/show_bug.cgi?id=177230
     5
     6        Reviewed by Saam Barati.
     7
     8        * stress/super-call-function-subclass.js: Added.
     9        (assert):
     10        (A.prototype.t):
     11        (A):
     12        * stress/super-dot-call-and-apply.js: Added.
     13        (assert):
     14        (A):
     15        (A.prototype.call):
     16        (A.prototype.apply):
     17        (B.prototype.testSuper):
     18        (B):
     19        (const.obj.new.B.string_appeared_here.obj.testSuper.C):
     20        (D.prototype.testSuper):
     21        (D):
     22
    1232017-10-10  Saam Barati  <sbarati@apple.com>
    224
  • trunk/Source/JavaScriptCore/ChangeLog

    r223173 r223175  
     12017-10-11  Caio Lima  <ticaiolima@gmail.com>
     2
     3        Object properties are undefined in super.call() but not in this.call()
     4        https://bugs.webkit.org/show_bug.cgi?id=177230
     5
     6        Reviewed by Saam Barati.
     7
     8        Bytecode generation for "super.call(...)" or "super.apply(...)"
     9        shouldn't be considered as CallFunctionCallDotNode or
     10        ApplyFunctionCallDotNode because they should be considered as common
     11        super property access as any other function. According to spec[1],
     12        "super" is not refering to parent constructor.
     13
     14        [1] - https://tc39.github.io/ecma262/#sec-super-keyword-runtime-semantics-evaluation
     15
     16        * parser/ASTBuilder.h:
     17        (JSC::ASTBuilder::makeFunctionCallNode):
     18        * parser/Parser.cpp:
     19        (JSC::Parser<LexerType>::parseMemberExpression):
     20        * parser/SyntaxChecker.h:
     21        (JSC::SyntaxChecker::makeFunctionCallNode):
     22
    1232017-10-11  Yusuke Suzuki  <utatane.tea@gmail.com>
    224
  • trunk/Source/JavaScriptCore/parser/ASTBuilder.h

    r221358 r223175  
    130130
    131131    ExpressionNode* makeBinaryNode(const JSTokenLocation&, int token, std::pair<ExpressionNode*, BinaryOpInfo>, std::pair<ExpressionNode*, BinaryOpInfo>);
    132     ExpressionNode* makeFunctionCallNode(const JSTokenLocation&, ExpressionNode* func, ArgumentsNode* args, const JSTextPosition& divotStart, const JSTextPosition& divot, const JSTextPosition& divotEnd, size_t callOrApplyChildDepth);
     132    ExpressionNode* makeFunctionCallNode(const JSTokenLocation&, ExpressionNode* func, bool previousBaseWasSuper, ArgumentsNode* args, const JSTextPosition& divotStart, const JSTextPosition& divot, const JSTextPosition& divotEnd, size_t callOrApplyChildDepth);
    133133
    134134    JSC::SourceElements* createSourceElements() { return new (m_parserArena) JSC::SourceElements(); }
     
    13181318}
    13191319
    1320 ExpressionNode* ASTBuilder::makeFunctionCallNode(const JSTokenLocation& location, ExpressionNode* func, ArgumentsNode* args, const JSTextPosition& divotStart, const JSTextPosition& divot, const JSTextPosition& divotEnd, size_t callOrApplyChildDepth)
     1320ExpressionNode* ASTBuilder::makeFunctionCallNode(const JSTokenLocation& location, ExpressionNode* func, bool previousBaseWasSuper, ArgumentsNode* args, const JSTextPosition& divotStart, const JSTextPosition& divot, const JSTextPosition& divotEnd, size_t callOrApplyChildDepth)
    13211321{
    13221322    ASSERT(divot.offset >= divot.lineStartOffset);
     
    13491349    DotAccessorNode* dot = static_cast<DotAccessorNode*>(func);
    13501350    FunctionCallDotNode* node;
    1351     if (dot->identifier() == m_vm->propertyNames->builtinNames().callPublicName() || dot->identifier() == m_vm->propertyNames->builtinNames().callPrivateName())
     1351    if (!previousBaseWasSuper && (dot->identifier() == m_vm->propertyNames->builtinNames().callPublicName() || dot->identifier() == m_vm->propertyNames->builtinNames().callPrivateName()))
    13521352        node = new (m_parserArena) CallFunctionCallDotNode(location, dot->base(), dot->identifier(), args, divot, divotStart, divotEnd, callOrApplyChildDepth);
    1353     else if (dot->identifier() == m_vm->propertyNames->builtinNames().applyPublicName() || dot->identifier() == m_vm->propertyNames->builtinNames().applyPrivateName())
     1353    else if (!previousBaseWasSuper && (dot->identifier() == m_vm->propertyNames->builtinNames().applyPublicName() || dot->identifier() == m_vm->propertyNames->builtinNames().applyPrivateName()))
    13541354        node = new (m_parserArena) ApplyFunctionCallDotNode(location, dot->base(), dot->identifier(), args, divot, divotStart, divotEnd, callOrApplyChildDepth);
    13551355    else
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r223124 r223175  
    46484648
    46494649    bool baseIsSuper = match(SUPER);
     4650    bool previousBaseWasSuper = false;
    46504651    bool baseIsImport = match(IMPORT);
    46514652    semanticFailIfTrue((baseIsSuper || baseIsImport) && newCount, "Cannot use new with ", getToken());
     
    47894790                        functionScope->setInnerArrowFunctionUsesSuperCall();
    47904791                }
    4791                 base = context.makeFunctionCallNode(startLocation, base, arguments, expressionStart,
     4792                base = context.makeFunctionCallNode(startLocation, base, previousBaseWasSuper, arguments, expressionStart,
    47924793                    expressionEnd, lastTokenEndPosition(), callOrApplyDepthScope ? callOrApplyDepthScope->distanceToInnermostChild() : 0);
    47934794            }
     
    48194820            goto endMemberExpression;
    48204821        }
     4822        previousBaseWasSuper = baseIsSuper;
    48214823        baseIsSuper = false;
    48224824    }
  • trunk/Source/JavaScriptCore/parser/SyntaxChecker.h

    r221358 r223175  
    144144
    145145    int createSourceElements() { return SourceElementsResult; }
    146     ExpressionType makeFunctionCallNode(const JSTokenLocation&, int, int, int, int, int, size_t) { return CallExpr; }
     146    ExpressionType makeFunctionCallNode(const JSTokenLocation&, int, bool, int, int, int, int, size_t) { return CallExpr; }
    147147    ExpressionType createCommaExpr(const JSTokenLocation&, ExpressionType expr) { return expr; }
    148148    ExpressionType appendToCommaExpr(const JSTokenLocation&, ExpressionType& head, ExpressionType, ExpressionType next) { head = next; return next; }
Note: See TracChangeset for help on using the changeset viewer.