Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: make util binding internal #22675

Merged
merged 2 commits into from
Sep 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 7 additions & 5 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ 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 { inherits } = util;
const Stream = require('stream');
const vm = require('vm');
Expand All @@ -78,8 +78,10 @@ const {
propertyFilter: {
ALL_PROPERTIES,
SKIP_SYMBOLS
}
} = process.binding('util');
},
startSigintWatchdog,
stopSigintWatchdog
} = internalBinding('util');

// Lazy-loaded.
let processTopLevelAwait;
Expand Down Expand Up @@ -313,7 +315,7 @@ function REPLServer(prompt,
if (self.breakEvalOnSigint) {
// Start the SIGINT watchdog before entering raw mode so that a very
// quick Ctrl+C doesn't lead to aborting the process completely.
if (!utilBinding.startSigintWatchdog())
if (!startSigintWatchdog())
throw new ERR_CANNOT_WATCH_SIGINT();
previouslyInRawMode = self._setRawMode(false);
}
Expand All @@ -337,7 +339,7 @@ function REPLServer(prompt,

// Returns true if there were pending SIGINTs *after* the script
// has terminated without being interrupted itself.
if (utilBinding.stopSigintWatchdog()) {
if (stopSigintWatchdog()) {
self.emit('SIGINT');
}
}
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;
Copy link
Member

@addaleax addaleax Oct 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to revert this change, since it is only left in the file for compatibility with prior Node.js versions in readable-stream.

/cc @nodejs/streams

edit: #23662

}
} 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