summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/arguments/mapped-unmapped-args.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/jit-test/tests/arguments/mapped-unmapped-args.js')
-rw-r--r--js/src/jit-test/tests/arguments/mapped-unmapped-args.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/arguments/mapped-unmapped-args.js b/js/src/jit-test/tests/arguments/mapped-unmapped-args.js
new file mode 100644
index 000000000..d1b063be3
--- /dev/null
+++ b/js/src/jit-test/tests/arguments/mapped-unmapped-args.js
@@ -0,0 +1,61 @@
+// An unmapped arguments object is created for strict functions or functions
+// with default/rest/destructuring args.
+
+load(libdir + "asserts.js");
+
+function testDefaults(a, b=3) {
+ a = 3;
+ b = 4;
+ assertEq(arguments.length, 1);
+ assertEq(arguments[0], 1);
+ assertEq(arguments[1], undefined);
+ arguments[0] = 5;
+ assertEq(a, 3);
+ assertThrowsInstanceOf(() => arguments.callee, TypeError);
+}
+testDefaults(1);
+
+function testRest(a, ...rest) {
+ a = 3;
+ assertEq(arguments.length, 3);
+ assertEq(arguments[0], 1);
+ assertEq(arguments[1], 2);
+ arguments[0] = 5;
+ assertEq(a, 3);
+ arguments[1] = 6;
+ assertEq(arguments[1], 6);
+ assertEq(rest.toString(), "2,3");
+ assertThrowsInstanceOf(() => arguments.callee, TypeError);
+}
+testRest(1, 2, 3);
+
+function testDestructuring(a, {foo, bar}, b) {
+ a = 3;
+ bar = 4;
+ b = 1;
+ assertEq(arguments.length, 3);
+ assertEq(arguments[0], 1);
+ assertEq(arguments[1].bar, 2);
+ assertEq(arguments[2], 9);
+ assertThrowsInstanceOf(() => arguments.callee, TypeError);
+}
+testDestructuring(1, {foo: 1, bar: 2}, 9);
+
+function testStrict(a) {
+ "use strict";
+ a = 3;
+ assertEq(arguments[0], 1);
+ arguments[0] = 8;
+ assertEq(a, 3);
+ assertThrowsInstanceOf(() => arguments.callee, TypeError);
+}
+testStrict(1, 2);
+
+function testMapped(a) {
+ a = 3;
+ assertEq(arguments[0], 3);
+ arguments[0] = 5;
+ assertEq(a, 5);
+ assertEq(arguments.callee, testMapped);
+}
+testMapped(1);