Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/BigInt/asUintN/bits-toindex-toprimitive.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: pending
6 info: |
7 BigInt.asUintN ( bits, bigint )
8
9 1. Let bits be ? ToIndex(bits).
10 features: [BigInt, Symbol.toPrimitive, computed-property-names]
11 ---*/
12
13 function err() {
14 throw new Test262Error();
15 }
16
17 function MyError() {}
18
19 assert.sameValue(BigInt.asUintN({
20 [Symbol.toPrimitive]: function() {
21 return 1;
22 },
23 valueOf: err,
24 toString: err
25 }, 1n), 1n, "ToPrimitive: @@toPrimitive takes precedence");
26 assert.sameValue(BigInt.asUintN({
27 valueOf: function() {
28 return 1;
29 },
30 toString: err
31 }, 1n), 1n, "ToPrimitive: valueOf takes precedence over toString");
32 assert.sameValue(BigInt.asUintN({
33 toString: function() {
34 return 1;
35 }
36 }, 1n), 1n, "ToPrimitive: toString with no valueOf");
37 assert.sameValue(BigInt.asUintN({
38 [Symbol.toPrimitive]: undefined,
39 valueOf: function() {
40 return 1;
41 }
42 }, 1n), 1n, "ToPrimitive: skip @@toPrimitive when it's undefined");
43 assert.sameValue(BigInt.asUintN({
44 [Symbol.toPrimitive]: null,
45 valueOf: function() {
46 return 1;
47 }
48 }, 1n), 1n, "ToPrimitive: skip @@toPrimitive when it's null");
49 assert.sameValue(BigInt.asUintN({
50 valueOf: null,
51 toString: function() {
52 return 1;
53 }
54 }, 1n), 1n, "ToPrimitive: skip valueOf when it's not callable");
55 assert.sameValue(BigInt.asUintN({
56 valueOf: 1,
57 toString: function() {
58 return 1;
59 }
60 }, 1n), 1n, "ToPrimitive: skip valueOf when it's not callable");
61 assert.sameValue(BigInt.asUintN({
62 valueOf: {},
63 toString: function() {
64 return 1;
65 }
66 }, 1n), 1n, "ToPrimitive: skip valueOf when it's not callable");
67 assert.sameValue(BigInt.asUintN({
68 valueOf: function() {
69 return {};
70 },
71 toString: function() {
72 return 1;
73 }
74 }, 1n), 1n, "ToPrimitive: skip valueOf when it returns an object");
75 assert.sameValue(BigInt.asUintN({
76 valueOf: function() {
77 return Object(12345);
78 },
79 toString: function() {
80 return 1;
81 }
82 }, 1n), 1n, "ToPrimitive: skip valueOf when it returns an object");
83 assert.throws(TypeError, function() {
84 BigInt.asUintN({
85 [Symbol.toPrimitive]: 1
86 }, 0n);
87 }, "ToPrimitive: throw when @@toPrimitive is not callable");
88 assert.throws(TypeError, function() {
89 BigInt.asUintN({
90 [Symbol.toPrimitive]: {}
91 }, 0n);
92 }, "ToPrimitive: throw when @@toPrimitive is not callable");
93 assert.throws(TypeError, function() {
94 BigInt.asUintN({
95 [Symbol.toPrimitive]: function() {
96 return Object(1);
97 }
98 }, 0n);
99 }, "ToPrimitive: throw when @@toPrimitive returns an object");
100 assert.throws(TypeError, function() {
101 BigInt.asUintN({
102 [Symbol.toPrimitive]: function() {
103 return {};
104 }
105 }, 0n);
106 }, "ToPrimitive: throw when @@toPrimitive returns an object");
107 assert.throws(MyError, function() {
108 BigInt.asUintN({
109 [Symbol.toPrimitive]: function() {
110 throw new MyError();
111 }
112 }, 0n);
113 }, "ToPrimitive: propagate errors from @@toPrimitive");
114 assert.throws(MyError, function() {
115 BigInt.asUintN({
116 valueOf: function() {
117 throw new MyError();
118 }
119 }, 0n);
120 }, "ToPrimitive: propagate errors from valueOf");
121 assert.throws(MyError, function() {
122 BigInt.asUintN({
123 toString: function() {
124 throw new MyError();
125 }
126 }, 0n);
127 }, "ToPrimitive: propagate errors from toString");
128 assert.throws(TypeError, function() {
129 BigInt.asUintN({
130 valueOf: null,
131 toString: null
132 }, 0n);
133 }, "ToPrimitive: throw when skipping both valueOf and toString");
134 assert.throws(TypeError, function() {
135 BigInt.asUintN({
136 valueOf: 1,
137 toString: 1
138 }, 0n);
139 }, "ToPrimitive: throw when skipping both valueOf and toString");
140 assert.throws(TypeError, function() {
141 BigInt.asUintN({
142 valueOf: {},
143 toString: {}
144 }, 0n);
145 }, "ToPrimitive: throw when skipping both valueOf and toString");
146 assert.throws(TypeError, function() {
147 BigInt.asUintN({
148 valueOf: function() {
149 return Object(1);
150 },
151 toString: function() {
152 return Object(1);
153 }
154 }, 0n);
155 }, "ToPrimitive: throw when skipping both valueOf and toString");
156 assert.throws(TypeError, function() {
157 BigInt.asUintN({
158 valueOf: function() {
159 return {};
160 },
161 toString: function() {
162 return {};
163 }
164 }, 0n);
165 }, "ToPrimitive: throw when skipping both valueOf and toString");