From 7e4b0a4850a5c7d9e14824db20f818db947305d3 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Mon, 3 Sep 2018 11:16:48 -0400 Subject: [PATCH] util: make util binding internal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs: https://github.com/nodejs/node/issues/22160 PR-URL: https://github.com/nodejs/node/pull/22675 Reviewed-By: Michaƫl Zasso Reviewed-By: Luigi Pinca Reviewed-By: Gus Caplan Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Trivikram Kamat --- benchmark/util/type-check.js | 3 ++- lib/console.js | 3 ++- lib/internal/bootstrap/node.js | 3 ++- lib/internal/modules/cjs/loader.js | 4 ++-- lib/internal/process/promises.js | 3 ++- lib/internal/util.js | 5 ++--- lib/internal/util/comparisons.js | 2 +- lib/os.js | 3 ++- lib/repl.js | 5 +++-- lib/stream.js | 3 ++- lib/util.js | 4 ++-- src/node_util.cc | 2 +- test/parallel/test-internal-module-wrap.js | 2 +- test/parallel/test-internal-util-decorate-error-stack.js | 3 ++- test/parallel/test-util-inspect-proxy.js | 4 +++- test/parallel/test-util-inspect.js | 4 +++- test/parallel/test-util-internal.js | 3 ++- test/parallel/test-util-sigint-watchdog.js | 4 +++- 18 files changed, 37 insertions(+), 23 deletions(-) diff --git a/benchmark/util/type-check.js b/benchmark/util/type-check.js index e1d1ac553fedcf..d9ba7bc209de07 100644 --- a/benchmark/util/type-check.js +++ b/benchmark/util/type-check.js @@ -38,7 +38,8 @@ function main({ type, argument, version, n }) { // For testing, if supplied with an empty type, default to ArrayBufferView. type = type || 'ArrayBufferView'; - const util = process.binding('util'); + const { internalBinding } = require('internal/test/binding'); + const util = internalBinding('util'); const types = require('internal/util/types'); const func = { native: util, js: types }[version][`is${type}`]; diff --git a/lib/console.js b/lib/console.js index a5b2265f58ff13..30a9a0e7331062 100644 --- a/lib/console.js +++ b/lib/console.js @@ -29,7 +29,8 @@ const { ERR_INVALID_ARG_VALUE, }, } = require('internal/errors'); -const { previewEntries } = process.binding('util'); +const { internalBinding } = require('internal/bootstrap/loaders'); +const { previewEntries } = internalBinding('util'); const { Buffer: { isBuffer } } = require('buffer'); const util = require('util'); const { diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index de9fd21e77effe..8f05c1a4ce1b53 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -176,7 +176,7 @@ // TODO(addaleax): Turn into a full runtime deprecation. const { pendingDeprecation } = process.binding('config'); const { deprecate } = NativeModule.require('internal/util'); - const utilBinding = process.binding('util'); + const utilBinding = internalBinding('util'); const types = internalBinding('types'); for (const name of [ 'isArrayBuffer', 'isArrayBufferView', 'isAsyncFunction', @@ -374,6 +374,7 @@ 'contextify', 'tcp_wrap', 'tls_wrap', + 'util', 'async_wrap']); process.binding = function binding(name) { return internalBindingWhitelist.has(name) ? diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 1e93791237c92f..39f9766d3e595d 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -21,7 +21,7 @@ 'use strict'; -const { NativeModule } = require('internal/bootstrap/loaders'); +const { internalBinding, NativeModule } = require('internal/bootstrap/loaders'); const util = require('util'); const vm = require('vm'); const assert = require('assert').ok; @@ -32,7 +32,7 @@ const { internalModuleReadJSON, internalModuleStat } = process.binding('fs'); -const { safeGetenv } = process.binding('util'); +const { safeGetenv } = internalBinding('util'); const { makeRequireFunction, requireDepth, diff --git a/lib/internal/process/promises.js b/lib/internal/process/promises.js index f54f34b9ae92f4..0ae81820dbed9a 100644 --- a/lib/internal/process/promises.js +++ b/lib/internal/process/promises.js @@ -1,6 +1,7 @@ 'use strict'; -const { safeToString } = process.binding('util'); +const { internalBinding } = require('internal/bootstrap/loaders'); +const { safeToString } = internalBinding('util'); const maybeUnhandledPromises = new WeakMap(); const pendingUnhandledRejections = []; diff --git a/lib/internal/util.js b/lib/internal/util.js index 40afd9207e70f4..43b99740683b39 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -6,15 +6,14 @@ const { ERR_UNKNOWN_SIGNAL } = require('internal/errors').codes; const { signals } = process.binding('constants').os; - +const { internalBinding } = require('internal/bootstrap/loaders'); const { getHiddenValue, setHiddenValue, arrow_message_private_symbol: kArrowMessagePrivateSymbolIndex, decorated_private_symbol: kDecoratedPrivateSymbolIndex -} = process.binding('util'); +} = internalBinding('util'); -const { internalBinding } = require('internal/bootstrap/loaders'); const { errmap } = internalBinding('uv'); const noCrypto = !process.versions.openssl; diff --git a/lib/internal/util/comparisons.js b/lib/internal/util/comparisons.js index bcbe12181bfbfc..1cef5533bc1195 100644 --- a/lib/internal/util/comparisons.js +++ b/lib/internal/util/comparisons.js @@ -15,7 +15,7 @@ const { propertyFilter: { ONLY_ENUMERABLE } -} = process.binding('util'); +} = internalBinding('util'); const ReflectApply = Reflect.apply; diff --git a/lib/os.js b/lib/os.js index ace39c8e120397..9a05201ea4459c 100644 --- a/lib/os.js +++ b/lib/os.js @@ -21,7 +21,8 @@ 'use strict'; -const { pushValToArrayMax, safeGetenv } = process.binding('util'); +const { internalBinding } = require('internal/bootstrap/loaders'); +const { pushValToArrayMax, safeGetenv } = internalBinding('util'); const constants = process.binding('constants').os; const { deprecate } = require('internal/util'); const isWindows = process.platform === 'win32'; diff --git a/lib/repl.js b/lib/repl.js index 46f81a02f0c5d5..a7e8b4cd27969f 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -53,7 +53,8 @@ const { } = require('internal/deps/acorn/dist/acorn'); const internalUtil = require('internal/util'); const util = require('util'); -const utilBinding = process.binding('util'); +const { internalBinding } = require('internal/bootstrap/loaders'); +const utilBinding = internalBinding('util'); const { inherits } = util; const Stream = require('stream'); const vm = require('vm'); @@ -79,7 +80,7 @@ const { ALL_PROPERTIES, SKIP_SYMBOLS } -} = process.binding('util'); +} = internalBinding('util'); // Lazy-loaded. let processTopLevelAwait; diff --git a/lib/stream.js b/lib/stream.js index 7c235108c07256..860c875bec01a1 100644 --- a/lib/stream.js +++ b/lib/stream.js @@ -49,7 +49,8 @@ try { } else { // This throws for Node < 4.2.0 because there's no util binding and // returns undefined for Node < 7.4.0. - Stream._isUint8Array = process.binding('util').isUint8Array; + const { internalBinding } = require('internal/bootstrap/loaders'); + Stream._isUint8Array = internalBinding('util').isUint8Array; } } catch (e) { } diff --git a/lib/util.js b/lib/util.js index e8fb41a2198a99..f0b7285fe01035 100644 --- a/lib/util.js +++ b/lib/util.js @@ -31,15 +31,15 @@ const { validateNumber } = require('internal/validators'); const { TextDecoder, TextEncoder } = require('internal/encoding'); const { isBuffer } = require('buffer').Buffer; +const { internalBinding } = require('internal/bootstrap/loaders'); const { getPromiseDetails, getProxyDetails, kPending, kRejected, previewEntries -} = process.binding('util'); +} = internalBinding('util'); -const { internalBinding } = require('internal/bootstrap/loaders'); const types = internalBinding('types'); Object.assign(types, require('internal/util/types')); const { diff --git a/src/node_util.cc b/src/node_util.cc index 5adecf4d9753c3..8f261e8989de39 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -234,4 +234,4 @@ void Initialize(Local target, } // namespace util } // namespace node -NODE_BUILTIN_MODULE_CONTEXT_AWARE(util, node::util::Initialize) +NODE_MODULE_CONTEXT_AWARE_INTERNAL(util, node::util::Initialize) diff --git a/test/parallel/test-internal-module-wrap.js b/test/parallel/test-internal-module-wrap.js index a1461e34b0dcb1..ee0b722d450103 100644 --- a/test/parallel/test-internal-module-wrap.js +++ b/test/parallel/test-internal-module-wrap.js @@ -7,7 +7,7 @@ const assert = require('assert'); const { internalBinding } = require('internal/test/binding'); const { ModuleWrap } = internalBinding('module_wrap'); -const { getPromiseDetails, isPromise } = process.binding('util'); +const { getPromiseDetails, isPromise } = internalBinding('util'); const setTimeoutAsync = require('util').promisify(setTimeout); const foo = new ModuleWrap('export * from "bar"; 6;', 'foo'); diff --git a/test/parallel/test-internal-util-decorate-error-stack.js b/test/parallel/test-internal-util-decorate-error-stack.js index 5694d746c667f4..40fbf1d48caf20 100644 --- a/test/parallel/test-internal-util-decorate-error-stack.js +++ b/test/parallel/test-internal-util-decorate-error-stack.js @@ -4,7 +4,8 @@ require('../common'); const fixtures = require('../common/fixtures'); const assert = require('assert'); const internalUtil = require('internal/util'); -const binding = process.binding('util'); +const { internalBinding } = require('internal/test/binding'); +const binding = internalBinding('util'); const spawnSync = require('child_process').spawnSync; const kArrowMessagePrivateSymbolIndex = binding.arrow_message_private_symbol; diff --git a/test/parallel/test-util-inspect-proxy.js b/test/parallel/test-util-inspect-proxy.js index d7fb28ddc77282..b3438a625240a2 100644 --- a/test/parallel/test-util-inspect-proxy.js +++ b/test/parallel/test-util-inspect-proxy.js @@ -1,9 +1,11 @@ +// Flags: --expose-internals 'use strict'; require('../common'); const assert = require('assert'); const util = require('util'); -const processUtil = process.binding('util'); +const { internalBinding } = require('internal/test/binding'); +const processUtil = internalBinding('util'); const opts = { showProxy: true }; const target = {}; diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 8e78430c01204d..b5ccdf019a5226 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -1,3 +1,4 @@ +// Flags: --expose-internals // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -22,10 +23,11 @@ 'use strict'; const common = require('../common'); const assert = require('assert'); +const { internalBinding } = require('internal/test/binding'); const JSStream = process.binding('js_stream').JSStream; const util = require('util'); const vm = require('vm'); -const { previewEntries } = process.binding('util'); +const { previewEntries } = internalBinding('util'); const { inspect } = util; assert.strictEqual(util.inspect(1), '1'); diff --git a/test/parallel/test-util-internal.js b/test/parallel/test-util-internal.js index ac7cf12229487a..4b78cefc6efe60 100644 --- a/test/parallel/test-util-internal.js +++ b/test/parallel/test-util-internal.js @@ -4,13 +4,14 @@ require('../common'); const assert = require('assert'); const fixtures = require('../common/fixtures'); +const { internalBinding } = require('internal/test/binding'); const { getHiddenValue, setHiddenValue, arrow_message_private_symbol: kArrowMessagePrivateSymbolIndex, safeGetenv -} = process.binding('util'); +} = internalBinding('util'); for (const oneEnv in process.env) { assert.strictEqual( diff --git a/test/parallel/test-util-sigint-watchdog.js b/test/parallel/test-util-sigint-watchdog.js index 16bc6d37651710..7ac1261eabab40 100644 --- a/test/parallel/test-util-sigint-watchdog.js +++ b/test/parallel/test-util-sigint-watchdog.js @@ -1,3 +1,4 @@ +// Flags: --expose-internals 'use strict'; const common = require('../common'); if (common.isWindows) { @@ -6,7 +7,8 @@ if (common.isWindows) { } const assert = require('assert'); -const binding = process.binding('util'); +const { internalBinding } = require('internal/test/binding'); +const binding = internalBinding('util'); [(next) => { // Test with no signal observed.