@@ -40,6 +40,7 @@ const { internalBinding, NativeModule } = loaderExports;
4040const { Object, Symbol } = primordials ;
4141const { getOptionValue } = NativeModule . require ( 'internal/options' ) ;
4242const config = internalBinding ( 'config' ) ;
43+ const { deprecate } = NativeModule . require ( 'internal/util' ) ;
4344
4445setupTraceCategoryState ( ) ;
4546
@@ -63,7 +64,11 @@ setupProcessObject();
6364 hasUncaughtExceptionCaptureCallback ;
6465}
6566
66- setupGlobalVariables ( ) ;
67+ setupGlobalProxy ( ) ;
68+ setupBuffer ( ) ;
69+
70+ process . domain = null ;
71+ process . _exiting = false ;
6772
6873// Bootstrappers for all threads, including worker threads and main thread
6974const perThreadSetup = NativeModule . require ( 'internal/process/per_thread' ) ;
@@ -228,7 +233,6 @@ if (process._invalidDebug) {
228233 'DeprecationWarning' , 'DEP0062' , undefined , true ) ;
229234}
230235
231- const { deprecate } = NativeModule . require ( 'internal/util' ) ;
232236// TODO(jasnell): The following have been globals since around 2012.
233237// That's just silly. The underlying perfctr support has been removed
234238// so these are now deprecated non-ops that can be removed after one
@@ -388,6 +392,8 @@ function setupProcessObject() {
388392 const origProcProto = Object . getPrototypeOf ( process ) ;
389393 Object . setPrototypeOf ( origProcProto , EventEmitter . prototype ) ;
390394 EventEmitter . call ( process ) ;
395+ // Make process globally available to users by putting it on the global proxy
396+ global . process = process ;
391397}
392398
393399function setupProcessStdio ( getStdout , getStdin , getStderr ) {
@@ -415,24 +421,22 @@ function setupProcessStdio(getStdout, getStdin, getStderr) {
415421 } ;
416422}
417423
418- function setupGlobalVariables ( ) {
424+ function setupGlobalProxy ( ) {
419425 Object . defineProperty ( global , Symbol . toStringTag , {
420426 value : 'global' ,
421427 writable : false ,
422428 enumerable : false ,
423429 configurable : true
424430 } ) ;
425- global . process = process ;
426- const util = NativeModule . require ( 'util' ) ;
427431
428432 function makeGetter ( name ) {
429- return util . deprecate ( function ( ) {
433+ return deprecate ( function ( ) {
430434 return this ;
431435 } , `'${ name } ' is deprecated, use 'global'` , 'DEP0016' ) ;
432436 }
433437
434438 function makeSetter ( name ) {
435- return util . deprecate ( function ( value ) {
439+ return deprecate ( function ( value ) {
436440 Object . defineProperty ( this , name , {
437441 configurable : true ,
438442 writable : true ,
@@ -454,7 +458,9 @@ function setupGlobalVariables() {
454458 set : makeSetter ( 'root' )
455459 }
456460 } ) ;
461+ }
457462
463+ function setupBuffer ( ) {
458464 const { Buffer } = NativeModule . require ( 'buffer' ) ;
459465 const bufferBinding = internalBinding ( 'buffer' ) ;
460466
@@ -464,8 +470,6 @@ function setupGlobalVariables() {
464470 delete bufferBinding . zeroFill ;
465471
466472 global . Buffer = Buffer ;
467- process . domain = null ;
468- process . _exiting = false ;
469473}
470474
471475function setupGlobalTimeouts ( ) {
0 commit comments