11'use strict' ;
22
33const {
4+ ArrayPrototypeMap,
5+ ArrayPrototypePush,
6+ FunctionPrototypeCall,
47 ObjectAssign,
58 ObjectCreate,
69 ObjectDefineProperty,
710 ObjectDefineProperties,
811 ObjectGetOwnPropertyDescriptors,
912 ObjectGetPrototypeOf,
1013 ObjectSetPrototypeOf,
14+ ReflectApply,
1115 Symbol,
1216} = primordials ;
1317
@@ -142,7 +146,7 @@ ObjectDefineProperty(
142146{
143147value : function ( data , type ) {
144148if ( type !== 'message' && type !== 'messageerror' ) {
145- return originalCreateEvent . call ( this , data , type ) ;
149+ return ReflectApply ( originalCreateEvent , this , arguments ) ;
146150}
147151return new MessageEvent ( type , { data } ) ;
148152} ,
@@ -186,7 +190,7 @@ ObjectDefineProperty(MessagePort.prototype, handleOnCloseSymbol,{
186190MessagePort . prototype . close = function ( cb ) {
187191if ( typeof cb === 'function' )
188192this . once ( 'close' , cb ) ;
189- MessagePortPrototype . close . call ( this ) ;
193+ FunctionPrototypeCall ( MessagePortPrototype . close , this ) ;
190194} ;
191195
192196ObjectDefineProperty ( MessagePort . prototype , inspect . custom , {
@@ -197,7 +201,7 @@ ObjectDefineProperty(MessagePort.prototype, inspect.custom,{
197201try {
198202// This may throw when `this` does not refer to a native object,
199203// e.g. when accessing the prototype directly.
200- ref = MessagePortPrototype . hasRef . call ( this ) ;
204+ ref = FunctionPrototypeCall ( MessagePortPrototype . hasRef , this ) ;
201205} catch { return this ; }
202206return ObjectAssign ( ObjectCreate ( MessagePort . prototype ) ,
203207ref === undefined ? {
@@ -225,18 +229,18 @@ function setupPortReferencing(port, eventEmitter, eventName){
225229const origNewListener = eventEmitter [ kNewListener ] ;
226230eventEmitter [ kNewListener ] = function ( size , type , ...args ) {
227231if ( type === eventName ) newListener ( size - 1 ) ;
228- return origNewListener . call ( this , size , type , ... args ) ;
232+ return ReflectApply ( origNewListener , this , arguments ) ;
229233} ;
230234const origRemoveListener = eventEmitter [ kRemoveListener ] ;
231235eventEmitter [ kRemoveListener ] = function ( size , type , ...args ) {
232236if ( type === eventName ) removeListener ( size ) ;
233- return origRemoveListener . call ( this , size , type , ... args ) ;
237+ return ReflectApply ( origRemoveListener , this , arguments ) ;
234238} ;
235239
236240function newListener ( size ) {
237241if ( size === 0 ) {
238242port . ref ( ) ;
239- MessagePortPrototype . start . call ( port ) ;
243+ FunctionPrototypeCall ( MessagePortPrototype . start , port ) ;
240244}
241245}
242246
@@ -290,9 +294,10 @@ class WritableWorkerStdio extends Writable{
290294this [ kPort ] . postMessage ( {
291295type : messageTypes . STDIO_PAYLOAD ,
292296stream : this [ kName ] ,
293- chunks : chunks . map ( ( { chunk, encoding } ) => ( { chunk, encoding } ) )
297+ chunks : ArrayPrototypeMap ( chunks ,
298+ ( { chunk, encoding } ) => ( { chunk, encoding } ) ) ,
294299} ) ;
295- this [ kWritableCallbacks ] . push ( cb ) ;
300+ ArrayPrototypePush ( this [ kWritableCallbacks ] , cb ) ;
296301if ( this [ kPort ] [ kWaitingStreams ] ++ === 0 )
297302this [ kPort ] . ref ( ) ;
298303}
0 commit comments