• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3/* globals
4	Set,
5	Map,
6	WeakSet,
7	WeakMap,
8
9	Promise,
10
11	Symbol,
12	Proxy,
13
14	Atomics,
15	SharedArrayBuffer,
16
17	ArrayBuffer,
18	DataView,
19	Uint8Array,
20	Float32Array,
21	Float64Array,
22	Int8Array,
23	Int16Array,
24	Int32Array,
25	Uint8ClampedArray,
26	Uint16Array,
27	Uint32Array,
28*/
29
30var undefined; // eslint-disable-line no-shadow-restricted-names
31
32var ThrowTypeError = Object.getOwnPropertyDescriptor
33	? (function () { return Object.getOwnPropertyDescriptor(arguments, 'callee').get; }())
34	: function () { throw new TypeError(); };
35
36var hasSymbols = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol';
37
38var getProto = Object.getPrototypeOf || function (x) { return x.__proto__; }; // eslint-disable-line no-proto
39
40var generator; // = function * () {};
41var generatorFunction = generator ? getProto(generator) : undefined;
42var asyncFn; // async function() {};
43var asyncFunction = asyncFn ? asyncFn.constructor : undefined;
44var asyncGen; // async function * () {};
45var asyncGenFunction = asyncGen ? getProto(asyncGen) : undefined;
46var asyncGenIterator = asyncGen ? asyncGen() : undefined;
47
48var TypedArray = typeof Uint8Array === 'undefined' ? undefined : getProto(Uint8Array);
49
50var INTRINSICS = {
51	'$ %Array%': Array,
52	'$ %ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined : ArrayBuffer,
53	'$ %ArrayBufferPrototype%': typeof ArrayBuffer === 'undefined' ? undefined : ArrayBuffer.prototype,
54	'$ %ArrayIteratorPrototype%': hasSymbols ? getProto([][Symbol.iterator]()) : undefined,
55	'$ %ArrayPrototype%': Array.prototype,
56	'$ %ArrayProto_entries%': Array.prototype.entries,
57	'$ %ArrayProto_forEach%': Array.prototype.forEach,
58	'$ %ArrayProto_keys%': Array.prototype.keys,
59	'$ %ArrayProto_values%': Array.prototype.values,
60	'$ %AsyncFromSyncIteratorPrototype%': undefined,
61	'$ %AsyncFunction%': asyncFunction,
62	'$ %AsyncFunctionPrototype%': asyncFunction ? asyncFunction.prototype : undefined,
63	'$ %AsyncGenerator%': asyncGen ? getProto(asyncGenIterator) : undefined,
64	'$ %AsyncGeneratorFunction%': asyncGenFunction,
65	'$ %AsyncGeneratorPrototype%': asyncGenFunction ? asyncGenFunction.prototype : undefined,
66	'$ %AsyncIteratorPrototype%': asyncGenIterator && hasSymbols && Symbol.asyncIterator ? asyncGenIterator[Symbol.asyncIterator]() : undefined,
67	'$ %Atomics%': typeof Atomics === 'undefined' ? undefined : Atomics,
68	'$ %Boolean%': Boolean,
69	'$ %BooleanPrototype%': Boolean.prototype,
70	'$ %DataView%': typeof DataView === 'undefined' ? undefined : DataView,
71	'$ %DataViewPrototype%': typeof DataView === 'undefined' ? undefined : DataView.prototype,
72	'$ %Date%': Date,
73	'$ %DatePrototype%': Date.prototype,
74	'$ %decodeURI%': decodeURI,
75	'$ %decodeURIComponent%': decodeURIComponent,
76	'$ %encodeURI%': encodeURI,
77	'$ %encodeURIComponent%': encodeURIComponent,
78	'$ %Error%': Error,
79	'$ %ErrorPrototype%': Error.prototype,
80	'$ %eval%': eval, // eslint-disable-line no-eval
81	'$ %EvalError%': EvalError,
82	'$ %EvalErrorPrototype%': EvalError.prototype,
83	'$ %Float32Array%': typeof Float32Array === 'undefined' ? undefined : Float32Array,
84	'$ %Float32ArrayPrototype%': typeof Float32Array === 'undefined' ? undefined : Float32Array.prototype,
85	'$ %Float64Array%': typeof Float64Array === 'undefined' ? undefined : Float64Array,
86	'$ %Float64ArrayPrototype%': typeof Float64Array === 'undefined' ? undefined : Float64Array.prototype,
87	'$ %Function%': Function,
88	'$ %FunctionPrototype%': Function.prototype,
89	'$ %Generator%': generator ? getProto(generator()) : undefined,
90	'$ %GeneratorFunction%': generatorFunction,
91	'$ %GeneratorPrototype%': generatorFunction ? generatorFunction.prototype : undefined,
92	'$ %Int8Array%': typeof Int8Array === 'undefined' ? undefined : Int8Array,
93	'$ %Int8ArrayPrototype%': typeof Int8Array === 'undefined' ? undefined : Int8Array.prototype,
94	'$ %Int16Array%': typeof Int16Array === 'undefined' ? undefined : Int16Array,
95	'$ %Int16ArrayPrototype%': typeof Int16Array === 'undefined' ? undefined : Int8Array.prototype,
96	'$ %Int32Array%': typeof Int32Array === 'undefined' ? undefined : Int32Array,
97	'$ %Int32ArrayPrototype%': typeof Int32Array === 'undefined' ? undefined : Int32Array.prototype,
98	'$ %isFinite%': isFinite,
99	'$ %isNaN%': isNaN,
100	'$ %IteratorPrototype%': hasSymbols ? getProto(getProto([][Symbol.iterator]())) : undefined,
101	'$ %JSON%': JSON,
102	'$ %JSONParse%': JSON.parse,
103	'$ %Map%': typeof Map === 'undefined' ? undefined : Map,
104	'$ %MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols ? undefined : getProto(new Map()[Symbol.iterator]()),
105	'$ %MapPrototype%': typeof Map === 'undefined' ? undefined : Map.prototype,
106	'$ %Math%': Math,
107	'$ %Number%': Number,
108	'$ %NumberPrototype%': Number.prototype,
109	'$ %Object%': Object,
110	'$ %ObjectPrototype%': Object.prototype,
111	'$ %ObjProto_toString%': Object.prototype.toString,
112	'$ %ObjProto_valueOf%': Object.prototype.valueOf,
113	'$ %parseFloat%': parseFloat,
114	'$ %parseInt%': parseInt,
115	'$ %Promise%': typeof Promise === 'undefined' ? undefined : Promise,
116	'$ %PromisePrototype%': typeof Promise === 'undefined' ? undefined : Promise.prototype,
117	'$ %PromiseProto_then%': typeof Promise === 'undefined' ? undefined : Promise.prototype.then,
118	'$ %Promise_all%': typeof Promise === 'undefined' ? undefined : Promise.all,
119	'$ %Promise_reject%': typeof Promise === 'undefined' ? undefined : Promise.reject,
120	'$ %Promise_resolve%': typeof Promise === 'undefined' ? undefined : Promise.resolve,
121	'$ %Proxy%': typeof Proxy === 'undefined' ? undefined : Proxy,
122	'$ %RangeError%': RangeError,
123	'$ %RangeErrorPrototype%': RangeError.prototype,
124	'$ %ReferenceError%': ReferenceError,
125	'$ %ReferenceErrorPrototype%': ReferenceError.prototype,
126	'$ %Reflect%': typeof Reflect === 'undefined' ? undefined : Reflect,
127	'$ %RegExp%': RegExp,
128	'$ %RegExpPrototype%': RegExp.prototype,
129	'$ %Set%': typeof Set === 'undefined' ? undefined : Set,
130	'$ %SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols ? undefined : getProto(new Set()[Symbol.iterator]()),
131	'$ %SetPrototype%': typeof Set === 'undefined' ? undefined : Set.prototype,
132	'$ %SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined : SharedArrayBuffer,
133	'$ %SharedArrayBufferPrototype%': typeof SharedArrayBuffer === 'undefined' ? undefined : SharedArrayBuffer.prototype,
134	'$ %String%': String,
135	'$ %StringIteratorPrototype%': hasSymbols ? getProto(''[Symbol.iterator]()) : undefined,
136	'$ %StringPrototype%': String.prototype,
137	'$ %Symbol%': hasSymbols ? Symbol : undefined,
138	'$ %SymbolPrototype%': hasSymbols ? Symbol.prototype : undefined,
139	'$ %SyntaxError%': SyntaxError,
140	'$ %SyntaxErrorPrototype%': SyntaxError.prototype,
141	'$ %ThrowTypeError%': ThrowTypeError,
142	'$ %TypedArray%': TypedArray,
143	'$ %TypedArrayPrototype%': TypedArray ? TypedArray.prototype : undefined,
144	'$ %TypeError%': TypeError,
145	'$ %TypeErrorPrototype%': TypeError.prototype,
146	'$ %Uint8Array%': typeof Uint8Array === 'undefined' ? undefined : Uint8Array,
147	'$ %Uint8ArrayPrototype%': typeof Uint8Array === 'undefined' ? undefined : Uint8Array.prototype,
148	'$ %Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined : Uint8ClampedArray,
149	'$ %Uint8ClampedArrayPrototype%': typeof Uint8ClampedArray === 'undefined' ? undefined : Uint8ClampedArray.prototype,
150	'$ %Uint16Array%': typeof Uint16Array === 'undefined' ? undefined : Uint16Array,
151	'$ %Uint16ArrayPrototype%': typeof Uint16Array === 'undefined' ? undefined : Uint16Array.prototype,
152	'$ %Uint32Array%': typeof Uint32Array === 'undefined' ? undefined : Uint32Array,
153	'$ %Uint32ArrayPrototype%': typeof Uint32Array === 'undefined' ? undefined : Uint32Array.prototype,
154	'$ %URIError%': URIError,
155	'$ %URIErrorPrototype%': URIError.prototype,
156	'$ %WeakMap%': typeof WeakMap === 'undefined' ? undefined : WeakMap,
157	'$ %WeakMapPrototype%': typeof WeakMap === 'undefined' ? undefined : WeakMap.prototype,
158	'$ %WeakSet%': typeof WeakSet === 'undefined' ? undefined : WeakSet,
159	'$ %WeakSetPrototype%': typeof WeakSet === 'undefined' ? undefined : WeakSet.prototype
160};
161
162module.exports = function GetIntrinsic(name, allowMissing) {
163	if (arguments.length > 1 && typeof allowMissing !== 'boolean') {
164		throw new TypeError('"allowMissing" argument must be a boolean');
165	}
166
167	var key = '$ ' + name;
168	if (!(key in INTRINSICS)) {
169		throw new SyntaxError('intrinsic ' + name + ' does not exist!');
170	}
171
172	// istanbul ignore if // hopefully this is impossible to test :-)
173	if (typeof INTRINSICS[key] === 'undefined' && !allowMissing) {
174		throw new TypeError('intrinsic ' + name + ' exists, but is not available. Please file an issue!');
175	}
176	return INTRINSICS[key];
177};
178