bigint-non-primitive.js (2109B)
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: Bitwise AND for BigInt non-primitive values 5 esid: sec-binary-bitwise-operators-runtime-semantics-evaluation 6 info: | 7 5. Let lnum be ? ToNumeric(lval). 8 6. Let rnum be ? ToNumeric(rval). 9 ... 10 8. Let T be Type(lnum). 11 9. If @ is &, return T::bitwiseAND(lnum, rnum). 12 13 features: [BigInt] 14 ---*/ 15 assert.sameValue( 16 Object(0b101n) & 0b011n, 17 0b001n, 18 'The result of (Object(0b101n) & 0b011n) is 0b001n' 19 ); 20 21 assert.sameValue( 22 0b011n & Object(0b101n), 23 0b001n, 24 'The result of (0b011n & Object(0b101n)) is 0b001n' 25 ); 26 27 assert.sameValue( 28 Object(0b101n) & Object(0b011n), 29 0b001n, 30 'The result of (Object(0b101n) & Object(0b011n)) is 0b001n' 31 ); 32 33 function err() { 34 throw new Test262Error(); 35 } 36 37 assert.sameValue({ 38 [Symbol.toPrimitive]: function() { 39 return 0b101n; 40 }, 41 42 valueOf: err, 43 toString: err 44 } & 0b011n, 0b001n, 'The result of (({[Symbol.toPrimitive]: function() {return 0b101n;}, valueOf: err, toString: err}) & 0b011n) is 0b001n'); 45 46 assert.sameValue(0b011n & { 47 [Symbol.toPrimitive]: function() { 48 return 0b101n; 49 }, 50 51 valueOf: err, 52 toString: err 53 }, 0b001n, 'The result of (0b011n & {[Symbol.toPrimitive]: function() {return 0b101n;}, valueOf: err, toString: err}) is 0b001n'); 54 55 assert.sameValue({ 56 valueOf: function() { 57 return 0b101n; 58 }, 59 60 toString: err 61 } & 0b011n, 0b001n, 'The result of (({valueOf: function() {return 0b101n;}, toString: err}) & 0b011n) is 0b001n'); 62 63 assert.sameValue(0b011n & { 64 valueOf: function() { 65 return 0b101n; 66 }, 67 68 toString: err 69 }, 0b001n, 'The result of (0b011n & {valueOf: function() {return 0b101n;}, toString: err}) is 0b001n'); 70 71 assert.sameValue({ 72 toString: function() { 73 return 0b101n; 74 } 75 } & 0b011n, 0b001n, 'The result of (({toString: function() {return 0b101n;}}) & 0b011n) is 0b001n'); 76 77 assert.sameValue(0b011n & { 78 toString: function() { 79 return 0b101n; 80 } 81 }, 0b001n, 'The result of (0b011n & {toString: function() {return 0b101n;}}) is 0b001n'); 82 83 reportCompare(0, 0);