Issue #2142 - Pass through arguments in synthesized constructors for derived classes

Based-on: m-c 1552022
This commit is contained in:
Martok 2023-04-09 21:16:52 +02:00 committed by roytam1
commit 1031b1fc43
2 changed files with 27 additions and 2 deletions

View file

@ -7845,9 +7845,22 @@ Parser<ParseHandler>::synthesizeConstructor(HandleAtom className, uint32_t class
if (!argsbody)
return null();
handler.setFunctionFormalParametersAndBody(funNode, argsbody);
funbox->function()->setArgCount(0);
funbox->setStart(tokenStream);
if (hasHeritage) {
// Synthesize the equivalent to `function f(...args)`
funbox->setHasRest();
if (!notePositionalFormalParameter(funNode, context->names().args,
synthesizedBodyPos.begin,
/* disallowDuplicateParams = */ false,
/* duplicatedParam = */ nullptr)) {
return null();
}
funbox->function()->setArgCount(1);
} else {
funbox->function()->setArgCount(0);
}
pc->functionScope().useAsVarScope(pc);
auto stmtList = handler.newStatementList(synthesizedBodyPos);
@ -7881,7 +7894,18 @@ Parser<ParseHandler>::synthesizeConstructor(HandleAtom className, uint32_t class
if (!arguments)
return null();
BinaryNodeType superCall = handler.newSuperCall(superBase, arguments, false);
NameNodeType argsNameNode = newName(context->names().args, synthesizedBodyPos);
if (!argsNameNode)
return null();
if (!noteUsedName(context->names().args))
return null();
UnaryNodeType spreadArgs = handler.newSpread(synthesizedBodyPos.begin, argsNameNode);
if (!spreadArgs)
return null();
handler.addList(arguments, spreadArgs);
BinaryNodeType superCall = handler.newSuperCall(superBase, arguments, /* isSpread = */ true);
if (!superCall)
return null();

View file

@ -16,6 +16,7 @@
macro(anonymous, anonymous, "anonymous") \
macro(Any, Any, "Any") \
macro(apply, apply, "apply") \
macro(args, args, "args") \
macro(arguments, arguments, "arguments") \
macro(ArrayBufferSpecies, ArrayBufferSpecies, "ArrayBufferSpecies") \
macro(ArrayIterator, ArrayIterator, "Array Iterator") \