Skip to content

Commit 006e78c

Browse files
committed
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 <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent e5da922 commit 006e78c

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

lib/internal/bootstrap/node.js

Lines changed: 18 additions & 15 deletions
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');
@@ -235,7 +240,6 @@ Object.defineProperty(process, 'allowedNodeEnvironmentFlags', {
235240
configurable: true
236241
});
237242

238-
const { deprecate } = NativeModule.require('internal/util');
239243
// process.assert
240244
process.assert = deprecate(
241245
perThreadSetup.assert,
@@ -350,6 +354,13 @@ function setupProcessObject() {
350354
const origProcProto = Object.getPrototypeOf(process);
351355
Object.setPrototypeOf(origProcProto, EventEmitter.prototype);
352356
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+
});
353364
}
354365

355366
function setupProcessStdio(getStdout, getStdin, getStderr) {
@@ -377,29 +388,22 @@ function setupProcessStdio(getStdout, getStdin, getStderr) {
377388
};
378389
}
379390

380-
function setupGlobalVariables() {
391+
function setupGlobalProxy() {
381392
Object.defineProperty(global, Symbol.toStringTag, {
382393
value: 'global',
383394
writable: false,
384395
enumerable: false,
385396
configurable: true
386397
});
387-
Object.defineProperty(global, 'process', {
388-
value: process,
389-
enumerable: false,
390-
writable: true,
391-
configurable: true
392-
});
393-
const util = NativeModule.require('util');
394398

395399
function makeGetter(name) {
396-
return util.deprecate(function() {
400+
return deprecate(function() {
397401
return this;
398402
}, `'${name}' is deprecated, use 'global'`, 'DEP0016');
399403
}
400404

401405
function makeSetter(name) {
402-
return util.deprecate(function(value) {
406+
return deprecate(function(value) {
403407
Object.defineProperty(this, name, {
404408
configurable: true,
405409
writable: true,
@@ -421,7 +425,9 @@ function setupGlobalVariables() {
421425
set: makeSetter('root')
422426
}
423427
});
428+
}
424429

430+
function setupBuffer() {
425431
const { Buffer } = NativeModule.require('buffer');
426432
const bufferBinding = internalBinding('buffer');
427433

@@ -436,9 +442,6 @@ function setupGlobalVariables() {
436442
writable: true,
437443
configurable: true
438444
});
439-
440-
process.domain = null;
441-
process._exiting = false;
442445
}
443446

444447
function setupGlobalTimeouts() {

0 commit comments

Comments
 (0)