number-isnan-opt.js 1.43 KB
Newer Older
1 2 3 4 5 6 7 8 9
// 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(x) { return Number.isNaN(x); }

10
  %PrepareFunctionForOptimization(foo);
11 12 13 14 15 16 17 18 19 20
  assertTrue(foo(+undefined));
  assertFalse(foo(undefined));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(+undefined));
  assertFalse(foo(undefined));
})();

(function() {
  function foo(x) { return Number.isNaN(+x); }

21
  %PrepareFunctionForOptimization(foo);
22 23 24 25 26 27 28 29 30 31
  assertTrue(foo(+undefined));
  assertFalse(foo(0));
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo(+undefined));
  assertFalse(foo(0));
})();

(function() {
  function foo(x) { return Number.isNaN(x|0); }

32
  %PrepareFunctionForOptimization(foo);
33 34 35 36 37 38 39 40 41 42
  assertFalse(foo(+undefined));
  assertFalse(foo(0));
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo(+undefined));
  assertFalse(foo(0));
})();

(function() {
  function foo(x) { return Number.isNaN("" + x); }

43
  %PrepareFunctionForOptimization(foo);
44 45 46 47 48 49 50 51 52 53
  assertFalse(foo(undefined));
  assertFalse(foo(0));
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo(undefined));
  assertFalse(foo(0));
})();

(function() {
  function foo(x) { return Number.isNaN(0/0); }

54
  %PrepareFunctionForOptimization(foo);
55 56 57 58 59 60
  assertTrue(foo());
  assertTrue(foo());
  %OptimizeFunctionOnNextCall(foo);
  assertTrue(foo());
  assertTrue(foo());
})();