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
ObjectGetOwnPropertyDescriptors,
8
11
ObjectGetPrototypeOf,
9
12
ObjectSetPrototypeOf,
13
+ ReflectApply,
10
14
Symbol,
11
15
} = primordials ;
12
16
@@ -87,7 +91,7 @@ ObjectDefineProperty(
87
91
{
88
92
value : function ( data , type ) {
89
93
if ( type !== 'message' && type !== 'messageerror' ) {
90
- return originalCreateEvent . call ( this , data , type ) ;
94
+ return ReflectApply ( originalCreateEvent , this , arguments ) ;
91
95
}
92
96
return new MessageEvent ( data , this , type ) ;
93
97
} ,
@@ -131,7 +135,7 @@ ObjectDefineProperty(MessagePort.prototype, handleOnCloseSymbol, {
131
135
MessagePort . prototype . close = function ( cb ) {
132
136
if ( typeof cb === 'function' )
133
137
this . once ( 'close' , cb ) ;
134
- MessagePortPrototype . close . call ( this ) ;
138
+ FunctionPrototypeCall ( MessagePortPrototype . close , this ) ;
135
139
} ;
136
140
137
141
ObjectDefineProperty ( MessagePort . prototype , inspect . custom , {
@@ -142,7 +146,7 @@ ObjectDefineProperty(MessagePort.prototype, inspect.custom, {
142
146
try {
143
147
// This may throw when `this` does not refer to a native object,
144
148
// e.g. when accessing the prototype directly.
145
- ref = MessagePortPrototype . hasRef . call ( this ) ;
149
+ ref = FunctionPrototypeCall ( MessagePortPrototype . hasRef , this ) ;
146
150
} catch { return this ; }
147
151
return ObjectAssign ( ObjectCreate ( MessagePort . prototype ) ,
148
152
ref === undefined ? {
@@ -170,18 +174,18 @@ function setupPortReferencing(port, eventEmitter, eventName) {
170
174
const origNewListener = eventEmitter [ kNewListener ] ;
171
175
eventEmitter [ kNewListener ] = function ( size , type , ...args ) {
172
176
if ( type === eventName ) newListener ( size - 1 ) ;
173
- return origNewListener . call ( this , size , type , ... args ) ;
177
+ return ReflectApply ( origNewListener , this , arguments ) ;
174
178
} ;
175
179
const origRemoveListener = eventEmitter [ kRemoveListener ] ;
176
180
eventEmitter [ kRemoveListener ] = function ( size , type , ...args ) {
177
181
if ( type === eventName ) removeListener ( size ) ;
178
- return origRemoveListener . call ( this , size , type , ... args ) ;
182
+ return ReflectApply ( origRemoveListener , this , arguments ) ;
179
183
} ;
180
184
181
185
function newListener ( size ) {
182
186
if ( size === 0 ) {
183
187
port . ref ( ) ;
184
- MessagePortPrototype . start . call ( port ) ;
188
+ FunctionPrototypeCall ( MessagePortPrototype . start , port ) ;
185
189
}
186
190
}
187
191
@@ -235,9 +239,10 @@ class WritableWorkerStdio extends Writable {
235
239
this [ kPort ] . postMessage ( {
236
240
type : messageTypes . STDIO_PAYLOAD ,
237
241
stream : this [ kName ] ,
238
- chunks : chunks . map ( ( { chunk, encoding } ) => ( { chunk, encoding } ) )
242
+ chunks : ArrayPrototypeMap ( chunks ,
243
+ ( { chunk, encoding } ) => ( { chunk, encoding } ) ) ,
239
244
} ) ;
240
- this [ kWritableCallbacks ] . push ( cb ) ;
245
+ ArrayPrototypePush ( this [ kWritableCallbacks ] , cb ) ;
241
246
if ( this [ kPort ] [ kWaitingStreams ] ++ === 0 )
242
247
this [ kPort ] . ref ( ) ;
243
248
}
0 commit comments