bitwiseNOT.js 578 B

12345678910111213141516171819
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $TypeError = GetIntrinsic('%TypeError%');
  4. var ToInt32 = require('../ToInt32');
  5. var Type = require('../Type');
  6. // https://262.ecma-international.org/11.0/#sec-numeric-types-number-bitwiseNOT
  7. module.exports = function NumberBitwiseNOT(x) {
  8. if (Type(x) !== 'Number') {
  9. throw new $TypeError('Assertion failed: `x` argument must be a Number');
  10. }
  11. var oldValue = ToInt32(x);
  12. // Return the result of applying the bitwise operator op to lnum and rnum. The result is a signed 32-bit integer.
  13. return ~oldValue;
  14. };