<html>
<head>
<base href="https://bugs.webkit.org/" />
</head>
<body><span class="vcard"><a class="email" href="mailto:ticaiolima@gmail.com" title="Caio Lima <ticaiolima@gmail.com>"> <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>
</td>
<td>ticaiolima@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@gmail.com" title="Caio Lima <ticaiolima@gmail.com>"> <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 = () => super.foo) {
return y();
}
}
if ((new D).x() === 45) {
print("passed");
} else {
print("failed");
}
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 ||= () => 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->isReparsingFunction()) {
SuperBinding functionSuperBinding = !functionScope->isArrowFunction() && !closestOrdinaryFunctionScope->isEvalContext()
? functionScope->expectedSuperBinding()
: closestOrdinaryFunctionScope->expectedSuperBinding();
semanticFailIfTrue(functionSuperBinding == SuperBinding::NotNeeded, "super is not valid in this context");
}
In the first test case, the "closestOrdinaryFunctionScope->expectedSuperBinding()" returned "SuperBinding::NotNeeded" and in the second case the return was "SuperBinding::Needed". I thought it was strange, since the "closestOrdinaryFunctionScope" in both cases should be in the same configuration. I debugged the parsing phase and noticed that "closestOrdinaryFunctionScope->m_expectedSuperBinding" was not being set before "parseFunctionParameters" in "Parser<LexerType>::parseFunctionInfo" (Parser.cpp).
In my patch proposal, I am setting "functionScope->setExpectedSuperBinding(expectedSuperBinding)" before call "parseFunctionParameters" in Parser.cpp:2019 as a proof of concept, however, I think it should be placed in the first 13 lines of the "Parser<LexerType>::parseFunctionInfo" function, since there are others "parseFunctionParameters" 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>