joepeck@webkit.org | 094223d5 | 2017-09-21 03:23:17 +0000 | [diff] [blame] | 1 | // Copyright (C) 2017 Josh Wolfe. All rights reserved. |
| 2 | // This code is governed by the BSD license found in the LICENSE file. |
| 3 | /*--- |
joepeck@webkit.org | 094223d5 | 2017-09-21 03:23:17 +0000 | [diff] [blame] | 4 | description: BigInt.asIntN type coercion for bits parameter |
utatane.tea@gmail.com | 292d75e | 2018-02-02 21:48:40 +0000 | [diff] [blame] | 5 | esid: pending |
| 6 | info: | |
joepeck@webkit.org | 094223d5 | 2017-09-21 03:23:17 +0000 | [diff] [blame] | 7 | BigInt.asIntN ( bits, bigint ) |
| 8 | |
| 9 | 1. Let bits be ? ToIndex(bits). |
utatane.tea@gmail.com | 292d75e | 2018-02-02 21:48:40 +0000 | [diff] [blame] | 10 | features: [BigInt] |
joepeck@webkit.org | 094223d5 | 2017-09-21 03:23:17 +0000 | [diff] [blame] | 11 | ---*/ |
| 12 | |
utatane.tea@gmail.com | 292d75e | 2018-02-02 21:48:40 +0000 | [diff] [blame] | 13 | assert.sameValue(BigInt.asIntN(0, 1n), 0n); |
| 14 | assert.sameValue(BigInt.asIntN(1, 1n), -1n); |
| 15 | assert.sameValue(BigInt.asIntN(-0.9, 1n), 0n, "ToIndex: truncate towards 0"); |
| 16 | assert.sameValue(BigInt.asIntN(0.9, 1n), 0n, "ToIndex: truncate towards 0"); |
| 17 | assert.sameValue(BigInt.asIntN(NaN, 1n), 0n, "ToIndex: NaN => 0"); |
| 18 | assert.sameValue(BigInt.asIntN(undefined, 1n), 0n, "ToIndex: undefined => NaN => 0"); |
| 19 | assert.sameValue(BigInt.asIntN(null, 1n), 0n, "ToIndex: null => 0"); |
| 20 | assert.sameValue(BigInt.asIntN(false, 1n), 0n, "ToIndex: false => 0"); |
| 21 | assert.sameValue(BigInt.asIntN(true, 1n), -1n, "ToIndex: true => 1"); |
| 22 | assert.sameValue(BigInt.asIntN("0", 1n), 0n, "ToIndex: parse Number"); |
| 23 | assert.sameValue(BigInt.asIntN("1", 1n), -1n, "ToIndex: parse Number"); |
| 24 | assert.sameValue(BigInt.asIntN("", 1n), 0n, "ToIndex: parse Number => NaN => 0"); |
| 25 | assert.sameValue(BigInt.asIntN("foo", 1n), 0n, "ToIndex: parse Number => NaN => 0"); |
| 26 | assert.sameValue(BigInt.asIntN("true", 1n), 0n, "ToIndex: parse Number => NaN => 0"); |
| 27 | assert.sameValue(BigInt.asIntN(3, 10n), 2n); |
| 28 | assert.sameValue(BigInt.asIntN("3", 10n), 2n, "toIndex: parse Number"); |
| 29 | assert.sameValue(BigInt.asIntN(3.9, 10n), 2n, "toIndex: truncate towards 0"); |
| 30 | assert.sameValue(BigInt.asIntN("3.9", 10n), 2n, "toIndex: parse Number => truncate towards 0"); |
| 31 | assert.sameValue(BigInt.asIntN([0], 1n), 0n, 'ToIndex: [0].toString() => "0" => 0'); |
| 32 | assert.sameValue(BigInt.asIntN(["1"], 1n), -1n, 'ToIndex: ["1"].toString() => "1" => 1'); |
| 33 | assert.sameValue(BigInt.asIntN({}, 1n), 0n, |
| 34 | 'ToIndex: ({}).toString() => "[object Object]" => NaN => 0'); |
| 35 | assert.sameValue(BigInt.asIntN([], 1n), 0n, 'ToIndex: [].toString() => "" => NaN => 0'); |