From: Fabrice Bellard Date: Sat, 28 Nov 2026 10:27:14 +0000 (+0100) Subject: Fix destructuring rest param function length count (taxor03) X-Git-Url: https://git.kaiwu.me/http/%22../$%7BGITURL%7D/static/%7B@url%7D?a=commitdiff_plain;h=802848b558554f74b026a02dff169a5b2a881a1a;p=quickjs.git Fix destructuring rest param function length count (taxor03) --- diff --git a/quickjs.c b/quickjs.c index 06d9ecc..2dfbd1f 100644 --- 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++; diff --git a/tests/test_language.js b/tests/test_language.js index ba479ba..44509e5 100644 --- a/tests/test_language.js +++ b/tests/test_language.js @@ -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()