Skip to content

Commit 2fd37db

Browse files
ExE-Bosstargos
authored andcommitted
lib: add %TypedArray% abstract constructor to primordials
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]>
1 parent 538ec98 commit 2fd37db

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

lib/internal/freeze_intrinsics.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ const {
6565
SymbolIterator,
6666
SyntaxError,
6767
TypeError,
68+
TypedArray,
69+
TypedArrayPrototype,
6870
Uint16Array,
6971
Uint32Array,
7072
Uint8Array,
@@ -105,7 +107,7 @@ module.exports = function() {
105107
// AsyncGeneratorFunction
106108
ObjectGetPrototypeOf(async function* () {}),
107109
// TypedArray
108-
ObjectGetPrototypeOf(Uint8Array),
110+
TypedArrayPrototype,
109111

110112
// 19 Fundamental Objects
111113
Object.prototype, // 19.1
@@ -189,7 +191,7 @@ module.exports = function() {
189191
// AsyncGeneratorFunction
190192
ObjectGetPrototypeOf(async function* () {}),
191193
// TypedArray
192-
ObjectGetPrototypeOf(Uint8Array),
194+
TypedArray,
193195

194196
// 18 The Global Object
195197
eval,

lib/internal/per_context/primordials.js

+13
Original file line numberDiff line numberDiff line change
@@ -171,5 +171,18 @@ primordials.SafeWeakSet = makeSafe(
171171
copyPrototype(original.prototype, primordials, `${name}Prototype`);
172172
});
173173

174+
// Create copies of abstract intrinsic objects that are not directly exposed
175+
// on the global object.
176+
// Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object
177+
[
178+
{ name: 'TypedArray', original: Reflect.getPrototypeOf(Uint8Array) },
179+
].forEach(({ name, original }) => {
180+
primordials[name] = original;
181+
// The static %TypedArray% methods require a valid `this`, but can't be bound,
182+
// as they need a subclass constructor as the receiver:
183+
copyPrototype(original, primordials, name);
184+
copyPrototype(original.prototype, primordials, `${name}Prototype`);
185+
});
186+
174187
Object.setPrototypeOf(primordials, null);
175188
Object.freeze(primordials);

lib/internal/util/inspect.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ const {
5858
SymbolPrototypeValueOf,
5959
SymbolIterator,
6060
SymbolToStringTag,
61+
TypedArrayPrototype,
6162
Uint16Array,
6263
Uint32Array,
6364
Uint8Array,
64-
Uint8ArrayPrototype,
6565
Uint8ClampedArray,
6666
uncurryThis,
6767
} = primordials;
@@ -142,8 +142,7 @@ const setSizeGetter = uncurryThis(
142142
const mapSizeGetter = uncurryThis(
143143
ObjectGetOwnPropertyDescriptor(MapPrototype, 'size').get);
144144
const typedArraySizeGetter = uncurryThis(
145-
ObjectGetOwnPropertyDescriptor(
146-
ObjectGetPrototypeOf(Uint8ArrayPrototype), 'length').get);
145+
ObjectGetOwnPropertyDescriptor(TypedArrayPrototype, 'length').get);
147146

148147
let hexSlice;
149148

lib/internal/util/types.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
const {
44
ArrayBufferIsView,
55
ObjectGetOwnPropertyDescriptor,
6-
ObjectGetPrototypeOf,
76
SymbolToStringTag,
8-
Uint8ArrayPrototype,
7+
TypedArrayPrototype,
98
uncurryThis,
109
} = primordials;
1110

12-
const TypedArrayPrototype = ObjectGetPrototypeOf(Uint8ArrayPrototype);
13-
1411
const TypedArrayProto_toStringTag =
1512
uncurryThis(
1613
ObjectGetOwnPropertyDescriptor(TypedArrayPrototype,

0 commit comments

Comments
 (0)