Changeset 291577 in webkit


Ignore:
Timestamp:
Mar 21, 2022 12:57:19 PM (4 months ago)
Author:
ysuzuki@apple.com
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):

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r290981 r291577  
     12022-03-21  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] ReferenceError when using extra parens in class fields
     4        https://bugs.webkit.org/show_bug.cgi?id=236843
     5
     6        Reviewed by Saam Barati.
     7
     8        * stress/class-field-initializer-should-have-variable-scope.js: Added.
     9        (shouldBe):
     10        (test1.const.a.x.B):
     11        (test1):
     12        (test2.const.a.x.B):
     13        (test2):
     14        (test3.B.prototype.b):
     15        (test3.B):
     16        (test3):
     17
    1182022-03-08  Mark Lam  <mark.lam@apple.com>
    219
  • trunk/Source/JavaScriptCore/ChangeLog

    r291559 r291577  
     12022-03-21  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] ReferenceError when using extra parens in class fields
     4        https://bugs.webkit.org/show_bug.cgi?id=236843
     5
     6        Reviewed by Saam Barati.
     7
     8        class field initializer should create its own used-variables set
     9        to capture used variables separately from the other variables since
     10        it becomes independent CodeBlock internally later. The current code
     11        was wrong since,
     12
     13            1. Incorrectly using the current set of class-scope.
     14            2. Incorrectly marking only the last set while parseAssignmentExpression can create a new set inside it.
     15
     16        * parser/Parser.cpp:
     17        (JSC::Parser<LexerType>::parseClass):
     18        * parser/Parser.h:
     19        (JSC::Scope::markLastUsedVariablesSetAsCaptured):
     20
    1212022-03-21  Jonathan Bedard  <jbedard@apple.com>
    222
  • 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");
  • trunk/Source/JavaScriptCore/parser/Parser.h

    r288473 r291577  
    664664    }
    665665
    666     void markLastUsedVariablesSetAsCaptured()
    667     {
    668         for (UniquedStringImpl* impl : m_usedVariables.last())
    669             m_closedVariableCandidates.add(impl);
     666    void markLastUsedVariablesSetAsCaptured(unsigned from)
     667    {
     668        for (unsigned index = from; index < m_usedVariables.size(); ++index) {
     669            for (UniquedStringImpl* impl : m_usedVariables[index])
     670                m_closedVariableCandidates.add(impl);
     671        }
    670672    }
    671673   
Note: See TracChangeset for help on using the changeset viewer.