blob: 1fd12980e2928b5fea36fa3c6053c49a17ab5946 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4var callBound = require('call-bind/callBound');
5
6var $TypeError = GetIntrinsic('%TypeError%');
7var $bigIntValueOf = callBound('BigInt.prototype.valueOf', true);
8
9var Type = require('./Type');
10
11// https://262.ecma-international.org/11.0/#sec-thisbigintvalue
12
13module.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};