<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body><span class="vcard"><a class="email" href="mailto:ticaiolima&#64;gmail.com" title="Caio Lima &lt;ticaiolima&#64;gmail.com&gt;"> <span class="fn">Caio Lima</span></a>
</span> changed
              <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Our parser doesn't properly parse default parameter expressions in a class method"
   href="https://bugs.webkit.org/show_bug.cgi?id=157872">bug 157872</a>
        <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">CC</td>
           <td>
               &nbsp;
           </td>
           <td>ticaiolima&#64;gmail.com
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Our parser doesn't properly parse default parameter expressions in a class method"
   href="https://bugs.webkit.org/show_bug.cgi?id=157872#c2">Comment # 2</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Our parser doesn't properly parse default parameter expressions in a class method"
   href="https://bugs.webkit.org/show_bug.cgi?id=157872">bug 157872</a>
              from <span class="vcard"><a class="email" href="mailto:ticaiolima&#64;gmail.com" title="Caio Lima &lt;ticaiolima&#64;gmail.com&gt;"> <span class="fn">Caio Lima</span></a>
</span></b>
        <pre>Hello guys, It is a RFC.

I created a test case based on the Saam's sample:

class C {
  constructor() { this._x = 45; }
  get foo() { return this._x;}
}

class D extends C {

  x(y = () =&gt; super.foo) {
    return y();
  }
}

if ((new D).x() === 45) {
  print(&quot;passed&quot;);
} else {
  print(&quot;failed&quot;);
}

I tested it in V8 and SpiderMonkey and they parsed and executed correctly. So, I decided to investigate the problem.

I tested the following workaround to find the reason of failing

class D extends C {

  x(y) {
    y ||= () =&gt; super.foo;
    return y();
  }
}

And it worked. I noticed that the failing point was the following test present in Parser.cpp::parseMemberExpression():

if (!m_lexer-&gt;isReparsingFunction()) {
                SuperBinding functionSuperBinding = !functionScope-&gt;isArrowFunction() &amp;&amp; !closestOrdinaryFunctionScope-&gt;isEvalContext()
                    ? functionScope-&gt;expectedSuperBinding()
                    : closestOrdinaryFunctionScope-&gt;expectedSuperBinding();
                semanticFailIfTrue(functionSuperBinding == SuperBinding::NotNeeded, &quot;super is not valid in this context&quot;);
            }

In the first test case, the &quot;closestOrdinaryFunctionScope-&gt;expectedSuperBinding()&quot; returned &quot;SuperBinding::NotNeeded&quot; and in the second case the return was &quot;SuperBinding::Needed&quot;. I thought it was strange, since the &quot;closestOrdinaryFunctionScope&quot; in both cases should be in the same configuration. I debugged the parsing phase and noticed that &quot;closestOrdinaryFunctionScope-&gt;m_expectedSuperBinding&quot; was not being set before &quot;parseFunctionParameters&quot; in &quot;Parser&lt;LexerType&gt;::parseFunctionInfo&quot; (Parser.cpp).

In my patch proposal, I am setting &quot;functionScope-&gt;setExpectedSuperBinding(expectedSuperBinding)&quot; before call &quot;parseFunctionParameters&quot; in Parser.cpp:2019 as a proof of concept, however, I think it should be placed in the first 13 lines of the &quot;Parser&lt;LexerType&gt;::parseFunctionInfo&quot; function, since there are others &quot;parseFunctionParameters&quot; above the current modification. What do you think?

Also, I would like to know where I should can create a test case for this case.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>