source: trip-planner-front/node_modules/core-js/modules/es.number.constructor.js@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.6 KB
Line 
1'use strict';
2var DESCRIPTORS = require('../internals/descriptors');
3var global = require('../internals/global');
4var isForced = require('../internals/is-forced');
5var redefine = require('../internals/redefine');
6var has = require('../internals/has');
7var classof = require('../internals/classof-raw');
8var inheritIfRequired = require('../internals/inherit-if-required');
9var isSymbol = require('../internals/is-symbol');
10var toPrimitive = require('../internals/to-primitive');
11var fails = require('../internals/fails');
12var create = require('../internals/object-create');
13var getOwnPropertyNames = require('../internals/object-get-own-property-names').f;
14var getOwnPropertyDescriptor = require('../internals/object-get-own-property-descriptor').f;
15var defineProperty = require('../internals/object-define-property').f;
16var trim = require('../internals/string-trim').trim;
17
18var NUMBER = 'Number';
19var NativeNumber = global[NUMBER];
20var NumberPrototype = NativeNumber.prototype;
21
22// Opera ~12 has broken Object#toString
23var BROKEN_CLASSOF = classof(create(NumberPrototype)) == NUMBER;
24
25// `ToNumber` abstract operation
26// https://tc39.es/ecma262/#sec-tonumber
27var toNumber = function (argument) {
28 if (isSymbol(argument)) throw TypeError('Cannot convert a Symbol value to a number');
29 var it = toPrimitive(argument, 'number');
30 var first, third, radix, maxCode, digits, length, index, code;
31 if (typeof it == 'string' && it.length > 2) {
32 it = trim(it);
33 first = it.charCodeAt(0);
34 if (first === 43 || first === 45) {
35 third = it.charCodeAt(2);
36 if (third === 88 || third === 120) return NaN; // Number('+0x1') should be NaN, old V8 fix
37 } else if (first === 48) {
38 switch (it.charCodeAt(1)) {
39 case 66: case 98: radix = 2; maxCode = 49; break; // fast equal of /^0b[01]+$/i
40 case 79: case 111: radix = 8; maxCode = 55; break; // fast equal of /^0o[0-7]+$/i
41 default: return +it;
42 }
43 digits = it.slice(2);
44 length = digits.length;
45 for (index = 0; index < length; index++) {
46 code = digits.charCodeAt(index);
47 // parseInt parses a string to a first unavailable symbol
48 // but ToNumber should return NaN if a string contains unavailable symbols
49 if (code < 48 || code > maxCode) return NaN;
50 } return parseInt(digits, radix);
51 }
52 } return +it;
53};
54
55// `Number` constructor
56// https://tc39.es/ecma262/#sec-number-constructor
57if (isForced(NUMBER, !NativeNumber(' 0o1') || !NativeNumber('0b1') || NativeNumber('+0x1'))) {
58 var NumberWrapper = function Number(value) {
59 var it = arguments.length < 1 ? 0 : value;
60 var dummy = this;
61 return dummy instanceof NumberWrapper
62 // check on 1..constructor(foo) case
63 && (BROKEN_CLASSOF ? fails(function () { NumberPrototype.valueOf.call(dummy); }) : classof(dummy) != NUMBER)
64 ? inheritIfRequired(new NativeNumber(toNumber(it)), dummy, NumberWrapper) : toNumber(it);
65 };
66 for (var keys = DESCRIPTORS ? getOwnPropertyNames(NativeNumber) : (
67 // ES3:
68 'MAX_VALUE,MIN_VALUE,NaN,NEGATIVE_INFINITY,POSITIVE_INFINITY,' +
69 // ES2015 (in case, if modules with ES2015 Number statics required before):
70 'EPSILON,isFinite,isInteger,isNaN,isSafeInteger,MAX_SAFE_INTEGER,' +
71 'MIN_SAFE_INTEGER,parseFloat,parseInt,isInteger,' +
72 // ESNext
73 'fromString,range'
74 ).split(','), j = 0, key; keys.length > j; j++) {
75 if (has(NativeNumber, key = keys[j]) && !has(NumberWrapper, key)) {
76 defineProperty(NumberWrapper, key, getOwnPropertyDescriptor(NativeNumber, key));
77 }
78 }
79 NumberWrapper.prototype = NumberPrototype;
80 NumberPrototype.constructor = NumberWrapper;
81 redefine(global, NUMBER, NumberWrapper);
82}
Note: See TracBrowser for help on using the repository browser.