Debian Codegraph @

js/src/jit-test/tests/cacheir/object-constructor.js

raw
1 // Test various inlinable Object constructor calls.
2
3 function callNoArgs() {
4 for (let i = 0; i < 100; ++i) {
5 let obj = Object();
6
7 // Creates a new empty object.
8 assertEq(Reflect.getPrototypeOf(obj), Object.prototype);
9 assertEq(Reflect.ownKeys(obj).length, 0);
10 }
11 }
12 for (let i = 0; i < 2; ++i) callNoArgs();
13
14 function constructNoArgs() {
15 for (let i = 0; i < 100; ++i) {
16 let obj = new Object();
17
18 // Creates a new empty object.
19 assertEq(Reflect.getPrototypeOf(obj), Object.prototype);
20 assertEq(Reflect.ownKeys(obj).length, 0);
21 }
22 }
23 for (let i = 0; i < 2; ++i) constructNoArgs();
24
25 function funCallNoArgs() {
26 // NB: Function.prototype.call is only inlined when the thisValue argument is present.
27 const thisValue = null;
28
29 for (let i = 0; i < 100; ++i) {
30 let obj = Object.call(thisValue);
31
32 // Creates a new empty object.
33 assertEq(Reflect.getPrototypeOf(obj), Object.prototype);
34 assertEq(Reflect.ownKeys(obj).length, 0);
35 }
36 }
37 for (let i = 0; i < 2; ++i) funCallNoArgs();
38
39 function callObjectArg() {
40 let xs = [{}, {}];
41 for (let i = 0; i < 100; ++i) {
42 let x = xs[i & 1];
43 let obj = Object(x);
44
45 // Returns the input object.
46 assertEq(obj, x);
47 }
48 }
49 for (let i = 0; i < 2; ++i) callObjectArg();
50
51 function constructObjectArg() {
52 let xs = [{}, {}];
53 for (let i = 0; i < 100; ++i) {
54 let x = xs[i & 1];
55 let obj = new Object(x);
56
57 // Returns the input object.
58 assertEq(obj, x);
59 }
60 }
61 for (let i = 0; i < 2; ++i) constructObjectArg();
62
63 function funCallObjectArg() {
64 // NB: Function.prototype.call is only inlined when the thisValue argument is present.
65 const thisValue = null;
66
67 let xs = [{}, {}];
68 for (let i = 0; i < 100; ++i) {
69 let x = xs[i & 1];
70 let obj = Object.call(thisValue, x);
71
72 // Returns the input object.
73 assertEq(obj, x);
74 }
75 }
76 for (let i = 0; i < 2; ++i) funCallObjectArg();