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: https://github.com/nodejs/node/pull/26033 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
e5da922668
commit
006e78cecb
@ -40,6 +40,7 @@ const { internalBinding, NativeModule } = loaderExports;
|
|||||||
const { Object, Symbol } = primordials;
|
const { Object, Symbol } = primordials;
|
||||||
const { getOptionValue } = NativeModule.require('internal/options');
|
const { getOptionValue } = NativeModule.require('internal/options');
|
||||||
const config = internalBinding('config');
|
const config = internalBinding('config');
|
||||||
|
const { deprecate } = NativeModule.require('internal/util');
|
||||||
|
|
||||||
setupTraceCategoryState();
|
setupTraceCategoryState();
|
||||||
|
|
||||||
@ -63,7 +64,11 @@ setupProcessObject();
|
|||||||
hasUncaughtExceptionCaptureCallback;
|
hasUncaughtExceptionCaptureCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
setupGlobalVariables();
|
setupGlobalProxy();
|
||||||
|
setupBuffer();
|
||||||
|
|
||||||
|
process.domain = null;
|
||||||
|
process._exiting = false;
|
||||||
|
|
||||||
// Bootstrappers for all threads, including worker threads and main thread
|
// Bootstrappers for all threads, including worker threads and main thread
|
||||||
const perThreadSetup = NativeModule.require('internal/process/per_thread');
|
const perThreadSetup = NativeModule.require('internal/process/per_thread');
|
||||||
@ -235,7 +240,6 @@ Object.defineProperty(process, 'allowedNodeEnvironmentFlags', {
|
|||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const { deprecate } = NativeModule.require('internal/util');
|
|
||||||
// process.assert
|
// process.assert
|
||||||
process.assert = deprecate(
|
process.assert = deprecate(
|
||||||
perThreadSetup.assert,
|
perThreadSetup.assert,
|
||||||
@ -350,6 +354,13 @@ function setupProcessObject() {
|
|||||||
const origProcProto = Object.getPrototypeOf(process);
|
const origProcProto = Object.getPrototypeOf(process);
|
||||||
Object.setPrototypeOf(origProcProto, EventEmitter.prototype);
|
Object.setPrototypeOf(origProcProto, EventEmitter.prototype);
|
||||||
EventEmitter.call(process);
|
EventEmitter.call(process);
|
||||||
|
// Make process globally available to users by putting it on the global proxy
|
||||||
|
Object.defineProperty(global, 'process', {
|
||||||
|
value: process,
|
||||||
|
enumerable: false,
|
||||||
|
writable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupProcessStdio(getStdout, getStdin, getStderr) {
|
function setupProcessStdio(getStdout, getStdin, getStderr) {
|
||||||
@ -377,29 +388,22 @@ function setupProcessStdio(getStdout, getStdin, getStderr) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupGlobalVariables() {
|
function setupGlobalProxy() {
|
||||||
Object.defineProperty(global, Symbol.toStringTag, {
|
Object.defineProperty(global, Symbol.toStringTag, {
|
||||||
value: 'global',
|
value: 'global',
|
||||||
writable: false,
|
writable: false,
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
Object.defineProperty(global, 'process', {
|
|
||||||
value: process,
|
|
||||||
enumerable: false,
|
|
||||||
writable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
const util = NativeModule.require('util');
|
|
||||||
|
|
||||||
function makeGetter(name) {
|
function makeGetter(name) {
|
||||||
return util.deprecate(function() {
|
return deprecate(function() {
|
||||||
return this;
|
return this;
|
||||||
}, `'${name}' is deprecated, use 'global'`, 'DEP0016');
|
}, `'${name}' is deprecated, use 'global'`, 'DEP0016');
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeSetter(name) {
|
function makeSetter(name) {
|
||||||
return util.deprecate(function(value) {
|
return deprecate(function(value) {
|
||||||
Object.defineProperty(this, name, {
|
Object.defineProperty(this, name, {
|
||||||
configurable: true,
|
configurable: true,
|
||||||
writable: true,
|
writable: true,
|
||||||
@ -421,7 +425,9 @@ function setupGlobalVariables() {
|
|||||||
set: makeSetter('root')
|
set: makeSetter('root')
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupBuffer() {
|
||||||
const { Buffer } = NativeModule.require('buffer');
|
const { Buffer } = NativeModule.require('buffer');
|
||||||
const bufferBinding = internalBinding('buffer');
|
const bufferBinding = internalBinding('buffer');
|
||||||
|
|
||||||
@ -436,9 +442,6 @@ function setupGlobalVariables() {
|
|||||||
writable: true,
|
writable: true,
|
||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
|
|
||||||
process.domain = null;
|
|
||||||
process._exiting = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupGlobalTimeouts() {
|
function setupGlobalTimeouts() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user