diff --git a/lib/internal/freeze_intrinsics.js b/lib/internal/freeze_intrinsics.js index 21612790ce749c..5e99af2d9ad0bb 100644 --- a/lib/internal/freeze_intrinsics.js +++ b/lib/internal/freeze_intrinsics.js @@ -65,6 +65,8 @@ const { SymbolIterator, SyntaxError, TypeError, + TypedArray, + TypedArrayPrototype, Uint16Array, Uint32Array, Uint8Array, @@ -105,7 +107,7 @@ module.exports = function() { // AsyncGeneratorFunction ObjectGetPrototypeOf(async function* () {}), // TypedArray - ObjectGetPrototypeOf(Uint8Array), + TypedArrayPrototype, // 19 Fundamental Objects Object.prototype, // 19.1 @@ -189,7 +191,7 @@ module.exports = function() { // AsyncGeneratorFunction ObjectGetPrototypeOf(async function* () {}), // TypedArray - ObjectGetPrototypeOf(Uint8Array), + TypedArray, // 18 The Global Object eval, diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index 5ba9f504441cc2..0ff52255feff41 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -171,5 +171,18 @@ primordials.SafeWeakSet = makeSafe( copyPrototype(original.prototype, primordials, `${name}Prototype`); }); +// Create copies of abstract intrinsic objects that are not directly exposed +// on the global object. +// Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object +[ + { name: 'TypedArray', original: Reflect.getPrototypeOf(Uint8Array) }, +].forEach(({ name, original }) => { + primordials[name] = original; + // The static %TypedArray% methods require a valid `this`, but can't be bound, + // as they need a subclass constructor as the receiver: + copyPrototype(original, primordials, name); + copyPrototype(original.prototype, primordials, `${name}Prototype`); +}); + Object.setPrototypeOf(primordials, null); Object.freeze(primordials); diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index fd3bef5d63effc..a82018da796bc8 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -58,10 +58,10 @@ const { SymbolPrototypeValueOf, SymbolIterator, SymbolToStringTag, + TypedArrayPrototype, Uint16Array, Uint32Array, Uint8Array, - Uint8ArrayPrototype, Uint8ClampedArray, uncurryThis, } = primordials; @@ -142,8 +142,7 @@ const setSizeGetter = uncurryThis( const mapSizeGetter = uncurryThis( ObjectGetOwnPropertyDescriptor(MapPrototype, 'size').get); const typedArraySizeGetter = uncurryThis( - ObjectGetOwnPropertyDescriptor( - ObjectGetPrototypeOf(Uint8ArrayPrototype), 'length').get); + ObjectGetOwnPropertyDescriptor(TypedArrayPrototype, 'length').get); let hexSlice; diff --git a/lib/internal/util/types.js b/lib/internal/util/types.js index 4b9eeb469b2d19..115c473ae221d4 100644 --- a/lib/internal/util/types.js +++ b/lib/internal/util/types.js @@ -3,14 +3,11 @@ const { ArrayBufferIsView, ObjectGetOwnPropertyDescriptor, - ObjectGetPrototypeOf, SymbolToStringTag, - Uint8ArrayPrototype, + TypedArrayPrototype, uncurryThis, } = primordials; -const TypedArrayPrototype = ObjectGetPrototypeOf(Uint8ArrayPrototype); - const TypedArrayProto_toStringTag = uncurryThis( ObjectGetOwnPropertyDescriptor(TypedArrayPrototype,