diff --git a/lib/buffer.js b/lib/buffer.js index dc7f5c7cdb829b..5ecf88d55b848e 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -55,9 +55,7 @@ const { isArrayBufferView, isUint8Array } = require('internal/util/types'); -const { - pendingDeprecation -} = internalBinding('config'); + const { formatProperty, kObjectType @@ -150,7 +148,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 diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 51e27afecaea3c..7ebfe0b0f073b7 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -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 [ diff --git a/src/node_config.cc b/src/node_config.cc index a8ffac2cc158a4..1ba1fe9d277af5 100644 --- a/src/node_config.cc +++ b/src/node_config.cc @@ -77,9 +77,6 @@ static void Initialize(Local 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"); diff --git a/test/parallel/test-pending-deprecation.js b/test/parallel/test-pending-deprecation.js index bb11d84bcc0aec..6cabf9ddc693f7 100644 --- a/test/parallel/test-pending-deprecation.js +++ b/test/parallel/test-pending-deprecation.js @@ -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'));