mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +00:00
LibJS: Rest parameter in setter functions is a syntax error
This commit is contained in:
parent
6331d45a6f
commit
1e86379327
Notes:
sideshowbarker
2024-07-19 01:49:38 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/1e863793270 Pull-request: https://github.com/SerenityOS/serenity/pull/3809
3 changed files with 7 additions and 1 deletions
|
@ -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();
|
||||
|
|
|
@ -70,6 +70,11 @@ describe("syntax errors", () => {
|
|||
class A {
|
||||
set foo(bar, baz) {
|
||||
}
|
||||
}`).not.toEval();
|
||||
expect(`
|
||||
class A {
|
||||
set foo(...bar) {
|
||||
}
|
||||
}`).not.toEval();
|
||||
});
|
||||
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue