source: imaps-frontend/node_modules/get-intrinsic/index.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 14.0 KB
Line 
1'use strict';
2
3var undefined;
4
5var $Object = require('es-object-atoms');
6
7var $Error = require('es-errors');
8var $EvalError = require('es-errors/eval');
9var $RangeError = require('es-errors/range');
10var $ReferenceError = require('es-errors/ref');
11var $SyntaxError = require('es-errors/syntax');
12var $TypeError = require('es-errors/type');
13var $URIError = require('es-errors/uri');
14
15var abs = require('math-intrinsics/abs');
16var floor = require('math-intrinsics/floor');
17var max = require('math-intrinsics/max');
18var min = require('math-intrinsics/min');
19var pow = require('math-intrinsics/pow');
20var round = require('math-intrinsics/round');
21var sign = require('math-intrinsics/sign');
22
23var $Function = Function;
24
25// eslint-disable-next-line consistent-return
26var getEvalledConstructor = function (expressionSyntax) {
27 try {
28 return $Function('"use strict"; return (' + expressionSyntax + ').constructor;')();
29 } catch (e) {}
30};
31
32var $gOPD = require('gopd');
33var $defineProperty = require('es-define-property');
34
35var throwTypeError = function () {
36 throw new $TypeError();
37};
38var ThrowTypeError = $gOPD
39 ? (function () {
40 try {
41 // eslint-disable-next-line no-unused-expressions, no-caller, no-restricted-properties
42 arguments.callee; // IE 8 does not throw here
43 return throwTypeError;
44 } catch (calleeThrows) {
45 try {
46 // IE 8 throws on Object.getOwnPropertyDescriptor(arguments, '')
47 return $gOPD(arguments, 'callee').get;
48 } catch (gOPDthrows) {
49 return throwTypeError;
50 }
51 }
52 }())
53 : throwTypeError;
54
55var hasSymbols = require('has-symbols')();
56
57var getProto = require('get-proto');
58var $ObjectGPO = require('get-proto/Object.getPrototypeOf');
59var $ReflectGPO = require('get-proto/Reflect.getPrototypeOf');
60
61var $apply = require('call-bind-apply-helpers/functionApply');
62var $call = require('call-bind-apply-helpers/functionCall');
63
64var needsEval = {};
65
66var TypedArray = typeof Uint8Array === 'undefined' || !getProto ? undefined : getProto(Uint8Array);
67
68var INTRINSICS = {
69 __proto__: null,
70 '%AggregateError%': typeof AggregateError === 'undefined' ? undefined : AggregateError,
71 '%Array%': Array,
72 '%ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined : ArrayBuffer,
73 '%ArrayIteratorPrototype%': hasSymbols && getProto ? getProto([][Symbol.iterator]()) : undefined,
74 '%AsyncFromSyncIteratorPrototype%': undefined,
75 '%AsyncFunction%': needsEval,
76 '%AsyncGenerator%': needsEval,
77 '%AsyncGeneratorFunction%': needsEval,
78 '%AsyncIteratorPrototype%': needsEval,
79 '%Atomics%': typeof Atomics === 'undefined' ? undefined : Atomics,
80 '%BigInt%': typeof BigInt === 'undefined' ? undefined : BigInt,
81 '%BigInt64Array%': typeof BigInt64Array === 'undefined' ? undefined : BigInt64Array,
82 '%BigUint64Array%': typeof BigUint64Array === 'undefined' ? undefined : BigUint64Array,
83 '%Boolean%': Boolean,
84 '%DataView%': typeof DataView === 'undefined' ? undefined : DataView,
85 '%Date%': Date,
86 '%decodeURI%': decodeURI,
87 '%decodeURIComponent%': decodeURIComponent,
88 '%encodeURI%': encodeURI,
89 '%encodeURIComponent%': encodeURIComponent,
90 '%Error%': $Error,
91 '%eval%': eval, // eslint-disable-line no-eval
92 '%EvalError%': $EvalError,
93 '%Float32Array%': typeof Float32Array === 'undefined' ? undefined : Float32Array,
94 '%Float64Array%': typeof Float64Array === 'undefined' ? undefined : Float64Array,
95 '%FinalizationRegistry%': typeof FinalizationRegistry === 'undefined' ? undefined : FinalizationRegistry,
96 '%Function%': $Function,
97 '%GeneratorFunction%': needsEval,
98 '%Int8Array%': typeof Int8Array === 'undefined' ? undefined : Int8Array,
99 '%Int16Array%': typeof Int16Array === 'undefined' ? undefined : Int16Array,
100 '%Int32Array%': typeof Int32Array === 'undefined' ? undefined : Int32Array,
101 '%isFinite%': isFinite,
102 '%isNaN%': isNaN,
103 '%IteratorPrototype%': hasSymbols && getProto ? getProto(getProto([][Symbol.iterator]())) : undefined,
104 '%JSON%': typeof JSON === 'object' ? JSON : undefined,
105 '%Map%': typeof Map === 'undefined' ? undefined : Map,
106 '%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols || !getProto ? undefined : getProto(new Map()[Symbol.iterator]()),
107 '%Math%': Math,
108 '%Number%': Number,
109 '%Object%': $Object,
110 '%Object.getOwnPropertyDescriptor%': $gOPD,
111 '%parseFloat%': parseFloat,
112 '%parseInt%': parseInt,
113 '%Promise%': typeof Promise === 'undefined' ? undefined : Promise,
114 '%Proxy%': typeof Proxy === 'undefined' ? undefined : Proxy,
115 '%RangeError%': $RangeError,
116 '%ReferenceError%': $ReferenceError,
117 '%Reflect%': typeof Reflect === 'undefined' ? undefined : Reflect,
118 '%RegExp%': RegExp,
119 '%Set%': typeof Set === 'undefined' ? undefined : Set,
120 '%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols || !getProto ? undefined : getProto(new Set()[Symbol.iterator]()),
121 '%SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined : SharedArrayBuffer,
122 '%String%': String,
123 '%StringIteratorPrototype%': hasSymbols && getProto ? getProto(''[Symbol.iterator]()) : undefined,
124 '%Symbol%': hasSymbols ? Symbol : undefined,
125 '%SyntaxError%': $SyntaxError,
126 '%ThrowTypeError%': ThrowTypeError,
127 '%TypedArray%': TypedArray,
128 '%TypeError%': $TypeError,
129 '%Uint8Array%': typeof Uint8Array === 'undefined' ? undefined : Uint8Array,
130 '%Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined : Uint8ClampedArray,
131 '%Uint16Array%': typeof Uint16Array === 'undefined' ? undefined : Uint16Array,
132 '%Uint32Array%': typeof Uint32Array === 'undefined' ? undefined : Uint32Array,
133 '%URIError%': $URIError,
134 '%WeakMap%': typeof WeakMap === 'undefined' ? undefined : WeakMap,
135 '%WeakRef%': typeof WeakRef === 'undefined' ? undefined : WeakRef,
136 '%WeakSet%': typeof WeakSet === 'undefined' ? undefined : WeakSet,
137
138 '%Function.prototype.call%': $call,
139 '%Function.prototype.apply%': $apply,
140 '%Object.defineProperty%': $defineProperty,
141 '%Object.getPrototypeOf%': $ObjectGPO,
142 '%Math.abs%': abs,
143 '%Math.floor%': floor,
144 '%Math.max%': max,
145 '%Math.min%': min,
146 '%Math.pow%': pow,
147 '%Math.round%': round,
148 '%Math.sign%': sign,
149 '%Reflect.getPrototypeOf%': $ReflectGPO
150};
151
152if (getProto) {
153 try {
154 null.error; // eslint-disable-line no-unused-expressions
155 } catch (e) {
156 // https://github.com/tc39/proposal-shadowrealm/pull/384#issuecomment-1364264229
157 var errorProto = getProto(getProto(e));
158 INTRINSICS['%Error.prototype%'] = errorProto;
159 }
160}
161
162var doEval = function doEval(name) {
163 var value;
164 if (name === '%AsyncFunction%') {
165 value = getEvalledConstructor('async function () {}');
166 } else if (name === '%GeneratorFunction%') {
167 value = getEvalledConstructor('function* () {}');
168 } else if (name === '%AsyncGeneratorFunction%') {
169 value = getEvalledConstructor('async function* () {}');
170 } else if (name === '%AsyncGenerator%') {
171 var fn = doEval('%AsyncGeneratorFunction%');
172 if (fn) {
173 value = fn.prototype;
174 }
175 } else if (name === '%AsyncIteratorPrototype%') {
176 var gen = doEval('%AsyncGenerator%');
177 if (gen && getProto) {
178 value = getProto(gen.prototype);
179 }
180 }
181
182 INTRINSICS[name] = value;
183
184 return value;
185};
186
187var LEGACY_ALIASES = {
188 __proto__: null,
189 '%ArrayBufferPrototype%': ['ArrayBuffer', 'prototype'],
190 '%ArrayPrototype%': ['Array', 'prototype'],
191 '%ArrayProto_entries%': ['Array', 'prototype', 'entries'],
192 '%ArrayProto_forEach%': ['Array', 'prototype', 'forEach'],
193 '%ArrayProto_keys%': ['Array', 'prototype', 'keys'],
194 '%ArrayProto_values%': ['Array', 'prototype', 'values'],
195 '%AsyncFunctionPrototype%': ['AsyncFunction', 'prototype'],
196 '%AsyncGenerator%': ['AsyncGeneratorFunction', 'prototype'],
197 '%AsyncGeneratorPrototype%': ['AsyncGeneratorFunction', 'prototype', 'prototype'],
198 '%BooleanPrototype%': ['Boolean', 'prototype'],
199 '%DataViewPrototype%': ['DataView', 'prototype'],
200 '%DatePrototype%': ['Date', 'prototype'],
201 '%ErrorPrototype%': ['Error', 'prototype'],
202 '%EvalErrorPrototype%': ['EvalError', 'prototype'],
203 '%Float32ArrayPrototype%': ['Float32Array', 'prototype'],
204 '%Float64ArrayPrototype%': ['Float64Array', 'prototype'],
205 '%FunctionPrototype%': ['Function', 'prototype'],
206 '%Generator%': ['GeneratorFunction', 'prototype'],
207 '%GeneratorPrototype%': ['GeneratorFunction', 'prototype', 'prototype'],
208 '%Int8ArrayPrototype%': ['Int8Array', 'prototype'],
209 '%Int16ArrayPrototype%': ['Int16Array', 'prototype'],
210 '%Int32ArrayPrototype%': ['Int32Array', 'prototype'],
211 '%JSONParse%': ['JSON', 'parse'],
212 '%JSONStringify%': ['JSON', 'stringify'],
213 '%MapPrototype%': ['Map', 'prototype'],
214 '%NumberPrototype%': ['Number', 'prototype'],
215 '%ObjectPrototype%': ['Object', 'prototype'],
216 '%ObjProto_toString%': ['Object', 'prototype', 'toString'],
217 '%ObjProto_valueOf%': ['Object', 'prototype', 'valueOf'],
218 '%PromisePrototype%': ['Promise', 'prototype'],
219 '%PromiseProto_then%': ['Promise', 'prototype', 'then'],
220 '%Promise_all%': ['Promise', 'all'],
221 '%Promise_reject%': ['Promise', 'reject'],
222 '%Promise_resolve%': ['Promise', 'resolve'],
223 '%RangeErrorPrototype%': ['RangeError', 'prototype'],
224 '%ReferenceErrorPrototype%': ['ReferenceError', 'prototype'],
225 '%RegExpPrototype%': ['RegExp', 'prototype'],
226 '%SetPrototype%': ['Set', 'prototype'],
227 '%SharedArrayBufferPrototype%': ['SharedArrayBuffer', 'prototype'],
228 '%StringPrototype%': ['String', 'prototype'],
229 '%SymbolPrototype%': ['Symbol', 'prototype'],
230 '%SyntaxErrorPrototype%': ['SyntaxError', 'prototype'],
231 '%TypedArrayPrototype%': ['TypedArray', 'prototype'],
232 '%TypeErrorPrototype%': ['TypeError', 'prototype'],
233 '%Uint8ArrayPrototype%': ['Uint8Array', 'prototype'],
234 '%Uint8ClampedArrayPrototype%': ['Uint8ClampedArray', 'prototype'],
235 '%Uint16ArrayPrototype%': ['Uint16Array', 'prototype'],
236 '%Uint32ArrayPrototype%': ['Uint32Array', 'prototype'],
237 '%URIErrorPrototype%': ['URIError', 'prototype'],
238 '%WeakMapPrototype%': ['WeakMap', 'prototype'],
239 '%WeakSetPrototype%': ['WeakSet', 'prototype']
240};
241
242var bind = require('function-bind');
243var hasOwn = require('hasown');
244var $concat = bind.call($call, Array.prototype.concat);
245var $spliceApply = bind.call($apply, Array.prototype.splice);
246var $replace = bind.call($call, String.prototype.replace);
247var $strSlice = bind.call($call, String.prototype.slice);
248var $exec = bind.call($call, RegExp.prototype.exec);
249
250/* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */
251var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g;
252var reEscapeChar = /\\(\\)?/g; /** Used to match backslashes in property paths. */
253var stringToPath = function stringToPath(string) {
254 var first = $strSlice(string, 0, 1);
255 var last = $strSlice(string, -1);
256 if (first === '%' && last !== '%') {
257 throw new $SyntaxError('invalid intrinsic syntax, expected closing `%`');
258 } else if (last === '%' && first !== '%') {
259 throw new $SyntaxError('invalid intrinsic syntax, expected opening `%`');
260 }
261 var result = [];
262 $replace(string, rePropName, function (match, number, quote, subString) {
263 result[result.length] = quote ? $replace(subString, reEscapeChar, '$1') : number || match;
264 });
265 return result;
266};
267/* end adaptation */
268
269var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) {
270 var intrinsicName = name;
271 var alias;
272 if (hasOwn(LEGACY_ALIASES, intrinsicName)) {
273 alias = LEGACY_ALIASES[intrinsicName];
274 intrinsicName = '%' + alias[0] + '%';
275 }
276
277 if (hasOwn(INTRINSICS, intrinsicName)) {
278 var value = INTRINSICS[intrinsicName];
279 if (value === needsEval) {
280 value = doEval(intrinsicName);
281 }
282 if (typeof value === 'undefined' && !allowMissing) {
283 throw new $TypeError('intrinsic ' + name + ' exists, but is not available. Please file an issue!');
284 }
285
286 return {
287 alias: alias,
288 name: intrinsicName,
289 value: value
290 };
291 }
292
293 throw new $SyntaxError('intrinsic ' + name + ' does not exist!');
294};
295
296module.exports = function GetIntrinsic(name, allowMissing) {
297 if (typeof name !== 'string' || name.length === 0) {
298 throw new $TypeError('intrinsic name must be a non-empty string');
299 }
300 if (arguments.length > 1 && typeof allowMissing !== 'boolean') {
301 throw new $TypeError('"allowMissing" argument must be a boolean');
302 }
303
304 if ($exec(/^%?[^%]*%?$/, name) === null) {
305 throw new $SyntaxError('`%` may not be present anywhere but at the beginning and end of the intrinsic name');
306 }
307 var parts = stringToPath(name);
308 var intrinsicBaseName = parts.length > 0 ? parts[0] : '';
309
310 var intrinsic = getBaseIntrinsic('%' + intrinsicBaseName + '%', allowMissing);
311 var intrinsicRealName = intrinsic.name;
312 var value = intrinsic.value;
313 var skipFurtherCaching = false;
314
315 var alias = intrinsic.alias;
316 if (alias) {
317 intrinsicBaseName = alias[0];
318 $spliceApply(parts, $concat([0, 1], alias));
319 }
320
321 for (var i = 1, isOwn = true; i < parts.length; i += 1) {
322 var part = parts[i];
323 var first = $strSlice(part, 0, 1);
324 var last = $strSlice(part, -1);
325 if (
326 (
327 (first === '"' || first === "'" || first === '`')
328 || (last === '"' || last === "'" || last === '`')
329 )
330 && first !== last
331 ) {
332 throw new $SyntaxError('property names with quotes must have matching quotes');
333 }
334 if (part === 'constructor' || !isOwn) {
335 skipFurtherCaching = true;
336 }
337
338 intrinsicBaseName += '.' + part;
339 intrinsicRealName = '%' + intrinsicBaseName + '%';
340
341 if (hasOwn(INTRINSICS, intrinsicRealName)) {
342 value = INTRINSICS[intrinsicRealName];
343 } else if (value != null) {
344 if (!(part in value)) {
345 if (!allowMissing) {
346 throw new $TypeError('base intrinsic for ' + name + ' exists, but the property is not available.');
347 }
348 return void undefined;
349 }
350 if ($gOPD && (i + 1) >= parts.length) {
351 var desc = $gOPD(value, part);
352 isOwn = !!desc;
353
354 // By convention, when a data property is converted to an accessor
355 // property to emulate a data property that does not suffer from
356 // the override mistake, that accessor's getter is marked with
357 // an `originalValue` property. Here, when we detect this, we
358 // uphold the illusion by pretending to see that original data
359 // property, i.e., returning the value rather than the getter
360 // itself.
361 if (isOwn && 'get' in desc && !('originalValue' in desc.get)) {
362 value = desc.get;
363 } else {
364 value = value[part];
365 }
366 } else {
367 isOwn = hasOwn(value, part);
368 value = value[part];
369 }
370
371 if (isOwn && !skipFurtherCaching) {
372 INTRINSICS[intrinsicRealName] = value;
373 }
374 }
375 }
376 return value;
377};
Note: See TracBrowser for help on using the repository browser.