diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /js/src/tests/non262/argumentsLengthOpt.js | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-adbda400be353e676059e335c3c0aaf99e719475.tar.xz firefox-adbda400be353e676059e335c3c0aaf99e719475.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/argumentsLengthOpt.js')
-rw-r--r-- | js/src/tests/non262/argumentsLengthOpt.js | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/js/src/tests/non262/argumentsLengthOpt.js b/js/src/tests/non262/argumentsLengthOpt.js new file mode 100644 index 0000000000..16385fa5a4 --- /dev/null +++ b/js/src/tests/non262/argumentsLengthOpt.js @@ -0,0 +1,87 @@ +// Test cases for arguments.length optimization. + +function f1() { + return arguments.length; +} + +function f2(a, b, c) { + return arguments.length; +} + +// arrow functions don't have their own arguments, and so capture the enclosing +// scope. +function f3(a, b, c, d) { + return (() => arguments.length)(); +} + +// Test a function which mutates arguments.length +function f4(a, b, c, d) { + arguments.length = 42; + return arguments.length; +} + +// Manually read out arguments; should disable the length opt +function f5() { + for (var i = 0; i < arguments.length; i++) { + if (arguments[i] == 10) { return true } + } + return false; +} + +function f6() { + function inner() { + return arguments.length; + } + return inner(1, 2, 3); +} + +// edge cases of the arguments bindings: +function f7() { + var arguments = 42; + return arguments; +} + +function f8() { + var arguments = [1, 2]; + return arguments.length; +} + +function f9() { + eval("arguments.length = 42"); + return arguments.length; +} + +function test() { + assertEq(f1(), 0); + assertEq(f1(1), 1); + assertEq(f1(1, 2), 2); + assertEq(f1(1, 2, 3), 3); + + assertEq(f2(), 0); + assertEq(f2(1, 2, 3), 3); + + assertEq(f3(), 0); + assertEq(f3(1, 2, 3), 3); + + assertEq(f4(), 42); + assertEq(f4(1, 2, 3), 42); + + assertEq(f5(), false); + assertEq(f5(1, 2, 3, 10), true); + assertEq(f5(1, 2, 3, 10, 20), true); + assertEq(f5(1, 2, 3, 9, 20, 30), false); + + assertEq(f6(), 3) + assertEq(f6(1, 2, 3, 4), 3) + + assertEq(f7(), 42); + + assertEq(f8(), 2); + + assertEq(f9(), 42); +} + +test(); + +if (typeof reportCompare === "function") + reportCompare(0, 0, "ok"); |