v8/test/mjsunit/harmony/to-number.js
Benedikt Meurer 44c24bf827 [cleanup] Remove a lot of dead intrinsics/runtime functions.
The following runtime functions (and their intrinsic counter parts) are
completely unused/obsolete by now

  - %ToInteger
  - %GeneratorGetInputOrDebugPos

and in addition the intrinsics for %_ToNumber and %_IsJSProxy are also
dead (according to code coverage and manual verification), so drop them
as well (their runtime function counterparts are still somewhat used).

Bug: v8:8015
Change-Id: I60d53762dd9717fb43de38cb490b46676c467212
Reviewed-on: https://chromium-review.googlesource.com/1235923
Reviewed-by: Yang Guo <yangguo@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56076}
2018-09-20 12:48:57 +00:00

47 lines
1.1 KiB
JavaScript

// Copyright 2015 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
assertEquals(1, %ToNumber(1));
assertEquals(.5, %ToNumber(.5));
assertEquals(0, %ToNumber(null));
assertEquals(1, %ToNumber(true));
assertEquals(0, %ToNumber(false));
assertEquals(NaN, %ToNumber(undefined));
assertEquals(-1, %ToNumber("-1"));
assertEquals(123, %ToNumber("123"));
assertEquals(NaN, %ToNumber("random text"));
assertThrows(function() { %ToNumber(Symbol.toPrimitive) }, TypeError);
var a = { toString: function() { return 54321 }};
assertEquals(54321, %ToNumber(a));
var b = { valueOf: function() { return 42 }};
assertEquals(42, %ToNumber(b));
var c = {
toString: function() { return "x"},
valueOf: function() { return 123 }
};
assertEquals(123, %ToNumber(c));
var d = {
[Symbol.toPrimitive]: function(hint) {
assertEquals("number", hint);
return 987654321;
}
};
assertEquals(987654321, %ToNumber(d));
var e = new Date(0);
assertEquals(0, %ToNumber(e));