diff options
Diffstat (limited to 'src/node_modules/es-abstract/2020/BigIntBitwiseOp.js')
-rw-r--r-- | src/node_modules/es-abstract/2020/BigIntBitwiseOp.js | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/node_modules/es-abstract/2020/BigIntBitwiseOp.js b/src/node_modules/es-abstract/2020/BigIntBitwiseOp.js new file mode 100644 index 0000000..6d5cee6 --- /dev/null +++ b/src/node_modules/es-abstract/2020/BigIntBitwiseOp.js @@ -0,0 +1,66 @@ +'use strict'; + +var GetIntrinsic = require('../GetIntrinsic'); + +var $TypeError = GetIntrinsic('%TypeError%'); +// var $BigInt = GetIntrinsic('%BigInt%', true); +// var $pow = GetIntrinsic('%Math.pow%'); + +// var BinaryAnd = require('./BinaryAnd'); +// var BinaryOr = require('./BinaryOr'); +// var BinaryXor = require('./BinaryXor'); +var Type = require('./Type'); +// var modulo = require('./modulo'); + +// var zero = $BigInt && $BigInt(0); +// var negOne = $BigInt && $BigInt(-1); +// var two = $BigInt && $BigInt(2); + +// https://www.ecma-international.org/ecma-262/11.0/#sec-bigintbitwiseop + +module.exports = function BigIntBitwiseOp(op, x, y) { + if (op !== '&' && op !== '|' && op !== '^') { + throw new $TypeError('Assertion failed: `op` must be `&`, `|`, or `^`'); + } + if (Type(x) !== 'BigInt' || Type(y) !== 'BigInt') { + throw new $TypeError('`x` and `y` must be BigInts'); + } + + if (op === '&') { + return x & y; + } + if (op === '|') { + return x | y; + } + return x ^ y; + /* + var result = zero; + var shift = 0; + while (x !== zero && x !== negOne && y !== zero && y !== negOne) { + var xDigit = modulo(x, two); + var yDigit = modulo(y, two); + if (op === '&') { + result += $pow(2, shift) * BinaryAnd(xDigit, yDigit); + } else if (op === '|') { + result += $pow(2, shift) * BinaryOr(xDigit, yDigit); + } else if (op === '^') { + result += $pow(2, shift) * BinaryXor(xDigit, yDigit); + } + shift += 1; + x = (x - xDigit) / two; + y = (y - yDigit) / two; + } + var tmp; + if (op === '&') { + tmp = BinaryAnd(modulo(x, two), modulo(y, two)); + } else if (op === '|') { + tmp = BinaryAnd(modulo(x, two), modulo(y, two)); + } else { + tmp = BinaryXor(modulo(x, two), modulo(y, two)); + } + if (tmp !== 0) { + result -= $pow(2, shift); + } + return result; + */ +}; |