Skip to content

Commit

Permalink
util: make util binding internal
Browse files Browse the repository at this point in the history
Refs: #22160
PR-URL: #22675
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
cjihrig committed Sep 6, 2018
1 parent 04195ad commit 7e4b0a4
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 23 deletions.
3 changes: 2 additions & 1 deletion benchmark/util/type-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`];
Expand Down
3 changes: 2 additions & 1 deletion lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -374,6 +374,7 @@
'contextify',
'tcp_wrap',
'tls_wrap',
'util',
'async_wrap']);
process.binding = function binding(name) {
return internalBindingWhitelist.has(name) ?
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,7 +32,7 @@ const {
internalModuleReadJSON,
internalModuleStat
} = process.binding('fs');
const { safeGetenv } = process.binding('util');
const { safeGetenv } = internalBinding('util');
const {
makeRequireFunction,
requireDepth,
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/process/promises.js
Original file line number Diff line number Diff line change
@@ -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 = [];
Expand Down
5 changes: 2 additions & 3 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/util/comparisons.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {
propertyFilter: {
ONLY_ENUMERABLE
}
} = process.binding('util');
} = internalBinding('util');

const ReflectApply = Reflect.apply;

Expand Down
3 changes: 2 additions & 1 deletion lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
5 changes: 3 additions & 2 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -79,7 +80,7 @@ const {
ALL_PROPERTIES,
SKIP_SYMBOLS
}
} = process.binding('util');
} = internalBinding('util');

// Lazy-loaded.
let processTopLevelAwait;
Expand Down
3 changes: 2 additions & 1 deletion lib/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
Expand Down
4 changes: 2 additions & 2 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/node_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,4 @@ void Initialize(Local<Object> target,
} // namespace util
} // namespace node

NODE_BUILTIN_MODULE_CONTEXT_AWARE(util, node::util::Initialize)
NODE_MODULE_CONTEXT_AWARE_INTERNAL(util, node::util::Initialize)
2 changes: 1 addition & 1 deletion test/parallel/test-internal-module-wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-internal-util-decorate-error-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-util-inspect-proxy.js
Original file line number Diff line number Diff line change
@@ -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 = {};
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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');
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-util-internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-util-sigint-watchdog.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Flags: --expose-internals
'use strict';
const common = require('../common');
if (common.isWindows) {
Expand All @@ -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.
Expand Down

0 comments on commit 7e4b0a4

Please sign in to comment.