Skip to content

Commit

Permalink
lib: add %TypedArray% abstract constructor to primordials
Browse files Browse the repository at this point in the history
Refs: #35448
Refs: #36003
Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object

Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>

PR-URL: #36016
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
  • Loading branch information
ExE-Boss authored and targos committed Jun 11, 2021
1 parent d84b05a commit 24d4d63
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
6 changes: 4 additions & 2 deletions lib/internal/freeze_intrinsics.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
5 changes: 2 additions & 3 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ const {
SymbolPrototypeValueOf,
SymbolIterator,
SymbolToStringTag,
TypedArrayPrototype,
Uint16Array,
Uint32Array,
Uint8Array,
Uint8ArrayPrototype,
Uint8ClampedArray,
uncurryThis,
} = primordials;
Expand Down Expand Up @@ -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;

Expand Down
5 changes: 1 addition & 4 deletions lib/internal/util/types.js
Original file line number Diff line number Diff line change
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

0 comments on commit 24d4d63

Please sign in to comment.