1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:17:44 +00:00

LibJS: Function.length respects default and rest parameters

"[Function.length is] the number of formal parameters. This number
excludes the rest parameter and only includes parameters before
the first one with a default value." - MDN
This commit is contained in:
Matthew Olsson 2020-05-05 20:02:14 -07:00 committed by Andreas Kling
parent 2c14714ee0
commit 838390171c
6 changed files with 43 additions and 15 deletions

View file

@ -11,6 +11,16 @@ try {
assert((bar.length = 5) === 5);
assert(bar.length === 3);
function baz(a, b = 1, c) {}
assert(baz.length === 1);
assert((baz.length = 5) === 5);
assert(baz.length === 1);
function qux(a, b, ...c) {}
assert(qux.length === 2);
assert((qux.length = 5) === 5);
assert(qux.length === 2);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);