Bug 1855672 - Enable some new clang-tidy checkers r=andi DONTBUILD
[gecko.git] / js / src / jit-test / tests / basic / object-assign-plain-cache.js
blob9936fffbdc8293ed9a67096364f7005e08cba0e8
1 // The cache lookup must happen after ensuring there are no dense elements.
2 function testNewDenseElement() {
3     var from = {x: 1, y: 2, z: 3};
5     for (var i = 0; i < 10; i++) {
6         if (i === 6) {
7             from[0] = 1;
8         }
9         var to = Object.assign({}, from);
10         if (i >= 6) {
11             assertEq(JSON.stringify(to), '{"0":1,"x":1,"y":2,"z":3}');
12         } else {
13             assertEq(JSON.stringify(to), '{"x":1,"y":2,"z":3}');
14         }
15     }
17 testNewDenseElement();
19 // The cache lookup must happen after ensuring there are non-writable
20 // properties on the proto chain.
21 function testProtoNonWritable() {
22     var proto = {x: 1};
23     var from = {x: 1, y: 2, z: 3};
25     for (var i = 0; i < 10; i++) {
26         if (i === 6) {
27             Object.freeze(proto);
28         }
30         var to = Object.create(proto);
31         var ex = null;
32         try {
33             Object.assign(to, from);
34         } catch (e) {
35             ex = e;
36         }
38         assertEq(ex instanceof TypeError, i > 5);
40         if (i <= 5) {
41             assertEq(JSON.stringify(to), '{"x":1,"y":2,"z":3}');
42         } else {
43             assertEq(JSON.stringify(to), '{}');
44         }
45     }
47 testProtoNonWritable();