@@ -40,6 +40,7 @@ const { internalBinding, NativeModule } = loaderExports;
40
40
const { Object, Symbol } = primordials ;
41
41
const { getOptionValue } = NativeModule . require ( 'internal/options' ) ;
42
42
const config = internalBinding ( 'config' ) ;
43
+ const { deprecate } = NativeModule . require ( 'internal/util' ) ;
43
44
44
45
setupTraceCategoryState ( ) ;
45
46
@@ -63,7 +64,11 @@ setupProcessObject();
63
64
hasUncaughtExceptionCaptureCallback ;
64
65
}
65
66
66
- setupGlobalVariables ( ) ;
67
+ setupGlobalProxy ( ) ;
68
+ setupBuffer ( ) ;
69
+
70
+ process . domain = null ;
71
+ process . _exiting = false ;
67
72
68
73
// Bootstrappers for all threads, including worker threads and main thread
69
74
const perThreadSetup = NativeModule . require ( 'internal/process/per_thread' ) ;
@@ -235,7 +240,6 @@ Object.defineProperty(process, 'allowedNodeEnvironmentFlags', {
235
240
configurable : true
236
241
} ) ;
237
242
238
- const { deprecate } = NativeModule . require ( 'internal/util' ) ;
239
243
// process.assert
240
244
process . assert = deprecate (
241
245
perThreadSetup . assert ,
@@ -350,6 +354,13 @@ function setupProcessObject() {
350
354
const origProcProto = Object . getPrototypeOf ( process ) ;
351
355
Object . setPrototypeOf ( origProcProto , EventEmitter . prototype ) ;
352
356
EventEmitter . call ( process ) ;
357
+ // Make process globally available to users by putting it on the global proxy
358
+ Object . defineProperty ( global , 'process' , {
359
+ value : process ,
360
+ enumerable : false ,
361
+ writable : true ,
362
+ configurable : true
363
+ } ) ;
353
364
}
354
365
355
366
function setupProcessStdio ( getStdout , getStdin , getStderr ) {
@@ -377,29 +388,22 @@ function setupProcessStdio(getStdout, getStdin, getStderr) {
377
388
} ;
378
389
}
379
390
380
- function setupGlobalVariables ( ) {
391
+ function setupGlobalProxy ( ) {
381
392
Object . defineProperty ( global , Symbol . toStringTag , {
382
393
value : 'global' ,
383
394
writable : false ,
384
395
enumerable : false ,
385
396
configurable : true
386
397
} ) ;
387
- Object . defineProperty ( global , 'process' , {
388
- value : process ,
389
- enumerable : false ,
390
- writable : true ,
391
- configurable : true
392
- } ) ;
393
- const util = NativeModule . require ( 'util' ) ;
394
398
395
399
function makeGetter ( name ) {
396
- return util . deprecate ( function ( ) {
400
+ return deprecate ( function ( ) {
397
401
return this ;
398
402
} , `'${ name } ' is deprecated, use 'global'` , 'DEP0016' ) ;
399
403
}
400
404
401
405
function makeSetter ( name ) {
402
- return util . deprecate ( function ( value ) {
406
+ return deprecate ( function ( value ) {
403
407
Object . defineProperty ( this , name , {
404
408
configurable : true ,
405
409
writable : true ,
@@ -421,7 +425,9 @@ function setupGlobalVariables() {
421
425
set : makeSetter ( 'root' )
422
426
}
423
427
} ) ;
428
+ }
424
429
430
+ function setupBuffer ( ) {
425
431
const { Buffer } = NativeModule . require ( 'buffer' ) ;
426
432
const bufferBinding = internalBinding ( 'buffer' ) ;
427
433
@@ -436,9 +442,6 @@ function setupGlobalVariables() {
436
442
writable : true ,
437
443
configurable : true
438
444
} ) ;
439
-
440
- process . domain = null ;
441
- process . _exiting = false ;
442
445
}
443
446
444
447
function setupGlobalTimeouts ( ) {
0 commit comments