Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v11.x] process: refactor lib/internal/bootstrap/node.js #26085

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
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