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>
  • Loading branch information
ExE-Boss and aduh95 committed Nov 8, 2020
1 parent adae822 commit 8fee9b7
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
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 }) => {
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
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

0 comments on commit 8fee9b7

Please sign in to comment.