summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/cacheir/object-constructor.js
blob: 144e732a090ac9efdad7bcf5a7c4513ee5a4946d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Test various inlinable Object constructor calls.

function callNoArgs() {
  for (let i = 0; i < 100; ++i) {
    let obj = Object();

    // Creates a new empty object.
    assertEq(Reflect.getPrototypeOf(obj), Object.prototype);
    assertEq(Reflect.ownKeys(obj).length, 0);
  }
}
for (let i = 0; i < 2; ++i) callNoArgs();

function constructNoArgs() {
  for (let i = 0; i < 100; ++i) {
    let obj = new Object();

    // Creates a new empty object.
    assertEq(Reflect.getPrototypeOf(obj), Object.prototype);
    assertEq(Reflect.ownKeys(obj).length, 0);
  }
}
for (let i = 0; i < 2; ++i) constructNoArgs();

function funCallNoArgs() {
  // NB: Function.prototype.call is only inlined when the thisValue argument is present.
  const thisValue = null;

  for (let i = 0; i < 100; ++i) {
    let obj = Object.call(thisValue);

    // Creates a new empty object.
    assertEq(Reflect.getPrototypeOf(obj), Object.prototype);
    assertEq(Reflect.ownKeys(obj).length, 0);
  }
}
for (let i = 0; i < 2; ++i) funCallNoArgs();

function callObjectArg() {
  let xs = [{}, {}];
  for (let i = 0; i < 100; ++i) {
    let x = xs[i & 1];
    let obj = Object(x);

    // Returns the input object.
    assertEq(obj, x);
  }
}
for (let i = 0; i < 2; ++i) callObjectArg();

function constructObjectArg() {
  let xs = [{}, {}];
  for (let i = 0; i < 100; ++i) {
    let x = xs[i & 1];
    let obj = new Object(x);

    // Returns the input object.
    assertEq(obj, x);
  }
}
for (let i = 0; i < 2; ++i) constructObjectArg();

function funCallObjectArg() {
  // NB: Function.prototype.call is only inlined when the thisValue argument is present.
  const thisValue = null;

  let xs = [{}, {}];
  for (let i = 0; i < 100; ++i) {
    let x = xs[i & 1];
    let obj = Object.call(thisValue, x);

    // Returns the input object.
    assertEq(obj, x);
  }
}
for (let i = 0; i < 2; ++i) funCallObjectArg();