| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | 'use strict'; |
| 2 | |
| 3 | var GetIntrinsic = require('get-intrinsic'); |
| 4 | var callBound = require('call-bind/callBound'); |
| 5 | |
| 6 | var $TypeError = GetIntrinsic('%TypeError%'); |
| 7 | var $bigIntValueOf = callBound('BigInt.prototype.valueOf', true); |
| 8 | |
| 9 | var Type = require('./Type'); |
| 10 | |
| 11 | // https://262.ecma-international.org/11.0/#sec-thisbigintvalue |
| 12 | |
| 13 | module.exports = function thisBigIntValue(value) { |
| 14 | var type = Type(value); |
| 15 | if (type === 'BigInt') { |
| 16 | return value; |
| 17 | } |
| 18 | if (!$bigIntValueOf) { |
| 19 | throw new $TypeError('BigInt is not supported'); |
| 20 | } |
| 21 | return $bigIntValueOf(value); |
| 22 | }; |