1 // Copyright (C) 2017 Josh Wolfe. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
4 description: BigInt.asIntN type coercion for bigint parameter
5 esid: sec-bigint.asintn
7 BigInt.asIntN ( bits, bigint )
9 2. Let bigint ? ToBigInt(bigint).
10 features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive]
12 assert.sameValue(typeof BigInt, 'function');
13 assert.sameValue(typeof BigInt.asIntN, 'function');
15 throw new Test262Error();
20 assert.sameValue(BigInt.asIntN(2, {
21 [Symbol.toPrimitive]: function() {
26 }), 1n, "ToPrimitive: @@toPrimitive takes precedence");
27 assert.sameValue(BigInt.asIntN(2, {
32 }), 1n, "ToPrimitive: valueOf takes precedence over toString");
33 assert.sameValue(BigInt.asIntN(2, {
34 toString: function() {
37 }), 1n, "ToPrimitive: toString with no valueOf");
38 assert.sameValue(BigInt.asIntN(2, {
39 [Symbol.toPrimitive]: undefined,
43 }), 1n, "ToPrimitive: skip @@toPrimitive when it's undefined");
44 assert.sameValue(BigInt.asIntN(2, {
45 [Symbol.toPrimitive]: null,
49 }), 1n, "ToPrimitive: skip @@toPrimitive when it's null");
50 assert.sameValue(BigInt.asIntN(2, {
52 toString: function() {
55 }), 1n, "ToPrimitive: skip valueOf when it's not callable");
56 assert.sameValue(BigInt.asIntN(2, {
58 toString: function() {
61 }), 1n, "ToPrimitive: skip valueOf when it's not callable");
62 assert.sameValue(BigInt.asIntN(2, {
64 toString: function() {
67 }), 1n, "ToPrimitive: skip valueOf when it's not callable");
68 assert.sameValue(BigInt.asIntN(2, {
72 toString: function() {
75 }), 1n, "ToPrimitive: skip valueOf when it returns an object");
76 assert.sameValue(BigInt.asIntN(2, {
80 toString: function() {
83 }), 1n, "ToPrimitive: skip valueOf when it returns an object");
84 assert.throws(TypeError, function() {
86 [Symbol.toPrimitive]: 1
88 }, "ToPrimitive: throw when @@toPrimitive is not callable");
89 assert.throws(TypeError, function() {
91 [Symbol.toPrimitive]: {}
93 }, "ToPrimitive: throw when @@toPrimitive is not callable");
94 assert.throws(TypeError, function() {
96 [Symbol.toPrimitive]: function() {
100 }, "ToPrimitive: throw when @@toPrimitive returns an object");
101 assert.throws(TypeError, function() {
103 [Symbol.toPrimitive]: function() {
107 }, "ToPrimitive: throw when @@toPrimitive returns an object");
108 assert.throws(MyError, function() {
110 [Symbol.toPrimitive]: function() {
114 }, "ToPrimitive: propagate errors from @@toPrimitive");
115 assert.throws(MyError, function() {
117 valueOf: function() {
121 }, "ToPrimitive: propagate errors from valueOf");
122 assert.throws(MyError, function() {
124 toString: function() {
128 }, "ToPrimitive: propagate errors from toString");
129 assert.throws(TypeError, function() {
134 }, "ToPrimitive: throw when skipping both valueOf and toString");
135 assert.throws(TypeError, function() {
140 }, "ToPrimitive: throw when skipping both valueOf and toString");
141 assert.throws(TypeError, function() {
146 }, "ToPrimitive: throw when skipping both valueOf and toString");
147 assert.throws(TypeError, function() {
149 valueOf: function() {
152 toString: function() {
156 }, "ToPrimitive: throw when skipping both valueOf and toString");
157 assert.throws(TypeError, function() {
159 valueOf: function() {
162 toString: function() {
166 }, "ToPrimitive: throw when skipping both valueOf and toString");