* Returns ToNumber(V). * @see https://tc39.es/ecma262/#sec-tonumber * @param {any} V JavaScript value. * @param {ConversionOptions} [options] Conversion options. * @returns {number}
(V, options = kEmptyObject)
| 261 | * @returns {number} |
| 262 | */ |
| 263 | function toNumber(V, options = kEmptyObject) { |
| 264 | if (typeof V === 'bigint') { |
| 265 | // ECMA-262 ToNumber step 2: BigInt values throw. |
| 266 | throw makeException( |
| 267 | 'is a BigInt and cannot be converted to a number.', |
| 268 | options); |
| 269 | } |
| 270 | if (typeof V === 'symbol') { |
| 271 | // ECMA-262 ToNumber step 2: Symbol values throw. |
| 272 | throw makeException( |
| 273 | 'is a Symbol and cannot be converted to a number.', |
| 274 | options); |
| 275 | } |
| 276 | |
| 277 | // Unary plus performs ToNumber, including ToPrimitive(V, number) for |
| 278 | // objects. Number(V) is not equivalent because it converts BigInt values, |
| 279 | // including BigInt values produced by ToPrimitive. |
| 280 | // Abrupt completions and native TypeErrors propagate unchanged. This is an |
| 281 | // intentional diagnostics tradeoff: decorating object conversion failures |
| 282 | // would require maintaining local ECMA-262 ToPrimitive and |
| 283 | // OrdinaryToPrimitive implementations. |
| 284 | return +V; |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * Returns ToString(V). |
no test coverage detected
searching dependent graphs…