Skip to content

Commit 95bee8f

Browse files
jasnelladdaleax
authored andcommitted
util: eliminate unnecessary exports
The getHiddenValue and setHiddenValue functions are exported from internalUtil for no really good reason PR-URL: #11451 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 1d86a9f commit 95bee8f

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

lib/internal/util.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ const prefix = `(${process.release.name}:${process.pid}) `;
66
const kArrowMessagePrivateSymbolIndex = binding['arrow_message_private_symbol'];
77
const kDecoratedPrivateSymbolIndex = binding['decorated_private_symbol'];
88

9-
exports.getHiddenValue = binding.getHiddenValue;
10-
exports.setHiddenValue = binding.setHiddenValue;
11-
129
// The `buffer` module uses this. Defining it here instead of in the public
1310
// `util` module makes it accessible without having to `require('util')` there.
1411
exports.customInspectSymbol = Symbol('util.inspect.custom');
@@ -77,14 +74,14 @@ exports._deprecate = function(fn, msg) {
7774

7875
exports.decorateErrorStack = function decorateErrorStack(err) {
7976
if (!(exports.isError(err) && err.stack) ||
80-
exports.getHiddenValue(err, kDecoratedPrivateSymbolIndex) === true)
77+
binding.getHiddenValue(err, kDecoratedPrivateSymbolIndex) === true)
8178
return;
8279

83-
const arrow = exports.getHiddenValue(err, kArrowMessagePrivateSymbolIndex);
80+
const arrow = binding.getHiddenValue(err, kArrowMessagePrivateSymbolIndex);
8481

8582
if (arrow) {
8683
err.stack = arrow + err.stack;
87-
exports.setHiddenValue(err, kDecoratedPrivateSymbolIndex, true);
84+
binding.setHiddenValue(err, kDecoratedPrivateSymbolIndex, true);
8885
}
8986
};
9087

test/parallel/test-internal-util-decorate-error-stack.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ const path = require('path');
1010
const kArrowMessagePrivateSymbolIndex = binding['arrow_message_private_symbol'];
1111
const kDecoratedPrivateSymbolIndex = binding['decorated_private_symbol'];
1212

13+
const decorateErrorStack = internalUtil.decorateErrorStack;
14+
1315
assert.doesNotThrow(function() {
14-
internalUtil.decorateErrorStack();
15-
internalUtil.decorateErrorStack(null);
16-
internalUtil.decorateErrorStack(1);
17-
internalUtil.decorateErrorStack(true);
16+
decorateErrorStack();
17+
decorateErrorStack(null);
18+
decorateErrorStack(1);
19+
decorateErrorStack(true);
1820
});
1921

2022
// Verify that a stack property is not added to non-Errors
2123
const obj = {};
22-
internalUtil.decorateErrorStack(obj);
24+
decorateErrorStack(obj);
2325
assert.strictEqual(obj.stack, undefined);
2426

2527
// Verify that the stack is decorated when possible
@@ -43,8 +45,8 @@ assert(typeof err, 'object');
4345
checkStack(err.stack);
4446

4547
// Verify that the stack is only decorated once
46-
internalUtil.decorateErrorStack(err);
47-
internalUtil.decorateErrorStack(err);
48+
decorateErrorStack(err);
49+
decorateErrorStack(err);
4850
checkStack(err.stack);
4951

5052
// Verify that the stack is only decorated once for uncaught exceptions
@@ -58,7 +60,7 @@ checkStack(result.stderr);
5860
// Verify that the stack is unchanged when there is no arrow message
5961
err = new Error('foo');
6062
let originalStack = err.stack;
61-
internalUtil.decorateErrorStack(err);
63+
decorateErrorStack(err);
6264
assert.strictEqual(originalStack, err.stack);
6365

6466
// Verify that the arrow message is added to the start of the stack when it
@@ -67,9 +69,9 @@ const arrowMessage = 'arrow_message';
6769
err = new Error('foo');
6870
originalStack = err.stack;
6971

70-
internalUtil.setHiddenValue(err, kArrowMessagePrivateSymbolIndex, arrowMessage);
71-
internalUtil.decorateErrorStack(err);
72+
binding.setHiddenValue(err, kArrowMessagePrivateSymbolIndex, arrowMessage);
73+
decorateErrorStack(err);
7274

7375
assert.strictEqual(err.stack, `${arrowMessage}${originalStack}`);
74-
assert.strictEqual(internalUtil
75-
.getHiddenValue(err, kDecoratedPrivateSymbolIndex), true);
76+
assert.strictEqual(
77+
binding.getHiddenValue(err, kDecoratedPrivateSymbolIndex), true);

test/parallel/test-util-internal.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@
44
const common = require('../common');
55
const path = require('path');
66
const assert = require('assert');
7-
const internalUtil = require('internal/util');
87
const spawnSync = require('child_process').spawnSync;
98

109
const binding = process.binding('util');
1110
const kArrowMessagePrivateSymbolIndex = binding['arrow_message_private_symbol'];
1211

1312
function getHiddenValue(obj, index) {
1413
return function() {
15-
internalUtil.getHiddenValue(obj, index);
14+
binding.getHiddenValue(obj, index);
1615
};
1716
}
1817

1918
function setHiddenValue(obj, index, val) {
2019
return function() {
21-
internalUtil.setHiddenValue(obj, index, val);
20+
binding.setHiddenValue(obj, index, val);
2221
};
2322
}
2423

@@ -31,7 +30,7 @@ assert.throws(getHiddenValue({}), /index must be an uint32/);
3130
assert.throws(getHiddenValue({}, null), /index must be an uint32/);
3231
assert.throws(getHiddenValue({}, []), /index must be an uint32/);
3332
assert.deepStrictEqual(
34-
internalUtil.getHiddenValue({}, kArrowMessagePrivateSymbolIndex),
33+
binding.getHiddenValue({}, kArrowMessagePrivateSymbolIndex),
3534
undefined);
3635

3736
assert.throws(setHiddenValue(), /obj must be an object/);
@@ -44,10 +43,10 @@ assert.throws(setHiddenValue({}, null), /index must be an uint32/);
4443
assert.throws(setHiddenValue({}, []), /index must be an uint32/);
4544
const obj = {};
4645
assert.strictEqual(
47-
internalUtil.setHiddenValue(obj, kArrowMessagePrivateSymbolIndex, 'bar'),
46+
binding.setHiddenValue(obj, kArrowMessagePrivateSymbolIndex, 'bar'),
4847
true);
4948
assert.strictEqual(
50-
internalUtil.getHiddenValue(obj, kArrowMessagePrivateSymbolIndex),
49+
binding.getHiddenValue(obj, kArrowMessagePrivateSymbolIndex),
5150
'bar');
5251

5352
let arrowMessage;
@@ -56,7 +55,7 @@ try {
5655
require(path.join(common.fixturesDir, 'syntax', 'bad_syntax'));
5756
} catch (err) {
5857
arrowMessage =
59-
internalUtil.getHiddenValue(err, kArrowMessagePrivateSymbolIndex);
58+
binding.getHiddenValue(err, kArrowMessagePrivateSymbolIndex);
6059
}
6160

6261
assert(/bad_syntax\.js:1/.test(arrowMessage));

0 commit comments

Comments
 (0)