]> git.kaiwu.me - quickjs.git/commitdiff
Fix destructuring rest param function length count (taxor03)
authorFabrice Bellard <fabrice@bellard.org>
Sat, 28 Nov 2026 10:27:14 +0000 (11:27 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Sat, 28 Nov 2026 10:27:14 +0000 (11:27 +0100)
quickjs.c
tests/test_language.js

index 06d9ecc498802e21b39635d28e49ec668dca34d1..2dfbd1f00fc0d8f987c92e48e625960a95048153 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -38136,7 +38136,7 @@ static __exception int js_parse_function_decl2(JSParseState *s,
                 has_initializer = js_parse_destructuring_element(s, fd->has_parameter_expressions ? TOK_LET : TOK_VAR, 1, TRUE, -1, TRUE, FALSE);
                 if (has_initializer < 0)
                     goto fail;
-                if (has_initializer)
+                if (has_initializer || rest)
                     has_opt_arg = TRUE;
                 if (!has_opt_arg)
                     fd->defined_arg_count++;
index ba479bac4b8a1f152d86c21c639aac721ccd1498..44509e59b51f8629f8b9130d0bb45f0e2540f4e1 100644 (file)
@@ -482,6 +482,11 @@ function test_function_length()
     assert( (([a,b]) => {}).length, 1);
     assert( (({a,b}) => {}).length, 1);
     assert( ((c, [a,b] = 1, d) => {}).length, 1);
+    assert( ((a, ...b) => {}).length, 1);
+    assert( ((a, ...[b]) => {}).length, 1);
+    assert( ((a, ...{b}) => {}).length, 1);
+    assert( ((...[a, b]) => {}).length, 0);
+    assert( (function (a, ...[b]) {}).length, 1);
 }
 
 function test_argument_scope()