Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: add %TypedArray% abstract constructor to primordials #36016

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/internal/freeze_intrinsics.js
Expand Up @@ -65,6 +65,8 @@ const {
SymbolIterator,
SyntaxError,
TypeError,
TypedArray,
TypedArrayPrototype,
Uint16Array,
Uint32Array,
Uint8Array,
Expand Down Expand Up @@ -105,7 +107,7 @@ module.exports = function() {
// AsyncGeneratorFunction
ObjectGetPrototypeOf(async function* () {}),
// TypedArray
ObjectGetPrototypeOf(Uint8Array),
TypedArrayPrototype,

// 19 Fundamental Objects
Object.prototype, // 19.1
Expand Down Expand Up @@ -189,7 +191,7 @@ module.exports = function() {
// AsyncGeneratorFunction
ObjectGetPrototypeOf(async function* () {}),
// TypedArray
ObjectGetPrototypeOf(Uint8Array),
TypedArray,

// 18 The Global Object
eval,
Expand Down
13 changes: 13 additions & 0 deletions lib/internal/per_context/primordials.js
Expand Up @@ -175,5 +175,18 @@ primordials.SafePromise = 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 }) => {
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
primordials[name] = original;
ExE-Boss marked this conversation as resolved.
Show resolved Hide resolved
// 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);
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
copyPrototype(original.prototype, primordials, `${name}Prototype`);
});

Object.setPrototypeOf(primordials, null);
Object.freeze(primordials);
5 changes: 2 additions & 3 deletions lib/internal/util/inspect.js
Expand Up @@ -57,10 +57,10 @@ const {
SymbolPrototypeValueOf,
SymbolIterator,
SymbolToStringTag,
TypedArrayPrototype,
Uint16Array,
Uint32Array,
Uint8Array,
Uint8ArrayPrototype,
Uint8ClampedArray,
uncurryThis,
} = primordials;
Expand Down Expand Up @@ -141,8 +141,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;

Expand Down
5 changes: 1 addition & 4 deletions lib/internal/util/types.js
Expand Up @@ -3,14 +3,11 @@
const {
ArrayBufferIsView,
ObjectGetOwnPropertyDescriptor,
ObjectGetPrototypeOf,
SymbolToStringTag,
Uint8ArrayPrototype,
TypedArrayPrototype,
uncurryThis,
} = primordials;

const TypedArrayPrototype = ObjectGetPrototypeOf(Uint8ArrayPrototype);

const TypedArrayProto_toStringTag =
uncurryThis(
ObjectGetOwnPropertyDescriptor(TypedArrayPrototype,
Expand Down