strict-equal-receiver.js 3.5 KB
Newer Older
1 2 3 4
// 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.

5
// Flags: --allow-natives-syntax --turbofan --noalways-turbofan
6 7 8 9 10 11 12 13

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

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

14
  %PrepareFunctionForOptimization(foo);
15 16 17 18 19 20 21 22 23 24 25 26 27
  assertFalse(foo());
  assertFalse(foo());
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo());
})();

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

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

28
  %PrepareFunctionForOptimization(foo);
29 30 31 32 33 34 35 36 37 38 39 40 41
  assertFalse(foo());
  assertFalse(foo());
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo());
})();

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

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

42
  %PrepareFunctionForOptimization(foo);
43 44 45 46 47 48 49 50 51 52 53 54 55
  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; }

56
  %PrepareFunctionForOptimization(foo);
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
  assertTrue(foo(b));
  assertFalse(foo(a));
  assertTrue(foo(b));
  assertFalse(foo(a));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(b));
  assertFalse(foo(a));
})();

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

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

73
  %PrepareFunctionForOptimization(foo);
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
  assertTrue(foo(b));
  assertFalse(foo(a));
  assertTrue(foo(b));
  assertFalse(foo(a));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(b));
  assertFalse(foo(a));
})();

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

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

90
  %PrepareFunctionForOptimization(foo);
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
  assertTrue(foo(b));
  assertFalse(foo(a));
  assertTrue(foo(b));
  assertFalse(foo(a));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(b));
  assertFalse(foo(a));
})();

// Feedback based receiver strict equality.
(function() {
  const a = {};
  const b = {};

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

107
  %PrepareFunctionForOptimization(foo);
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
  assertTrue(foo(b, b));
  assertFalse(foo(a, b));
  assertTrue(foo(a, a));
  assertFalse(foo(b, a));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(a, a));
  assertFalse(foo(b, a));

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

// Feedback based receiver/null strict equality.
(function() {
  const a = {};
  const b = null;

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

128
  %PrepareFunctionForOptimization(foo);
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
  assertTrue(foo(b, b));
  assertFalse(foo(a, b));
  assertTrue(foo(a, a));
  assertFalse(foo(b, a));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(a, a));
  assertFalse(foo(b, a));

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

// Feedback based receiver/undefined strict equality.
(function() {
  const a = {};
  const b = undefined;

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

149
  %PrepareFunctionForOptimization(foo);
150 151 152 153 154 155 156 157 158 159 160 161
  assertTrue(foo(b, b));
  assertFalse(foo(a, b));
  assertTrue(foo(a, a));
  assertFalse(foo(b, a));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(a, a));
  assertFalse(foo(b, a));

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