From 63b06551f4c51d8868f36b184a6539ebc51cf0b4 Mon Sep 17 00:00:00 2001 From: Masashi Hirano Date: Tue, 9 Oct 2018 08:10:07 +0900 Subject: [PATCH] src,lib: make process.binding('config') internal PR-URL: https://github.com/nodejs/node/pull/23400 Refs: https://github.com/nodejs/node/issues/22160 Reviewed-By: Joyee Cheung Reviewed-By: Gireesh Punathil Reviewed-By: Colin Ihrig Reviewed-By: Trivikram Kamat --- lib/buffer.js | 4 ++-- lib/crypto.js | 2 +- lib/internal/async_hooks.js | 2 +- lib/internal/bootstrap/loaders.js | 4 +++- lib/internal/bootstrap/node.js | 4 ++-- lib/internal/encoding.js | 2 +- lib/internal/inspector_async_hook.js | 2 +- lib/internal/print_help.js | 2 +- lib/internal/process/warning.js | 2 +- lib/internal/readline.js | 2 +- lib/trace_events.js | 2 +- lib/url.js | 2 +- src/node_config.cc | 2 +- test/parallel/test-icu-data-dir.js | 4 +++- test/parallel/test-internal-modules-expose.js | 3 ++- test/parallel/test-readline-position.js | 4 +++- 16 files changed, 25 insertions(+), 18 deletions(-) diff --git a/lib/buffer.js b/lib/buffer.js index af69f43735f26f..ac5e19c40819c1 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -50,7 +50,7 @@ const { } = require('internal/util/types'); const { pendingDeprecation -} = process.binding('config'); +} = internalBinding('config'); const { ERR_BUFFER_OUT_OF_BOUNDS, ERR_OUT_OF_RANGE, @@ -1067,7 +1067,7 @@ Buffer.prototype.swap64 = function swap64() { Buffer.prototype.toLocaleString = Buffer.prototype.toString; let transcode; -if (process.binding('config').hasIntl) { +if (internalBinding('config').hasIntl) { const { icuErrName, transcode: _transcode diff --git a/lib/crypto.js b/lib/crypto.js index a3865ab7e46d9b..4707ab2b35ca51 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -40,7 +40,7 @@ const pendingDeprecation = getOptionValue('--pending-deprecation'); const { fipsMode, fipsForced -} = process.binding('config'); +} = internalBinding('config'); const { getFipsCrypto, setFipsCrypto } = internalBinding('crypto'); const { randomBytes, diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js index a42f603293c82e..d382fe36e1847f 100644 --- a/lib/internal/async_hooks.js +++ b/lib/internal/async_hooks.js @@ -107,7 +107,7 @@ function fatalError(e) { Error.captureStackTrace(o, fatalError); process._rawDebug(o.stack); } - if (process.binding('config').shouldAbortOnUncaughtException) { + if (internalBinding('config').shouldAbortOnUncaughtException) { process.abort(); } process.exit(1); diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index 155d9c9239627e..dfe904857fa3e5 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -73,6 +73,7 @@ ObjectDefineProperty(process, 'moduleLoadList', { writable: false }); + // internalBindingWhitelist contains the name of internalBinding modules // that are whitelisted for access via process.binding()... This is used // to provide a transition path for modules that are being moved over to @@ -81,6 +82,7 @@ const internalBindingWhitelist = [ 'async_wrap', 'buffer', 'cares_wrap', + 'config', 'constants', 'contextify', 'crypto', @@ -168,7 +170,7 @@ function NativeModule(id) { NativeModule._source = getInternalBinding('natives'); NativeModule._cache = {}; -const config = getBinding('config'); +const config = getInternalBinding('config'); // Think of this as module.exports in this file even though it is not // written in CommonJS style. diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 414cbec733d229..51e27afecaea3c 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 } = process.binding('config'); + const { pendingDeprecation } = internalBinding('config'); const utilBinding = internalBinding('util'); const types = internalBinding('types'); for (const name of [ @@ -638,7 +638,7 @@ function setupProcessFatal() { } function setupProcessICUVersions() { - const icu = process.binding('config').hasIntl ? + const icu = internalBinding('config').hasIntl ? internalBinding('icu') : undefined; if (!icu) return; // no Intl/ICU: nothing to add here. // With no argument, getVersion() returns a comma separated list diff --git a/lib/internal/encoding.js b/lib/internal/encoding.js index ce3cc7411a65b8..ad056fd0bd997f 100644 --- a/lib/internal/encoding.js +++ b/lib/internal/encoding.js @@ -342,7 +342,7 @@ Object.defineProperties( } }); const TextDecoder = - process.binding('config').hasIntl ? + internalBinding('config').hasIntl ? makeTextDecoderICU() : makeTextDecoderJS(); diff --git a/lib/internal/inspector_async_hook.js b/lib/internal/inspector_async_hook.js index 6a7489af974a40..1ad0cbf3a533f2 100644 --- a/lib/internal/inspector_async_hook.js +++ b/lib/internal/inspector_async_hook.js @@ -12,7 +12,7 @@ let config; function lazyHookCreation() { const { createHook } = require('async_hooks'); - config = process.binding('config'); + config = internalBinding('config'); hook = createHook({ init(asyncId, type, triggerAsyncId, resource) { diff --git a/lib/internal/print_help.js b/lib/internal/print_help.js index 5d2c1daa075e0d..c3e984dd9f4987 100644 --- a/lib/internal/print_help.js +++ b/lib/internal/print_help.js @@ -9,7 +9,7 @@ for (const key of Object.keys(types)) // Environment variables are parsed ad-hoc throughout the code base, // so we gather the documentation here. -const { hasIntl, hasSmallICU, hasNodeOptions } = process.binding('config'); +const { hasIntl, hasSmallICU, hasNodeOptions } = internalBinding('config'); const envVars = new Map([ ['NODE_DEBUG', { helpText: "','-separated list of core modules that " + 'should print debug information' }], diff --git a/lib/internal/process/warning.js b/lib/internal/process/warning.js index 637b9ffb54b406..5dac78082bf205 100644 --- a/lib/internal/process/warning.js +++ b/lib/internal/process/warning.js @@ -1,6 +1,6 @@ 'use strict'; -const config = process.binding('config'); +const config = internalBinding('config'); const prefix = `(${process.release.name}:${process.pid}) `; const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes; diff --git a/lib/internal/readline.js b/lib/internal/readline.js index 0f7d969d20c218..c325f42cf42328 100644 --- a/lib/internal/readline.js +++ b/lib/internal/readline.js @@ -30,7 +30,7 @@ CSI.kClearToEnd = CSI`0K`; CSI.kClearLine = CSI`2K`; CSI.kClearScreenDown = CSI`0J`; -if (process.binding('config').hasIntl) { +if (internalBinding('config').hasIntl) { const icu = internalBinding('icu'); getStringWidth = function getStringWidth(str, options) { options = options || {}; diff --git a/lib/trace_events.js b/lib/trace_events.js index 878580c67f5a2f..d2977679e168b8 100644 --- a/lib/trace_events.js +++ b/lib/trace_events.js @@ -1,6 +1,6 @@ 'use strict'; -const { hasTracing } = process.binding('config'); +const { hasTracing } = internalBinding('config'); const kHandle = Symbol('handle'); const kEnabled = Symbol('enabled'); const kCategories = Symbol('categories'); diff --git a/lib/url.js b/lib/url.js index a5f8f45d014841..eac9d1511b9f8c 100644 --- a/lib/url.js +++ b/lib/url.js @@ -21,7 +21,7 @@ 'use strict'; -const { toASCII } = process.binding('config').hasIntl ? +const { toASCII } = internalBinding('config').hasIntl ? internalBinding('icu') : require('punycode'); const { hexTable } = require('internal/querystring'); diff --git a/src/node_config.cc b/src/node_config.cc index 6b7f4e62b7cd94..c2bf3349c46269 100644 --- a/src/node_config.cc +++ b/src/node_config.cc @@ -112,4 +112,4 @@ static void Initialize(Local target, } // namespace node -NODE_BUILTIN_MODULE_CONTEXT_AWARE(config, node::Initialize) +NODE_MODULE_CONTEXT_AWARE_INTERNAL(config, node::Initialize) diff --git a/test/parallel/test-icu-data-dir.js b/test/parallel/test-icu-data-dir.js index 47c955bc740fb3..daf15ba880ced7 100644 --- a/test/parallel/test-icu-data-dir.js +++ b/test/parallel/test-icu-data-dir.js @@ -1,8 +1,10 @@ +// Flags: --expose-internals 'use strict'; +const { internalBinding } = require('internal/test/binding'); const common = require('../common'); const os = require('os'); -const { hasSmallICU } = process.binding('config'); +const { hasSmallICU } = internalBinding('config'); if (!(common.hasIntl && hasSmallICU)) common.skip('missing Intl'); diff --git a/test/parallel/test-internal-modules-expose.js b/test/parallel/test-internal-modules-expose.js index ab48e36881268c..5229032573088e 100644 --- a/test/parallel/test-internal-modules-expose.js +++ b/test/parallel/test-internal-modules-expose.js @@ -3,7 +3,8 @@ require('../common'); const assert = require('assert'); -const config = process.binding('config'); +const { internalBinding } = require('internal/test/binding'); +const config = internalBinding('config'); console.log(config, process.argv); diff --git a/test/parallel/test-readline-position.js b/test/parallel/test-readline-position.js index 4e1114418eb380..0e62761ca57b40 100644 --- a/test/parallel/test-readline-position.js +++ b/test/parallel/test-readline-position.js @@ -1,4 +1,6 @@ +// Flags: --expose-internals 'use strict'; +const { internalBinding } = require('internal/test/binding'); require('../common'); const { PassThrough } = require('stream'); const readline = require('readline'); @@ -23,7 +25,7 @@ const ctrlU = { ctrl: true, name: 'u' }; // The non-ICU JS implementation of character width calculation is only aware // of the wide/narrow distinction. Only test these more advanced cases when // ICU is available. - if (process.binding('config').hasIntl) { + if (internalBinding('config').hasIntl) { tests.push( [0, '\u0301'], // COMBINING ACUTE ACCENT [1, 'a\u0301'], // á