MCPcopy Index your code
hub / github.com/nodejs/node / toNumber

Function toNumber

lib/internal/webidl.js:263–285  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

261 * @returns {number}
262 */
263function 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).

Callers 1

convertToIntFunction · 0.70

Calls 1

makeExceptionFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…