File: bits-toindex.js

package info (click to toggle)
qtdeclarative-opensource-src-gles 5.15.17%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 258,992 kB
  • sloc: javascript: 512,415; cpp: 497,385; xml: 8,892; python: 3,304; ansic: 2,764; sh: 206; makefile: 46; php: 27
file content (35 lines) | stat: -rw-r--r-- 1,994 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (C) 2017 Josh Wolfe. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: BigInt.asUintN type coercion for bits parameter
esid: pending
info: |
  BigInt.asUintN ( bits, bigint )

  1. Let bits be ? ToIndex(bits).
features: [BigInt]
---*/

assert.sameValue(BigInt.asUintN(0, 1n), 0n);
assert.sameValue(BigInt.asUintN(1, 1n), 1n);
assert.sameValue(BigInt.asUintN(-0.9, 1n), 0n, "ToIndex: truncate towards 0");
assert.sameValue(BigInt.asUintN(0.9, 1n), 0n, "ToIndex: truncate towards 0");
assert.sameValue(BigInt.asUintN(NaN, 1n), 0n, "ToIndex: NaN => 0");
assert.sameValue(BigInt.asUintN(undefined, 1n), 0n, "ToIndex: undefined => NaN => 0");
assert.sameValue(BigInt.asUintN(null, 1n), 0n, "ToIndex: null => 0");
assert.sameValue(BigInt.asUintN(false, 1n), 0n, "ToIndex: false => 0");
assert.sameValue(BigInt.asUintN(true, 1n), 1n, "ToIndex: true => 1");
assert.sameValue(BigInt.asUintN("0", 1n), 0n, "ToIndex: parse Number");
assert.sameValue(BigInt.asUintN("1", 1n), 1n, "ToIndex: parse Number");
assert.sameValue(BigInt.asUintN("", 1n), 0n, "ToIndex: parse Number => NaN => 0");
assert.sameValue(BigInt.asUintN("foo", 1n), 0n, "ToIndex: parse Number => NaN => 0");
assert.sameValue(BigInt.asUintN("true", 1n), 0n, "ToIndex: parse Number => NaN => 0");
assert.sameValue(BigInt.asUintN(3, 10n), 2n);
assert.sameValue(BigInt.asUintN("3", 10n), 2n, "toIndex: parse Number");
assert.sameValue(BigInt.asUintN(3.9, 10n), 2n, "toIndex: truncate towards 0");
assert.sameValue(BigInt.asUintN("3.9", 10n), 2n, "toIndex: parse Number => truncate towards 0");
assert.sameValue(BigInt.asUintN([0], 1n), 0n, 'ToIndex: [0].toString() => "0" => 0');
assert.sameValue(BigInt.asUintN(["1"], 1n), 1n, 'ToIndex: ["1"].toString() => "1" => 1');
assert.sameValue(BigInt.asUintN({}, 1n), 0n,
  'ToIndex: ({}).toString() => "[object Object]" => NaN => 0');
assert.sameValue(BigInt.asUintN([], 1n), 0n, 'ToIndex: [].toString() => "" => NaN => 0');