@@ -253,6 +253,8 @@ const {
253
253
Map,
254
254
ObjectFreeze,
255
255
ObjectSetPrototypeOf,
256
+ Promise,
257
+ PromisePrototypeThen,
256
258
Set,
257
259
SymbolIterator,
258
260
WeakMap,
@@ -384,5 +386,34 @@ primordials.SafeWeakRef = makeSafe(
384
386
}
385
387
) ;
386
388
389
+ const SafePromise = makeSafe (
390
+ Promise ,
391
+ class SafePromise extends Promise {
392
+ // eslint-disable-next-line no-useless-constructor
393
+ constructor ( executor ) { super ( executor ) ; }
394
+ }
395
+ ) ;
396
+
397
+ primordials . PromisePrototypeCatch = ( thisPromise , onRejected ) =>
398
+ PromisePrototypeThen ( thisPromise , undefined , onRejected ) ;
399
+
400
+ /**
401
+ * Attaches a callback that is invoked when the Promise is settled (fulfilled or
402
+ * rejected). The resolved value cannot be modified from the callback.
403
+ * Prefer using async functions when possible.
404
+ * @param {Promise<any> } thisPromise
405
+ * @param {() => void) | undefined | null } onFinally The callback to execute
406
+ * when the Promise is settled (fulfilled or rejected).
407
+ * @returns A Promise for the completion of the callback.
408
+ */
409
+ primordials . SafePromisePrototypeFinally = ( thisPromise , onFinally ) =>
410
+ // Wrapping on a new Promise is necessary to not expose the SafePromise
411
+ // prototype to user-land.
412
+ new Promise ( ( a , b ) =>
413
+ new SafePromise ( ( a , b ) => PromisePrototypeThen ( thisPromise , a , b ) )
414
+ . finally ( onFinally )
415
+ . then ( a , b )
416
+ ) ;
417
+
387
418
ObjectSetPrototypeOf ( primordials , null ) ;
388
419
ObjectFreeze ( primordials ) ;
0 commit comments