LibJS: Rest parameter in setter functions is a syntax error

This commit is contained in:
Linus Groh 2020-10-20 18:43:58 +01:00 committed by Andreas Kling
parent 6331d45a6f
commit 1e86379327
Notes: sideshowbarker 2024-07-19 01:49:38 +09:00
3 changed files with 7 additions and 1 deletions

View file

@ -1278,7 +1278,7 @@ Vector<FunctionNode::Parameter> Parser::parse_function_parameters(int& function_
while (match(TokenType::Identifier) || match(TokenType::TripleDot)) {
if (parse_options & FunctionNodeParseOptions::IsGetterFunction)
syntax_error("Getter function must have no arguments");
if (parse_options & FunctionNodeParseOptions::IsSetterFunction && parameters.size() >= 1)
if (parse_options & FunctionNodeParseOptions::IsSetterFunction && (parameters.size() >= 1 || match(TokenType::TripleDot)))
syntax_error("Setter function must have one argument");
if (match(TokenType::TripleDot)) {
consume();

View file

@ -70,6 +70,11 @@ describe("syntax errors", () => {
class A {
set foo(bar, baz) {
}
}`).not.toEval();
expect(`
class A {
set foo(...bar) {
}
}`).not.toEval();
});

View file

@ -151,6 +151,7 @@ describe("errors", () => {
expect("({ get ...[foo] })").not.toEval();
expect("({ get foo(bar) {} })").not.toEval();
expect("({ set foo() {} })").not.toEval();
expect("({ set foo(...bar) {} })").not.toEval();
expect("({ set foo(bar, baz) {} })").not.toEval();
expect("({ ...foo: bar })").not.toEval();
});