Improve code metrics in intrinsics
MODIFY
packages/intrinsics-global/.eslintrc.json
packages/intrinsics-global/.eslintrc.json
"function-paren-newline": "off",
"arrow-parens": "off",
"strict": "off",
- "no-console": "off",
+ "max-depth": ["error", { "max": 4 }],
+ "max-lines": ["error", 300],
+ "max-nested-callbacks": ["error", 4],
+ "max-statements": ["error", 32],
+ "max-statements-per-line": ["error", { "max": 1 }], "no-console": "off",
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"no-return-assign": "off",
"no-param-reassign": "off",

MODIFY
packages/intrinsics/.eslintrc.json
packages/intrinsics/.eslintrc.json
"function-paren-newline": "off",
"arrow-parens": "off",
"strict": "off",
- "no-console": "off",
+ "max-depth": ["error", { "max": 4 }],
+ "max-lines": ["error", 300],
+ "max-nested-callbacks": ["error", 4],
+ "max-statements": ["error", 32],
+ "max-statements-per-line": ["error", { "max": 1 }], "no-console": "off",
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"no-return-assign": "off",
"no-param-reassign": "off",

ADD
packages/intrinsics/src/assert.js
+export function assert(condition, errorMessage) {
+ if (!condition) {
+ throw new TypeError(errorMessage);
+ }
+}

ADD
packages/intrinsics/src/checkAnonIntrinsics.js
+import { assert } from './assert.js';
+
+const { getPrototypeOf } = Object;
+
+/**
+ * checkAnonIntrinsics()
+ * Ensure that the rootAnonIntrinsics are consistent with specs. These
+ * tests are necesary to ensure that sampling was correctly done.
+ */
+
+export function checkAnonIntrinsics(intrinsics) {
+ const {
+ FunctionPrototypeConstructor,
+ ArrayIteratorPrototype,
+ AsyncFunction,
+ AsyncGenerator,
+ AsyncGeneratorFunction,
+ AsyncGeneratorPrototype,
+ AsyncIteratorPrototype,
+ Generator,
+ GeneratorFunction,
+ IteratorPrototype,
+ MapIteratorPrototype,
+ RegExpStringIteratorPrototype,
+ SetIteratorPrototype,
+ StringIteratorPrototype,
+ ThrowTypeError,
+ TypedArray,
+ } = intrinsics;
+
+ // 9.2.4.1 %ThrowTypeError%
+
+ assert(
+ getPrototypeOf(ThrowTypeError) === Function.prototype,
+ 'ThrowTypeError.__proto__ should be Function.prototype',
+ );
+
+ // 21.1.5.2 The %StringIteratorPrototype% Object
+
+ assert(
+ getPrototypeOf(StringIteratorPrototype) === IteratorPrototype,
+ 'StringIteratorPrototype.__proto__ should be IteratorPrototype',
+ );
+
+ // 21.2.7.1 The %RegExpStringIteratorPrototype% Object
+
+ assert(
+ getPrototypeOf(RegExpStringIteratorPrototype) === IteratorPrototype,
+ 'RegExpStringIteratorPrototype.__proto__ should be IteratorPrototype',
+ );
+
+ // 22.2.1 The %TypedArray% Intrinsic Object
+
+ // http://bespin.cz/~ondras/html/classv8_1_1ArrayBufferView.html
+ // has me worried that someone might make such an intermediate
+ // object visible.
+ assert(
+ getPrototypeOf(TypedArray) === Function.prototype,
+
+ 'TypedArray.__proto__ should be Function.prototype',
+ );
+
+ // 23.1.5.2 The %MapIteratorPrototype% Object
+
+ assert(
+ getPrototypeOf(MapIteratorPrototype) === IteratorPrototype,
+ 'MapIteratorPrototype.__proto__ should be IteratorPrototype',
+ );
+
+ // 23.2.5.2 The %SetIteratorPrototype% Object
+
+ assert(
+ getPrototypeOf(SetIteratorPrototype) === IteratorPrototype,
+ 'SetIteratorPrototype.__proto__ should be IteratorPrototype',
+ );
+
+ // 25.1.2 The %IteratorPrototype% Object
+
+ assert(
+ getPrototypeOf(IteratorPrototype) === Object.prototype,
+ 'IteratorPrototype.__proto__ should be Object.prototype',
+ );
+
+ // 25.1.3 The %AsyncIteratorPrototype% Object
+
+ assert(
+ getPrototypeOf(AsyncIteratorPrototype) === Object.prototype,
+ 'AsyncIteratorPrototype.__proto__ should be Object.prototype',
+ );
+
+ // 22.1.5.2 The %ArrayIteratorPrototype% Object
+
+ assert(
+ getPrototypeOf(ArrayIteratorPrototype) === IteratorPrototype,
+ 'AsyncIteratorPrototype.__proto__ should be IteratorPrototype',
+ );
+
+ // 25.2.2 Properties of the GeneratorFunction Constructor
+
+ // Use Function.prototype.constructor in case Function has been tamed
+ assert(
+ getPrototypeOf(GeneratorFunction) === FunctionPrototypeConstructor,
+ 'GeneratorFunction.__proto__ should be Function',
+ );
+
+ assert(
+ GeneratorFunction.name === 'GeneratorFunction',
+ 'GeneratorFunction.name should be "GeneratorFunction"',
+ );
+
+ // 25.2.3 Properties of the GeneratorFunction Prototype Object
+
+ assert(
+ getPrototypeOf(Generator) === Function.prototype,
+ 'Generator.__proto__ should be Function.prototype',
+ );
+
+ // 25.3.1 The AsyncGeneratorFunction Constructor
+
+ // Use Function.prototype.constructor in case Function has been tamed
+ assert(
+ getPrototypeOf(AsyncGeneratorFunction) === FunctionPrototypeConstructor,
+ 'AsyncGeneratorFunction.__proto__ should be Function',
+ );
+ assert(
+ AsyncGeneratorFunction.name === 'AsyncGeneratorFunction',
+ 'AsyncGeneratorFunction.name should be "AsyncGeneratorFunction"',
+ );
+
+ // 25.3.3 Properties of the AsyncGeneratorFunction Prototype Object
+
+ assert(
+ getPrototypeOf(AsyncGenerator) === Function.prototype,
+ 'AsyncGenerator.__proto__ should be Function.prototype',
+ );
+
+ // 25.5.1 Properties of the AsyncGenerator Prototype Object
+
+ assert(
+ getPrototypeOf(AsyncGeneratorPrototype) === AsyncIteratorPrototype,
+ 'AsyncGeneratorPrototype.__proto__ should be AsyncIteratorPrototype',
+ );
+
+ // 25.7.1 The AsyncFunction Constructor
+
+ // Use Function.prototype.constructor in case Function has been tamed
+ assert(
+ getPrototypeOf(AsyncFunction) === FunctionPrototypeConstructor,
+ 'AsyncFunction.__proto__ should be Function',
+ );
+ assert(
+ AsyncFunction.name === 'AsyncFunction',
+ 'AsyncFunction.name should be "AsyncFunction"',
+ );
+}

