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

View File

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

View File

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

View File

@ -1,36 +1,45 @@
'use strict';
// Tests that --pending-deprecation and NODE_PENDING_DEPRECATION both
// set the process.binding('config').pendingDeprecation flag that is
// used to determine if pending deprecation messages should be shown.
// The test is performed by launching two child processes that run
// Flags: --expose-internals
// Tests that --pending-deprecation and NODE_PENDING_DEPRECATION both set the
// `require('internal/options').getOptionValue('--pending-deprecation')`
// 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
// 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 assert = require('assert');
const config = process.binding('config');
const fork = require('child_process').fork;
const { getOptionValue } = require('internal/options');
function message(name) {
return `${name} did not set the process.binding('config').` +
'pendingDeprecation flag.';
return `${name} did not affect getOptionValue('--pending-deprecation')`;
}
switch (process.argv[2]) {
case 'env':
case 'switch':
assert.strictEqual(config.pendingDeprecation, true);
assert.strictEqual(
getOptionValue('--pending-deprecation'),
true
);
break;
default:
// Verify that the flag is off by default.
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.
fork(__filename, ['switch'], {
execArgv: ['--pending-deprecation'],
execArgv: ['--pending-deprecation', '--expose-internals'],
silent: true
}).on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0, message('--pending-deprecation'));
@ -38,7 +47,7 @@ switch (process.argv[2]) {
// Test the --pending_deprecation command line switch.
fork(__filename, ['switch'], {
execArgv: ['--pending_deprecation'],
execArgv: ['--pending_deprecation', '--expose-internals'],
silent: true
}).on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0, message('--pending_deprecation'));
@ -47,6 +56,7 @@ switch (process.argv[2]) {
// Test the NODE_PENDING_DEPRECATION environment var.
fork(__filename, ['env'], {
env: Object.assign({}, process.env, { NODE_PENDING_DEPRECATION: 1 }),
execArgv: ['--expose-internals'],
silent: true
}).on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0, message('NODE_PENDING_DEPRECATION'));