Ignore:
Timestamp:
Jan 7, 2021, 3:17:44 PM (4 years ago)
Author:
[email protected]
Message:

[JSC] New expression and value function call should reserve function register if arguments include assignments
https://bugs.webkit.org/show_bug.cgi?id=220429
<rdar://problem/70598359>

Reviewed by Alexey Shvayka.

JSTests:

  • stress/comma-value-func-call-resolve.js: Added.

(shouldBe):
(fn.x):
(fn):

  • stress/construct-overwritten-variable.js:

(shouldThrow):
(new.x.x): Deleted.

  • stress/construct-spread-overwritten-variable-2.js:

(shouldThrow):
(new.x.x): Deleted.

  • stress/construct-spread-overwritten-variable.js:

(shouldThrow):
(new.x.x): Deleted.

  • stress/destructuring-func-call-resolve.js: Added.

(shouldBe):
(fn.x):
(fn):
(fn2.x):
(fn2):

  • stress/resolve-func-call-resolve.js: Added.

(shouldBe):
(fn.x):
(fn):

  • stress/tagged-template-call-resolve.js: Added.

(shouldBe):
(fn.x):
(fn):

  • test262/expectations.yaml:

Source/JavaScriptCore:

If the following code is executed, we need to reserve |x| before evaluating arguments since arguments can override
local |x| variable before calling it.

new x(x = 1)

We found there are two places we are not doing this.

  1. new expression
  2. function value call (it is checking isLocation(), but we can still use local variables for function if we use comma expression)

We introduced hasAssignment flag to ArgumentsNode, and reserve a function in a new temporary register if arguments include assignments.
We also need to increment assignmentCount in destructuring assignment.

  • bytecompiler/NodesCodegen.cpp:

(JSC::NewExprNode::emitBytecode):
(JSC::FunctionCallValueNode::emitBytecode):

  • parser/ASTBuilder.h:

(JSC::ASTBuilder::createArguments):

  • parser/NodeConstructors.h:

(JSC::ArgumentsNode::ArgumentsNode):

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

(JSC::Parser<LexerType>::parseDestructuringPattern):
(JSC::Parser<LexerType>::parseArguments):

  • parser/SyntaxChecker.h:

(JSC::SyntaxChecker::createArguments):

File:
1 edited

Legend:

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

    r266264 r271265  
    478478
    479479    ArgumentsNode* createArguments() { return new (m_parserArena) ArgumentsNode(); }
    480     ArgumentsNode* createArguments(ArgumentListNode* args) { return new (m_parserArena) ArgumentsNode(args); }
     480    ArgumentsNode* createArguments(ArgumentListNode* args, bool hasAssignments) { return new (m_parserArena) ArgumentsNode(args, hasAssignments); }
    481481    ArgumentListNode* createArgumentsList(const JSTokenLocation& location, ExpressionNode* arg) { return new (m_parserArena) ArgumentListNode(location, arg); }
    482482    ArgumentListNode* createArgumentsList(const JSTokenLocation& location, ArgumentListNode* args, ExpressionNode* arg) { return new (m_parserArena) ArgumentListNode(location, args, arg); }
Note: See TracChangeset for help on using the changeset viewer.