ADD
packages/intrinsics/src/checkIntrinsics.js
+/**
+ * checkIntrinsics()
+ * Ensure that the intrinsics are consistent with defined.
+ */
+export function checkIntrinsics(intrinsics) {
+ Object.keys(intrinsics).forEach(name => {
+ if (intrinsics[name] === undefined) {
+ throw new TypeError(`Malformed intrinsic: ${name}`);
+ }
+ });
+}

ADD
packages/intrinsics/src/getAnonymousIntrinsics.js
+const { getOwnPropertyDescriptor, getPrototypeOf } = Object;
+
+/**
+ * Object.getConstructorOf()
+ * Helper function to improve readability, similar to Object.getPrototypeOf().
+ */
+function getConstructorOf(obj) {
+ return getPrototypeOf(obj).constructor;
+}
+
+/**
+ * getAnonymousIntrinsics()
+ * Get the intrinsics not otherwise reachable by named own property
+ * traversal from the global object.
+ */
+export function getAnonymousIntrinsics() {
+ const FunctionPrototypeConstructor = Function.prototype.constructor;
+
+ const SymbolIterator = (typeof Symbol && Symbol.iterator) || '@@iterator';
+ const SymbolMatchAll = (typeof Symbol && Symbol.matchAll) || '@@matchAll';
+
+ // 9.2.4.1 %ThrowTypeError%
+
+ // eslint-disable-next-line prefer-rest-params
+ const ThrowTypeError = getOwnPropertyDescriptor(arguments, 'callee').get;
+
+ // 21.1.5.2 The %StringIteratorPrototype% Object
+
+ // eslint-disable-next-line no-new-wrappers
+ const StringIteratorObject = new String()[SymbolIterator]();
+ const StringIteratorPrototype = getPrototypeOf(StringIteratorObject);
+
+ // 21.2.7.1 The %RegExpStringIteratorPrototype% Object
+
+ const RegExpStringIterator = new RegExp()[SymbolMatchAll]();
+ const RegExpStringIteratorPrototype = getPrototypeOf(RegExpStringIterator);
+
+ // 22.1.5.2 The %ArrayIteratorPrototype% Object
+
+ // eslint-disable-next-line no-array-constructor
+ const ArrayIteratorObject = new Array()[SymbolIterator]();
+ const ArrayIteratorPrototype = getPrototypeOf(ArrayIteratorObject);
+
+ // 22.2.1 The %TypedArray% Intrinsic Object
+
+ const TypedArray = getPrototypeOf(Float32Array);
+
+ // 23.1.5.2 The %MapIteratorPrototype% Object
+
+ const MapIteratorObject = new Map()[SymbolIterator]();
+ const MapIteratorPrototype = getPrototypeOf(MapIteratorObject);
+
+ // 23.2.5.2 The %SetIteratorPrototype% Object
+
+ const SetIteratorObject = new Set()[SymbolIterator]();
+ const SetIteratorPrototype = getPrototypeOf(SetIteratorObject);
+
+ // 25.1.2 The %IteratorPrototype% Object
+
+ const IteratorPrototype = getPrototypeOf(ArrayIteratorPrototype);
+
+ // 25.2.1 The GeneratorFunction Constructor
+
+ function* GeneratorFunctionInstance() {} // eslint-disable-line no-empty-function
+ const GeneratorFunction = getConstructorOf(GeneratorFunctionInstance);
+
+ // 25.2.3 Properties of the GeneratorFunction Prototype Object
+
+ const Generator = GeneratorFunction.prototype;
+
+ // 25.3.1 The AsyncGeneratorFunction Constructor
+
+ async function* AsyncGeneratorFunctionInstance() {} // eslint-disable-line no-empty-function
+ const AsyncGeneratorFunction = getConstructorOf(
+ AsyncGeneratorFunctionInstance,
+ );
+
+ // 25.3.2.2 AsyncGeneratorFunction.prototype
+ const AsyncGenerator = AsyncGeneratorFunction.prototype;
+ // 25.5.1 Properties of the AsyncGenerator Prototype Object
+ const AsyncGeneratorPrototype = AsyncGenerator.prototype;
+ const AsyncIteratorPrototype = getPrototypeOf(AsyncGeneratorPrototype);
+
+ // 25.7.1 The AsyncFunction Constructor
+
+ async function AsyncFunctionInstance() {} // eslint-disable-line no-empty-function
+ const AsyncFunction = getConstructorOf(AsyncFunctionInstance);
+
+ // VALIDATION
+
+ const intrinsics = {
+ FunctionPrototypeConstructor,
+ ArrayIteratorPrototype,
+ AsyncFunction,
+ AsyncGenerator,
+ AsyncGeneratorFunction,
+ AsyncGeneratorPrototype,
+ AsyncIteratorPrototype,
+ Generator,
+ GeneratorFunction,
+ IteratorPrototype,
+ MapIteratorPrototype,
+ RegExpStringIteratorPrototype,
+ SetIteratorPrototype,
+ StringIteratorPrototype,
+ ThrowTypeError,
+ TypedArray,
+ };
+
+ return intrinsics;
+}

