From d7bf070652882cc099863c15dbf9ce14fa0776cb Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 31 Jan 2019 03:08:25 +0800 Subject: [PATCH] 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 Reviewed-By: Daniel Bevenius Reviewed-By: James M Snell --- lib/internal/bootstrap/node.js | 23 +------------- lib/internal/bootstrap/pre_execution.js | 40 +++++++++++++++++++++++++ lib/internal/main/check_syntax.js | 2 ++ lib/internal/main/eval_stdin.js | 2 ++ lib/internal/main/eval_string.js | 2 ++ lib/internal/main/repl.js | 2 ++ lib/internal/main/run_main_module.js | 2 ++ lib/internal/main/worker_thread.js | 2 ++ 8 files changed, 53 insertions(+), 22 deletions(-) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 7a59b4f369bf54..338abcf55bb03e 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -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 @@ -307,6 +285,7 @@ Object.defineProperty(process, 'allowedNodeEnvironmentFlags', { enumerable: true, configurable: true }); + // process.assert process.assert = deprecate( perThreadSetup.assert, diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index 798c581a721735..d09fdb131a2ca9 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -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, diff --git a/lib/internal/main/check_syntax.js b/lib/internal/main/check_syntax.js index 5d4d7a04ebd0eb..97584841b3a0c2 100644 --- a/lib/internal/main/check_syntax.js +++ b/lib/internal/main/check_syntax.js @@ -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(); diff --git a/lib/internal/main/eval_stdin.js b/lib/internal/main/eval_stdin.js index ad15fdb93cd49d..f02d9ffa0cea03 100644 --- a/lib/internal/main/eval_stdin.js +++ b/lib/internal/main/eval_stdin.js @@ -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(); diff --git a/lib/internal/main/eval_string.js b/lib/internal/main/eval_string.js index cd382b48e76663..7f746a6b11a951 100644 --- a/lib/internal/main/eval_string.js +++ b/lib/internal/main/eval_string.js @@ -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(); diff --git a/lib/internal/main/repl.js b/lib/internal/main/repl.js index 4ca328421bcb9a..e931444ef32502 100644 --- a/lib/internal/main/repl.js +++ b/lib/internal/main/repl.js @@ -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(); diff --git a/lib/internal/main/run_main_module.js b/lib/internal/main/run_main_module.js index b5049cffc5250c..abc41fc20220f0 100644 --- a/lib/internal/main/run_main_module.js +++ b/lib/internal/main/run_main_module.js @@ -1,12 +1,14 @@ 'use strict'; const { + initializeDeprecations, initializeClusterIPC, initializePolicy, initializeESMLoader, loadPreloadModules } = require('internal/bootstrap/pre_execution'); +initializeDeprecations(); initializeClusterIPC(); initializePolicy(); initializeESMLoader(); diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js index 94d0e613e8ce38..7e4466c24d0c31 100644 --- a/lib/internal/main/worker_thread.js +++ b/lib/internal/main/worker_thread.js @@ -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();