summaryrefslogtreecommitdiff
path: root/js/src
diff options
context:
space:
mode:
authorMartok <martok@martoks-place.de>2023-04-09 21:16:52 +0200
committerMartok <martok@martoks-place.de>2023-05-01 17:16:19 +0200
commitc1681ef6147eb7d2f01fc4456ab7fc61678cdf64 (patch)
tree32201ba9b95faa6a5c91f74f946add1158549362 /js/src
parent7521dd33e760b2fbe93f3d6c07c3384d652dbac7 (diff)
downloaduxp-c1681ef6147eb7d2f01fc4456ab7fc61678cdf64.tar.gz
Issue #2142 - Pass through arguments in synthesized constructors for derived classes
Based-on: m-c 1552022
Diffstat (limited to 'js/src')
-rw-r--r--js/src/frontend/Parser.cpp28
-rw-r--r--js/src/vm/CommonPropertyNames.h1
2 files changed, 27 insertions, 2 deletions
diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp
index e5daabc8d5..213af5d72b 100644
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -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();
diff --git a/js/src/vm/CommonPropertyNames.h b/js/src/vm/CommonPropertyNames.h
index f69dfe3ca9..f7f324da5e 100644
--- a/js/src/vm/CommonPropertyNames.h
+++ b/js/src/vm/CommonPropertyNames.h
@@ -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") \