1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- 'use strict';
- var DESCRIPTORS = require('../internals/descriptors');
- var global = require('../internals/global');
- var isForced = require('../internals/is-forced');
- var redefine = require('../internals/redefine');
- var has = require('../internals/has');
- var classof = require('../internals/classof-raw');
- var inheritIfRequired = require('../internals/inherit-if-required');
- var toPrimitive = require('../internals/to-primitive');
- var fails = require('../internals/fails');
- var create = require('../internals/object-create');
- var getOwnPropertyNames = require('../internals/object-get-own-property-names').f;
- var getOwnPropertyDescriptor = require('../internals/object-get-own-property-descriptor').f;
- var defineProperty = require('../internals/object-define-property').f;
- var trim = require('../internals/string-trim').trim;
- var NUMBER = 'Number';
- var NativeNumber = global[NUMBER];
- var NumberPrototype = NativeNumber.prototype;
- var BROKEN_CLASSOF = classof(create(NumberPrototype)) == NUMBER;
- var toNumber = function (argument) {
- var it = toPrimitive(argument, false);
- var first, third, radix, maxCode, digits, length, index, code;
- if (typeof it == 'string' && it.length > 2) {
- it = trim(it);
- first = it.charCodeAt(0);
- if (first === 43 || first === 45) {
- third = it.charCodeAt(2);
- if (third === 88 || third === 120) return NaN;
- } else if (first === 48) {
- switch (it.charCodeAt(1)) {
- case 66: case 98: radix = 2; maxCode = 49; break;
- case 79: case 111: radix = 8; maxCode = 55; break;
- default: return +it;
- }
- digits = it.slice(2);
- length = digits.length;
- for (index = 0; index < length; index++) {
- code = digits.charCodeAt(index);
-
-
- if (code < 48 || code > maxCode) return NaN;
- } return parseInt(digits, radix);
- }
- } return +it;
- };
- if (isForced(NUMBER, !NativeNumber(' 0o1') || !NativeNumber('0b1') || NativeNumber('+0x1'))) {
- var NumberWrapper = function Number(value) {
- var it = arguments.length < 1 ? 0 : value;
- var dummy = this;
- return dummy instanceof NumberWrapper
-
- && (BROKEN_CLASSOF ? fails(function () { NumberPrototype.valueOf.call(dummy); }) : classof(dummy) != NUMBER)
- ? inheritIfRequired(new NativeNumber(toNumber(it)), dummy, NumberWrapper) : toNumber(it);
- };
- for (var keys = DESCRIPTORS ? getOwnPropertyNames(NativeNumber) : (
-
- 'MAX_VALUE,MIN_VALUE,NaN,NEGATIVE_INFINITY,POSITIVE_INFINITY,' +
-
- 'EPSILON,isFinite,isInteger,isNaN,isSafeInteger,MAX_SAFE_INTEGER,' +
- 'MIN_SAFE_INTEGER,parseFloat,parseInt,isInteger,' +
-
- 'fromString,range'
- ).split(','), j = 0, key; keys.length > j; j++) {
- if (has(NativeNumber, key = keys[j]) && !has(NumberWrapper, key)) {
- defineProperty(NumberWrapper, key, getOwnPropertyDescriptor(NativeNumber, key));
- }
- }
- NumberWrapper.prototype = NumberPrototype;
- NumberPrototype.constructor = NumberWrapper;
- redefine(global, NUMBER, NumberWrapper);
- }
|