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