4
4
5
5
const {
6
6
ArrayIsArray,
7
+ ArrayPrototypeForEach,
7
8
ArrayPrototypeMap,
8
9
ArrayPrototypePush,
9
10
Float64Array,
@@ -14,7 +15,9 @@ const {
14
15
ObjectEntries,
15
16
Promise,
16
17
PromiseResolve,
18
+ ReflectApply,
17
19
RegExpPrototypeTest,
20
+ SafeArrayIterator,
18
21
String,
19
22
Symbol,
20
23
SymbolFor,
@@ -155,8 +158,10 @@ class Worker extends EventEmitter {
155
158
let env ;
156
159
if ( typeof options . env === 'object' && options . env !== null ) {
157
160
env = ObjectCreate ( null ) ;
158
- for ( const [ key , value ] of ObjectEntries ( options . env ) )
159
- env [ key ] = `${ value } ` ;
161
+ ArrayPrototypeForEach (
162
+ ObjectEntries ( options . env ) ,
163
+ ( { 0 : key , 1 : value } ) => { env [ key ] = `${ value } ` ; }
164
+ ) ;
160
165
} else if ( options . env == null ) {
161
166
env = process . env ;
162
167
} else if ( options . env !== SHARE_ENV ) {
@@ -209,12 +214,13 @@ class Worker extends EventEmitter {
209
214
const transferList = [ port2 ] ;
210
215
// If transferList is provided.
211
216
if ( options . transferList )
212
- ArrayPrototypePush ( transferList , ...options . transferList ) ;
217
+ ArrayPrototypePush ( transferList ,
218
+ ...new SafeArrayIterator ( options . transferList ) ) ;
213
219
214
220
this [ kPublicPort ] = port1 ;
215
- for ( const event of [ 'message' , 'messageerror' ] ) {
221
+ ArrayPrototypeForEach ( [ 'message' , 'messageerror' ] , ( event ) => {
216
222
this [ kPublicPort ] . on ( event , ( message ) => this . emit ( event , message ) ) ;
217
- }
223
+ } ) ;
218
224
setupPortReferencing ( this [ kPublicPort ] , this , 'message' ) ;
219
225
this [ kPort ] . postMessage ( {
220
226
argv,
@@ -279,8 +285,9 @@ class Worker extends EventEmitter {
279
285
{
280
286
const { stream, chunks } = message ;
281
287
const readable = this [ kParentSideStdio ] [ stream ] ;
282
- for ( const { chunk, encoding } of chunks )
288
+ ArrayPrototypeForEach ( chunks , ( { chunk, encoding } ) => {
283
289
readable . push ( chunk , encoding ) ;
290
+ } ) ;
284
291
return ;
285
292
}
286
293
case messageTypes . STDIO_WANTS_MORE_DATA :
@@ -314,7 +321,7 @@ class Worker extends EventEmitter {
314
321
postMessage ( ...args ) {
315
322
if ( this [ kPublicPort ] === null ) return ;
316
323
317
- this [ kPublicPort ] . postMessage ( ... args ) ;
324
+ ReflectApply ( this [ kPublicPort ] . postMessage , this [ kPublicPort ] , args ) ;
318
325
}
319
326
320
327
terminate ( callback ) {
0 commit comments