summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/warp/mega-morphic-load-and-has-prop.js
blob: 0d77ceb3162893fe402eb04baba17c6bfb6e0f4c (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
function testMegamorphicLoadSlot(i) {
  var xs = [
    {p: 0},
    {a: 0, p: 1},
    {a: 0, b: 0, p: 2},
    {a: 0, b: 0, c: 0, p: 3},
    {a: 0, b: 0, c: 0, d: 0, p: 4},
    {a: 0, b: 0, c: 0, d: 0, e: 0, p: 5},
    {a: 0, b: 0, c: 0, d: 0, e: 0, f: 0, p: 6},
    {a: 0, b: 0, c: 0, d: 0, e: 0, f: 0, g: 0, p: 7},
    {a: 0, b: 0, c: 0, d: 0, e: 0, f: 0, g: 0, h: 0, p: 8},
    {a: 0, b: 0, c: 0, d: 0, e: 0, f: 0, g: 0, h: 0, i: 0, p: 9},
  ];
  var called = 0;
  var obj = {
    get p() {
      called++;
    }
  };

  for (var j = 0; j <= 100; ++j) {
    // Don't use if-statements to avoid cold code bailouts.
    var x = xs[j % 10];
    var y = [x, obj][(i === 1 && j === 100)|0];

    // Can't DCE this instruction.
    y.p;
  }

  assertEq(i === 0 || called === 1, true);
}
for (var i = 0; i < 2; ++i) testMegamorphicLoadSlot(i);

function testMegamorphicLoadSlotByValue(i) {
  var xs = [
    {p: 0},
    {a: 0, p: 1},
    {a: 0, b: 0, p: 2},
    {a: 0, b: 0, c: 0, p: 3},
    {a: 0, b: 0, c: 0, d: 0, p: 4},
    {a: 0, b: 0, c: 0, d: 0, e: 0, p: 5},
    {a: 0, b: 0, c: 0, d: 0, e: 0, f: 0, p: 6},
    {a: 0, b: 0, c: 0, d: 0, e: 0, f: 0, g: 0, p: 7},
    {a: 0, b: 0, c: 0, d: 0, e: 0, f: 0, g: 0, h: 0, p: 8},
    {a: 0, b: 0, c: 0, d: 0, e: 0, f: 0, g: 0, h: 0, i: 0, p: 9},
  ];
  var called = 0;
  var obj = {
    get p() {
      called++;
    }
  };

  var p = "p";
  for (var j = 0; j <= 100; ++j) {
    // Don't use if-statements to avoid cold code bailouts.
    var x = xs[j % 10];
    var y = [x, obj][(i === 1 && j === 100)|0];

    // Can't DCE this instruction.
    y[p];
  }

  assertEq(i === 0 || called === 1, true);
}
for (var i = 0; i < 2; ++i) testMegamorphicLoadSlotByValue(i);

function testMegamorphicHasProp(i) {
  var xs = [
    {p: 0},
    {a: 0, p: 1},
    {a: 0, b: 0, p: 2},
    {a: 0, b: 0, c: 0, p: 3},
    {a: 0, b: 0, c: 0, d: 0, p: 4},
    {a: 0, b: 0, c: 0, d: 0, e: 0, p: 5},
    {a: 0, b: 0, c: 0, d: 0, e: 0, f: 0, p: 6},
    {a: 0, b: 0, c: 0, d: 0, e: 0, f: 0, g: 0, p: 7},
    {a: 0, b: 0, c: 0, d: 0, e: 0, f: 0, g: 0, h: 0, p: 8},
    {a: 0, b: 0, c: 0, d: 0, e: 0, f: 0, g: 0, h: 0, i: 0, p: 9},
  ];
  var called = 0;
  var obj = new Proxy({}, {
    has() {
      called++;
    }
  });

  for (var j = 0; j <= 100; ++j) {
    // Don't use if-statements to avoid cold code bailouts.
    var x = xs[j % 10];
    var y = [x, obj][(i === 1 && j === 100)|0];

    // Can't DCE this instruction.
    "p" in y;
  }

  assertEq(i === 0 || called === 1, true);
}
for (var i = 0; i < 2; ++i) testMegamorphicHasProp(i);