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 <[email protected]>

PR-URL: #36016
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Shingo Inoue <[email protected]>
  • Loading branch information
ExE-Boss authored and danielleadams committed Nov 9, 2020
1 parent 77e4f19 commit af2a560
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 @@ -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 }) => {
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 @@ -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
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 af2a560

Please sign in to comment.