| | |
| | | 'use strict'; |
| | | var DESCRIPTORS = require('../internals/descriptors'); |
| | | var global = require('../internals/global'); |
| | | var uncurryThis = require('../internals/function-uncurry-this'); |
| | | var isForced = require('../internals/is-forced'); |
| | | var redefine = require('../internals/redefine'); |
| | | var defineBuiltIn = require('../internals/define-built-in'); |
| | | var hasOwn = require('../internals/has-own-property'); |
| | | var inheritIfRequired = require('../internals/inherit-if-required'); |
| | | var isPrototypeOf = require('../internals/object-is-prototype-of'); |
| | | var isSymbol = require('../internals/is-symbol'); |
| | | var toPrimitive = require('../internals/to-primitive'); |
| | | var fails = require('../internals/fails'); |
| | |
| | | var NUMBER = 'Number'; |
| | | var NativeNumber = global[NUMBER]; |
| | | var NumberPrototype = NativeNumber.prototype; |
| | | var TypeError = global.TypeError; |
| | | var arraySlice = uncurryThis(''.slice); |
| | | var charCodeAt = uncurryThis(''.charCodeAt); |
| | | |
| | | // `ToNumeric` abstract operation |
| | | // https://tc39.es/ecma262/#sec-tonumeric |
| | | var toNumeric = function (value) { |
| | | var primValue = toPrimitive(value, 'number'); |
| | | return typeof primValue === 'bigint' ? primValue : toNumber(primValue); |
| | | return typeof primValue == 'bigint' ? primValue : toNumber(primValue); |
| | | }; |
| | | |
| | | // `ToNumber` abstract operation |
| | |
| | | if (isSymbol(it)) throw TypeError('Cannot convert a Symbol value to a number'); |
| | | if (typeof it == 'string' && it.length > 2) { |
| | | it = trim(it); |
| | | first = it.charCodeAt(0); |
| | | first = charCodeAt(it, 0); |
| | | if (first === 43 || first === 45) { |
| | | third = it.charCodeAt(2); |
| | | third = charCodeAt(it, 2); |
| | | if (third === 88 || third === 120) return NaN; // Number('+0x1') should be NaN, old V8 fix |
| | | } else if (first === 48) { |
| | | switch (it.charCodeAt(1)) { |
| | | switch (charCodeAt(it, 1)) { |
| | | case 66: case 98: radix = 2; maxCode = 49; break; // fast equal of /^0b[01]+$/i |
| | | case 79: case 111: radix = 8; maxCode = 55; break; // fast equal of /^0o[0-7]+$/i |
| | | default: return +it; |
| | | } |
| | | digits = it.slice(2); |
| | | digits = arraySlice(it, 2); |
| | | length = digits.length; |
| | | for (index = 0; index < length; index++) { |
| | | code = digits.charCodeAt(index); |
| | | code = charCodeAt(digits, index); |
| | | // parseInt parses a string to a first unavailable symbol |
| | | // but ToNumber should return NaN if a string contains unavailable symbols |
| | | if (code < 48 || code > maxCode) return NaN; |
| | |
| | | var n = arguments.length < 1 ? 0 : NativeNumber(toNumeric(value)); |
| | | var dummy = this; |
| | | // check on 1..constructor(foo) case |
| | | return dummy instanceof NumberWrapper && fails(function () { thisNumberValue(dummy); }) |
| | | return isPrototypeOf(NumberPrototype, dummy) && fails(function () { thisNumberValue(dummy); }) |
| | | ? inheritIfRequired(Object(n), dummy, NumberWrapper) : n; |
| | | }; |
| | | for (var keys = DESCRIPTORS ? getOwnPropertyNames(NativeNumber) : ( |
| | |
| | | } |
| | | NumberWrapper.prototype = NumberPrototype; |
| | | NumberPrototype.constructor = NumberWrapper; |
| | | redefine(global, NUMBER, NumberWrapper); |
| | | defineBuiltIn(global, NUMBER, NumberWrapper, { constructor: true }); |
| | | } |