Browse Source

LibJS: Disallow multiple parameters in paren-less arrow function

Fixes #2323.
Linus Groh 5 years ago
parent
commit
27913154ea
2 changed files with 6 additions and 1 deletions
  1. 1 1
      Libraries/LibJS/Parser.cpp
  2. 5 0
      Libraries/LibJS/Tests/arrow-functions.js

+ 1 - 1
Libraries/LibJS/Parser.cpp

@@ -287,7 +287,7 @@ RefPtr<FunctionExpression> Parser::try_parse_arrow_function_expression(bool expe
     i32 function_length = -1;
     i32 function_length = -1;
     while (true) {
     while (true) {
         if (match(TokenType::Comma)) {
         if (match(TokenType::Comma)) {
-            if (has_rest_parameter) {
+            if (has_rest_parameter || !expect_parens) {
                 parse_failed = true;
                 parse_failed = true;
                 break;
                 break;
             }
             }

+ 5 - 0
Libraries/LibJS/Tests/arrow-functions.js

@@ -55,6 +55,11 @@ try {
     })(10);
     })(10);
     assert(half === 5);
     assert(half === 5);
 
 
+    var foo, bar;
+    foo = bar, baz => {};
+    assert(foo === undefined);
+    assert(bar === undefined);
+
     console.log("PASS");
     console.log("PASS");
 } catch {
 } catch {
     console.log("FAIL");
     console.log("FAIL");