Debian Codegraph @

js/src/tests/test262/built-ins/BigInt/asUintN/bits-toindex-errors.js

raw
1 // Copyright (C) 2017 Josh Wolfe. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 description: BigInt.asUintN type coercion for bits parameter
5 esid: sec-bigint.asuintn
6 info: |
7 BigInt.asUintN ( bits, bigint )
8
9 1. Let bits be ? ToIndex(bits).
10 features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive]
11 ---*/
12 assert.sameValue(typeof BigInt, 'function');
13 assert.sameValue(typeof BigInt.asUintN, 'function');
14
15 assert.throws(RangeError, function() {
16 BigInt.asUintN(-1, 0n);
17 }, "ToIndex: throw when integerIndex < 0");
18 assert.throws(RangeError, function() {
19 BigInt.asUintN(-2.5, 0n);
20 }, "ToIndex: throw when integerIndex < 0");
21 assert.throws(RangeError, function() {
22 BigInt.asUintN("-2.5", 0n);
23 }, "ToIndex: parse Number => throw when integerIndex < 0");
24 assert.throws(RangeError, function() {
25 BigInt.asUintN(-Infinity, 0n);
26 }, "ToIndex: throw when integerIndex < 0");
27 assert.throws(RangeError, function() {
28 BigInt.asUintN(9007199254740992, 0n);
29 }, "ToIndex: throw when integerIndex > 2**53-1");
30 assert.throws(RangeError, function() {
31 BigInt.asUintN(Infinity, 0n);
32 }, "ToIndex: throw when integerIndex > 2**53-1");
33 assert.throws(TypeError, function() {
34 BigInt.asUintN(0n, 0n);
35 }, "ToIndex: BigInt => TypeError");
36 assert.throws(TypeError, function() {
37 BigInt.asUintN(Object(0n), 0n);
38 }, "ToIndex: unbox object with internal slot => BigInt => TypeError");
39 assert.throws(TypeError, function() {
40 BigInt.asUintN({
41 [Symbol.toPrimitive]: function() {
42 return 0n;
43 }
44 }, 0n);
45 }, "ToIndex: @@toPrimitive => BigInt => TypeError");
46 assert.throws(TypeError, function() {
47 BigInt.asUintN({
48 valueOf: function() {
49 return 0n;
50 }
51 }, 0n);
52 }, "ToIndex: valueOf => BigInt => TypeError");
53 assert.throws(TypeError, function() {
54 BigInt.asUintN({
55 toString: function() {
56 return 0n;
57 }
58 }, 0n);
59 }, "ToIndex: toString => BigInt => TypeError");
60 assert.throws(TypeError, function() {
61 BigInt.asUintN(Symbol("1"), 0n);
62 }, "ToIndex: Symbol => TypeError");
63 assert.throws(TypeError, function() {
64 BigInt.asUintN(Object(Symbol("1")), 0n);
65 }, "ToIndex: unbox object with internal slot => Symbol => TypeError");
66 assert.throws(TypeError, function() {
67 BigInt.asUintN({
68 [Symbol.toPrimitive]: function() {
69 return Symbol("1");
70 }
71 }, 0n);
72 }, "ToIndex: @@toPrimitive => Symbol => TypeError");
73 assert.throws(TypeError, function() {
74 BigInt.asUintN({
75 valueOf: function() {
76 return Symbol("1");
77 }
78 }, 0n);
79 }, "ToIndex: valueOf => Symbol => TypeError");
80 assert.throws(TypeError, function() {
81 BigInt.asUintN({
82 toString: function() {
83 return Symbol("1");
84 }
85 }, 0n);
86 }, "ToIndex: toString => Symbol => TypeError");
87
88 reportCompare(0, 0);