Skip to content

Commit 9d6291a

Browse files
joyeecheungtargos
authored andcommitted
process: refactor lib/internal/bootstrap/node.js
- Use `deprecate` from `internal/util` instead of from `util` - Split `setupGlobalVariables()` into `setupGlobalProxy()` and `setupBuffer()`, and move out manipulation of the process object. PR-URL: #26033 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Backport-PR-URL: #26085
1 parent 5f6a710 commit 9d6291a

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lib/internal/bootstrap/node.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const { internalBinding, NativeModule } = loaderExports;
4040
const { Object, Symbol } = primordials;
4141
const { getOptionValue } = NativeModule.require('internal/options');
4242
const config = internalBinding('config');
43+
const { deprecate } = NativeModule.require('internal/util');
4344

4445
setupTraceCategoryState();
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
6974
const 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

393399
function 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

471475
function setupGlobalTimeouts() {

0 commit comments

Comments
 (0)