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 authored and targos committed Feb 10, 2019
1 parent 88019b0 commit d7bf070
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 22 deletions.
23 changes: 1 addition & 22 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,28 +241,6 @@ if (process._invalidDebug) {
}

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];
}
}

// 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 @@ -307,6 +285,7 @@ Object.defineProperty(process, 'allowedNodeEnvironmentFlags', {
enumerable: true,
configurable: true
});

// 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 d7bf070

Please sign in to comment.