v8/test/mjsunit/compiler/constant-fold-tostring.js
Benedikt Meurer 5bfed8cc94 [turbofan] Properly constant-fold JSToString with numbers.
So far we didn't properly constant-fold JSToString operators in
JSTypedLowering where the input was a known number constant.

Bug: v8:6815
Change-Id: Iac87346b7d38f0f75461f285ea7daa2d5a5e1524
Reviewed-on: https://chromium-review.googlesource.com/663358
Reviewed-by: Michael Stanton <mvstanton@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47972}
2017-09-12 13:13:57 +00:00

27 lines
845 B
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 --no-always-opt --opt
// Check that constant-folding of ToString operations works properly for NaN.
(function() {
const foo = () => `${NaN}`;
assertEquals("NaN", foo());
assertEquals("NaN", foo());
%OptimizeFunctionOnNextCall(foo);
assertEquals("NaN", foo());
})();
// Check that constant-folding of ToString operations works properly for 0/-0.
(function() {
const foo = x => `${x ? 0 : -0}`;
assertEquals("0", foo(true));
assertEquals("0", foo(false));
assertEquals("0", foo(true));
assertEquals("0", foo(false));
%OptimizeFunctionOnNextCall(foo);
assertEquals("0", foo(true));
assertEquals("0", foo(false));
})();