Skip to content

Commit 24c8908

Browse files
Renegade334aduh95
authored andcommitted
lib: improve control abstraction coverage in frozen intrinsics
Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk> PR-URL: #63698 Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 1e33e80 commit 24c8908

3 files changed

Lines changed: 52 additions & 26 deletions

File tree

lib/internal/freeze_intrinsics.js

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ const {
3131
ArrayPrototype,
3232
ArrayPrototypeForEach,
3333
ArrayPrototypePush,
34+
AsyncFunctionPrototype,
35+
AsyncGeneratorFunctionPrototype,
36+
AsyncGeneratorFunctionPrototypePrototype,
3437
AsyncIteratorPrototype,
3538
Atomics,
3639
BigInt,
@@ -57,14 +60,19 @@ const {
5760
Float64ArrayPrototype,
5861
Function,
5962
FunctionPrototype,
63+
GeneratorFunctionPrototype,
64+
GeneratorFunctionPrototypePrototype,
6065
Int16Array,
6166
Int16ArrayPrototype,
6267
Int32Array,
6368
Int32ArrayPrototype,
6469
Int8Array,
6570
Int8ArrayPrototype,
71+
Iterator,
72+
IteratorHelperPrototype,
6673
IteratorPrototype,
6774
Map,
75+
MapIteratorPrototype,
6876
MapPrototype,
6977
Number,
7078
NumberPrototype,
@@ -88,15 +96,15 @@ const {
8896
ReflectOwnKeys,
8997
RegExp,
9098
RegExpPrototype,
99+
RegExpStringIteratorPrototype,
91100
SafeSet,
92101
Set,
102+
SetIteratorPrototype,
93103
SetPrototype,
94104
String,
95105
StringIteratorPrototype,
96106
StringPrototype,
97107
Symbol,
98-
SymbolIterator,
99-
SymbolMatchAll,
100108
SymbolPrototype,
101109
SyntaxError,
102110
SyntaxErrorPrototype,
@@ -120,6 +128,7 @@ const {
120128
WeakRefPrototype,
121129
WeakSet,
122130
WeakSetPrototype,
131+
WrapForValidIteratorPrototype,
123132
decodeURI,
124133
decodeURIComponent,
125134
encodeURI,
@@ -172,8 +181,7 @@ module.exports = function() {
172181
StringPrototype, // 22.1
173182
StringIteratorPrototype, // 22.1.5
174183
RegExpPrototype, // 22.2
175-
// 22.2.7 RegExpStringIteratorPrototype
176-
ObjectGetPrototypeOf(/e/[SymbolMatchAll]()),
184+
RegExpStringIteratorPrototype, // 22.2.9
177185

178186
// 23 Indexed Collections
179187
ArrayPrototype, // 23.1
@@ -194,11 +202,9 @@ module.exports = function() {
194202

195203
// 24 Keyed Collections
196204
MapPrototype, // 24.1
197-
// 24.1.5 MapIteratorPrototype
198-
ObjectGetPrototypeOf(new Map()[SymbolIterator]()),
205+
MapIteratorPrototype, // 24.1.5
199206
SetPrototype, // 24.2
200-
// 24.2.5 SetIteratorPrototype
201-
ObjectGetPrototypeOf(new Set()[SymbolIterator]()),
207+
SetIteratorPrototype, // 24.2.6
202208
WeakMapPrototype, // 24.3
203209
WeakSetPrototype, // 24.4
204210

@@ -211,10 +217,18 @@ module.exports = function() {
211217
FinalizationRegistryPrototype, // 26.2
212218

213219
// 27 Control Abstraction Objects
214-
// 27.1 Iteration
215-
IteratorPrototype, // 27.1.2 IteratorPrototype
216-
AsyncIteratorPrototype, // 27.1.3 AsyncIteratorPrototype
220+
IteratorHelperPrototype, // 27.1.2
221+
IteratorPrototype, // 27.1.3
222+
WrapForValidIteratorPrototype, // 27.1.3.2.2.1
223+
AsyncIteratorPrototype, // 27.1.4
217224
PromisePrototype, // 27.2
225+
GeneratorFunctionPrototype, // 27.3
226+
AsyncGeneratorFunctionPrototype, // 27.4
227+
// 27.5 GeneratorPrototype
228+
GeneratorFunctionPrototypePrototype,
229+
// 27.6 AsyncGeneratorPrototype
230+
AsyncGeneratorFunctionPrototypePrototype,
231+
AsyncFunctionPrototype, // 27.7
218232

219233
// Other APIs / Web Compatibility
220234
Console.prototype,
@@ -267,8 +281,7 @@ module.exports = function() {
267281
String, // 22.1
268282
StringIteratorPrototype, // 22.1.5
269283
RegExp, // 22.2
270-
// 22.2.7 RegExpStringIteratorPrototype
271-
ObjectGetPrototypeOf(/e/[SymbolMatchAll]()),
284+
RegExpStringIteratorPrototype, // 22.2.9
272285

273286
// 23 Indexed Collections
274287
Array, // 23.1
@@ -289,11 +302,9 @@ module.exports = function() {
289302

290303
// 24 Keyed Collections
291304
Map, // 24.1
292-
// 24.1.5 MapIteratorPrototype
293-
ObjectGetPrototypeOf(new Map()[SymbolIterator]()),
305+
MapIteratorPrototype, // 24.1.5
294306
Set, // 24.2
295-
// 24.2.5 SetIteratorPrototype
296-
ObjectGetPrototypeOf(new Set()[SymbolIterator]()),
307+
SetIteratorPrototype, // 24.2.6
297308
WeakMap, // 24.3
298309
WeakSet, // 24.4
299310

@@ -309,19 +320,19 @@ module.exports = function() {
309320
FinalizationRegistry, // 26.2
310321

311322
// 27 Control Abstraction Objects
312-
// 27.1 Iteration
313-
ObjectGetPrototypeOf(ArrayIteratorPrototype), // 27.1.2 IteratorPrototype
314-
// 27.1.3 AsyncIteratorPrototype
315-
ObjectGetPrototypeOf(ObjectGetPrototypeOf(ObjectGetPrototypeOf(
316-
(async function*() {})(),
317-
))),
323+
IteratorHelperPrototype, // 27.1.2
324+
Iterator, // 27.1.3
325+
WrapForValidIteratorPrototype, // 27.1.3.2.2.1
326+
ArrayIteratorPrototype, // 27.1.4
318327
Promise, // 27.2
319328
// 27.3 GeneratorFunction
320-
ObjectGetPrototypeOf(function* () {}),
329+
// 27.5 Generator
330+
GeneratorFunctionPrototype,
321331
// 27.4 AsyncGeneratorFunction
322-
ObjectGetPrototypeOf(async function* () {}),
332+
// 27.6 AsyncGenerator
333+
AsyncGeneratorFunctionPrototype,
323334
// 27.7 AsyncFunction
324-
ObjectGetPrototypeOf(async function() {}),
335+
AsyncFunctionPrototype,
325336

326337
// 28 Reflection
327338
// eslint-disable-next-line node-core/prefer-primordials

lib/internal/per_context/primordials.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,22 @@ function copyPrototype(src, dest, prefix) {
263263
name: 'ArrayIteratorPrototype',
264264
original: Reflect.getPrototypeOf(Array.prototype[Symbol.iterator]()),
265265
},
266+
{
267+
name: 'AsyncFunctionPrototype',
268+
original: Reflect.getPrototypeOf(async function() {}),
269+
},
270+
{
271+
name: 'AsyncGeneratorFunctionPrototype',
272+
original: Reflect.getPrototypeOf(async function*() {}),
273+
},
266274
{
267275
name: 'AsyncIteratorPrototype',
268276
original: Reflect.getPrototypeOf(Reflect.getPrototypeOf(async function*() {}).prototype),
269277
},
278+
{
279+
name: 'GeneratorFunctionPrototype',
280+
original: Reflect.getPrototypeOf(function*() {}),
281+
},
270282
{
271283
name: 'IteratorHelperPrototype',
272284
original: Reflect.getPrototypeOf(primordials.IteratorPrototypeDrop({ __proto__: null }, null)),

typings/primordials.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,10 @@ declare namespace primordials {
561561
export const IteratorPrototypeSymbolIterator: UncurryMethod<typeof Iterator.prototype, typeof Symbol.iterator>
562562
export const ArrayIteratorPrototype: ReturnType<typeof Array.prototype[typeof Symbol.iterator]>
563563
export const ArrayIteratorPrototypeNext: UncurryThis<typeof ArrayIteratorPrototype.next>
564+
export const AsyncFunctionPrototype: Function
565+
export const AsyncGeneratorFunctionPrototype: Function
564566
export const AsyncIteratorPrototype: AsyncIterable<any>
567+
export const GeneratorFunctionPrototype: Function
565568
export const IteratorHelperPrototype: ReturnType<typeof Iterator.prototype.drop>
566569
export const MapIteratorPrototype: ReturnType<typeof Map.prototype[typeof Symbol.iterator]>
567570
export const MapIteratorPrototypeNext: UncurryThis<typeof MapIteratorPrototype.next>

0 commit comments

Comments
 (0)