diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /js/src/tests/non262/destructuring/rest-parameter-arguments.js | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/destructuring/rest-parameter-arguments.js')
-rw-r--r-- | js/src/tests/non262/destructuring/rest-parameter-arguments.js | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/js/src/tests/non262/destructuring/rest-parameter-arguments.js b/js/src/tests/non262/destructuring/rest-parameter-arguments.js new file mode 100644 index 0000000000..e87cdff339 --- /dev/null +++ b/js/src/tests/non262/destructuring/rest-parameter-arguments.js @@ -0,0 +1,101 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Ensure the |arguments| object works as expected when a destructuring rest +// parameter is present. + +// |arguments.length| with destructuring rest array. +function argsLengthEmptyRestArray(...[]) { + return arguments.length; +} +assertEq(argsLengthEmptyRestArray(), 0); +assertEq(argsLengthEmptyRestArray(10), 1); +assertEq(argsLengthEmptyRestArray(10, 20), 2); + +function argsLengthRestArray(...[a]) { + return arguments.length; +} +assertEq(argsLengthRestArray(), 0); +assertEq(argsLengthRestArray(10), 1); +assertEq(argsLengthRestArray(10, 20), 2); + +function argsLengthRestArrayWithDefault(...[a = 0]) { + return arguments.length; +} +assertEq(argsLengthRestArrayWithDefault(), 0); +assertEq(argsLengthRestArrayWithDefault(10), 1); +assertEq(argsLengthRestArrayWithDefault(10, 20), 2); + + +// |arguments.length| with destructuring rest object. +function argsLengthEmptyRestObject(...{}) { + return arguments.length; +} +assertEq(argsLengthEmptyRestObject(), 0); +assertEq(argsLengthEmptyRestObject(10), 1); +assertEq(argsLengthEmptyRestObject(10, 20), 2); + +function argsLengthRestObject(...{a}) { + return arguments.length; +} +assertEq(argsLengthRestObject(), 0); +assertEq(argsLengthRestObject(10), 1); +assertEq(argsLengthRestObject(10, 20), 2); + +function argsLengthRestObjectWithDefault(...{a = 0}) { + return arguments.length; +} +assertEq(argsLengthRestObjectWithDefault(), 0); +assertEq(argsLengthRestObjectWithDefault(10), 1); +assertEq(argsLengthRestObjectWithDefault(10, 20), 2); + + +// |arguments| access with destructuring rest array. +function argsAccessEmptyRestArray(...[]) { + return arguments[0]; +} +assertEq(argsAccessEmptyRestArray(), undefined); +assertEq(argsAccessEmptyRestArray(10), 10); +assertEq(argsAccessEmptyRestArray(10, 20), 10); + +function argsAccessRestArray(...[a]) { + return arguments[0]; +} +assertEq(argsAccessRestArray(), undefined); +assertEq(argsAccessRestArray(10), 10); +assertEq(argsAccessRestArray(10, 20), 10); + +function argsAccessRestArrayWithDefault(...[a = 0]) { + return arguments[0]; +} +assertEq(argsAccessRestArrayWithDefault(), undefined); +assertEq(argsAccessRestArrayWithDefault(10), 10); +assertEq(argsAccessRestArrayWithDefault(10, 20), 10); + + +// |arguments| access with destructuring rest object. +function argsAccessEmptyRestObject(...{}) { + return arguments[0]; +} +assertEq(argsAccessEmptyRestObject(), undefined); +assertEq(argsAccessEmptyRestObject(10), 10); +assertEq(argsAccessEmptyRestObject(10, 20), 10); + +function argsAccessRestObject(...{a}) { + return arguments[0]; +} +assertEq(argsAccessRestObject(), undefined); +assertEq(argsAccessRestObject(10), 10); +assertEq(argsAccessRestObject(10, 20), 10); + +function argsAccessRestObjectWithDefault(...{a = 0}) { + return arguments[0]; +} +assertEq(argsAccessRestObjectWithDefault(), undefined); +assertEq(argsAccessRestObjectWithDefault(10), 10); +assertEq(argsAccessRestObjectWithDefault(10, 20), 10); + + +if (typeof reportCompare === "function") + reportCompare(0, 0); |