1
+ /*
2
+ This file is copied from https://github.com/nodejs/node/blob/v14.19.3/lib/internal/per_context/primordials.js
3
+ under the following license:
4
+
5
+ Copyright Node.js contributors. All rights reserved.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to
9
+ deal in the Software without restriction, including without limitation the
10
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11
+ sell copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23
+ IN THE SOFTWARE.
24
+ */
25
+
1
26
'use strict' ;
2
27
3
28
/* eslint-disable node-core/prefer-primordials */
@@ -169,7 +194,6 @@ function copyPrototype(src, dest, prefix) {
169
194
170
195
// Create copies of intrinsic objects
171
196
[
172
- 'AggregateError' ,
173
197
'Array' ,
174
198
'ArrayBuffer' ,
175
199
'BigInt' ,
@@ -180,7 +204,6 @@ function copyPrototype(src, dest, prefix) {
180
204
'Date' ,
181
205
'Error' ,
182
206
'EvalError' ,
183
- 'FinalizationRegistry' ,
184
207
'Float32Array' ,
185
208
'Float64Array' ,
186
209
'Function' ,
@@ -204,7 +227,6 @@ function copyPrototype(src, dest, prefix) {
204
227
'Uint8Array' ,
205
228
'Uint8ClampedArray' ,
206
229
'WeakMap' ,
207
- 'WeakRef' ,
208
230
'WeakSet' ,
209
231
] . forEach ( ( name ) => {
210
232
// eslint-disable-next-line no-restricted-globals
@@ -232,16 +254,12 @@ function copyPrototype(src, dest, prefix) {
232
254
// Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object
233
255
[
234
256
{ name : 'TypedArray' , original : Reflect . getPrototypeOf ( Uint8Array ) } ,
235
- {
236
- name : 'ArrayIterator' , original : {
237
- prototype : Reflect . getPrototypeOf ( Array . prototype [ Symbol . iterator ] ( ) ) ,
238
- }
239
- } ,
240
- {
241
- name : 'StringIterator' , original : {
242
- prototype : Reflect . getPrototypeOf ( String . prototype [ Symbol . iterator ] ( ) ) ,
243
- }
244
- } ,
257
+ { name : 'ArrayIterator' , original : {
258
+ prototype : Reflect . getPrototypeOf ( Array . prototype [ Symbol . iterator ] ( ) ) ,
259
+ } } ,
260
+ { name : 'StringIterator' , original : {
261
+ prototype : Reflect . getPrototypeOf ( String . prototype [ Symbol . iterator ] ( ) ) ,
262
+ } } ,
245
263
] . forEach ( ( { name, original } ) => {
246
264
primordials [ name ] = original ;
247
265
// The static %TypedArray% methods require a valid `this`, but can't be bound,
@@ -254,17 +272,13 @@ function copyPrototype(src, dest, prefix) {
254
272
255
273
const {
256
274
ArrayPrototypeForEach,
257
- FinalizationRegistry,
258
275
FunctionPrototypeCall,
259
276
Map,
260
277
ObjectFreeze,
261
278
ObjectSetPrototypeOf,
262
- Promise,
263
- PromisePrototypeThen,
264
279
Set,
265
280
SymbolIterator,
266
281
WeakMap,
267
- WeakRef,
268
282
WeakSet,
269
283
} = primordials ;
270
284
@@ -309,9 +323,6 @@ const copyProps = (src, dest) => {
309
323
} ) ;
310
324
} ;
311
325
312
- /**
313
- * @type {typeof primordials.makeSafe }
314
- */
315
326
const makeSafe = ( unsafe , safe ) => {
316
327
if ( SymbolIterator in unsafe . prototype ) {
317
328
const dummy = new unsafe ( ) ;
@@ -326,7 +337,7 @@ const makeSafe = (unsafe, safe) => {
326
337
SymbolIterator in ( FunctionPrototypeCall ( desc . value , dummy ) ?? { } )
327
338
) {
328
339
const createIterator = uncurryThis ( desc . value ) ;
329
- next ??= uncurryThis ( createIterator ( dummy ) . next ) ;
340
+ next = next ?? uncurryThis ( createIterator ( dummy ) . next ) ;
330
341
const SafeIterator = createSafeIterator ( createIterator , next ) ;
331
342
desc . value = function ( ) {
332
343
return new SafeIterator ( this ) ;
@@ -363,7 +374,6 @@ primordials.SafeWeakMap = makeSafe(
363
374
constructor ( i ) { super ( i ) ; } // eslint-disable-line no-useless-constructor
364
375
}
365
376
) ;
366
-
367
377
primordials . SafeSet = makeSafe (
368
378
Set ,
369
379
class SafeSet extends Set {
@@ -377,55 +387,6 @@ primordials.SafeWeakSet = makeSafe(
377
387
}
378
388
) ;
379
389
380
- primordials . SafeFinalizationRegistry = makeSafe (
381
- FinalizationRegistry ,
382
- class SafeFinalizationRegistry extends FinalizationRegistry {
383
- // eslint-disable-next-line no-useless-constructor
384
- constructor ( cleanupCallback ) { super ( cleanupCallback ) ; }
385
- }
386
- ) ;
387
- primordials . SafeWeakRef = makeSafe (
388
- WeakRef ,
389
- class SafeWeakRef extends WeakRef {
390
- // eslint-disable-next-line no-useless-constructor
391
- constructor ( target ) { super ( target ) ; }
392
- }
393
- ) ;
394
-
395
- const SafePromise = makeSafe (
396
- Promise ,
397
- class SafePromise extends Promise {
398
- // eslint-disable-next-line no-useless-constructor
399
- constructor ( executor ) { super ( executor ) ; }
400
- }
401
- ) ;
402
-
403
- primordials . PromisePrototypeCatch = ( thisPromise , onRejected ) =>
404
- PromisePrototypeThen ( thisPromise , undefined , onRejected ) ;
405
-
406
- /**
407
- * Attaches a callback that is invoked when the Promise is settled (fulfilled or
408
- * rejected). The resolved value cannot be modified from the callback.
409
- * Prefer using async functions when possible.
410
- * @param {Promise<any> } thisPromise
411
- * @param {() => void) | undefined | null } onFinally The callback to execute
412
- * when the Promise is settled (fulfilled or rejected).
413
- * @returns {Promise } A Promise for the completion of the callback.
414
- */
415
- primordials . SafePromisePrototypeFinally = ( thisPromise , onFinally ) =>
416
- // Wrapping on a new Promise is necessary to not expose the SafePromise
417
- // prototype to user-land.
418
- new Promise ( ( a , b ) =>
419
- new SafePromise ( ( a , b ) => PromisePrototypeThen ( thisPromise , a , b ) )
420
- . finally ( onFinally )
421
- . then ( a , b )
422
- ) ;
423
-
424
- primordials . AsyncIteratorPrototype =
425
- primordials . ReflectGetPrototypeOf (
426
- primordials . ReflectGetPrototypeOf (
427
- async function * ( ) { } ) . prototype ) ;
428
-
429
390
ObjectSetPrototypeOf ( primordials , null ) ;
430
391
ObjectFreeze ( primordials ) ;
431
392
0 commit comments