// Copyright (C) 2018 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- description: | An Array of all representable Well-Known Intrinsic Objects defines: [WellKnownIntrinsicObjects, getWellKnownIntrinsicObject] ---*/ const WellKnownIntrinsicObjects = [ { name: '%AggregateError%', source: 'AggregateError', }, { name: '%Array%', source: 'Array', }, { name: '%ArrayBuffer%', source: 'ArrayBuffer', }, { name: '%ArrayIteratorPrototype%', source: 'Object.getPrototypeOf([][Symbol.iterator]())', }, { // Not currently accessible to ECMAScript user code name: '%AsyncFromSyncIteratorPrototype%', source: '', }, { name: '%AsyncFunction%', source: '(async function() {}).constructor', }, { name: '%AsyncGeneratorFunction%', source: '(async function* () {}).constructor', }, { name: '%AsyncGeneratorPrototype%', source: 'Object.getPrototypeOf(async function* () {}).prototype', }, { name: '%AsyncIteratorPrototype%', source: '((async function * () {})())[Symbol.asyncIterator]()', }, { name: '%Atomics%', source: 'Atomics', }, { name: '%BigInt%', source: 'BigInt', }, { name: '%BigInt64Array%', source: 'BigInt64Array', }, { name: '%BigUint64Array%', source: 'BigUint64Array', }, { name: '%Boolean%', source: 'Boolean', }, { name: '%DataView%', source: 'DataView', }, { name: '%Date%', source: 'Date', }, { name: '%decodeURI%', source: 'decodeURI', }, { name: '%decodeURIComponent%', source: 'decodeURIComponent', }, { name: '%encodeURI%', source: 'encodeURI', }, { name: '%encodeURIComponent%', source: 'encodeURIComponent', }, { name: '%Error%', source: 'Error', }, { name: '%eval%', source: 'eval', }, { name: '%EvalError%', source: 'EvalError', }, { name: '%FinalizationRegistry%', source: 'FinalizationRegistry', }, { name: '%Float32Array%', source: 'Float32Array', }, { name: '%Float64Array%', source: 'Float64Array', }, { // Not currently accessible to ECMAScript user code name: '%ForInIteratorPrototype%', source: '', }, { name: '%Function%', source: 'Function', }, { name: '%GeneratorFunction%', source: '(function* () {}).constructor', }, { name: '%GeneratorPrototype%', source: 'Object.getPrototypeOf(function * () {}).prototype', }, { name: '%Int8Array%', source: 'Int8Array', }, { name: '%Int16Array%', source: 'Int16Array', }, { name: '%Int32Array%', source: 'Int32Array', }, { name: '%isFinite%', source: 'isFinite', }, { name: '%isNaN%', source: 'isNaN', }, { name: '%Iterator%', source: 'typeof Iterator !== "undefined" ? Iterator : Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())).constructor', }, { name: '%IteratorHelperPrototype%', source: 'Object.getPrototypeOf(Iterator.from([]).drop(0))', }, { name: '%JSON%', source: 'JSON', }, { name: '%Map%', source: 'Map', }, { name: '%MapIteratorPrototype%', source: 'Object.getPrototypeOf(new Map()[Symbol.iterator]())', }, { name: '%Math%', source: 'Math', }, { name: '%Number%', source: 'Number', }, { name: '%Object%', source: 'Object', }, { name: '%parseFloat%', source: 'parseFloat', }, { name: '%parseInt%', source: 'parseInt', }, { name: '%Promise%', source: 'Promise', }, { name: '%Proxy%', source: 'Proxy', }, { name: '%RangeError%', source: 'RangeError', }, { name: '%ReferenceError%', source: 'ReferenceError', }, { name: '%Reflect%', source: 'Reflect', }, { name: '%RegExp%', source: 'RegExp', }, { name: '%RegExpStringIteratorPrototype%', source: 'RegExp.prototype[Symbol.matchAll]("")', }, { name: '%Set%', source: 'Set', }, { name: '%SetIteratorPrototype%', source: 'Object.getPrototypeOf(new Set()[Symbol.iterator]())', }, { name: '%SharedArrayBuffer%', source: 'SharedArrayBuffer', }, { name: '%String%', source: 'String', }, { name: '%StringIteratorPrototype%', source: 'Object.getPrototypeOf(new String()[Symbol.iterator]())', }, { name: '%Symbol%', source: 'Symbol', }, { name: '%SyntaxError%', source: 'SyntaxError', }, { name: '%ThrowTypeError%', source: '(function() { "use strict"; return Object.getOwnPropertyDescriptor(arguments, "callee").get })()', }, { name: '%TypedArray%', source: 'Object.getPrototypeOf(Uint8Array)', }, { name: '%TypeError%', source: 'TypeError', }, { name: '%Uint8Array%', source: 'Uint8Array', }, { name: '%Uint8ClampedArray%', source: 'Uint8ClampedArray', }, { name: '%Uint16Array%', source: 'Uint16Array', }, { name: '%Uint32Array%', source: 'Uint32Array', }, { name: '%URIError%', source: 'URIError', }, { name: '%WeakMap%', source: 'WeakMap', }, { name: '%WeakRef%', source: 'WeakRef', }, { name: '%WeakSet%', source: 'WeakSet', }, { name: '%WrapForValidIteratorPrototype%', source: 'Object.getPrototypeOf(Iterator.from({ [Symbol.iterator](){ return {}; } }))', }, ]; WellKnownIntrinsicObjects.forEach((wkio) => { var actual; try { actual = new Function("return " + wkio.source)(); } catch (exception) { // Nothing to do here. } wkio.value = actual; }); /** * Returns a well-known intrinsic object, if the implementation provides it. * Otherwise, throws. * @param {string} key - the specification's name for the intrinsic, for example * "%Array%" * @returns {object} the well-known intrinsic object. */ function getWellKnownIntrinsicObject(key) { for (var ix = 0; ix < WellKnownIntrinsicObjects.length; ix++) { if (WellKnownIntrinsicObjects[ix].name === key) { var value = WellKnownIntrinsicObjects[ix].value; if (value !== undefined) return value; throw new Test262Error('this implementation could not obtain ' + key); } } throw new Test262Error('unknown well-known intrinsic ' + key); }