diff options
author | Linus Groh <mail@linusgroh.de> | 2020-10-20 18:43:58 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-10-20 20:27:58 +0200 |
commit | 1e86379327053dabd88ff27560b8a3379bd9fd0d (patch) | |
tree | 99e71728efc463a1674b8dd31a72b942d1067929 | |
parent | 6331d45a6f0a111b483a5c4b84cc24926bc9205d (diff) | |
download | serenity-1e86379327053dabd88ff27560b8a3379bd9fd0d.zip |
LibJS: Rest parameter in setter functions is a syntax error
-rw-r--r-- | Libraries/LibJS/Parser.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibJS/Tests/classes/class-errors.js | 5 | ||||
-rw-r--r-- | Libraries/LibJS/Tests/object-basic.js | 1 |
3 files changed, 7 insertions, 1 deletions
diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp index 9a68bdfe42..3257c1f524 100644 --- a/Libraries/LibJS/Parser.cpp +++ b/Libraries/LibJS/Parser.cpp @@ -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(); diff --git a/Libraries/LibJS/Tests/classes/class-errors.js b/Libraries/LibJS/Tests/classes/class-errors.js index 93c50829d0..fb479a0af2 100644 --- a/Libraries/LibJS/Tests/classes/class-errors.js +++ b/Libraries/LibJS/Tests/classes/class-errors.js @@ -71,6 +71,11 @@ describe("syntax errors", () => { set foo(bar, baz) { } }`).not.toEval(); + expect(` + class A { + set foo(...bar) { + } + }`).not.toEval(); }); test("super reference inside different |this| scope", () => { diff --git a/Libraries/LibJS/Tests/object-basic.js b/Libraries/LibJS/Tests/object-basic.js index e00382fdc2..37f5c6e4dd 100644 --- a/Libraries/LibJS/Tests/object-basic.js +++ b/Libraries/LibJS/Tests/object-basic.js @@ -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(); }); |