Skip to content

Commit

Permalink
process: refactor lib/internal/bootstrap/node.js
Browse files Browse the repository at this point in the history
- 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: nodejs#26033
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
joyeecheung authored and addaleax committed Feb 13, 2019
1 parent 5198297 commit 7d1a00c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/internal/bootstrap/node.js
Expand Up @@ -40,6 +40,7 @@ const { internalBinding, NativeModule } = loaderExports;
const { Object, Symbol } = primordials;
const { getOptionValue } = NativeModule.require('internal/options');
const config = internalBinding('config');
const { deprecate } = NativeModule.require('internal/util');

setupTraceCategoryState();

Expand All @@ -63,7 +64,11 @@ setupProcessObject();
hasUncaughtExceptionCaptureCallback;
}

setupGlobalVariables();
setupGlobalProxy();
setupBuffer();

process.domain = null;
process._exiting = false;

// Bootstrappers for all threads, including worker threads and main thread
const perThreadSetup = NativeModule.require('internal/process/per_thread');
Expand Down Expand Up @@ -228,7 +233,6 @@ if (process._invalidDebug) {
'DeprecationWarning', 'DEP0062', undefined, true);
}

const { deprecate } = NativeModule.require('internal/util');
// TODO(jasnell): The following have been globals since around 2012.
// That's just silly. The underlying perfctr support has been removed
// so these are now deprecated non-ops that can be removed after one
Expand Down Expand Up @@ -388,6 +392,8 @@ function setupProcessObject() {
const origProcProto = Object.getPrototypeOf(process);
Object.setPrototypeOf(origProcProto, EventEmitter.prototype);
EventEmitter.call(process);
// Make process globally available to users by putting it on the global proxy
global.process = process;
}

function setupProcessStdio(getStdout, getStdin, getStderr) {
Expand Down Expand Up @@ -415,24 +421,22 @@ function setupProcessStdio(getStdout, getStdin, getStderr) {
};
}

function setupGlobalVariables() {
function setupGlobalProxy() {
Object.defineProperty(global, Symbol.toStringTag, {
value: 'global',
writable: false,
enumerable: false,
configurable: true
});
global.process = process;
const util = NativeModule.require('util');

function makeGetter(name) {
return util.deprecate(function() {
return deprecate(function() {
return this;
}, `'${name}' is deprecated, use 'global'`, 'DEP0016');
}

function makeSetter(name) {
return util.deprecate(function(value) {
return deprecate(function(value) {
Object.defineProperty(this, name, {
configurable: true,
writable: true,
Expand All @@ -454,7 +458,9 @@ function setupGlobalVariables() {
set: makeSetter('root')
}
});
}

function setupBuffer() {
const { Buffer } = NativeModule.require('buffer');
const bufferBinding = internalBinding('buffer');

Expand All @@ -464,8 +470,6 @@ function setupGlobalVariables() {
delete bufferBinding.zeroFill;

global.Buffer = Buffer;
process.domain = null;
process._exiting = false;
}

function setupGlobalTimeouts() {
Expand Down

0 comments on commit 7d1a00c

Please sign in to comment.