@@ -55,6 +55,8 @@ const {
5555
5656const children = new Set ( ) ;
5757
58+ const SHARE_ENV = Symbol . for ( 'nodejs.worker_threads.SHARE_ENV' ) ;
59+
5860let uid = 1 ;
5961let exitBound = false ;
6062let bundled = null ;
@@ -76,6 +78,13 @@ class Worker extends EventEmitter {
7678 if ( typeof options !== 'object' )
7779 throw new ArgError ( 'options' , options , 'object' ) ;
7880
81+ if ( options . env != null
82+ && typeof options . env !== 'object'
83+ && options . env !== SHARE_ENV ) {
84+ throw new ArgError ( 'env' , options . env ,
85+ [ 'object' , 'worker_threads.SHARE_ENV' ] ) ;
86+ }
87+
7988 if ( options . execArgv && ! Array . isArray ( options . execArgv ) )
8089 throw new ArgError ( 'execArgv' , options . execArgv , 'Array' ) ;
8190
@@ -109,6 +118,9 @@ class Worker extends EventEmitter {
109118 const bin = process . execPath || process . argv [ 0 ] ;
110119 const args = [ ] ;
111120
121+ if ( options . env === SHARE_ENV )
122+ throw new WorkerError ( errors . NO_SHARE_ENV ) ;
123+
112124 // Validate filename.
113125 if ( ! options . eval ) {
114126 if ( ! isAbsolute ( file )
@@ -229,9 +241,10 @@ class Worker extends EventEmitter {
229241 }
230242
231243 // Setup options.
244+ const env = options . env || process . env ;
232245 const opt = {
233246 stdio : [ 'pipe' , 'pipe' , 'pipe' ] ,
234- env : Object . assign ( Object . create ( null ) , process . env , {
247+ env : Object . assign ( Object . create ( null ) , env , {
235248 BTHREADS_WORKER_ID : this . threadId . toString ( 10 ) ,
236249 BTHREADS_WORKER_DATA : encoding . stringify ( options . workerData ) ,
237250 BTHREADS_WORKER_STDIN : options . stdin ? '1' : '0' ,
0 commit comments