ADD
packages/intrinsics/src/getNamedIntrinsic.js
+import { assert } from './assert.js';
+
+const { getOwnPropertyDescriptor } = Object;
+
+/**
+ * getNamedIntrinsic()
+ * Get the intrinsic from the global object.
+ */
+export function getNamedIntrinsic(root, name) {
+ // Assumption: the intrinsic name matches a global object with the same name.
+ const desc = getOwnPropertyDescriptor(root, name);
+
+ // Abort if an accessor is found on the object instead of a data property.
+ // We should never get into this non standard situation.
+ assert(
+ !('get' in desc || 'set' in desc),
+ `unexpected accessor on global property: ${name}`,
+ );
+
+ return desc.value;
+}

ADD
packages/intrinsics/src/intrinsicNames.js
+/**
+ * intrinsicNames
+ * The following list contains all intrisics names as defined in the specs, except
+ * that the leading an trailing '%' characters have been removed. We want to design
+ * from the specs so we can better track changes to the specs.
+ */
+export const intrinsicNames = [
+ // 6.1.7.4 Well-Known Intrinsic Objects
+ // Table 8: Well-Known Intrinsic Objects
+ 'Array',
+ 'ArrayBuffer',
+ 'ArrayBufferPrototype',
+ 'ArrayIteratorPrototype',
+ 'ArrayPrototype',
+ // TODO ArrayProto_*
+ // 'ArrayProto_entries',
+ // 'ArrayProto_forEach',
+ // 'ArrayProto_keys',
+ // 'ArrayProto_values',
+ // 25.1.4.2 The %AsyncFromSyncIteratorPrototype% Object
+ // TODO Beleived to not be directly accessible to ECMAScript code.
+ // 'AsyncFromSyncIteratorPrototype',
+ 'AsyncFunction',
+ 'AsyncFunctionPrototype',
+ 'AsyncGenerator',
+ 'AsyncGeneratorFunction',
+ 'AsyncGeneratorPrototype',
+ 'AsyncIteratorPrototype',
+ 'Atomics',
+ 'BigInt',
+ // TOTO: Missing in the specs.
+ 'BigIntPrototype',
+ 'BigInt64Array',
+ // TOTO: Missing in the specs.
+ 'BigInt64ArrayPrototype',
+ 'BigUint64Array',
+ // TOTO: Missing in the specs.
+ 'BigUint64ArrayPrototype',
+ 'Boolean',
+ 'BooleanPrototype',
+ 'DataView',
+ 'DataViewPrototype',
+ 'Date',
+ 'DatePrototype',
+ 'decodeURI',
+ 'decodeURIComponent',
+ 'encodeURI',
+ 'encodeURIComponent',
+ 'Error',
+ 'ErrorPrototype',
+ 'eval',
+ 'EvalError',
+ 'EvalErrorPrototype',
+ 'Float32Array',
+ 'Float32ArrayPrototype',
+ 'Float64Array',
+ 'Float64ArrayPrototype',
+ // 13.7.5.16.2 The %ForInIteratorPrototype% Object
+ // Documneted as "never directly accessible to ECMAScript code."
+ // 'ForInIteratorPrototype',
+ 'Function',
+ 'FunctionPrototype',
+ 'Generator',
+ 'GeneratorFunction',
+ 'GeneratorPrototype',
+ 'Int8Array',
+ 'Int8ArrayPrototype',
+ 'Int16Array',
+ 'Int16ArrayPrototype',
+ 'Int32Array',
+ 'Int32ArrayPrototype',
+ 'isFinite',
+ 'isNaN',
+ 'IteratorPrototype',
+ 'JSON',
+ // TODO
+ // 'JSONParse',
+ // 'JSONStringify',
+ 'Map',
+ 'MapIteratorPrototype',
+ 'MapPrototype',
+ 'Math',
+ 'Number',
+ 'NumberPrototype',
+ 'Object',
+ 'ObjectPrototype',
+ // TODO
+ // 'ObjProto_toString',
+ // 'ObjProto_valueOf',
+ 'parseFloat',
+ 'parseInt',
+ 'Promise',
+ 'PromisePrototype',
+ // TODO
+ // 'PromiseProto_then',
+ // 'Promise_all',
+ // 'Promise_reject',
+ // 'Promise_resolve',
+ 'Proxy',
+ 'RangeError',
+ 'RangeErrorPrototype',
+ 'ReferenceError',
+ 'ReferenceErrorPrototype',
+ 'Reflect',
+ 'RegExp',
+ 'RegExpPrototype',
+ 'RegExpStringIteratorPrototype',
+ 'Set',
+ 'SetIteratorPrototype',
+ 'SetPrototype',
+ 'SharedArrayBuffer',
+ 'SharedArrayBufferPrototype',
+ 'String',
+ 'StringIteratorPrototype',
+ 'StringPrototype',
+ 'Symbol',
+ 'SymbolPrototype',
+ 'SyntaxError',
+ 'SyntaxErrorPrototype',
+ 'ThrowTypeError',
+ 'TypedArray',
+ 'TypedArrayPrototype',
+ 'TypeError',
+ 'TypeErrorPrototype',
+ 'Uint8Array',
+ 'Uint8ArrayPrototype',
+ 'Uint8ClampedArray',
+ 'Uint8ClampedArrayPrototype',
+ 'Uint16Array',
+ 'Uint16ArrayPrototype',
+ 'Uint32Array',
+ 'Uint32ArrayPrototype',
+ 'URIError',
+ 'URIErrorPrototype',
+ 'WeakMap',
+ 'WeakMapPrototype',
+ 'WeakSet',
+ 'WeakSetPrototype',
+
+ // B.2.1 Additional Properties of the Global Object
+ // Table 87: Additional Well-known Intrinsic Objects
+ 'escape',
+ 'unescape',
+
+ // ESNext
+ 'FunctionPrototypeConstructor',
+ 'Compartment',
+ 'CompartmentPrototype',
+ 'harden',
+];

