OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --allow-natives-syntax |
| 6 |
| 7 assertEquals(0, %ToLength(NaN)); |
| 8 assertEquals(0, %_ToLength(NaN)); |
| 9 |
| 10 assertEquals(0, %ToLength(-Infinity)); |
| 11 assertEquals(0, %_ToLength(-Infinity)); |
| 12 |
| 13 assertEquals(0, %ToLength(0)); |
| 14 assertEquals(0, %_ToLength(0)); |
| 15 |
| 16 assertEquals(0, %ToLength(.5)); |
| 17 assertEquals(0, %_ToLength(.5)); |
| 18 |
| 19 assertEquals(42, %ToLength(42.99999)); |
| 20 assertEquals(42, %_ToLength(42.99999)); |
| 21 |
| 22 assertEquals(9007199254740991, %ToLength(9007199254740991)); |
| 23 assertEquals(9007199254740991, %_ToLength(9007199254740991)); |
| 24 |
| 25 assertEquals(9007199254740991, %ToLength(Infinity)); |
| 26 assertEquals(9007199254740991, %_ToLength(Infinity)); |
| 27 |
| 28 assertEquals(0, %ToLength(null)); |
| 29 assertEquals(0, %_ToLength(null)); |
| 30 |
| 31 assertEquals(1, %ToLength(true)); |
| 32 assertEquals(1, %_ToLength(true)); |
| 33 |
| 34 assertEquals(0, %ToLength(false)); |
| 35 assertEquals(0, %_ToLength(false)); |
| 36 |
| 37 assertEquals(0, %ToLength(undefined)); |
| 38 assertEquals(0, %_ToLength(undefined)); |
| 39 |
| 40 assertEquals(0, %ToLength("-1")); |
| 41 assertEquals(0, %_ToLength("-1")); |
| 42 assertEquals(123, %ToLength("123")); |
| 43 assertEquals(123, %_ToLength("123")); |
| 44 assertEquals(0, %ToLength("random text")); |
| 45 assertEquals(0, %_ToLength("random text")); |
| 46 |
| 47 assertThrows(function() { %ToLength(Symbol.toPrimitive) }, TypeError); |
| 48 assertThrows(function() { %_ToLength(Symbol.toPrimitive) }, TypeError); |
| 49 |
| 50 var a = { toString: function() { return 54321 }}; |
| 51 assertEquals(54321, %ToLength(a)); |
| 52 assertEquals(54321, %_ToLength(a)); |
| 53 |
| 54 var b = { valueOf: function() { return 42 }}; |
| 55 assertEquals(42, %ToLength(b)); |
| 56 assertEquals(42, %_ToLength(b)); |
| 57 |
| 58 var c = { |
| 59 toString: function() { return "x"}, |
| 60 valueOf: function() { return 123 } |
| 61 }; |
| 62 assertEquals(123, %ToLength(c)); |
| 63 assertEquals(123, %_ToLength(c)); |
| 64 |
| 65 var d = { |
| 66 [Symbol.toPrimitive]: function(hint) { |
| 67 assertEquals("number", hint); |
| 68 return 987654321; |
| 69 } |
| 70 }; |
| 71 assertEquals(987654321, %ToLength(d)); |
| 72 assertEquals(987654321, %_ToLength(d)); |
| 73 |
| 74 var e = new Date(0); |
| 75 assertEquals(0, %ToLength(e)); |
| 76 assertEquals(0, %_ToLength(e)); |
OLD | NEW |