@@ -47,6 +47,22 @@ function copyPropsRenamed(src, dest, prefix) {
47
47
}
48
48
}
49
49
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
+
50
66
function copyPrototype ( src , dest , prefix ) {
51
67
for ( const key of Reflect . ownKeys ( src ) ) {
52
68
if ( typeof key === 'string' ) {
@@ -135,5 +151,17 @@ primordials.SafePromise = makeSafe(
135
151
copyPrototype ( original . prototype , primordials , `${ name } Prototype` ) ;
136
152
} ) ;
137
153
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
+
138
166
Object . setPrototypeOf ( primordials , null ) ;
139
167
Object . freeze ( primordials ) ;
0 commit comments