MODIFY
packages/intrinsics/src/main.js
packages/intrinsics/src/main.js
-const { getOwnPropertyDescriptor, getPrototypeOf } = Object;
+import { checkAnonIntrinsics } from './checkAnonIntrinsics.js';
+import { getAnonymousIntrinsics } from './getAnonymousIntrinsics.js';
+import { intrinsicNames } from './intrinsicNames.js';
+import { getNamedIntrinsic } from './getNamedIntrinsic.js';
+import { checkIntrinsics } from './checkIntrinsics.js';
const { apply } = Reflect;
const uncurryThis = fn => (thisArg, ...args) => apply(fn, thisArg, args);
const hasOwnProperty = uncurryThis(Object.prototype.hasOwnProperty);
-/**
- * Object.getConstructorOf()
- * Helper function to improve readability, similar to Object.getPrototypeOf().
- */
-function getConstructorOf(obj) {
- return getPrototypeOf(obj).constructor;
-}
-
-/**
- * intrinsicNames
- * The following list contains all intrisics names as defined in the specs, except
- * that the leading an trailing '%' characters have been removed. We want to design
- * from the specs so we can better track changes to the specs.
- */
-const intrinsicNames = [
- // 6.1.7.4 Well-Known Intrinsic Objects
- // Table 8: Well-Known Intrinsic Objects
- 'Array',
- 'ArrayBuffer',
- 'ArrayBufferPrototype',
- 'ArrayIteratorPrototype',
- 'ArrayPrototype',
- // TODO ArrayProto_*
- // 'ArrayProto_entries',
- // 'ArrayProto_forEach',
- // 'ArrayProto_keys',
- // 'ArrayProto_values',
- // 25.1.4.2 The %AsyncFromSyncIteratorPrototype% Object
- // TODO Beleived to not be directly accessible to ECMAScript code.
- // 'AsyncFromSyncIteratorPrototype',
- 'AsyncFunction',
- 'AsyncFunctionPrototype',
- 'AsyncGenerator',
- 'AsyncGeneratorFunction',
- 'AsyncGeneratorPrototype',
- 'AsyncIteratorPrototype',
- 'Atomics',
- 'BigInt',
- // TOTO: Missing in the specs.
- 'BigIntPrototype',
- 'BigInt64Array',
- // TOTO: Missing in the specs.
- 'BigInt64ArrayPrototype',
- 'BigUint64Array',
- // TOTO: Missing in the specs.
- 'BigUint64ArrayPrototype',
- 'Boolean',
- 'BooleanPrototype',
- 'DataView',
- 'DataViewPrototype',
- 'Date',
- 'DatePrototype',
- 'decodeURI',
- 'decodeURIComponent',
- 'encodeURI',
- 'encodeURIComponent',
- 'Error',
- 'ErrorPrototype',
- 'eval',
- 'EvalError',
- 'EvalErrorPrototype',
- 'Float32Array',
- 'Float32ArrayPrototype',
- 'Float64Array',
- 'Float64ArrayPrototype',
- // 13.7.5.16.2 The %ForInIteratorPrototype% Object
- // Documneted as "never directly accessible to ECMAScript code."
- // 'ForInIteratorPrototype',
- 'Function',
- 'FunctionPrototype',
- 'Generator',
- 'GeneratorFunction',
- 'GeneratorPrototype',
- 'Int8Array',
- 'Int8ArrayPrototype',
- 'Int16Array',
- 'Int16ArrayPrototype',
- 'Int32Array',
- 'Int32ArrayPrototype',
- 'isFinite',
- 'isNaN',
- 'IteratorPrototype',
- 'JSON',
- // TODO
- // 'JSONParse',
- // 'JSONStringify',
- 'Map',
- 'MapIteratorPrototype',
- 'MapPrototype',
- 'Math',
- 'Number',
- 'NumberPrototype',
- 'Object',
- 'ObjectPrototype',
- // TODO
- // 'ObjProto_toString',
- // 'ObjProto_valueOf',
- 'parseFloat',
- 'parseInt',
- 'Promise',
- 'PromisePrototype',
- // TODO
- // 'PromiseProto_then',
- // 'Promise_all',
- // 'Promise_reject',
- // 'Promise_resolve',
- 'Proxy',
- 'RangeError',
- 'RangeErrorPrototype',
- 'ReferenceError',
- 'ReferenceErrorPrototype',
- 'Reflect',
- 'RegExp',
- 'RegExpPrototype',
- 'RegExpStringIteratorPrototype',
- 'Set',
- 'SetIteratorPrototype',
- 'SetPrototype',
- 'SharedArrayBuffer',
- 'SharedArrayBufferPrototype',
- 'String',
- 'StringIteratorPrototype',
- 'StringPrototype',
- 'Symbol',
- 'SymbolPrototype',
- 'SyntaxError',
- 'SyntaxErrorPrototype',
- 'ThrowTypeError',
- 'TypedArray',
- 'TypedArrayPrototype',
- 'TypeError',
- 'TypeErrorPrototype',
- 'Uint8Array',
- 'Uint8ArrayPrototype',
- 'Uint8ClampedArray',
- 'Uint8ClampedArrayPrototype',
- 'Uint16Array',
- 'Uint16ArrayPrototype',
- 'Uint32Array',
- 'Uint32ArrayPrototype',
- 'URIError',
- 'URIErrorPrototype',
- 'WeakMap',
- 'WeakMapPrototype',
- 'WeakSet',
- 'WeakSetPrototype',
-
- // B.2.1 Additional Properties of the Global Object
- // Table 87: Additional Well-known Intrinsic Objects
- 'escape',
- 'unescape',
-
- // ESNext
- 'FunctionPrototypeConstructor',
- 'Compartment',
- 'CompartmentPrototype',
- 'harden',
-];
-
-function assert(condition, errorMessage) {
- if (!condition) {
- throw new TypeError(errorMessage);
- }
-}
-
-/**
- * checkAnonIntrinsics()
- * Ensure that the rootAnonIntrinsics are consistent with specs. These
- * tests are necesary to ensure that sampling was correctly done.
- */
-function checkAnonIntrinsics(intrinsics) {
- const {
- FunctionPrototypeConstructor,
- ArrayIteratorPrototype,
- AsyncFunction,
- AsyncGenerator,
- AsyncGeneratorFunction,
- AsyncGeneratorPrototype,
- AsyncIteratorPrototype,
- Generator,
- GeneratorFunction,
- IteratorPrototype,
- MapIteratorPrototype,
- RegExpStringIteratorPrototype,
- SetIteratorPrototype,
- StringIteratorPrototype,
- ThrowTypeError,
- TypedArray,
- } = intrinsics;
-
- // 9.2.4.1 %ThrowTypeError%
-
- assert(
- getPrototypeOf(ThrowTypeError) === Function.prototype,
- 'ThrowTypeError.__proto__ should be Function.prototype',
- );
-
- // 21.1.5.2 The %StringIteratorPrototype% Object
-
- assert(
- getPrototypeOf(StringIteratorPrototype) === IteratorPrototype,
- 'StringIteratorPrototype.__proto__ should be IteratorPrototype',
- );
-
- // 21.2.7.1 The %RegExpStringIteratorPrototype% Object
-
- assert(
- getPrototypeOf(RegExpStringIteratorPrototype) === IteratorPrototype,
- 'RegExpStringIteratorPrototype.__proto__ should be IteratorPrototype',
- );
-
- // 22.2.1 The %TypedArray% Intrinsic Object
-
- // http://bespin.cz/~ondras/html/classv8_1_1ArrayBufferView.html
- // has me worried that someone might make such an intermediate
- // object visible.
- assert(
- getPrototypeOf(TypedArray) === Function.prototype,
-
- 'TypedArray.__proto__ should be Function.prototype',
- );
-
- // 23.1.5.2 The %MapIteratorPrototype% Object
-
- assert(
- getPrototypeOf(MapIteratorPrototype) === IteratorPrototype,
- 'MapIteratorPrototype.__proto__ should be IteratorPrototype',
- );
-
- // 23.2.5.2 The %SetIteratorPrototype% Object
-
- assert(
- getPrototypeOf(SetIteratorPrototype) === IteratorPrototype,
- 'SetIteratorPrototype.__proto__ should be IteratorPrototype',
- );
-
- // 25.1.2 The %IteratorPrototype% Object
-
- assert(
- getPrototypeOf(IteratorPrototype) === Object.prototype,
- 'IteratorPrototype.__proto__ should be Object.prototype',
- );
-
- // 25.1.3 The %AsyncIteratorPrototype% Object
-
- assert(
- getPrototypeOf(AsyncIteratorPrototype) === Object.prototype,
- 'AsyncIteratorPrototype.__proto__ should be Object.prototype',
- );
-
- // 22.1.5.2 The %ArrayIteratorPrototype% Object
-
- assert(
- getPrototypeOf(ArrayIteratorPrototype) === IteratorPrototype,
- 'AsyncIteratorPrototype.__proto__ should be IteratorPrototype',
- );
-
- // 25.2.2 Properties of the GeneratorFunction Constructor
-
- // Use Function.prototype.constructor in case Function has been tamed
- assert(
- getPrototypeOf(GeneratorFunction) === FunctionPrototypeConstructor,
- 'GeneratorFunction.__proto__ should be Function',
- );
-
- assert(
- GeneratorFunction.name === 'GeneratorFunction',
- 'GeneratorFunction.name should be "GeneratorFunction"',
- );
-
- // 25.2.3 Properties of the GeneratorFunction Prototype Object
-
- assert(
- getPrototypeOf(Generator) === Function.prototype,
- 'Generator.__proto__ should be Function.prototype',
- );
-
- // 25.3.1 The AsyncGeneratorFunction Constructor
-
- // Use Function.prototype.constructor in case Function has been tamed
- assert(
- getPrototypeOf(AsyncGeneratorFunction) === FunctionPrototypeConstructor,
- 'AsyncGeneratorFunction.__proto__ should be Function',
- );
- assert(
- AsyncGeneratorFunction.name === 'AsyncGeneratorFunction',
- 'AsyncGeneratorFunction.name should be "AsyncGeneratorFunction"',
- );
-
- // 25.3.3 Properties of the AsyncGeneratorFunction Prototype Object
-
- assert(
- getPrototypeOf(AsyncGenerator) === Function.prototype,
- 'AsyncGenerator.__proto__ should be Function.prototype',
- );
-
- // 25.5.1 Properties of the AsyncGenerator Prototype Object
-
- assert(
- getPrototypeOf(AsyncGeneratorPrototype) === AsyncIteratorPrototype,
- 'AsyncGeneratorPrototype.__proto__ should be AsyncIteratorPrototype',
- );
-
- // 25.7.1 The AsyncFunction Constructor
-
- // Use Function.prototype.constructor in case Function has been tamed
- assert(
- getPrototypeOf(AsyncFunction) === FunctionPrototypeConstructor,
- 'AsyncFunction.__proto__ should be Function',
- );
- assert(
- AsyncFunction.name === 'AsyncFunction',
- 'AsyncFunction.name should be "AsyncFunction"',
- );
-}
-
-/**
- * getAnonymousIntrinsics()
- * Get the intrinsics not otherwise reachable by named own property
- * traversal from the global object.
- */
-function getAnonymousIntrinsics() {
- const FunctionPrototypeConstructor = Function.prototype.constructor;
-
- const SymbolIterator = (typeof Symbol && Symbol.iterator) || '@@iterator';
- const SymbolMatchAll = (typeof Symbol && Symbol.matchAll) || '@@matchAll';
-
- // 9.2.4.1 %ThrowTypeError%
-
- // eslint-disable-next-line prefer-rest-params
- const ThrowTypeError = getOwnPropertyDescriptor(arguments, 'callee').get;
-
- // 21.1.5.2 The %StringIteratorPrototype% Object
-
- // eslint-disable-next-line no-new-wrappers
- const StringIteratorObject = new String()[SymbolIterator]();
- const StringIteratorPrototype = getPrototypeOf(StringIteratorObject);
-
- // 21.2.7.1 The %RegExpStringIteratorPrototype% Object
-
- const RegExpStringIterator = new RegExp()[SymbolMatchAll]();
- const RegExpStringIteratorPrototype = getPrototypeOf(RegExpStringIterator);
-
- // 22.1.5.2 The %ArrayIteratorPrototype% Object
-
- // eslint-disable-next-line no-array-constructor
- const ArrayIteratorObject = new Array()[SymbolIterator]();
- const ArrayIteratorPrototype = getPrototypeOf(ArrayIteratorObject);
-
- // 22.2.1 The %TypedArray% Intrinsic Object
-
- const TypedArray = getPrototypeOf(Float32Array);
-
- // 23.1.5.2 The %MapIteratorPrototype% Object
-
- const MapIteratorObject = new Map()[SymbolIterator]();
- const MapIteratorPrototype = getPrototypeOf(MapIteratorObject);
-
- // 23.2.5.2 The %SetIteratorPrototype% Object
-
- const SetIteratorObject = new Set()[SymbolIterator]();
- const SetIteratorPrototype = getPrototypeOf(SetIteratorObject);
-
- // 25.1.2 The %IteratorPrototype% Object
-
- const IteratorPrototype = getPrototypeOf(ArrayIteratorPrototype);
-
- // 25.2.1 The GeneratorFunction Constructor
-
- function* GeneratorFunctionInstance() {} // eslint-disable-line no-empty-function
- const GeneratorFunction = getConstructorOf(GeneratorFunctionInstance);
-
- // 25.2.3 Properties of the GeneratorFunction Prototype Object
-
- const Generator = GeneratorFunction.prototype;
-
- // 25.3.1 The AsyncGeneratorFunction Constructor
-
- async function* AsyncGeneratorFunctionInstance() {} // eslint-disable-line no-empty-function
- const AsyncGeneratorFunction = getConstructorOf(
- AsyncGeneratorFunctionInstance,
- );
-
- // 25.3.2.2 AsyncGeneratorFunction.prototype
- const AsyncGenerator = AsyncGeneratorFunction.prototype;
- // 25.5.1 Properties of the AsyncGenerator Prototype Object
- const AsyncGeneratorPrototype = AsyncGenerator.prototype;
- const AsyncIteratorPrototype = getPrototypeOf(AsyncGeneratorPrototype);
-
- // 25.7.1 The AsyncFunction Constructor
-
- async function AsyncFunctionInstance() {} // eslint-disable-line no-empty-function
- const AsyncFunction = getConstructorOf(AsyncFunctionInstance);
-
- // VALIDATION
-
- const intrinsics = {
- FunctionPrototypeConstructor,
- ArrayIteratorPrototype,
- AsyncFunction,
- AsyncGenerator,
- AsyncGeneratorFunction,
- AsyncGeneratorPrototype,
- AsyncIteratorPrototype,
- Generator,
- GeneratorFunction,
- IteratorPrototype,
- MapIteratorPrototype,
- RegExpStringIteratorPrototype,
- SetIteratorPrototype,
- StringIteratorPrototype,
- ThrowTypeError,
- TypedArray,
- };
-
- checkAnonIntrinsics(intrinsics);
-
- return intrinsics;
-}
-
-/**
- * getNamedIntrinsic()
- * Get the intrinsic from the global object.
- */
-function getNamedIntrinsic(root, name) {
- // Assumption: the intrinsic name matches a global object with the same name.
- const desc = getOwnPropertyDescriptor(root, name);
-
- // Abort if an accessor is found on the object instead of a data property.
- // We should never get into this non standard situation.
- assert(
- !('get' in desc || 'set' in desc),
- `unexpected accessor on global property: ${name}`,
- );
-
- return desc.value;
-}
-
-/**
- * checkIntrinsics()
- * Ensure that the intrinsics are consistent with defined.
- */
-function checkIntrinsics(intrinsics) {
- Object.keys(intrinsics).forEach(name => {
- if (intrinsics[name] === undefined) {
- throw new TypeError(`Malformed intrinsic: ${name}`);
- }
- });
-}
-
const suffix = 'Prototype';
/**
@@ -473,6 +27,7 @@ export function getIntrinsics() {
// eslint-disable-next-line no-new-func
const global = Function('return this')(); // TODO replace root with globalThis
const anonIntrinsics = getAnonymousIntrinsics();
+ checkAnonIntrinsics(anonIntrinsics);
for (const name of intrinsicNames) {
if (hasOwnProperty(anonIntrinsics, name)) {

Improve code metrics in intrinsics