object-is.js 5.32 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright 2017 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

(function() {
  function foo(o) { return Object.is(o, -0); }
9
  %PrepareFunctionForOptimization(foo);
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
  assertTrue(foo(-0));
  assertFalse(foo(0));
  assertFalse(foo(NaN));
  assertFalse(foo(''));
  assertFalse(foo([]));
  assertFalse(foo({}));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(-0));
  assertFalse(foo(0));
  assertFalse(foo(NaN));
  assertFalse(foo(''));
  assertFalse(foo([]));
  assertFalse(foo({}));
})();

(function() {
  function foo(o) { return Object.is(-0, o); }
27
  %PrepareFunctionForOptimization(foo);
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
  assertTrue(foo(-0));
  assertFalse(foo(0));
  assertFalse(foo(NaN));
  assertFalse(foo(''));
  assertFalse(foo([]));
  assertFalse(foo({}));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(-0));
  assertFalse(foo(0));
  assertFalse(foo(NaN));
  assertFalse(foo(''));
  assertFalse(foo([]));
  assertFalse(foo({}));
})();

(function() {
  function foo(o) { return Object.is(+o, -0); }
45
  %PrepareFunctionForOptimization(foo);
46 47 48 49 50 51 52 53 54 55 56
  assertTrue(foo(-0));
  assertFalse(foo(0));
  assertFalse(foo(NaN));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(-0));
  assertFalse(foo(0));
  assertFalse(foo(NaN));
})();

(function() {
  function foo(o) { return Object.is(-0, +o); }
57
  %PrepareFunctionForOptimization(foo);
58 59 60 61 62 63 64 65 66 67 68
  assertTrue(foo(-0));
  assertFalse(foo(0));
  assertFalse(foo(NaN));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(-0));
  assertFalse(foo(0));
  assertFalse(foo(NaN));
})();

(function() {
  function foo(o) { return Object.is(o, NaN); }
69
  %PrepareFunctionForOptimization(foo);
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
  assertFalse(foo(-0));
  assertFalse(foo(0));
  assertTrue(foo(NaN));
  assertFalse(foo(''));
  assertFalse(foo([]));
  assertFalse(foo({}));
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo(-0));
  assertFalse(foo(0));
  assertTrue(foo(NaN));
  assertFalse(foo(''));
  assertFalse(foo([]));
  assertFalse(foo({}));
})();

(function() {
  function foo(o) { return Object.is(NaN, o); }
87
  %PrepareFunctionForOptimization(foo);
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
  assertFalse(foo(-0));
  assertFalse(foo(0));
  assertTrue(foo(NaN));
  assertFalse(foo(''));
  assertFalse(foo([]));
  assertFalse(foo({}));
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo(-0));
  assertFalse(foo(0));
  assertTrue(foo(NaN));
  assertFalse(foo(''));
  assertFalse(foo([]));
  assertFalse(foo({}));
})();

(function() {
  function foo(o) { return Object.is(+o, NaN); }
105
  %PrepareFunctionForOptimization(foo);
106 107 108 109 110 111 112 113 114 115 116
  assertFalse(foo(-0));
  assertFalse(foo(0));
  assertTrue(foo(NaN));
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo(-0));
  assertFalse(foo(0));
  assertTrue(foo(NaN));
})();

(function() {
  function foo(o) { return Object.is(NaN, +o); }
117
  %PrepareFunctionForOptimization(foo);
118 119 120 121 122 123 124 125 126 127 128
  assertFalse(foo(-0));
  assertFalse(foo(0));
  assertTrue(foo(NaN));
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo(-0));
  assertFalse(foo(0));
  assertTrue(foo(NaN));
})();

(function() {
  function foo(o) { return Object.is(`${o}`, "foo"); }
129
  %PrepareFunctionForOptimization(foo);
130 131 132 133 134 135 136
  assertFalse(foo("bar"));
  assertTrue(foo("foo"));
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo("bar"));
  assertTrue(foo("foo"));
})();

137 138
(function() {
  function foo(o) { return Object.is(String(o), "foo"); }
139
  %PrepareFunctionForOptimization(foo);
140 141 142 143 144 145 146
  assertFalse(foo("bar"));
  assertTrue(foo("foo"));
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo("bar"));
  assertTrue(foo("foo"));
})();

147 148
(function() {
  function foo(o) { return Object.is(o, o); }
149
  %PrepareFunctionForOptimization(foo);
150 151 152 153 154 155 156 157 158 159 160 161 162 163
  assertTrue(foo(-0));
  assertTrue(foo(0));
  assertTrue(foo(NaN));
  assertTrue(foo(''));
  assertTrue(foo([]));
  assertTrue(foo({}));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(-0));
  assertTrue(foo(0));
  assertTrue(foo(NaN));
  assertTrue(foo(''));
  assertTrue(foo([]));
  assertTrue(foo({}));
})();
164 165 166

(function() {
  function foo(o) { return Object.is(o|0, 0); }
167
  %PrepareFunctionForOptimization(foo);
168 169 170 171 172 173 174 175 176 177 178 179 180 181
  assertTrue(foo(0));
  assertTrue(foo(-0));
  assertTrue(foo(NaN));
  assertFalse(foo(1));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(0));
  assertTrue(foo(-0));
  assertTrue(foo(NaN));
  assertFalse(foo(1));
})();

(function() {
  const s = Symbol();
  function foo() { return Object.is(s, Symbol()); }
182
  %PrepareFunctionForOptimization(foo);
183 184 185 186 187
  assertFalse(foo());
  assertFalse(foo());
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo());
})();
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217

(function() {
  function foo(a, b) { return Object.is(+a, +b); }
  %PrepareFunctionForOptimization(foo);
  assertFalse(foo(1, 2));
  assertFalse(foo(0, -0));
  assertFalse(foo(-0, 0));
  assertFalse(foo(-0, 1));
  assertFalse(foo(-0, 1));
  assertFalse(foo(-Infinity, Infinity));
  assertTrue(foo(0, 0));
  assertTrue(foo(0.1, 0.1));
  assertTrue(foo(Infinity, Infinity));
  assertTrue(foo(-0, -0));
  assertTrue(foo(NaN, NaN));
  assertFalse(foo(Infinity, NaN));
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo(1, 2));
  assertFalse(foo(0, -0));
  assertFalse(foo(-0, 0));
  assertFalse(foo(-0, 1));
  assertFalse(foo(-0, 1));
  assertFalse(foo(-Infinity, Infinity));
  assertTrue(foo(0, 0));
  assertTrue(foo(0.1, 0.1));
  assertTrue(foo(Infinity, Infinity));
  assertTrue(foo(-0, -0));
  assertTrue(foo(NaN, NaN));
  assertFalse(foo(Infinity, NaN));
})();