bigint-wrapped-values.js (1416B)
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: addition operator ToNumeric with BigInt operands 5 esid: sec-addition-operator-plus-runtime-semantics-evaluation 6 features: [BigInt, Symbol.toPrimitive, computed-property-names] 7 ---*/ 8 assert.sameValue(Object(2n) + 1n, 3n, 'The result of (Object(2n) + 1n) is 3n'); 9 assert.sameValue(1n + Object(2n), 3n, 'The result of (1n + Object(2n)) is 3n'); 10 11 assert.sameValue({ 12 [Symbol.toPrimitive]: function() { 13 return 2n; 14 } 15 } + 1n, 3n, 'The result of (({[Symbol.toPrimitive]: function() {return 2n;}}) + 1n) is 3n'); 16 17 assert.sameValue(1n + { 18 [Symbol.toPrimitive]: function() { 19 return 2n; 20 } 21 }, 3n, 'The result of (1n + {[Symbol.toPrimitive]: function() {return 2n;}}) is 3n'); 22 23 assert.sameValue({ 24 valueOf: function() { 25 return 2n; 26 } 27 } + 1n, 3n, 'The result of (({valueOf: function() {return 2n;}}) + 1n) is 3n'); 28 29 assert.sameValue(1n + { 30 valueOf: function() { 31 return 2n; 32 } 33 }, 3n, 'The result of (1n + {valueOf: function() {return 2n;}}) is 3n'); 34 35 assert.sameValue({ 36 toString: function() { 37 return 2n; 38 } 39 } + 1n, 3n, 'The result of (({toString: function() {return 2n;}}) + 1n) is 3n'); 40 41 assert.sameValue(1n + { 42 toString: function() { 43 return 2n; 44 } 45 }, 3n, 'The result of (1n + {toString: function() {return 2n;}}) is 3n'); 46 47 reportCompare(0, 0);