@@ -253,6 +253,8 @@ const {
253253 Map,
254254 ObjectFreeze,
255255 ObjectSetPrototypeOf,
256+ Promise,
257+ PromisePrototypeThen,
256258 Set,
257259 SymbolIterator,
258260 WeakMap,
@@ -384,5 +386,34 @@ primordials.SafeWeakRef = makeSafe(
384386 }
385387) ;
386388
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+
387418ObjectSetPrototypeOf ( primordials , null ) ;
388419ObjectFreeze ( primordials ) ;
0 commit comments