Ignore:
Timestamp:
Mar 21, 2022, 12:57:19 PM (3 years ago)
Author:
[email protected]
Message:

[JSC] ReferenceError when using extra parens in class fields
https://bugs.webkit.org/show_bug.cgi?id=236843

Reviewed by Saam Barati.

JSTests:

  • stress/class-field-initializer-should-have-variable-scope.js: Added.

(shouldBe):
(test1.const.a.x.B):
(test1):
(test2.const.a.x.B):
(test2):
(test3.B.prototype.b):
(test3.B):
(test3):

Source/JavaScriptCore:

class field initializer should create its own used-variables set
to capture used variables separately from the other variables since
it becomes independent CodeBlock internally later. The current code
was wrong since,

  1. Incorrectly using the current set of class-scope.
  2. Incorrectly marking only the last set while parseAssignmentExpression can create a new set inside it.
  • parser/Parser.cpp:

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

  • parser/Parser.h:

(JSC::Scope::markLastUsedVariablesSetAsCaptured):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r290575 r291577  
    31113111            TreeExpression initializer = 0;
    31123112            if (consume(EQUAL)) {
     3113                size_t usedVariablesSize = currentScope()->currentUsedVariablesSize();
     3114                currentScope()->pushUsedVariableSet();
    31133115                SetForScope overrideParsingClassFieldInitializer(m_parserState.isParsingClassFieldInitializer, true);
    31143116                classScope->setExpectedSuperBinding(SuperBinding::Needed);
     
    31163118                classScope->setExpectedSuperBinding(SuperBinding::NotNeeded);
    31173119                failIfFalse(initializer, "Cannot parse initializer for class field");
    3118                 classScope->markLastUsedVariablesSetAsCaptured();
     3120                classScope->markLastUsedVariablesSetAsCaptured(usedVariablesSize);
    31193121            }
    31203122            failIfFalse(autoSemiColon(), "Expected a ';' following a class field");
Note: See TracChangeset for help on using the changeset viewer.