bigint-tobigint-wrapped-values.js (1880B)
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.asIntN type coercion for bigint parameter 5 esid: sec-bigint.asintn 6 info: | 7 BigInt.asIntN ( bits, bigint ) 8 9 2. Let bigint ? ToBigInt(bigint). 10 features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive] 11 ---*/ 12 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() { 16 return 0n; 17 } 18 }), 0n, "ToPrimitive: @@toPrimitive"); 19 assert.sameValue(BigInt.asIntN(2, { 20 valueOf: function() { 21 return 0n; 22 } 23 }), 0n, "ToPrimitive: valueOf"); 24 assert.sameValue(BigInt.asIntN(2, { 25 toString: function() { 26 return 0n; 27 } 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() { 33 return true; 34 } 35 }), 1n, "ToBigInt: @@toPrimitive => true => 1n"); 36 assert.sameValue(BigInt.asIntN(2, { 37 valueOf: function() { 38 return true; 39 } 40 }), 1n, "ToBigInt: valueOf => true => 1n"); 41 assert.sameValue(BigInt.asIntN(2, { 42 toString: function() { 43 return true; 44 } 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() { 50 return "1"; 51 } 52 }), 1n, "ToBigInt: @@toPrimitive => parse BigInt"); 53 assert.sameValue(BigInt.asIntN(2, { 54 valueOf: function() { 55 return "1"; 56 } 57 }), 1n, "ToBigInt: valueOf => parse BigInt"); 58 assert.sameValue(BigInt.asIntN(2, { 59 toString: function() { 60 return "1"; 61 } 62 }), 1n, "ToBigInt: toString => parse BigInt"); 63 64 reportCompare(0, 0);