bits-toindex-wrapped-values.js (3216B)
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 bits parameter 5 esid: sec-bigint.asintn 6 info: | 7 BigInt.asIntN ( bits, bigint ) 8 9 1. Let bits be ? ToIndex(bits). 10 features: [BigInt, computed-property-names, Symbol, Symbol.toPrimitive] 11 ---*/ 12 13 assert.sameValue(BigInt.asIntN(Object(0), 1n), 0n, "ToPrimitive: unbox object with internal slot"); 14 assert.sameValue(BigInt.asIntN({ 15 [Symbol.toPrimitive]: function() { 16 return 0; 17 } 18 }, 1n), 0n, "ToPrimitive: @@toPrimitive"); 19 assert.sameValue(BigInt.asIntN({ 20 valueOf: function() { 21 return 0; 22 } 23 }, 1n), 0n, "ToPrimitive: valueOf"); 24 assert.sameValue(BigInt.asIntN({ 25 toString: function() { 26 return 0; 27 } 28 }, 1n), 0n, "ToPrimitive: toString"); 29 assert.sameValue(BigInt.asIntN(Object(NaN), 1n), 0n, 30 "ToIndex: unbox object with internal slot => NaN => 0"); 31 assert.sameValue(BigInt.asIntN({ 32 [Symbol.toPrimitive]: function() { 33 return NaN; 34 } 35 }, 1n), 0n, "ToIndex: @@toPrimitive => NaN => 0"); 36 assert.sameValue(BigInt.asIntN({ 37 valueOf: function() { 38 return NaN; 39 } 40 }, 1n), 0n, "ToIndex: valueOf => NaN => 0"); 41 assert.sameValue(BigInt.asIntN({ 42 toString: function() { 43 return NaN; 44 } 45 }, 1n), 0n, "ToIndex: toString => NaN => 0"); 46 assert.sameValue(BigInt.asIntN({ 47 [Symbol.toPrimitive]: function() { 48 return undefined; 49 } 50 }, 1n), 0n, "ToIndex: @@toPrimitive => undefined => NaN => 0"); 51 assert.sameValue(BigInt.asIntN({ 52 valueOf: function() { 53 return undefined; 54 } 55 }, 1n), 0n, "ToIndex: valueOf => undefined => NaN => 0"); 56 assert.sameValue(BigInt.asIntN({ 57 toString: function() { 58 return undefined; 59 } 60 }, 1n), 0n, "ToIndex: toString => undefined => NaN => 0"); 61 assert.sameValue(BigInt.asIntN({ 62 [Symbol.toPrimitive]: function() { 63 return null; 64 } 65 }, 1n), 0n, "ToIndex: @@toPrimitive => null => 0"); 66 assert.sameValue(BigInt.asIntN({ 67 valueOf: function() { 68 return null; 69 } 70 }, 1n), 0n, "ToIndex: valueOf => null => 0"); 71 assert.sameValue(BigInt.asIntN({ 72 toString: function() { 73 return null; 74 } 75 }, 1n), 0n, "ToIndex: toString => null => 0"); 76 assert.sameValue(BigInt.asIntN(Object(true), 1n), -1n, 77 "ToIndex: unbox object with internal slot => true => 1"); 78 assert.sameValue(BigInt.asIntN({ 79 [Symbol.toPrimitive]: function() { 80 return true; 81 } 82 }, 1n), -1n, "ToIndex: @@toPrimitive => true => 1"); 83 assert.sameValue(BigInt.asIntN({ 84 valueOf: function() { 85 return true; 86 } 87 }, 1n), -1n, "ToIndex: valueOf => true => 1"); 88 assert.sameValue(BigInt.asIntN({ 89 toString: function() { 90 return true; 91 } 92 }, 1n), -1n, "ToIndex: toString => true => 1"); 93 assert.sameValue(BigInt.asIntN(Object("1"), 1n), -1n, 94 "ToIndex: unbox object with internal slot => parse Number"); 95 assert.sameValue(BigInt.asIntN({ 96 [Symbol.toPrimitive]: function() { 97 return "1"; 98 } 99 }, 1n), -1n, "ToIndex: @@toPrimitive => parse Number"); 100 assert.sameValue(BigInt.asIntN({ 101 valueOf: function() { 102 return "1"; 103 } 104 }, 1n), -1n, "ToIndex: valueOf => parse Number"); 105 assert.sameValue(BigInt.asIntN({ 106 toString: function() { 107 return "1"; 108 } 109 }, 1n), -1n, "ToIndex: toString => parse Number"); 110 111 reportCompare(0, 0);