lib: remove internalBinding('config').pendingDeprecation

Instead use
`require('internal/options').getOptionValue('--pending-deprecation')`

PR-URL: https://github.com/nodejs/node/pull/24962
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Joyee Cheung 2018-12-12 01:24:59 +08:00 committed by Rich Trott
parent 6a24014ee5
commit b32e5e08b2
4 changed files with 24 additions and 19 deletions

View File

@ -48,9 +48,7 @@ const {
isArrayBufferView, isArrayBufferView,
isUint8Array isUint8Array
} = require('internal/util/types'); } = require('internal/util/types');
const {
pendingDeprecation
} = internalBinding('config');
const { const {
ERR_BUFFER_OUT_OF_BOUNDS, ERR_BUFFER_OUT_OF_BOUNDS,
ERR_OUT_OF_RANGE, ERR_OUT_OF_RANGE,
@ -138,7 +136,7 @@ const bufferWarning = 'Buffer() is deprecated due to security and usability ' +
function showFlaggedDeprecation() { function showFlaggedDeprecation() {
if (bufferWarningAlreadyEmitted || if (bufferWarningAlreadyEmitted ||
++nodeModulesCheckCounter > 10000 || ++nodeModulesCheckCounter > 10000 ||
(!pendingDeprecation && (!require('internal/options').getOptionValue('--pending-deprecation') &&
isInsideNodeModules())) { isInsideNodeModules())) {
// We don't emit a warning, because we either: // We don't emit a warning, because we either:
// - Already did so, or // - Already did so, or

View File

@ -176,7 +176,7 @@ function startup() {
{ {
// Install legacy getters on the `util` binding for typechecking. // Install legacy getters on the `util` binding for typechecking.
// TODO(addaleax): Turn into a full runtime deprecation. // TODO(addaleax): Turn into a full runtime deprecation.
const { pendingDeprecation } = internalBinding('config'); const pendingDeprecation = getOptionValue('--pending-deprecation');
const utilBinding = internalBinding('util'); const utilBinding = internalBinding('util');
const types = internalBinding('types'); const types = internalBinding('types');
for (const name of [ for (const name of [

View File

@ -77,9 +77,6 @@ static void Initialize(Local<Object> target,
if (env->options()->experimental_repl_await) if (env->options()->experimental_repl_await)
READONLY_TRUE_PROPERTY(target, "experimentalREPLAwait"); READONLY_TRUE_PROPERTY(target, "experimentalREPLAwait");
if (env->options()->pending_deprecation)
READONLY_TRUE_PROPERTY(target, "pendingDeprecation");
if (env->options()->expose_internals) if (env->options()->expose_internals)
READONLY_TRUE_PROPERTY(target, "exposeInternals"); READONLY_TRUE_PROPERTY(target, "exposeInternals");

View File

@ -1,36 +1,45 @@
'use strict'; 'use strict';
// Tests that --pending-deprecation and NODE_PENDING_DEPRECATION both // Flags: --expose-internals
// set the process.binding('config').pendingDeprecation flag that is // Tests that --pending-deprecation and NODE_PENDING_DEPRECATION both set the
// used to determine if pending deprecation messages should be shown. // `require('internal/options').getOptionValue('--pending-deprecation')`
// The test is performed by launching two child processes that run // flag that is used to determine if pending deprecation messages should be
// shown. The test is performed by launching two child processes that run
// this same test script with different arguments. If those exit with // this same test script with different arguments. If those exit with
// code 0, then the test passes. If they don't, it fails. // code 0, then the test passes. If they don't, it fails.
// TODO(joyeecheung): instead of testing internals, test the actual features
// pending deprecations.
const common = require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const config = process.binding('config');
const fork = require('child_process').fork; const fork = require('child_process').fork;
const { getOptionValue } = require('internal/options');
function message(name) { function message(name) {
return `${name} did not set the process.binding('config').` + return `${name} did not affect getOptionValue('--pending-deprecation')`;
'pendingDeprecation flag.';
} }
switch (process.argv[2]) { switch (process.argv[2]) {
case 'env': case 'env':
case 'switch': case 'switch':
assert.strictEqual(config.pendingDeprecation, true); assert.strictEqual(
getOptionValue('--pending-deprecation'),
true
);
break; break;
default: default:
// Verify that the flag is off by default. // Verify that the flag is off by default.
const envvar = process.env.NODE_PENDING_DEPRECATION; const envvar = process.env.NODE_PENDING_DEPRECATION;
assert.strictEqual(config.pendingDeprecation, envvar && envvar[0] === '1'); assert.strictEqual(
getOptionValue('--pending-deprecation'),
!!(envvar && envvar[0] === '1')
);
// Test the --pending-deprecation command line switch. // Test the --pending-deprecation command line switch.
fork(__filename, ['switch'], { fork(__filename, ['switch'], {
execArgv: ['--pending-deprecation'], execArgv: ['--pending-deprecation', '--expose-internals'],
silent: true silent: true
}).on('exit', common.mustCall((code) => { }).on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0, message('--pending-deprecation')); assert.strictEqual(code, 0, message('--pending-deprecation'));
@ -38,7 +47,7 @@ switch (process.argv[2]) {
// Test the --pending_deprecation command line switch. // Test the --pending_deprecation command line switch.
fork(__filename, ['switch'], { fork(__filename, ['switch'], {
execArgv: ['--pending_deprecation'], execArgv: ['--pending_deprecation', '--expose-internals'],
silent: true silent: true
}).on('exit', common.mustCall((code) => { }).on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0, message('--pending_deprecation')); assert.strictEqual(code, 0, message('--pending_deprecation'));
@ -47,6 +56,7 @@ switch (process.argv[2]) {
// Test the NODE_PENDING_DEPRECATION environment var. // Test the NODE_PENDING_DEPRECATION environment var.
fork(__filename, ['env'], { fork(__filename, ['env'], {
env: Object.assign({}, process.env, { NODE_PENDING_DEPRECATION: 1 }), env: Object.assign({}, process.env, { NODE_PENDING_DEPRECATION: 1 }),
execArgv: ['--expose-internals'],
silent: true silent: true
}).on('exit', common.mustCall((code) => { }).on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0, message('NODE_PENDING_DEPRECATION')); assert.strictEqual(code, 0, message('NODE_PENDING_DEPRECATION'));