aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/compiler/abstract-equal-receiver.js
blob: 1026b6834237b95a8aab2373bbd54056f22009ed (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --allow-natives-syntax --opt --noalways-opt

// Known receivers abstract equality.
(function() {
  const a = {};
  const b = {};

  function foo() { return a == b; }

  assertFalse(foo());
  assertFalse(foo());
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo());
})();

// Known receiver/null abstract equality.
(function() {
  const a = {};
  const b = null;

  function foo() { return a == b; }

  assertFalse(foo());
  assertFalse(foo());
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo());
})();

// Known null/receiver abstract equality.
(function() {
  const a = null;
  const b = {};

  function foo() { return a == b; }

  assertFalse(foo());
  assertFalse(foo());
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo());
})();

// Known receiver/undefined abstract equality.
(function() {
  const a = {};
  const b = undefined;

  function foo() { return a == b; }

  assertFalse(foo());
  assertFalse(foo());
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo());
})();

// Known undefined/receiver abstract equality.
(function() {
  const a = undefined;
  const b = {};

  function foo() { return a == b; }

  assertFalse(foo());
  assertFalse(foo());
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo());
})();

// Known receiver on one side strict equality.
(function() {
  const a = {};
  const b = {};

  function foo(a) { return a == b; }

  assertTrue(foo(b));
  assertFalse(foo(a));
  assertTrue(foo(b));
  assertFalse(foo(a));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(b));
  assertFalse(foo(a));

  // TurboFan bakes in feedback for the (unknown) left hand side.
  assertFalse(foo(null));
  assertUnoptimized(foo);
})();

// Known receiver on one side strict equality with null.
(function() {
  const a = null;
  const b = {};

  function foo(a) { return a == b; }

  assertTrue(foo(b));
  assertFalse(foo(a));
  assertTrue(foo(b));
  assertFalse(foo(a));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(b));
  assertFalse(foo(a));

  // TurboFan bakes in feedback for the (unknown) left hand side.
  assertFalse(foo(1));
  assertUnoptimized(foo);
})();

// Known receiver on one side strict equality with undefined.
(function() {
  const a = undefined;
  const b = {};

  function foo(a) { return a == b; }

  assertTrue(foo(b));
  assertFalse(foo(a));
  assertTrue(foo(b));
  assertFalse(foo(a));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(b));
  assertFalse(foo(a));

  // TurboFan bakes in feedback for the (unknown) left hand side.
  assertFalse(foo(1));
  assertUnoptimized(foo);
})();

// Known null on one side strict equality with receiver.
(function() {
  const a = {};
  const b = null;

  function foo(a) { return a == b; }

  assertTrue(foo(b));
  assertFalse(foo(a));
  assertTrue(foo(b));
  assertFalse(foo(a));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(b));
  assertFalse(foo(a));
  assertTrue(foo(null));
  assertTrue(foo(undefined));
  assertOptimized(foo);

  // TurboFan doesn't need to bake in feedback, since it sees the null.
  assertFalse(foo(1));
  assertOptimized(foo);
})();

// Known undefined on one side strict equality with receiver.
(function() {
  const a = {};
  const b = undefined;

  function foo(a) { return a == b; }

  assertTrue(foo(b));
  assertFalse(foo(a));
  assertTrue(foo(b));
  assertFalse(foo(a));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(b));
  assertFalse(foo(a));
  assertTrue(foo(null));
  assertTrue(foo(undefined));
  assertOptimized(foo);

  // TurboFan needs to bake in feedback, since undefined cannot
  // be context specialized.
  assertFalse(foo(1));
  assertUnoptimized(foo);
})();