From 96ba34c24033a98f2d17068b8d2c6695ebd05252 Mon Sep 17 00:00:00 2001 From: Josh Wolfe Date: Wed, 18 Oct 2017 11:47:42 -0700 Subject: [PATCH 1/2] bigint bitwise and, or, xor --- .../bitwise-and/bigint-non-primitive.js | 43 +++++++ .../expressions/bitwise-and/bigint.js | 107 ++++++++++++++++++ .../bitwise-or/bigint-non-primitive.js | 44 +++++++ .../language/expressions/bitwise-or/bigint.js | 107 ++++++++++++++++++ .../bitwise-xor/bigint-non-primitive.js | 44 +++++++ .../expressions/bitwise-xor/bigint.js | 107 ++++++++++++++++++ 6 files changed, 452 insertions(+) create mode 100644 test/language/expressions/bitwise-and/bigint-non-primitive.js create mode 100644 test/language/expressions/bitwise-and/bigint.js create mode 100644 test/language/expressions/bitwise-or/bigint-non-primitive.js create mode 100644 test/language/expressions/bitwise-or/bigint.js create mode 100644 test/language/expressions/bitwise-xor/bigint-non-primitive.js create mode 100644 test/language/expressions/bitwise-xor/bigint.js diff --git a/test/language/expressions/bitwise-and/bigint-non-primitive.js b/test/language/expressions/bitwise-and/bigint-non-primitive.js new file mode 100644 index 0000000000..1fffb06635 --- /dev/null +++ b/test/language/expressions/bitwise-and/bigint-non-primitive.js @@ -0,0 +1,43 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Bitwise AND for BigInt non-primitive values +esid: sec-binary-bitwise-operators-runtime-semantics-evaluation +info: | + + 5. Let lnum be ? ToNumeric(lval). + 6. Let rnum be ? ToNumeric(rval). + ... + 8. Let T be Type(lnum). + 9. If @ is &, return T::bitwiseAND(lnum, rnum). + +features: [BigInt] +---*/ + +assert.sameValue(Object(5n) & 3n, 1n, "Object(5n) & 3n === 1n"); +assert.sameValue(3n & Object(5n), 1n, "3n & Object(5n) === 1n"); +assert.sameValue(Object(5n) & Object(3n), 1n, "Object(5n) & Object(3n) === 1n"); + +function err() { + throw new Test262Error(); +} + +assert.sameValue( + {[Symbol.toPrimitive]: function() { return 5n; }, valueOf: err, toString: err} & 3n, 1n, + "primitive from @@toPrimitive"); +assert.sameValue( + 3n & {[Symbol.toPrimitive]: function() { return 5n; }, valueOf: err, toString: err}, 1n, + "primitive from @@toPrimitive"); +assert.sameValue( + {valueOf: function() { return 5n; }, toString: err} & 3n, 1n, + "primitive from {}.valueOf"); +assert.sameValue( + 3n & {valueOf: function() { return 5n; }, toString: err}, 1n, + "primitive from {}.valueOf"); +assert.sameValue( + {toString: function() { return 5n; }} & 3n, 1n, + "primitive from {}.toString"); +assert.sameValue( + 3n & {toString: function() { return 5n; }}, 1n, + "primitive from {}.toString"); diff --git a/test/language/expressions/bitwise-and/bigint.js b/test/language/expressions/bitwise-and/bigint.js new file mode 100644 index 0000000000..b9de1bebdc --- /dev/null +++ b/test/language/expressions/bitwise-and/bigint.js @@ -0,0 +1,107 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Bitwise AND for BigInt values +esid: sec-bitwise-op +info: | + BitwiseOp(op, x, y) + + 1. Let result be 0. + 2. Let shift be 0. + 3. Repeat, until (x = 0 or x = -1) and (y = 0 or y = -1), + a. Let xDigit be x modulo 2. + b. Let yDigit be y modulo 2. + c. Let result be result + 2**shift * op(xDigit, yDigit) + d. Let shift be shift + 1. + e. Let x be (x - xDigit) / 2. + f. Let y be (y - yDigit) / 2. + 4. If op(x modulo 2, y modulo 2) ≠ 0, + a. Let result be result - 2**shift. NOTE: This extends the sign. + 5. Return result. + +features: [BigInt] +---*/ + +assert.sameValue(0n & 0n, 0n, "0n & 0n === 0n"); +assert.sameValue(0n & 1n, 0n, "0n & 1n === 0n"); +assert.sameValue(1n & 0n, 0n, "1n & 0n === 0n"); +assert.sameValue(0n & 2n, 0n, "0n & 2n === 0n"); +assert.sameValue(2n & 0n, 0n, "2n & 0n === 0n"); +assert.sameValue(0n & 3n, 0n, "0n & 3n === 0n"); +assert.sameValue(3n & 0n, 0n, "3n & 0n === 0n"); +assert.sameValue(1n & 1n, 1n, "1n & 1n === 1n"); +assert.sameValue(1n & 2n, 0n, "1n & 2n === 0n"); +assert.sameValue(2n & 1n, 0n, "2n & 1n === 0n"); +assert.sameValue(1n & 3n, 1n, "1n & 3n === 1n"); +assert.sameValue(3n & 1n, 1n, "3n & 1n === 1n"); +assert.sameValue(2n & 2n, 2n, "2n & 2n === 2n"); +assert.sameValue(2n & 3n, 2n, "2n & 3n === 2n"); +assert.sameValue(3n & 2n, 2n, "3n & 2n === 2n"); +assert.sameValue(0xffffffffn & 0n, 0n, "0xffffffffn & 0n === 0n"); +assert.sameValue(0n & 0xffffffffn, 0n, "0n & 0xffffffffn === 0n"); +assert.sameValue(0xffffffffn & 0xffffffffn, 0xffffffffn, "0xffffffffn & 0xffffffffn === 0xffffffffn"); +assert.sameValue(0xffffffffffffffffn & 0n, 0n, "0xffffffffffffffffn & 0n === 0n"); +assert.sameValue(0n & 0xffffffffffffffffn, 0n, "0n & 0xffffffffffffffffn === 0n"); +assert.sameValue(0xffffffffffffffffn & 0xffffffffn, 0xffffffffn, "0xffffffffffffffffn & 0xffffffffn === 0xffffffffn"); +assert.sameValue(0xffffffffn & 0xffffffffffffffffn, 0xffffffffn, "0xffffffffn & 0xffffffffffffffffn === 0xffffffffn"); +assert.sameValue( + 0xffffffffffffffffn & 0xffffffffffffffffn, 0xffffffffffffffffn, + "0xffffffffffffffffn & 0xffffffffffffffffn === 0xffffffffffffffffn"); +assert.sameValue( + 0xbf2ed51ff75d380fd3be813ec6185780n & 0x4aabef2324cedff5387f1f65n, 0x42092803008e813400181700n, + "0xbf2ed51ff75d380fd3be813ec6185780n & 0x4aabef2324cedff5387f1f65n === 0x42092803008e813400181700n"); +assert.sameValue( + 0x4aabef2324cedff5387f1f65n & 0xbf2ed51ff75d380fd3be813ec6185780n, 0x42092803008e813400181700n, + "0x4aabef2324cedff5387f1f65n & 0xbf2ed51ff75d380fd3be813ec6185780n === 0x42092803008e813400181700n"); +assert.sameValue(0n & -1n, 0n, "0n & -1n === 0n"); +assert.sameValue(-1n & 0n, 0n, "-1n & 0n === 0n"); +assert.sameValue(0n & -2n, 0n, "0n & -2n === 0n"); +assert.sameValue(-2n & 0n, 0n, "-2n & 0n === 0n"); +assert.sameValue(1n & -2n, 0n, "1n & -2n === 0n"); +assert.sameValue(-2n & 1n, 0n, "-2n & 1n === 0n"); +assert.sameValue(2n & -2n, 2n, "2n & -2n === 2n"); +assert.sameValue(-2n & 2n, 2n, "-2n & 2n === 2n"); +assert.sameValue(2n & -3n, 0n, "2n & -3n === 0n"); +assert.sameValue(-3n & 2n, 0n, "-3n & 2n === 0n"); +assert.sameValue(-1n & -2n, -2n, "-1n & -2n === -2n"); +assert.sameValue(-2n & -1n, -2n, "-2n & -1n === -2n"); +assert.sameValue(-2n & -2n, -2n, "-2n & -2n === -2n"); +assert.sameValue(-2n & -3n, -4n, "-2n & -3n === -4n"); +assert.sameValue(-3n & -2n, -4n, "-3n & -2n === -4n"); +assert.sameValue(0xffffffffn & -1n, 0xffffffffn, "0xffffffffn & -1n === 0xffffffffn"); +assert.sameValue(-1n & 0xffffffffn, 0xffffffffn, "-1n & 0xffffffffn === 0xffffffffn"); +assert.sameValue(0xffffffffffffffffn & -1n, 0xffffffffffffffffn, "0xffffffffffffffffn & -1n === 0xffffffffffffffffn"); +assert.sameValue(-1n & 0xffffffffffffffffn, 0xffffffffffffffffn, "-1n & 0xffffffffffffffffn === 0xffffffffffffffffn"); +assert.sameValue( + 0xbf2ed51ff75d380fd3be813ec6185780n & -0x4aabef2324cedff5387f1f65n, 0xbf2ed51fb554100cd330000ac6004080n, + "0xbf2ed51ff75d380fd3be813ec6185780n & -0x4aabef2324cedff5387f1f65n === 0xbf2ed51fb554100cd330000ac6004080n"); +assert.sameValue( + -0x4aabef2324cedff5387f1f65n & 0xbf2ed51ff75d380fd3be813ec6185780n, 0xbf2ed51fb554100cd330000ac6004080n, + "-0x4aabef2324cedff5387f1f65n & 0xbf2ed51ff75d380fd3be813ec6185780n === 0xbf2ed51fb554100cd330000ac6004080n"); +assert.sameValue( + -0xbf2ed51ff75d380fd3be813ec6185780n & 0x4aabef2324cedff5387f1f65n, 0x8a2c72024405ec138670800n, + "-0xbf2ed51ff75d380fd3be813ec6185780n & 0x4aabef2324cedff5387f1f65n === 0x8a2c72024405ec138670800n"); +assert.sameValue( + 0x4aabef2324cedff5387f1f65n & -0xbf2ed51ff75d380fd3be813ec6185780n, 0x8a2c72024405ec138670800n, + "0x4aabef2324cedff5387f1f65n & -0xbf2ed51ff75d380fd3be813ec6185780n === 0x8a2c72024405ec138670800n"); +assert.sameValue( + -0xbf2ed51ff75d380fd3be813ec6185780n & -0x4aabef2324cedff5387f1f65n, -0xbf2ed51fffffff2ff7fedffffe7f5f80n, + "-0xbf2ed51ff75d380fd3be813ec6185780n & -0x4aabef2324cedff5387f1f65n === -0xbf2ed51fffffff2ff7fedffffe7f5f80n"); +assert.sameValue( + -0x4aabef2324cedff5387f1f65n & -0xbf2ed51ff75d380fd3be813ec6185780n, -0xbf2ed51fffffff2ff7fedffffe7f5f80n, + "-0x4aabef2324cedff5387f1f65n & -0xbf2ed51ff75d380fd3be813ec6185780n === -0xbf2ed51fffffff2ff7fedffffe7f5f80n"); +assert.sameValue(-0xffffffffn & 0n, 0n, "-0xffffffffn & 0n === 0n"); +assert.sameValue(0n & -0xffffffffn, 0n, "0n & -0xffffffffn === 0n"); +assert.sameValue( + -0xffffffffffffffffn & 0x10000000000000000n, 0x10000000000000000n, + "-0xffffffffffffffffn & 0x10000000000000000n === 0x10000000000000000n"); +assert.sameValue( + 0x10000000000000000n & -0xffffffffffffffffn, 0x10000000000000000n, + "0x10000000000000000n & -0xffffffffffffffffn === 0x10000000000000000n"); +assert.sameValue( + -0xffffffffffffffffffffffffn & 0x10000000000000000n, 0n, + "-0xffffffffffffffffffffffffn & 0x10000000000000000n === 0n"); +assert.sameValue( + 0x10000000000000000n & -0xffffffffffffffffffffffffn, 0n, + "0x10000000000000000n & -0xffffffffffffffffffffffffn === 0n"); diff --git a/test/language/expressions/bitwise-or/bigint-non-primitive.js b/test/language/expressions/bitwise-or/bigint-non-primitive.js new file mode 100644 index 0000000000..c40138590b --- /dev/null +++ b/test/language/expressions/bitwise-or/bigint-non-primitive.js @@ -0,0 +1,44 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Bitwise OR for BigInt non-primitive values +esid: sec-binary-bitwise-operators-runtime-semantics-evaluation +info: | + + 5. Let lnum be ? ToNumeric(lval). + 6. Let rnum be ? ToNumeric(rval). + ... + 8. Let T be Type(lnum). + ... + 10. If @ is |, return T::bitwiseOR(lnum, rnum). + +features: [BigInt] +---*/ + +assert.sameValue(Object(5n) | 3n, 7n, "Object(5n) | 3n === 7n"); +assert.sameValue(3n | Object(5n), 7n, "3n | Object(5n) === 7n"); +assert.sameValue(Object(5n) | Object(3n), 7n, "Object(5n) | Object(3n) === 7n"); + +function err() { + throw new Test262Error(); +} + +assert.sameValue( + {[Symbol.toPrimitive]: function() { return 5n; }, valueOf: err, toString: err} | 3n, 7n, + "primitive from @@toPrimitive"); +assert.sameValue( + 3n | {[Symbol.toPrimitive]: function() { return 5n; }, valueOf: err, toString: err}, 7n, + "primitive from @@toPrimitive"); +assert.sameValue( + {valueOf: function() { return 5n; }, toString: err} | 3n, 7n, + "primitive from {}.valueOf"); +assert.sameValue( + 3n | {valueOf: function() { return 5n; }, toString: err}, 7n, + "primitive from {}.valueOf"); +assert.sameValue( + {toString: function() { return 5n; }} | 3n, 7n, + "primitive from {}.toString"); +assert.sameValue( + 3n | {toString: function() { return 5n; }}, 7n, + "primitive from {}.toString"); diff --git a/test/language/expressions/bitwise-or/bigint.js b/test/language/expressions/bitwise-or/bigint.js new file mode 100644 index 0000000000..81cdd9cace --- /dev/null +++ b/test/language/expressions/bitwise-or/bigint.js @@ -0,0 +1,107 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Bitwise OR for BigInt values +esid: sec-bitwise-op +info: | + BitwiseOp(op, x, y) + + 1. Let result be 0. + 2. Let shift be 0. + 3. Repeat, until (x = 0 or x = -1) and (y = 0 or y = -1), + a. Let xDigit be x modulo 2. + b. Let yDigit be y modulo 2. + c. Let result be result + 2**shift * op(xDigit, yDigit) + d. Let shift be shift + 1. + e. Let x be (x - xDigit) / 2. + f. Let y be (y - yDigit) / 2. + 4. If op(x modulo 2, y modulo 2) ≠ 0, + a. Let result be result - 2**shift. NOTE: This extends the sign. + 5. Return result. + +features: [BigInt] +---*/ + +assert.sameValue(0n | 0n, 0n, "0n | 0n === 0n"); +assert.sameValue(0n | 1n, 1n, "0n | 1n === 1n"); +assert.sameValue(1n | 0n, 1n, "1n | 0n === 1n"); +assert.sameValue(0n | 2n, 2n, "0n | 2n === 2n"); +assert.sameValue(2n | 0n, 2n, "2n | 0n === 2n"); +assert.sameValue(0n | 3n, 3n, "0n | 3n === 3n"); +assert.sameValue(3n | 0n, 3n, "3n | 0n === 3n"); +assert.sameValue(1n | 1n, 1n, "1n | 1n === 1n"); +assert.sameValue(1n | 2n, 3n, "1n | 2n === 3n"); +assert.sameValue(2n | 1n, 3n, "2n | 1n === 3n"); +assert.sameValue(1n | 3n, 3n, "1n | 3n === 3n"); +assert.sameValue(3n | 1n, 3n, "3n | 1n === 3n"); +assert.sameValue(2n | 2n, 2n, "2n | 2n === 2n"); +assert.sameValue(2n | 3n, 3n, "2n | 3n === 3n"); +assert.sameValue(3n | 2n, 3n, "3n | 2n === 3n"); +assert.sameValue(0xffffffffn | 0n, 0xffffffffn, "0xffffffffn | 0n === 0xffffffffn"); +assert.sameValue(0n | 0xffffffffn, 0xffffffffn, "0n | 0xffffffffn === 0xffffffffn"); +assert.sameValue(0xffffffffn | 0xffffffffn, 0xffffffffn, "0xffffffffn | 0xffffffffn === 0xffffffffn"); +assert.sameValue(0xffffffffffffffffn | 0n, 0xffffffffffffffffn, "0xffffffffffffffffn | 0n === 0xffffffffffffffffn"); +assert.sameValue(0n | 0xffffffffffffffffn, 0xffffffffffffffffn, "0n | 0xffffffffffffffffn === 0xffffffffffffffffn"); +assert.sameValue(0xffffffffffffffffn | 0xffffffffn, 0xffffffffffffffffn, "0xffffffffffffffffn | 0xffffffffn === 0xffffffffffffffffn"); +assert.sameValue(0xffffffffn | 0xffffffffffffffffn, 0xffffffffffffffffn, "0xffffffffn | 0xffffffffffffffffn === 0xffffffffffffffffn"); +assert.sameValue( + 0xffffffffffffffffn | 0xffffffffffffffffn, 0xffffffffffffffffn, + "0xffffffffffffffffn | 0xffffffffffffffffn === 0xffffffffffffffffn"); +assert.sameValue( + 0xbf2ed51ff75d380fd3be813ec6185780n | 0x4aabef2324cedff5387f1f65n, 0xbf2ed51fffffff2ff7fedffffe7f5fe5n, + "0xbf2ed51ff75d380fd3be813ec6185780n | 0x4aabef2324cedff5387f1f65n === 0xbf2ed51fffffff2ff7fedffffe7f5fe5n"); +assert.sameValue( + 0x4aabef2324cedff5387f1f65n | 0xbf2ed51ff75d380fd3be813ec6185780n, 0xbf2ed51fffffff2ff7fedffffe7f5fe5n, + "0x4aabef2324cedff5387f1f65n | 0xbf2ed51ff75d380fd3be813ec6185780n === 0xbf2ed51fffffff2ff7fedffffe7f5fe5n"); +assert.sameValue(0n | -1n, -1n, "0n | -1n === -1n"); +assert.sameValue(-1n | 0n, -1n, "-1n | 0n === -1n"); +assert.sameValue(0n | -2n, -2n, "0n | -2n === -2n"); +assert.sameValue(-2n | 0n, -2n, "-2n | 0n === -2n"); +assert.sameValue(1n | -2n, -1n, "1n | -2n === -1n"); +assert.sameValue(-2n | 1n, -1n, "-2n | 1n === -1n"); +assert.sameValue(2n | -2n, -2n, "2n | -2n === -2n"); +assert.sameValue(-2n | 2n, -2n, "-2n | 2n === -2n"); +assert.sameValue(2n | -3n, -1n, "2n | -3n === -1n"); +assert.sameValue(-3n | 2n, -1n, "-3n | 2n === -1n"); +assert.sameValue(-1n | -2n, -1n, "-1n | -2n === -1n"); +assert.sameValue(-2n | -1n, -1n, "-2n | -1n === -1n"); +assert.sameValue(-2n | -2n, -2n, "-2n | -2n === -2n"); +assert.sameValue(-2n | -3n, -1n, "-2n | -3n === -1n"); +assert.sameValue(-3n | -2n, -1n, "-3n | -2n === -1n"); +assert.sameValue(0xffffffffn | -1n, -1n, "0xffffffffn | -1n === -1n"); +assert.sameValue(-1n | 0xffffffffn, -1n, "-1n | 0xffffffffn === -1n"); +assert.sameValue(0xffffffffffffffffn | -1n, -1n, "0xffffffffffffffffn | -1n === -1n"); +assert.sameValue(-1n | 0xffffffffffffffffn, -1n, "-1n | 0xffffffffffffffffn === -1n"); +assert.sameValue( + 0xbf2ed51ff75d380fd3be813ec6185780n | -0x4aabef2324cedff5387f1f65n, -0x8a2c72024405ec138670865n, + "0xbf2ed51ff75d380fd3be813ec6185780n | -0x4aabef2324cedff5387f1f65n === -0x8a2c72024405ec138670865n"); +assert.sameValue( + -0x4aabef2324cedff5387f1f65n | 0xbf2ed51ff75d380fd3be813ec6185780n, -0x8a2c72024405ec138670865n, + "-0x4aabef2324cedff5387f1f65n | 0xbf2ed51ff75d380fd3be813ec6185780n === -0x8a2c72024405ec138670865n"); +assert.sameValue( + -0xbf2ed51ff75d380fd3be813ec6185780n | 0x4aabef2324cedff5387f1f65n, -0xbf2ed51fb554100cd330000ac600401bn, + "-0xbf2ed51ff75d380fd3be813ec6185780n | 0x4aabef2324cedff5387f1f65n === -0xbf2ed51fb554100cd330000ac600401bn"); +assert.sameValue( + 0x4aabef2324cedff5387f1f65n | -0xbf2ed51ff75d380fd3be813ec6185780n, -0xbf2ed51fb554100cd330000ac600401bn, + "0x4aabef2324cedff5387f1f65n | -0xbf2ed51ff75d380fd3be813ec6185780n === -0xbf2ed51fb554100cd330000ac600401bn"); +assert.sameValue( + -0xbf2ed51ff75d380fd3be813ec6185780n | -0x4aabef2324cedff5387f1f65n, -0x42092803008e813400181765n, + "-0xbf2ed51ff75d380fd3be813ec6185780n | -0x4aabef2324cedff5387f1f65n === -0x42092803008e813400181765n"); +assert.sameValue( + -0x4aabef2324cedff5387f1f65n | -0xbf2ed51ff75d380fd3be813ec6185780n, -0x42092803008e813400181765n, + "-0x4aabef2324cedff5387f1f65n | -0xbf2ed51ff75d380fd3be813ec6185780n === -0x42092803008e813400181765n"); +assert.sameValue(-0xffffffffn | 0n, -0xffffffffn, "-0xffffffffn | 0n === -0xffffffffn"); +assert.sameValue(0n | -0xffffffffn, -0xffffffffn, "0n | -0xffffffffn === -0xffffffffn"); +assert.sameValue( + -0xffffffffffffffffn | 0x10000000000000000n, -0xffffffffffffffffn, + "-0xffffffffffffffffn | 0x10000000000000000n === -0xffffffffffffffffn"); +assert.sameValue( + 0x10000000000000000n | -0xffffffffffffffffn, -0xffffffffffffffffn, + "0x10000000000000000n | -0xffffffffffffffffn === -0xffffffffffffffffn"); +assert.sameValue( + -0xffffffffffffffffffffffffn | 0x10000000000000000n, -0xfffffffeffffffffffffffffn, + "-0xffffffffffffffffffffffffn | 0x10000000000000000n === -0xfffffffeffffffffffffffffn"); +assert.sameValue( + 0x10000000000000000n | -0xffffffffffffffffffffffffn, -0xfffffffeffffffffffffffffn, + "0x10000000000000000n | -0xffffffffffffffffffffffffn === -0xfffffffeffffffffffffffffn"); diff --git a/test/language/expressions/bitwise-xor/bigint-non-primitive.js b/test/language/expressions/bitwise-xor/bigint-non-primitive.js new file mode 100644 index 0000000000..2bde84dbe5 --- /dev/null +++ b/test/language/expressions/bitwise-xor/bigint-non-primitive.js @@ -0,0 +1,44 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Bitwise XOR for BigInt non-primitive values +esid: sec-binary-bitwise-operators-runtime-semantics-evaluation +info: | + + 5. Let lnum be ? ToNumeric(lval). + 6. Let rnum be ? ToNumeric(rval). + ... + 8. Let T be Type(lnum). + ... + 11. Otherwise, @ is ^; return T::bitwiseXOR(lnum, rnum). + +features: [BigInt] +---*/ + +assert.sameValue(Object(5n) ^ 3n, 6n, "Object(5n) ^ 3n === 6n"); +assert.sameValue(3n ^ Object(5n), 6n, "3n ^ Object(5n) === 6n"); +assert.sameValue(Object(5n) ^ Object(3n), 6n, "Object(5n) ^ Object(3n) === 6n"); + +function err() { + throw new Test262Error(); +} + +assert.sameValue( + {[Symbol.toPrimitive]: function() { return 5n; }, valueOf: err, toString: err} ^ 3n, 6n, + "primitive from @@toPrimitive"); +assert.sameValue( + 3n ^ {[Symbol.toPrimitive]: function() { return 5n; }, valueOf: err, toString: err}, 6n, + "primitive from @@toPrimitive"); +assert.sameValue( + {valueOf: function() { return 5n; }, toString: err} ^ 3n, 6n, + "primitive from {}.valueOf"); +assert.sameValue( + 3n ^ {valueOf: function() { return 5n; }, toString: err}, 6n, + "primitive from {}.valueOf"); +assert.sameValue( + {toString: function() { return 5n; }} ^ 3n, 6n, + "primitive from {}.toString"); +assert.sameValue( + 3n ^ {toString: function() { return 5n; }}, 6n, + "primitive from {}.toString"); diff --git a/test/language/expressions/bitwise-xor/bigint.js b/test/language/expressions/bitwise-xor/bigint.js new file mode 100644 index 0000000000..867d54523c --- /dev/null +++ b/test/language/expressions/bitwise-xor/bigint.js @@ -0,0 +1,107 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Bitwise XOR for BigInt values +esid: sec-bitwise-op +info: | + BitwiseOp(op, x, y) + + 1. Let result be 0. + 2. Let shift be 0. + 3. Repeat, until (x = 0 or x = -1) and (y = 0 or y = -1), + a. Let xDigit be x modulo 2. + b. Let yDigit be y modulo 2. + c. Let result be result + 2**shift * op(xDigit, yDigit) + d. Let shift be shift + 1. + e. Let x be (x - xDigit) / 2. + f. Let y be (y - yDigit) / 2. + 4. If op(x modulo 2, y modulo 2) ≠ 0, + a. Let result be result - 2**shift. NOTE: This extends the sign. + 5. Return result. + +features: [BigInt] +---*/ + +assert.sameValue(0n ^ 0n, 0n, "0n ^ 0n === 0n"); +assert.sameValue(0n ^ 1n, 1n, "0n ^ 1n === 1n"); +assert.sameValue(1n ^ 0n, 1n, "1n ^ 0n === 1n"); +assert.sameValue(0n ^ 2n, 2n, "0n ^ 2n === 2n"); +assert.sameValue(2n ^ 0n, 2n, "2n ^ 0n === 2n"); +assert.sameValue(0n ^ 3n, 3n, "0n ^ 3n === 3n"); +assert.sameValue(3n ^ 0n, 3n, "3n ^ 0n === 3n"); +assert.sameValue(1n ^ 1n, 0n, "1n ^ 1n === 0n"); +assert.sameValue(1n ^ 2n, 3n, "1n ^ 2n === 3n"); +assert.sameValue(2n ^ 1n, 3n, "2n ^ 1n === 3n"); +assert.sameValue(1n ^ 3n, 2n, "1n ^ 3n === 2n"); +assert.sameValue(3n ^ 1n, 2n, "3n ^ 1n === 2n"); +assert.sameValue(2n ^ 2n, 0n, "2n ^ 2n === 0n"); +assert.sameValue(2n ^ 3n, 1n, "2n ^ 3n === 1n"); +assert.sameValue(3n ^ 2n, 1n, "3n ^ 2n === 1n"); +assert.sameValue(0xffffffffn ^ 0n, 0xffffffffn, "0xffffffffn ^ 0n === 0xffffffffn"); +assert.sameValue(0n ^ 0xffffffffn, 0xffffffffn, "0n ^ 0xffffffffn === 0xffffffffn"); +assert.sameValue(0xffffffffn ^ 0xffffffffn, 0n, "0xffffffffn ^ 0xffffffffn === 0n"); +assert.sameValue(0xffffffffffffffffn ^ 0n, 0xffffffffffffffffn, "0xffffffffffffffffn ^ 0n === 0xffffffffffffffffn"); +assert.sameValue(0n ^ 0xffffffffffffffffn, 0xffffffffffffffffn, "0n ^ 0xffffffffffffffffn === 0xffffffffffffffffn"); +assert.sameValue(0xffffffffffffffffn ^ 0xffffffffn, 0xffffffff00000000n, "0xffffffffffffffffn ^ 0xffffffffn === 0xffffffff00000000n"); +assert.sameValue(0xffffffffn ^ 0xffffffffffffffffn, 0xffffffff00000000n, "0xffffffffn ^ 0xffffffffffffffffn === 0xffffffff00000000n"); +assert.sameValue( + 0xffffffffffffffffn ^ 0xffffffffffffffffn, 0n, + "0xffffffffffffffffn ^ 0xffffffffffffffffn === 0n"); +assert.sameValue( + 0xbf2ed51ff75d380fd3be813ec6185780n ^ 0x4aabef2324cedff5387f1f65n, 0xbf2ed51fbdf6d72cf7705ecbfe6748e5n, + "0xbf2ed51ff75d380fd3be813ec6185780n ^ 0x4aabef2324cedff5387f1f65n === 0xbf2ed51fbdf6d72cf7705ecbfe6748e5n"); +assert.sameValue( + 0x4aabef2324cedff5387f1f65n ^ 0xbf2ed51ff75d380fd3be813ec6185780n, 0xbf2ed51fbdf6d72cf7705ecbfe6748e5n, + "0x4aabef2324cedff5387f1f65n ^ 0xbf2ed51ff75d380fd3be813ec6185780n === 0xbf2ed51fbdf6d72cf7705ecbfe6748e5n"); +assert.sameValue(0n ^ -1n, -1n, "0n ^ -1n === -1n"); +assert.sameValue(-1n ^ 0n, -1n, "-1n ^ 0n === -1n"); +assert.sameValue(0n ^ -2n, -2n, "0n ^ -2n === -2n"); +assert.sameValue(-2n ^ 0n, -2n, "-2n ^ 0n === -2n"); +assert.sameValue(1n ^ -2n, -1n, "1n ^ -2n === -1n"); +assert.sameValue(-2n ^ 1n, -1n, "-2n ^ 1n === -1n"); +assert.sameValue(2n ^ -2n, -4n, "2n ^ -2n === -4n"); +assert.sameValue(-2n ^ 2n, -4n, "-2n ^ 2n === -4n"); +assert.sameValue(2n ^ -3n, -1n, "2n ^ -3n === -1n"); +assert.sameValue(-3n ^ 2n, -1n, "-3n ^ 2n === -1n"); +assert.sameValue(-1n ^ -2n, 1n, "-1n ^ -2n === 1n"); +assert.sameValue(-2n ^ -1n, 1n, "-2n ^ -1n === 1n"); +assert.sameValue(-2n ^ -2n, 0n, "-2n ^ -2n === 0n"); +assert.sameValue(-2n ^ -3n, 3n, "-2n ^ -3n === 3n"); +assert.sameValue(-3n ^ -2n, 3n, "-3n ^ -2n === 3n"); +assert.sameValue(0xffffffffn ^ -1n, -0x100000000n, "0xffffffffn ^ -1n === -0x100000000n"); +assert.sameValue(-1n ^ 0xffffffffn, -0x100000000n, "-1n ^ 0xffffffffn === -0x100000000n"); +assert.sameValue(0xffffffffffffffffn ^ -1n, -0x10000000000000000n, "0xffffffffffffffffn ^ -1n === -0x10000000000000000n"); +assert.sameValue(-1n ^ 0xffffffffffffffffn, -0x10000000000000000n, "-1n ^ 0xffffffffffffffffn === -0x10000000000000000n"); +assert.sameValue( + 0xbf2ed51ff75d380fd3be813ec6185780n ^ -0x4aabef2324cedff5387f1f65n, -0xbf2ed51fbdf6d72cf7705ecbfe6748e5n, + "0xbf2ed51ff75d380fd3be813ec6185780n ^ -0x4aabef2324cedff5387f1f65n === -0xbf2ed51fbdf6d72cf7705ecbfe6748e5n"); +assert.sameValue( + -0x4aabef2324cedff5387f1f65n ^ 0xbf2ed51ff75d380fd3be813ec6185780n, -0xbf2ed51fbdf6d72cf7705ecbfe6748e5n, + "-0x4aabef2324cedff5387f1f65n ^ 0xbf2ed51ff75d380fd3be813ec6185780n === -0xbf2ed51fbdf6d72cf7705ecbfe6748e5n"); +assert.sameValue( + -0xbf2ed51ff75d380fd3be813ec6185780n ^ 0x4aabef2324cedff5387f1f65n, -0xbf2ed51fbdf6d72cf7705ecbfe67481bn, + "-0xbf2ed51ff75d380fd3be813ec6185780n ^ 0x4aabef2324cedff5387f1f65n === -0xbf2ed51fbdf6d72cf7705ecbfe67481bn"); +assert.sameValue( + 0x4aabef2324cedff5387f1f65n ^ -0xbf2ed51ff75d380fd3be813ec6185780n, -0xbf2ed51fbdf6d72cf7705ecbfe67481bn, + "0x4aabef2324cedff5387f1f65n ^ -0xbf2ed51ff75d380fd3be813ec6185780n === -0xbf2ed51fbdf6d72cf7705ecbfe67481bn"); +assert.sameValue( + -0xbf2ed51ff75d380fd3be813ec6185780n ^ -0x4aabef2324cedff5387f1f65n, 0xbf2ed51fbdf6d72cf7705ecbfe67481bn, + "-0xbf2ed51ff75d380fd3be813ec6185780n ^ -0x4aabef2324cedff5387f1f65n === 0xbf2ed51fbdf6d72cf7705ecbfe67481bn"); +assert.sameValue( + -0x4aabef2324cedff5387f1f65n ^ -0xbf2ed51ff75d380fd3be813ec6185780n, 0xbf2ed51fbdf6d72cf7705ecbfe67481bn, + "-0x4aabef2324cedff5387f1f65n ^ -0xbf2ed51ff75d380fd3be813ec6185780n === 0xbf2ed51fbdf6d72cf7705ecbfe67481bn"); +assert.sameValue(-0xffffffffn ^ 0n, -0xffffffffn, "-0xffffffffn ^ 0n === -0xffffffffn"); +assert.sameValue(0n ^ -0xffffffffn, -0xffffffffn, "0n ^ -0xffffffffn === -0xffffffffn"); +assert.sameValue( + -0xffffffffffffffffn ^ 0x10000000000000000n, -0x1ffffffffffffffffn, + "-0xffffffffffffffffn ^ 0x10000000000000000n === -0x1ffffffffffffffffn"); +assert.sameValue( + 0x10000000000000000n ^ -0xffffffffffffffffn, -0x1ffffffffffffffffn, + "0x10000000000000000n ^ -0xffffffffffffffffn === -0x1ffffffffffffffffn"); +assert.sameValue( + -0xffffffffffffffffffffffffn ^ 0x10000000000000000n, -0xfffffffeffffffffffffffffn, + "-0xffffffffffffffffffffffffn ^ 0x10000000000000000n === -0xfffffffeffffffffffffffffn"); +assert.sameValue( + 0x10000000000000000n ^ -0xffffffffffffffffffffffffn, -0xfffffffeffffffffffffffffn, + "0x10000000000000000n ^ -0xffffffffffffffffffffffffn === -0xfffffffeffffffffffffffffn"); From 035e79610d995aef4bcc3fbcf59b9998d7c1459d Mon Sep 17 00:00:00 2001 From: Josh Wolfe Date: Mon, 23 Oct 2017 21:56:00 -0700 Subject: [PATCH 2/2] switch small values to 0b notation --- .../bitwise-and/bigint-non-primitive.js | 18 +++++------ .../expressions/bitwise-and/bigint.js | 30 +++++++++---------- .../bitwise-or/bigint-non-primitive.js | 18 +++++------ .../language/expressions/bitwise-or/bigint.js | 30 +++++++++---------- .../bitwise-xor/bigint-non-primitive.js | 18 +++++------ .../expressions/bitwise-xor/bigint.js | 30 +++++++++---------- 6 files changed, 72 insertions(+), 72 deletions(-) diff --git a/test/language/expressions/bitwise-and/bigint-non-primitive.js b/test/language/expressions/bitwise-and/bigint-non-primitive.js index 1fffb06635..3079500b19 100644 --- a/test/language/expressions/bitwise-and/bigint-non-primitive.js +++ b/test/language/expressions/bitwise-and/bigint-non-primitive.js @@ -15,29 +15,29 @@ info: | features: [BigInt] ---*/ -assert.sameValue(Object(5n) & 3n, 1n, "Object(5n) & 3n === 1n"); -assert.sameValue(3n & Object(5n), 1n, "3n & Object(5n) === 1n"); -assert.sameValue(Object(5n) & Object(3n), 1n, "Object(5n) & Object(3n) === 1n"); +assert.sameValue(Object(0b101n) & 0b011n, 0b001n, "Object(0b101n) & 0b011n === 0b001n"); +assert.sameValue(0b011n & Object(0b101n), 0b001n, "0b011n & Object(0b101n) === 0b001n"); +assert.sameValue(Object(0b101n) & Object(0b011n), 0b001n, "Object(0b101n) & Object(0b011n) === 0b001n"); function err() { throw new Test262Error(); } assert.sameValue( - {[Symbol.toPrimitive]: function() { return 5n; }, valueOf: err, toString: err} & 3n, 1n, + {[Symbol.toPrimitive]: function() { return 0b101n; }, valueOf: err, toString: err} & 0b011n, 0b001n, "primitive from @@toPrimitive"); assert.sameValue( - 3n & {[Symbol.toPrimitive]: function() { return 5n; }, valueOf: err, toString: err}, 1n, + 0b011n & {[Symbol.toPrimitive]: function() { return 0b101n; }, valueOf: err, toString: err}, 0b001n, "primitive from @@toPrimitive"); assert.sameValue( - {valueOf: function() { return 5n; }, toString: err} & 3n, 1n, + {valueOf: function() { return 0b101n; }, toString: err} & 0b011n, 0b001n, "primitive from {}.valueOf"); assert.sameValue( - 3n & {valueOf: function() { return 5n; }, toString: err}, 1n, + 0b011n & {valueOf: function() { return 0b101n; }, toString: err}, 0b001n, "primitive from {}.valueOf"); assert.sameValue( - {toString: function() { return 5n; }} & 3n, 1n, + {toString: function() { return 0b101n; }} & 0b011n, 0b001n, "primitive from {}.toString"); assert.sameValue( - 3n & {toString: function() { return 5n; }}, 1n, + 0b011n & {toString: function() { return 0b101n; }}, 0b001n, "primitive from {}.toString"); diff --git a/test/language/expressions/bitwise-and/bigint.js b/test/language/expressions/bitwise-and/bigint.js index b9de1bebdc..4f6eee641f 100644 --- a/test/language/expressions/bitwise-and/bigint.js +++ b/test/language/expressions/bitwise-and/bigint.js @@ -23,21 +23,21 @@ info: | features: [BigInt] ---*/ -assert.sameValue(0n & 0n, 0n, "0n & 0n === 0n"); -assert.sameValue(0n & 1n, 0n, "0n & 1n === 0n"); -assert.sameValue(1n & 0n, 0n, "1n & 0n === 0n"); -assert.sameValue(0n & 2n, 0n, "0n & 2n === 0n"); -assert.sameValue(2n & 0n, 0n, "2n & 0n === 0n"); -assert.sameValue(0n & 3n, 0n, "0n & 3n === 0n"); -assert.sameValue(3n & 0n, 0n, "3n & 0n === 0n"); -assert.sameValue(1n & 1n, 1n, "1n & 1n === 1n"); -assert.sameValue(1n & 2n, 0n, "1n & 2n === 0n"); -assert.sameValue(2n & 1n, 0n, "2n & 1n === 0n"); -assert.sameValue(1n & 3n, 1n, "1n & 3n === 1n"); -assert.sameValue(3n & 1n, 1n, "3n & 1n === 1n"); -assert.sameValue(2n & 2n, 2n, "2n & 2n === 2n"); -assert.sameValue(2n & 3n, 2n, "2n & 3n === 2n"); -assert.sameValue(3n & 2n, 2n, "3n & 2n === 2n"); +assert.sameValue(0b00n & 0b00n, 0b00n, "0b00n & 0b00n === 0b00n"); +assert.sameValue(0b00n & 0b01n, 0b00n, "0b00n & 0b01n === 0b00n"); +assert.sameValue(0b01n & 0b00n, 0b00n, "0b01n & 0b00n === 0b00n"); +assert.sameValue(0b00n & 0b10n, 0b00n, "0b00n & 0b10n === 0b00n"); +assert.sameValue(0b10n & 0b00n, 0b00n, "0b10n & 0b00n === 0b00n"); +assert.sameValue(0b00n & 0b11n, 0b00n, "0b00n & 0b11n === 0b00n"); +assert.sameValue(0b11n & 0b00n, 0b00n, "0b11n & 0b00n === 0b00n"); +assert.sameValue(0b01n & 0b01n, 0b01n, "0b01n & 0b01n === 0b01n"); +assert.sameValue(0b01n & 0b10n, 0b00n, "0b01n & 0b10n === 0b00n"); +assert.sameValue(0b10n & 0b01n, 0b00n, "0b10n & 0b01n === 0b00n"); +assert.sameValue(0b01n & 0b11n, 0b01n, "0b01n & 0b11n === 0b01n"); +assert.sameValue(0b11n & 0b01n, 0b01n, "0b11n & 0b01n === 0b01n"); +assert.sameValue(0b10n & 0b10n, 0b10n, "0b10n & 0b10n === 0b10n"); +assert.sameValue(0b10n & 0b11n, 0b10n, "0b10n & 0b11n === 0b10n"); +assert.sameValue(0b11n & 0b10n, 0b10n, "0b11n & 0b10n === 0b10n"); assert.sameValue(0xffffffffn & 0n, 0n, "0xffffffffn & 0n === 0n"); assert.sameValue(0n & 0xffffffffn, 0n, "0n & 0xffffffffn === 0n"); assert.sameValue(0xffffffffn & 0xffffffffn, 0xffffffffn, "0xffffffffn & 0xffffffffn === 0xffffffffn"); diff --git a/test/language/expressions/bitwise-or/bigint-non-primitive.js b/test/language/expressions/bitwise-or/bigint-non-primitive.js index c40138590b..66a78bc52b 100644 --- a/test/language/expressions/bitwise-or/bigint-non-primitive.js +++ b/test/language/expressions/bitwise-or/bigint-non-primitive.js @@ -16,29 +16,29 @@ info: | features: [BigInt] ---*/ -assert.sameValue(Object(5n) | 3n, 7n, "Object(5n) | 3n === 7n"); -assert.sameValue(3n | Object(5n), 7n, "3n | Object(5n) === 7n"); -assert.sameValue(Object(5n) | Object(3n), 7n, "Object(5n) | Object(3n) === 7n"); +assert.sameValue(Object(0b101n) | 0b011n, 0b111n, "Object(0b101n) | 0b011n === 0b111n"); +assert.sameValue(0b011n | Object(0b101n), 0b111n, "0b011n | Object(0b101n) === 0b111n"); +assert.sameValue(Object(0b101n) | Object(0b011n), 0b111n, "Object(0b101n) | Object(0b011n) === 0b111n"); function err() { throw new Test262Error(); } assert.sameValue( - {[Symbol.toPrimitive]: function() { return 5n; }, valueOf: err, toString: err} | 3n, 7n, + {[Symbol.toPrimitive]: function() { return 0b101n; }, valueOf: err, toString: err} | 0b011n, 0b111n, "primitive from @@toPrimitive"); assert.sameValue( - 3n | {[Symbol.toPrimitive]: function() { return 5n; }, valueOf: err, toString: err}, 7n, + 0b011n | {[Symbol.toPrimitive]: function() { return 0b101n; }, valueOf: err, toString: err}, 0b111n, "primitive from @@toPrimitive"); assert.sameValue( - {valueOf: function() { return 5n; }, toString: err} | 3n, 7n, + {valueOf: function() { return 0b101n; }, toString: err} | 0b011n, 0b111n, "primitive from {}.valueOf"); assert.sameValue( - 3n | {valueOf: function() { return 5n; }, toString: err}, 7n, + 0b011n | {valueOf: function() { return 0b101n; }, toString: err}, 0b111n, "primitive from {}.valueOf"); assert.sameValue( - {toString: function() { return 5n; }} | 3n, 7n, + {toString: function() { return 0b101n; }} | 0b011n, 0b111n, "primitive from {}.toString"); assert.sameValue( - 3n | {toString: function() { return 5n; }}, 7n, + 0b011n | {toString: function() { return 0b101n; }}, 0b111n, "primitive from {}.toString"); diff --git a/test/language/expressions/bitwise-or/bigint.js b/test/language/expressions/bitwise-or/bigint.js index 81cdd9cace..51aef99401 100644 --- a/test/language/expressions/bitwise-or/bigint.js +++ b/test/language/expressions/bitwise-or/bigint.js @@ -23,21 +23,21 @@ info: | features: [BigInt] ---*/ -assert.sameValue(0n | 0n, 0n, "0n | 0n === 0n"); -assert.sameValue(0n | 1n, 1n, "0n | 1n === 1n"); -assert.sameValue(1n | 0n, 1n, "1n | 0n === 1n"); -assert.sameValue(0n | 2n, 2n, "0n | 2n === 2n"); -assert.sameValue(2n | 0n, 2n, "2n | 0n === 2n"); -assert.sameValue(0n | 3n, 3n, "0n | 3n === 3n"); -assert.sameValue(3n | 0n, 3n, "3n | 0n === 3n"); -assert.sameValue(1n | 1n, 1n, "1n | 1n === 1n"); -assert.sameValue(1n | 2n, 3n, "1n | 2n === 3n"); -assert.sameValue(2n | 1n, 3n, "2n | 1n === 3n"); -assert.sameValue(1n | 3n, 3n, "1n | 3n === 3n"); -assert.sameValue(3n | 1n, 3n, "3n | 1n === 3n"); -assert.sameValue(2n | 2n, 2n, "2n | 2n === 2n"); -assert.sameValue(2n | 3n, 3n, "2n | 3n === 3n"); -assert.sameValue(3n | 2n, 3n, "3n | 2n === 3n"); +assert.sameValue(0b00n | 0b00n, 0b00n, "0b00n | 0b00n === 0b00n"); +assert.sameValue(0b00n | 0b01n, 0b01n, "0b00n | 0b01n === 0b01n"); +assert.sameValue(0b01n | 0b00n, 0b01n, "0b01n | 0b00n === 0b01n"); +assert.sameValue(0b00n | 0b10n, 0b10n, "0b00n | 0b10n === 0b10n"); +assert.sameValue(0b10n | 0b00n, 0b10n, "0b10n | 0b00n === 0b10n"); +assert.sameValue(0b00n | 0b11n, 0b11n, "0b00n | 0b11n === 0b11n"); +assert.sameValue(0b11n | 0b00n, 0b11n, "0b11n | 0b00n === 0b11n"); +assert.sameValue(0b01n | 0b01n, 0b01n, "0b01n | 0b01n === 0b01n"); +assert.sameValue(0b01n | 0b10n, 0b11n, "0b01n | 0b10n === 0b11n"); +assert.sameValue(0b10n | 0b01n, 0b11n, "0b10n | 0b01n === 0b11n"); +assert.sameValue(0b01n | 0b11n, 0b11n, "0b01n | 0b11n === 0b11n"); +assert.sameValue(0b11n | 0b01n, 0b11n, "0b11n | 0b01n === 0b11n"); +assert.sameValue(0b10n | 0b10n, 0b10n, "0b10n | 0b10n === 0b10n"); +assert.sameValue(0b10n | 0b11n, 0b11n, "0b10n | 0b11n === 0b11n"); +assert.sameValue(0b11n | 0b10n, 0b11n, "0b11n | 0b10n === 0b11n"); assert.sameValue(0xffffffffn | 0n, 0xffffffffn, "0xffffffffn | 0n === 0xffffffffn"); assert.sameValue(0n | 0xffffffffn, 0xffffffffn, "0n | 0xffffffffn === 0xffffffffn"); assert.sameValue(0xffffffffn | 0xffffffffn, 0xffffffffn, "0xffffffffn | 0xffffffffn === 0xffffffffn"); diff --git a/test/language/expressions/bitwise-xor/bigint-non-primitive.js b/test/language/expressions/bitwise-xor/bigint-non-primitive.js index 2bde84dbe5..c8558c930e 100644 --- a/test/language/expressions/bitwise-xor/bigint-non-primitive.js +++ b/test/language/expressions/bitwise-xor/bigint-non-primitive.js @@ -16,29 +16,29 @@ info: | features: [BigInt] ---*/ -assert.sameValue(Object(5n) ^ 3n, 6n, "Object(5n) ^ 3n === 6n"); -assert.sameValue(3n ^ Object(5n), 6n, "3n ^ Object(5n) === 6n"); -assert.sameValue(Object(5n) ^ Object(3n), 6n, "Object(5n) ^ Object(3n) === 6n"); +assert.sameValue(Object(0b101n) ^ 0b011n, 0b110n, "Object(0b101n) ^ 0b011n === 0b110n"); +assert.sameValue(0b011n ^ Object(0b101n), 0b110n, "0b011n ^ Object(0b101n) === 0b110n"); +assert.sameValue(Object(0b101n) ^ Object(0b011n), 0b110n, "Object(0b101n) ^ Object(0b011n) === 0b110n"); function err() { throw new Test262Error(); } assert.sameValue( - {[Symbol.toPrimitive]: function() { return 5n; }, valueOf: err, toString: err} ^ 3n, 6n, + {[Symbol.toPrimitive]: function() { return 0b101n; }, valueOf: err, toString: err} ^ 0b011n, 0b110n, "primitive from @@toPrimitive"); assert.sameValue( - 3n ^ {[Symbol.toPrimitive]: function() { return 5n; }, valueOf: err, toString: err}, 6n, + 0b011n ^ {[Symbol.toPrimitive]: function() { return 0b101n; }, valueOf: err, toString: err}, 0b110n, "primitive from @@toPrimitive"); assert.sameValue( - {valueOf: function() { return 5n; }, toString: err} ^ 3n, 6n, + {valueOf: function() { return 0b101n; }, toString: err} ^ 0b011n, 0b110n, "primitive from {}.valueOf"); assert.sameValue( - 3n ^ {valueOf: function() { return 5n; }, toString: err}, 6n, + 0b011n ^ {valueOf: function() { return 0b101n; }, toString: err}, 0b110n, "primitive from {}.valueOf"); assert.sameValue( - {toString: function() { return 5n; }} ^ 3n, 6n, + {toString: function() { return 0b101n; }} ^ 0b011n, 0b110n, "primitive from {}.toString"); assert.sameValue( - 3n ^ {toString: function() { return 5n; }}, 6n, + 0b011n ^ {toString: function() { return 0b101n; }}, 0b110n, "primitive from {}.toString"); diff --git a/test/language/expressions/bitwise-xor/bigint.js b/test/language/expressions/bitwise-xor/bigint.js index 867d54523c..d7679022eb 100644 --- a/test/language/expressions/bitwise-xor/bigint.js +++ b/test/language/expressions/bitwise-xor/bigint.js @@ -23,21 +23,21 @@ info: | features: [BigInt] ---*/ -assert.sameValue(0n ^ 0n, 0n, "0n ^ 0n === 0n"); -assert.sameValue(0n ^ 1n, 1n, "0n ^ 1n === 1n"); -assert.sameValue(1n ^ 0n, 1n, "1n ^ 0n === 1n"); -assert.sameValue(0n ^ 2n, 2n, "0n ^ 2n === 2n"); -assert.sameValue(2n ^ 0n, 2n, "2n ^ 0n === 2n"); -assert.sameValue(0n ^ 3n, 3n, "0n ^ 3n === 3n"); -assert.sameValue(3n ^ 0n, 3n, "3n ^ 0n === 3n"); -assert.sameValue(1n ^ 1n, 0n, "1n ^ 1n === 0n"); -assert.sameValue(1n ^ 2n, 3n, "1n ^ 2n === 3n"); -assert.sameValue(2n ^ 1n, 3n, "2n ^ 1n === 3n"); -assert.sameValue(1n ^ 3n, 2n, "1n ^ 3n === 2n"); -assert.sameValue(3n ^ 1n, 2n, "3n ^ 1n === 2n"); -assert.sameValue(2n ^ 2n, 0n, "2n ^ 2n === 0n"); -assert.sameValue(2n ^ 3n, 1n, "2n ^ 3n === 1n"); -assert.sameValue(3n ^ 2n, 1n, "3n ^ 2n === 1n"); +assert.sameValue(0b00n ^ 0b00n, 0b00n, "0b00n ^ 0b00n === 0b00n"); +assert.sameValue(0b00n ^ 0b01n, 0b01n, "0b00n ^ 0b01n === 0b01n"); +assert.sameValue(0b01n ^ 0b00n, 0b01n, "0b01n ^ 0b00n === 0b01n"); +assert.sameValue(0b00n ^ 0b10n, 0b10n, "0b00n ^ 0b10n === 0b10n"); +assert.sameValue(0b10n ^ 0b00n, 0b10n, "0b10n ^ 0b00n === 0b10n"); +assert.sameValue(0b00n ^ 0b11n, 0b11n, "0b00n ^ 0b11n === 0b11n"); +assert.sameValue(0b11n ^ 0b00n, 0b11n, "0b11n ^ 0b00n === 0b11n"); +assert.sameValue(0b01n ^ 0b01n, 0b00n, "0b01n ^ 0b01n === 0b00n"); +assert.sameValue(0b01n ^ 0b10n, 0b11n, "0b01n ^ 0b10n === 0b11n"); +assert.sameValue(0b10n ^ 0b01n, 0b11n, "0b10n ^ 0b01n === 0b11n"); +assert.sameValue(0b01n ^ 0b11n, 0b10n, "0b01n ^ 0b11n === 0b10n"); +assert.sameValue(0b11n ^ 0b01n, 0b10n, "0b11n ^ 0b01n === 0b10n"); +assert.sameValue(0b10n ^ 0b10n, 0b00n, "0b10n ^ 0b10n === 0b00n"); +assert.sameValue(0b10n ^ 0b11n, 0b01n, "0b10n ^ 0b11n === 0b01n"); +assert.sameValue(0b11n ^ 0b10n, 0b01n, "0b11n ^ 0b10n === 0b01n"); assert.sameValue(0xffffffffn ^ 0n, 0xffffffffn, "0xffffffffn ^ 0n === 0xffffffffn"); assert.sameValue(0n ^ 0xffffffffn, 0xffffffffn, "0n ^ 0xffffffffn === 0xffffffffn"); assert.sameValue(0xffffffffn ^ 0xffffffffn, 0n, "0xffffffffn ^ 0xffffffffn === 0n");