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]
13 assert.sameValue(BigInt.asIntN(2, Object(0n)), 0n, "ToPrimitive: unbox object with internal slot");
14 assert.sameValue(BigInt.asIntN(2, {
15 [Symbol.toPrimitive]: function() {
18 }), 0n, "ToPrimitive: @@toPrimitive");
19 assert.sameValue(BigInt.asIntN(2, {
23 }), 0n, "ToPrimitive: valueOf");
24 assert.sameValue(BigInt.asIntN(2, {
25 toString: function() {
28 }), 0n, "ToPrimitive: toString");
29 assert.sameValue(BigInt.asIntN(2, Object(true)), 1n,
30 "ToBigInt: unbox object with internal slot => true => 1n");
31 assert.sameValue(BigInt.asIntN(2, {
32 [Symbol.toPrimitive]: function() {
35 }), 1n, "ToBigInt: @@toPrimitive => true => 1n");
36 assert.sameValue(BigInt.asIntN(2, {
40 }), 1n, "ToBigInt: valueOf => true => 1n");
41 assert.sameValue(BigInt.asIntN(2, {
42 toString: function() {
45 }), 1n, "ToBigInt: toString => true => 1n");
46 assert.sameValue(BigInt.asIntN(2, Object("1")), 1n,
47 "ToBigInt: unbox object with internal slot => parse BigInt");
48 assert.sameValue(BigInt.asIntN(2, {
49 [Symbol.toPrimitive]: function() {
52 }), 1n, "ToBigInt: @@toPrimitive => parse BigInt");
53 assert.sameValue(BigInt.asIntN(2, {
57 }), 1n, "ToBigInt: valueOf => parse BigInt");
58 assert.sameValue(BigInt.asIntN(2, {
59 toString: function() {
62 }), 1n, "ToBigInt: toString => parse BigInt");