process: move deprecation warning initialization into pre_execution.js
Since this is only necessary when user code execution is expected. PR-URL: https://github.com/nodejs/node/pull/25825 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
041424f87c
commit
09a5f0252e
@ -226,29 +226,6 @@ Object.defineProperty(process, 'argv0', {
|
||||
});
|
||||
process.argv[0] = process.execPath;
|
||||
|
||||
const { deprecate } = NativeModule.require('internal/util');
|
||||
{
|
||||
// Install legacy getters on the `util` binding for typechecking.
|
||||
// TODO(addaleax): Turn into a full runtime deprecation.
|
||||
const pendingDeprecation = getOptionValue('--pending-deprecation');
|
||||
const utilBinding = internalBinding('util');
|
||||
const types = NativeModule.require('internal/util/types');
|
||||
for (const name of [
|
||||
'isArrayBuffer', 'isArrayBufferView', 'isAsyncFunction',
|
||||
'isDataView', 'isDate', 'isExternal', 'isMap', 'isMapIterator',
|
||||
'isNativeError', 'isPromise', 'isRegExp', 'isSet', 'isSetIterator',
|
||||
'isTypedArray', 'isUint8Array', 'isAnyArrayBuffer'
|
||||
]) {
|
||||
utilBinding[name] = pendingDeprecation ?
|
||||
deprecate(types[name],
|
||||
'Accessing native typechecking bindings of Node ' +
|
||||
'directly is deprecated. ' +
|
||||
`Please use \`util.types.${name}\` instead.`,
|
||||
'DEP0103') :
|
||||
types[name];
|
||||
}
|
||||
}
|
||||
|
||||
// process.allowedNodeEnvironmentFlags
|
||||
Object.defineProperty(process, 'allowedNodeEnvironmentFlags', {
|
||||
get() {
|
||||
@ -269,6 +246,8 @@ Object.defineProperty(process, 'allowedNodeEnvironmentFlags', {
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
const { deprecate } = NativeModule.require('internal/util');
|
||||
// process.assert
|
||||
process.assert = deprecate(
|
||||
perThreadSetup.assert,
|
||||
|
@ -2,6 +2,45 @@
|
||||
|
||||
const { getOptionValue } = require('internal/options');
|
||||
|
||||
// In general deprecations are intialized wherever the APIs are implemented,
|
||||
// this is used to deprecate APIs implemented in C++ where the deprecation
|
||||
// utitlities are not easily accessible.
|
||||
function initializeDeprecations() {
|
||||
const { deprecate } = require('internal/util');
|
||||
const pendingDeprecation = getOptionValue('--pending-deprecation');
|
||||
|
||||
// DEP0103: access to `process.binding('util').isX` type checkers
|
||||
// TODO(addaleax): Turn into a full runtime deprecation.
|
||||
const utilBinding = internalBinding('util');
|
||||
const types = require('internal/util/types');
|
||||
for (const name of [
|
||||
'isArrayBuffer',
|
||||
'isArrayBufferView',
|
||||
'isAsyncFunction',
|
||||
'isDataView',
|
||||
'isDate',
|
||||
'isExternal',
|
||||
'isMap',
|
||||
'isMapIterator',
|
||||
'isNativeError',
|
||||
'isPromise',
|
||||
'isRegExp',
|
||||
'isSet',
|
||||
'isSetIterator',
|
||||
'isTypedArray',
|
||||
'isUint8Array',
|
||||
'isAnyArrayBuffer'
|
||||
]) {
|
||||
utilBinding[name] = pendingDeprecation ?
|
||||
deprecate(types[name],
|
||||
'Accessing native typechecking bindings of Node ' +
|
||||
'directly is deprecated. ' +
|
||||
`Please use \`util.types.${name}\` instead.`,
|
||||
'DEP0103') :
|
||||
types[name];
|
||||
}
|
||||
}
|
||||
|
||||
function initializeClusterIPC() {
|
||||
// If this is a worker in cluster mode, start up the communication
|
||||
// channel. This needs to be done before any user code gets executed
|
||||
@ -75,6 +114,7 @@ function loadPreloadModules() {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
initializeDeprecations,
|
||||
initializeClusterIPC,
|
||||
initializePolicy,
|
||||
initializeESMLoader,
|
||||
|
@ -4,6 +4,7 @@
|
||||
// instead of actually running the file.
|
||||
|
||||
const {
|
||||
initializeDeprecations,
|
||||
initializeClusterIPC,
|
||||
initializePolicy,
|
||||
initializeESMLoader,
|
||||
@ -21,6 +22,7 @@ const {
|
||||
} = require('internal/modules/cjs/helpers');
|
||||
|
||||
// TODO(joyeecheung): not every one of these are necessary
|
||||
initializeDeprecations();
|
||||
initializeClusterIPC();
|
||||
initializePolicy();
|
||||
initializeESMLoader();
|
||||
|
@ -3,6 +3,7 @@
|
||||
// Stdin is not a TTY, we will read it and execute it.
|
||||
|
||||
const {
|
||||
initializeDeprecations,
|
||||
initializeClusterIPC,
|
||||
initializePolicy,
|
||||
initializeESMLoader,
|
||||
@ -14,6 +15,7 @@ const {
|
||||
readStdin
|
||||
} = require('internal/process/execution');
|
||||
|
||||
initializeDeprecations();
|
||||
initializeClusterIPC();
|
||||
initializePolicy();
|
||||
initializeESMLoader();
|
||||
|
@ -4,6 +4,7 @@
|
||||
// `--interactive`.
|
||||
|
||||
const {
|
||||
initializeDeprecations,
|
||||
initializeClusterIPC,
|
||||
initializePolicy,
|
||||
initializeESMLoader,
|
||||
@ -13,6 +14,7 @@ const { evalScript } = require('internal/process/execution');
|
||||
const { addBuiltinLibsToObject } = require('internal/modules/cjs/helpers');
|
||||
|
||||
const source = require('internal/options').getOptionValue('--eval');
|
||||
initializeDeprecations();
|
||||
initializeClusterIPC();
|
||||
initializePolicy();
|
||||
initializeESMLoader();
|
||||
|
@ -4,6 +4,7 @@
|
||||
// the main module is not specified and stdin is a TTY.
|
||||
|
||||
const {
|
||||
initializeDeprecations,
|
||||
initializeClusterIPC,
|
||||
initializePolicy,
|
||||
initializeESMLoader,
|
||||
@ -14,6 +15,7 @@ const {
|
||||
evalScript
|
||||
} = require('internal/process/execution');
|
||||
|
||||
initializeDeprecations();
|
||||
initializeClusterIPC();
|
||||
initializePolicy();
|
||||
initializeESMLoader();
|
||||
|
@ -1,12 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const {
|
||||
initializeDeprecations,
|
||||
initializeClusterIPC,
|
||||
initializePolicy,
|
||||
initializeESMLoader,
|
||||
loadPreloadModules
|
||||
} = require('internal/bootstrap/pre_execution');
|
||||
|
||||
initializeDeprecations();
|
||||
initializeClusterIPC();
|
||||
initializePolicy();
|
||||
initializeESMLoader();
|
||||
|
@ -4,6 +4,7 @@
|
||||
// message port.
|
||||
|
||||
const {
|
||||
initializeDeprecations,
|
||||
initializeClusterIPC,
|
||||
initializeESMLoader,
|
||||
loadPreloadModules
|
||||
@ -55,6 +56,7 @@ port.on('message', (message) => {
|
||||
if (manifestSrc) {
|
||||
require('internal/process/policy').setup(manifestSrc, manifestURL);
|
||||
}
|
||||
initializeDeprecations();
|
||||
initializeClusterIPC();
|
||||
initializeESMLoader();
|
||||
loadPreloadModules();
|
||||
|
Loading…
x
Reference in New Issue
Block a user