@@ -47,6 +47,22 @@ function copyPropsRenamed(src, dest, prefix) {
4747 }
4848}
4949
50+ function copyPropsRenamedBound ( src , dest , prefix ) {
51+ for ( const key of Reflect . ownKeys ( src ) ) {
52+ if ( typeof key === 'string' ) {
53+ const desc = Reflect . getOwnPropertyDescriptor ( src , key ) ;
54+ if ( typeof desc . value === 'function' ) {
55+ desc . value = desc . value . bind ( src ) ;
56+ }
57+ Reflect . defineProperty (
58+ dest ,
59+ `${ prefix } ${ key [ 0 ] . toUpperCase ( ) } ${ key . slice ( 1 ) } ` ,
60+ desc
61+ ) ;
62+ }
63+ }
64+ }
65+
5066function copyPrototype ( src , dest , prefix ) {
5167 for ( const key of Reflect . ownKeys ( src ) ) {
5268 if ( typeof key === 'string' ) {
@@ -135,5 +151,17 @@ primordials.SafePromise = makeSafe(
135151 copyPrototype ( original . prototype , primordials , `${ name } Prototype` ) ;
136152} ) ;
137153
154+ // Create copies of intrinsic objects that require a valid `this` to call
155+ // static methods.
156+ // Refs: https://www.ecma-international.org/ecma-262/#sec-promise.all
157+ [
158+ 'Promise' ,
159+ ] . forEach ( ( name ) => {
160+ const original = global [ name ] ;
161+ primordials [ name ] = original ;
162+ copyPropsRenamedBound ( original , primordials , name ) ;
163+ copyPrototype ( original . prototype , primordials , `${ name } Prototype` ) ;
164+ } ) ;
165+
138166Object . setPrototypeOf ( primordials , null ) ;
139167Object . freeze ( primordials ) ;
0 commit comments