thisBigIntValue.js 510 B

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