1
|
'use strict';
|
2
|
|
3
|
/* globals
|
4
|
Atomics,
|
5
|
SharedArrayBuffer,
|
6
|
*/
|
7
|
|
8
|
var undefined;
|
9
|
|
10
|
var $TypeError = TypeError;
|
11
|
|
12
|
var $gOPD = Object.getOwnPropertyDescriptor;
|
13
|
if ($gOPD) {
|
14
|
try {
|
15
|
$gOPD({}, '');
|
16
|
} catch (e) {
|
17
|
$gOPD = null; // this is IE 8, which has a broken gOPD
|
18
|
}
|
19
|
}
|
20
|
|
21
|
var throwTypeError = function () { throw new $TypeError(); };
|
22
|
var ThrowTypeError = $gOPD
|
23
|
? (function () {
|
24
|
try {
|
25
|
// eslint-disable-next-line no-unused-expressions, no-caller, no-restricted-properties
|
26
|
arguments.callee; // IE 8 does not throw here
|
27
|
return throwTypeError;
|
28
|
} catch (calleeThrows) {
|
29
|
try {
|
30
|
// IE 8 throws on Object.getOwnPropertyDescriptor(arguments, '')
|
31
|
return $gOPD(arguments, 'callee').get;
|
32
|
} catch (gOPDthrows) {
|
33
|
return throwTypeError;
|
34
|
}
|
35
|
}
|
36
|
}())
|
37
|
: throwTypeError;
|
38
|
|
39
|
var hasSymbols = require('has-symbols')();
|
40
|
|
41
|
var getProto = Object.getPrototypeOf || function (x) { return x.__proto__; }; // eslint-disable-line no-proto
|
42
|
|
43
|
var generator; // = function * () {};
|
44
|
var generatorFunction = generator ? getProto(generator) : undefined;
|
45
|
var asyncFn; // async function() {};
|
46
|
var asyncFunction = asyncFn ? asyncFn.constructor : undefined;
|
47
|
var asyncGen; // async function * () {};
|
48
|
var asyncGenFunction = asyncGen ? getProto(asyncGen) : undefined;
|
49
|
var asyncGenIterator = asyncGen ? asyncGen() : undefined;
|
50
|
|
51
|
var TypedArray = typeof Uint8Array === 'undefined' ? undefined : getProto(Uint8Array);
|
52
|
|
53
|
var INTRINSICS = {
|
54
|
'%Array%': Array,
|
55
|
'%ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined : ArrayBuffer,
|
56
|
'%ArrayBufferPrototype%': typeof ArrayBuffer === 'undefined' ? undefined : ArrayBuffer.prototype,
|
57
|
'%ArrayIteratorPrototype%': hasSymbols ? getProto([][Symbol.iterator]()) : undefined,
|
58
|
'%ArrayPrototype%': Array.prototype,
|
59
|
'%ArrayProto_entries%': Array.prototype.entries,
|
60
|
'%ArrayProto_forEach%': Array.prototype.forEach,
|
61
|
'%ArrayProto_keys%': Array.prototype.keys,
|
62
|
'%ArrayProto_values%': Array.prototype.values,
|
63
|
'%AsyncFromSyncIteratorPrototype%': undefined,
|
64
|
'%AsyncFunction%': asyncFunction,
|
65
|
'%AsyncFunctionPrototype%': asyncFunction ? asyncFunction.prototype : undefined,
|
66
|
'%AsyncGenerator%': asyncGen ? getProto(asyncGenIterator) : undefined,
|
67
|
'%AsyncGeneratorFunction%': asyncGenFunction,
|
68
|
'%AsyncGeneratorPrototype%': asyncGenFunction ? asyncGenFunction.prototype : undefined,
|
69
|
'%AsyncIteratorPrototype%': asyncGenIterator && hasSymbols && Symbol.asyncIterator ? asyncGenIterator[Symbol.asyncIterator]() : undefined,
|
70
|
'%Atomics%': typeof Atomics === 'undefined' ? undefined : Atomics,
|
71
|
'%Boolean%': Boolean,
|
72
|
'%BooleanPrototype%': Boolean.prototype,
|
73
|
'%DataView%': typeof DataView === 'undefined' ? undefined : DataView,
|
74
|
'%DataViewPrototype%': typeof DataView === 'undefined' ? undefined : DataView.prototype,
|
75
|
'%Date%': Date,
|
76
|
'%DatePrototype%': Date.prototype,
|
77
|
'%decodeURI%': decodeURI,
|
78
|
'%decodeURIComponent%': decodeURIComponent,
|
79
|
'%encodeURI%': encodeURI,
|
80
|
'%encodeURIComponent%': encodeURIComponent,
|
81
|
'%Error%': Error,
|
82
|
'%ErrorPrototype%': Error.prototype,
|
83
|
'%eval%': eval, // eslint-disable-line no-eval
|
84
|
'%EvalError%': EvalError,
|
85
|
'%EvalErrorPrototype%': EvalError.prototype,
|
86
|
'%Float32Array%': typeof Float32Array === 'undefined' ? undefined : Float32Array,
|
87
|
'%Float32ArrayPrototype%': typeof Float32Array === 'undefined' ? undefined : Float32Array.prototype,
|
88
|
'%Float64Array%': typeof Float64Array === 'undefined' ? undefined : Float64Array,
|
89
|
'%Float64ArrayPrototype%': typeof Float64Array === 'undefined' ? undefined : Float64Array.prototype,
|
90
|
'%Function%': Function,
|
91
|
'%FunctionPrototype%': Function.prototype,
|
92
|
'%Generator%': generator ? getProto(generator()) : undefined,
|
93
|
'%GeneratorFunction%': generatorFunction,
|
94
|
'%GeneratorPrototype%': generatorFunction ? generatorFunction.prototype : undefined,
|
95
|
'%Int8Array%': typeof Int8Array === 'undefined' ? undefined : Int8Array,
|
96
|
'%Int8ArrayPrototype%': typeof Int8Array === 'undefined' ? undefined : Int8Array.prototype,
|
97
|
'%Int16Array%': typeof Int16Array === 'undefined' ? undefined : Int16Array,
|
98
|
'%Int16ArrayPrototype%': typeof Int16Array === 'undefined' ? undefined : Int8Array.prototype,
|
99
|
'%Int32Array%': typeof Int32Array === 'undefined' ? undefined : Int32Array,
|
100
|
'%Int32ArrayPrototype%': typeof Int32Array === 'undefined' ? undefined : Int32Array.prototype,
|
101
|
'%isFinite%': isFinite,
|
102
|
'%isNaN%': isNaN,
|
103
|
'%IteratorPrototype%': hasSymbols ? getProto(getProto([][Symbol.iterator]())) : undefined,
|
104
|
'%JSON%': typeof JSON === 'object' ? JSON : undefined,
|
105
|
'%JSONParse%': typeof JSON === 'object' ? JSON.parse : undefined,
|
106
|
'%Map%': typeof Map === 'undefined' ? undefined : Map,
|
107
|
'%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols ? undefined : getProto(new Map()[Symbol.iterator]()),
|
108
|
'%MapPrototype%': typeof Map === 'undefined' ? undefined : Map.prototype,
|
109
|
'%Math%': Math,
|
110
|
'%Number%': Number,
|
111
|
'%NumberPrototype%': Number.prototype,
|
112
|
'%Object%': Object,
|
113
|
'%ObjectPrototype%': Object.prototype,
|
114
|
'%ObjProto_toString%': Object.prototype.toString,
|
115
|
'%ObjProto_valueOf%': Object.prototype.valueOf,
|
116
|
'%parseFloat%': parseFloat,
|
117
|
'%parseInt%': parseInt,
|
118
|
'%Promise%': typeof Promise === 'undefined' ? undefined : Promise,
|
119
|
'%PromisePrototype%': typeof Promise === 'undefined' ? undefined : Promise.prototype,
|
120
|
'%PromiseProto_then%': typeof Promise === 'undefined' ? undefined : Promise.prototype.then,
|
121
|
'%Promise_all%': typeof Promise === 'undefined' ? undefined : Promise.all,
|
122
|
'%Promise_reject%': typeof Promise === 'undefined' ? undefined : Promise.reject,
|
123
|
'%Promise_resolve%': typeof Promise === 'undefined' ? undefined : Promise.resolve,
|
124
|
'%Proxy%': typeof Proxy === 'undefined' ? undefined : Proxy,
|
125
|
'%RangeError%': RangeError,
|
126
|
'%RangeErrorPrototype%': RangeError.prototype,
|
127
|
'%ReferenceError%': ReferenceError,
|
128
|
'%ReferenceErrorPrototype%': ReferenceError.prototype,
|
129
|
'%Reflect%': typeof Reflect === 'undefined' ? undefined : Reflect,
|
130
|
'%RegExp%': RegExp,
|
131
|
'%RegExpPrototype%': RegExp.prototype,
|
132
|
'%Set%': typeof Set === 'undefined' ? undefined : Set,
|
133
|
'%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols ? undefined : getProto(new Set()[Symbol.iterator]()),
|
134
|
'%SetPrototype%': typeof Set === 'undefined' ? undefined : Set.prototype,
|
135
|
'%SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined : SharedArrayBuffer,
|
136
|
'%SharedArrayBufferPrototype%': typeof SharedArrayBuffer === 'undefined' ? undefined : SharedArrayBuffer.prototype,
|
137
|
'%String%': String,
|
138
|
'%StringIteratorPrototype%': hasSymbols ? getProto(''[Symbol.iterator]()) : undefined,
|
139
|
'%StringPrototype%': String.prototype,
|
140
|
'%Symbol%': hasSymbols ? Symbol : undefined,
|
141
|
'%SymbolPrototype%': hasSymbols ? Symbol.prototype : undefined,
|
142
|
'%SyntaxError%': SyntaxError,
|
143
|
'%SyntaxErrorPrototype%': SyntaxError.prototype,
|
144
|
'%ThrowTypeError%': ThrowTypeError,
|
145
|
'%TypedArray%': TypedArray,
|
146
|
'%TypedArrayPrototype%': TypedArray ? TypedArray.prototype : undefined,
|
147
|
'%TypeError%': $TypeError,
|
148
|
'%TypeErrorPrototype%': $TypeError.prototype,
|
149
|
'%Uint8Array%': typeof Uint8Array === 'undefined' ? undefined : Uint8Array,
|
150
|
'%Uint8ArrayPrototype%': typeof Uint8Array === 'undefined' ? undefined : Uint8Array.prototype,
|
151
|
'%Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined : Uint8ClampedArray,
|
152
|
'%Uint8ClampedArrayPrototype%': typeof Uint8ClampedArray === 'undefined' ? undefined : Uint8ClampedArray.prototype,
|
153
|
'%Uint16Array%': typeof Uint16Array === 'undefined' ? undefined : Uint16Array,
|
154
|
'%Uint16ArrayPrototype%': typeof Uint16Array === 'undefined' ? undefined : Uint16Array.prototype,
|
155
|
'%Uint32Array%': typeof Uint32Array === 'undefined' ? undefined : Uint32Array,
|
156
|
'%Uint32ArrayPrototype%': typeof Uint32Array === 'undefined' ? undefined : Uint32Array.prototype,
|
157
|
'%URIError%': URIError,
|
158
|
'%URIErrorPrototype%': URIError.prototype,
|
159
|
'%WeakMap%': typeof WeakMap === 'undefined' ? undefined : WeakMap,
|
160
|
'%WeakMapPrototype%': typeof WeakMap === 'undefined' ? undefined : WeakMap.prototype,
|
161
|
'%WeakSet%': typeof WeakSet === 'undefined' ? undefined : WeakSet,
|
162
|
'%WeakSetPrototype%': typeof WeakSet === 'undefined' ? undefined : WeakSet.prototype
|
163
|
};
|
164
|
|
165
|
var bind = require('function-bind');
|
166
|
var $replace = bind.call(Function.call, String.prototype.replace);
|
167
|
|
168
|
/* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */
|
169
|
var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g;
|
170
|
var reEscapeChar = /\\(\\)?/g; /** Used to match backslashes in property paths. */
|
171
|
var stringToPath = function stringToPath(string) {
|
172
|
var result = [];
|
173
|
$replace(string, rePropName, function (match, number, quote, subString) {
|
174
|
result[result.length] = quote ? $replace(subString, reEscapeChar, '$1') : (number || match);
|
175
|
});
|
176
|
return result;
|
177
|
};
|
178
|
/* end adaptation */
|
179
|
|
180
|
var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) {
|
181
|
if (!(name in INTRINSICS)) {
|
182
|
throw new SyntaxError('intrinsic ' + name + ' does not exist!');
|
183
|
}
|
184
|
|
185
|
// istanbul ignore if // hopefully this is impossible to test :-)
|
186
|
if (typeof INTRINSICS[name] === 'undefined' && !allowMissing) {
|
187
|
throw new $TypeError('intrinsic ' + name + ' exists, but is not available. Please file an issue!');
|
188
|
}
|
189
|
|
190
|
return INTRINSICS[name];
|
191
|
};
|
192
|
|
193
|
module.exports = function GetIntrinsic(name, allowMissing) {
|
194
|
if (typeof name !== 'string' || name.length === 0) {
|
195
|
throw new TypeError('intrinsic name must be a non-empty string');
|
196
|
}
|
197
|
if (arguments.length > 1 && typeof allowMissing !== 'boolean') {
|
198
|
throw new TypeError('"allowMissing" argument must be a boolean');
|
199
|
}
|
200
|
|
201
|
var parts = stringToPath(name);
|
202
|
|
203
|
var value = getBaseIntrinsic('%' + (parts.length > 0 ? parts[0] : '') + '%', allowMissing);
|
204
|
for (var i = 1; i < parts.length; i += 1) {
|
205
|
if (value != null) {
|
206
|
if ($gOPD && (i + 1) >= parts.length) {
|
207
|
var desc = $gOPD(value, parts[i]);
|
208
|
if (!allowMissing && !(parts[i] in value)) {
|
209
|
throw new $TypeError('base intrinsic for ' + name + ' exists, but the property is not available.');
|
210
|
}
|
211
|
value = desc ? (desc.get || desc.value) : value[parts[i]];
|
212
|
} else {
|
213
|
value = value[parts[i]];
|
214
|
}
|
215
|
}
|
216
|
}
|
217
|
return value;
|
218
|
};
|