@@ -108,7 +108,6 @@ class Worker extends EventEmitter {
108108
109109 _init ( file , options ) {
110110 const bin = process . execPath || process . argv [ 0 ] ;
111- const limits = options . resourceLimits ;
112111 const args = [ ] ;
113112
114113 // Validate filename.
@@ -187,18 +186,29 @@ class Worker extends EventEmitter {
187186 }
188187
189188 // Enforce resource limits.
190- if ( limits ) {
189+ const limits = new Uint32Array ( 3 ) ;
190+
191+ if ( options . resourceLimits ) {
191192 const argsLen = args . length ;
192- const maxOld = limits . maxOldSpaceSizeMb ;
193- const maxSemi = limits . maxSemiSpaceSizeMb ;
193+ const { maxOldSpaceSizeMb,
194+ maxSemiSpaceSizeMb,
195+ codeRangeSizeMb } = options . resourceLimits ;
196+
197+ if ( typeof maxOldSpaceSizeMb === 'number' )
198+ limits [ 0 ] = Math . max ( maxOldSpaceSizeMb , 2 ) ;
199+
200+ if ( typeof maxSemiSpaceSizeMb === 'number' )
201+ limits [ 1 ] = maxSemiSpaceSizeMb ;
202+
203+ if ( typeof codeRangeSizeMb === 'number' )
204+ limits [ 2 ] = codeRangeSizeMb ;
194205
195- if ( typeof maxOld === 'number' )
196- args . push ( `--max-old-space-size=${ Math . max ( maxOld , 2 ) } ` ) ;
206+ if ( limits [ 0 ] > 0 )
207+ args . push ( `--max-old-space-size=${ limits [ 0 ] } ` ) ;
197208
198- if ( typeof maxSemi === 'number' )
199- args . push ( `--max-semi-space-size=${ maxSemi } ` ) ;
209+ if ( limits [ 1 ] > 0 )
210+ args . push ( `--max-semi-space-size=${ limits [ 1 ] } ` ) ;
200211
201- // Todo: figure out how to do codeRangeSizeMb.
202212 this . _limits = args . length > argsLen ;
203213 }
204214
@@ -226,7 +236,8 @@ class Worker extends EventEmitter {
226236 BTHREADS_WORKER_ID : this . threadId . toString ( 10 ) ,
227237 BTHREADS_WORKER_DATA : encoding . stringify ( options . workerData ) ,
228238 BTHREADS_WORKER_STDIN : options . stdin ? '1' : '0' ,
229- BTHREADS_WORKER_EVAL : options . eval ? '1' : '0'
239+ BTHREADS_WORKER_EVAL : options . eval ? '1' : '0' ,
240+ BTHREADS_WORKER_LIMITS : encoding . stringify ( limits )
230241 } )
231242 } ;
232243
0 commit comments