thisBigIntValue.js 557 B

12345678910111213141516171819202122
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var callBound = require('call-bind/callBound');
  4. var $SyntaxError = GetIntrinsic('%SyntaxError%');
  5. var $bigIntValueOf = callBound('BigInt.prototype.valueOf', true);
  6. var Type = require('./Type');
  7. // https://262.ecma-international.org/11.0/#sec-thisbigintvalue
  8. module.exports = function thisBigIntValue(value) {
  9. var type = Type(value);
  10. if (type === 'BigInt') {
  11. return value;
  12. }
  13. if (!$bigIntValueOf) {
  14. throw new $SyntaxError('BigInt is not supported');
  15. }
  16. return $bigIntValueOf(value);
  17. };