1
1
'use strict' ;
2
2
3
3
const {
4
+ ArrayPrototypeMap,
5
+ ArrayPrototypePush,
6
+ FunctionPrototypeCall,
4
7
ObjectAssign,
5
8
ObjectCreate,
6
9
ObjectDefineProperty,
7
10
ObjectDefineProperties,
8
11
ObjectGetOwnPropertyDescriptors,
9
12
ObjectGetPrototypeOf,
10
13
ObjectSetPrototypeOf,
14
+ ReflectApply,
11
15
Symbol,
12
16
} = primordials ;
13
17
@@ -142,7 +146,7 @@ ObjectDefineProperty(
142
146
{
143
147
value : function ( data , type ) {
144
148
if ( type !== 'message' && type !== 'messageerror' ) {
145
- return originalCreateEvent . call ( this , data , type ) ;
149
+ return ReflectApply ( originalCreateEvent , this , arguments ) ;
146
150
}
147
151
return new MessageEvent ( type , { data } ) ;
148
152
} ,
@@ -186,7 +190,7 @@ ObjectDefineProperty(MessagePort.prototype, handleOnCloseSymbol, {
186
190
MessagePort . prototype . close = function ( cb ) {
187
191
if ( typeof cb === 'function' )
188
192
this . once ( 'close' , cb ) ;
189
- MessagePortPrototype . close . call ( this ) ;
193
+ FunctionPrototypeCall ( MessagePortPrototype . close , this ) ;
190
194
} ;
191
195
192
196
ObjectDefineProperty ( MessagePort . prototype , inspect . custom , {
@@ -197,7 +201,7 @@ ObjectDefineProperty(MessagePort.prototype, inspect.custom, {
197
201
try {
198
202
// This may throw when `this` does not refer to a native object,
199
203
// e.g. when accessing the prototype directly.
200
- ref = MessagePortPrototype . hasRef . call ( this ) ;
204
+ ref = FunctionPrototypeCall ( MessagePortPrototype . hasRef , this ) ;
201
205
} catch { return this ; }
202
206
return ObjectAssign ( ObjectCreate ( MessagePort . prototype ) ,
203
207
ref === undefined ? {
@@ -225,18 +229,18 @@ function setupPortReferencing(port, eventEmitter, eventName) {
225
229
const origNewListener = eventEmitter [ kNewListener ] ;
226
230
eventEmitter [ kNewListener ] = function ( size , type , ...args ) {
227
231
if ( type === eventName ) newListener ( size - 1 ) ;
228
- return origNewListener . call ( this , size , type , ... args ) ;
232
+ return ReflectApply ( origNewListener , this , arguments ) ;
229
233
} ;
230
234
const origRemoveListener = eventEmitter [ kRemoveListener ] ;
231
235
eventEmitter [ kRemoveListener ] = function ( size , type , ...args ) {
232
236
if ( type === eventName ) removeListener ( size ) ;
233
- return origRemoveListener . call ( this , size , type , ... args ) ;
237
+ return ReflectApply ( origRemoveListener , this , arguments ) ;
234
238
} ;
235
239
236
240
function newListener ( size ) {
237
241
if ( size === 0 ) {
238
242
port . ref ( ) ;
239
- MessagePortPrototype . start . call ( port ) ;
243
+ FunctionPrototypeCall ( MessagePortPrototype . start , port ) ;
240
244
}
241
245
}
242
246
@@ -290,9 +294,10 @@ class WritableWorkerStdio extends Writable {
290
294
this [ kPort ] . postMessage ( {
291
295
type : messageTypes . STDIO_PAYLOAD ,
292
296
stream : this [ kName ] ,
293
- chunks : chunks . map ( ( { chunk, encoding } ) => ( { chunk, encoding } ) )
297
+ chunks : ArrayPrototypeMap ( chunks ,
298
+ ( { chunk, encoding } ) => ( { chunk, encoding } ) ) ,
294
299
} ) ;
295
- this [ kWritableCallbacks ] . push ( cb ) ;
300
+ ArrayPrototypePush ( this [ kWritableCallbacks ] , cb ) ;
296
301
if ( this [ kPort ] [ kWaitingStreams ] ++ === 0 )
297
302
this [ kPort ] . ref ( ) ;
298
303
}
0 commit comments