Skip to content

Commit

Permalink
process: move deprecation warning initialization into pre_execution.js
Browse files Browse the repository at this point in the history
Since this is only necessary when user code execution is expected.

PR-URL: #25825
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
joyeecheung committed Feb 8, 2019
1 parent 041424f commit 09a5f02
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 23 deletions.
25 changes: 2 additions & 23 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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,
Expand Down
40 changes: 40 additions & 0 deletions lib/internal/bootstrap/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -75,6 +114,7 @@ function loadPreloadModules() {
}

module.exports = {
initializeDeprecations,
initializeClusterIPC,
initializePolicy,
initializeESMLoader,
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/main/check_syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// instead of actually running the file.

const {
initializeDeprecations,
initializeClusterIPC,
initializePolicy,
initializeESMLoader,
Expand All @@ -21,6 +22,7 @@ const {
} = require('internal/modules/cjs/helpers');

// TODO(joyeecheung): not every one of these are necessary
initializeDeprecations();
initializeClusterIPC();
initializePolicy();
initializeESMLoader();
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/main/eval_stdin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Stdin is not a TTY, we will read it and execute it.

const {
initializeDeprecations,
initializeClusterIPC,
initializePolicy,
initializeESMLoader,
Expand All @@ -14,6 +15,7 @@ const {
readStdin
} = require('internal/process/execution');

initializeDeprecations();
initializeClusterIPC();
initializePolicy();
initializeESMLoader();
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/main/eval_string.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// `--interactive`.

const {
initializeDeprecations,
initializeClusterIPC,
initializePolicy,
initializeESMLoader,
Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/main/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// the main module is not specified and stdin is a TTY.

const {
initializeDeprecations,
initializeClusterIPC,
initializePolicy,
initializeESMLoader,
Expand All @@ -14,6 +15,7 @@ const {
evalScript
} = require('internal/process/execution');

initializeDeprecations();
initializeClusterIPC();
initializePolicy();
initializeESMLoader();
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/main/run_main_module.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
'use strict';

const {
initializeDeprecations,
initializeClusterIPC,
initializePolicy,
initializeESMLoader,
loadPreloadModules
} = require('internal/bootstrap/pre_execution');

initializeDeprecations();
initializeClusterIPC();
initializePolicy();
initializeESMLoader();
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/main/worker_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// message port.

const {
initializeDeprecations,
initializeClusterIPC,
initializeESMLoader,
loadPreloadModules
Expand Down Expand Up @@ -55,6 +56,7 @@ port.on('message', (message) => {
if (manifestSrc) {
require('internal/process/policy').setup(manifestSrc, manifestURL);
}
initializeDeprecations();
initializeClusterIPC();
initializeESMLoader();
loadPreloadModules();
Expand Down

0 comments on commit 09a5f02

Please sign in to comment.