v8/test/mjsunit/number-isnan-opt.js
bmeurer de52562d8e [turbofan] Introduce dedicated ObjectIsNaN operator.
We can compile a !== a and Number.isNaN(a) to ObjectIsNaN. The former is
commonly used to check for NaN, i.e. in case of equals in AngularJS.

R=jarin@chromium.org
BUG=v8:5267

Review-Url: https://codereview.chromium.org/2722483003
Cr-Commit-Position: refs/heads/master@{#43572}
2017-03-03 09:08:14 +00:00

56 lines
1.2 KiB
JavaScript

// 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); }
assertTrue(foo(+undefined));
assertFalse(foo(undefined));
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo(+undefined));
assertFalse(foo(undefined));
})();
(function() {
function foo(x) { return Number.isNaN(+x); }
assertTrue(foo(+undefined));
assertFalse(foo(0));
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo(+undefined));
assertFalse(foo(0));
})();
(function() {
function foo(x) { return Number.isNaN(x|0); }
assertFalse(foo(+undefined));
assertFalse(foo(0));
%OptimizeFunctionOnNextCall(foo);
assertFalse(foo(+undefined));
assertFalse(foo(0));
})();
(function() {
function foo(x) { return Number.isNaN("" + x); }
assertFalse(foo(undefined));
assertFalse(foo(0));
%OptimizeFunctionOnNextCall(foo);
assertFalse(foo(undefined));
assertFalse(foo(0));
})();
(function() {
function foo(x) { return Number.isNaN(0/0); }
assertTrue(foo());
assertTrue(foo());
%OptimizeFunctionOnNextCall(foo);
assertTrue(foo());
assertTrue(foo());
})();