Skip to content

Commit 1e86379

Browse files
linusgawesomekling
authored andcommitted
LibJS: Rest parameter in setter functions is a syntax error
1 parent 6331d45 commit 1e86379

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

Libraries/LibJS/Parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ Vector<FunctionNode::Parameter> Parser::parse_function_parameters(int& function_
12781278
while (match(TokenType::Identifier) || match(TokenType::TripleDot)) {
12791279
if (parse_options & FunctionNodeParseOptions::IsGetterFunction)
12801280
syntax_error("Getter function must have no arguments");
1281-
if (parse_options & FunctionNodeParseOptions::IsSetterFunction && parameters.size() >= 1)
1281+
if (parse_options & FunctionNodeParseOptions::IsSetterFunction && (parameters.size() >= 1 || match(TokenType::TripleDot)))
12821282
syntax_error("Setter function must have one argument");
12831283
if (match(TokenType::TripleDot)) {
12841284
consume();

Libraries/LibJS/Tests/classes/class-errors.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ describe("syntax errors", () => {
7070
class A {
7171
set foo(bar, baz) {
7272
}
73+
}`).not.toEval();
74+
expect(`
75+
class A {
76+
set foo(...bar) {
77+
}
7378
}`).not.toEval();
7479
});
7580

Libraries/LibJS/Tests/object-basic.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ describe("errors", () => {
151151
expect("({ get ...[foo] })").not.toEval();
152152
expect("({ get foo(bar) {} })").not.toEval();
153153
expect("({ set foo() {} })").not.toEval();
154+
expect("({ set foo(...bar) {} })").not.toEval();
154155
expect("({ set foo(bar, baz) {} })").not.toEval();
155156
expect("({ ...foo: bar })").not.toEval();
156157
});

0 commit comments

Comments
 (0)