util: eliminate unnecessary exports
The getHiddenValue and setHiddenValue functions are exported from internalUtil for no really good reason PR-URL: https://github.com/nodejs/node/pull/11451 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
751404dc28
commit
b855dadae0
@ -6,9 +6,6 @@ const prefix = `(${process.release.name}:${process.pid}) `;
|
|||||||
const kArrowMessagePrivateSymbolIndex = binding['arrow_message_private_symbol'];
|
const kArrowMessagePrivateSymbolIndex = binding['arrow_message_private_symbol'];
|
||||||
const kDecoratedPrivateSymbolIndex = binding['decorated_private_symbol'];
|
const kDecoratedPrivateSymbolIndex = binding['decorated_private_symbol'];
|
||||||
|
|
||||||
exports.getHiddenValue = binding.getHiddenValue;
|
|
||||||
exports.setHiddenValue = binding.setHiddenValue;
|
|
||||||
|
|
||||||
// The `buffer` module uses this. Defining it here instead of in the public
|
// The `buffer` module uses this. Defining it here instead of in the public
|
||||||
// `util` module makes it accessible without having to `require('util')` there.
|
// `util` module makes it accessible without having to `require('util')` there.
|
||||||
exports.customInspectSymbol = Symbol('util.inspect.custom');
|
exports.customInspectSymbol = Symbol('util.inspect.custom');
|
||||||
@ -84,14 +81,14 @@ exports._deprecate = function(fn, msg, code) {
|
|||||||
|
|
||||||
exports.decorateErrorStack = function decorateErrorStack(err) {
|
exports.decorateErrorStack = function decorateErrorStack(err) {
|
||||||
if (!(exports.isError(err) && err.stack) ||
|
if (!(exports.isError(err) && err.stack) ||
|
||||||
exports.getHiddenValue(err, kDecoratedPrivateSymbolIndex) === true)
|
binding.getHiddenValue(err, kDecoratedPrivateSymbolIndex) === true)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const arrow = exports.getHiddenValue(err, kArrowMessagePrivateSymbolIndex);
|
const arrow = binding.getHiddenValue(err, kArrowMessagePrivateSymbolIndex);
|
||||||
|
|
||||||
if (arrow) {
|
if (arrow) {
|
||||||
err.stack = arrow + err.stack;
|
err.stack = arrow + err.stack;
|
||||||
exports.setHiddenValue(err, kDecoratedPrivateSymbolIndex, true);
|
binding.setHiddenValue(err, kDecoratedPrivateSymbolIndex, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,16 +10,18 @@ const path = require('path');
|
|||||||
const kArrowMessagePrivateSymbolIndex = binding['arrow_message_private_symbol'];
|
const kArrowMessagePrivateSymbolIndex = binding['arrow_message_private_symbol'];
|
||||||
const kDecoratedPrivateSymbolIndex = binding['decorated_private_symbol'];
|
const kDecoratedPrivateSymbolIndex = binding['decorated_private_symbol'];
|
||||||
|
|
||||||
|
const decorateErrorStack = internalUtil.decorateErrorStack;
|
||||||
|
|
||||||
assert.doesNotThrow(function() {
|
assert.doesNotThrow(function() {
|
||||||
internalUtil.decorateErrorStack();
|
decorateErrorStack();
|
||||||
internalUtil.decorateErrorStack(null);
|
decorateErrorStack(null);
|
||||||
internalUtil.decorateErrorStack(1);
|
decorateErrorStack(1);
|
||||||
internalUtil.decorateErrorStack(true);
|
decorateErrorStack(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Verify that a stack property is not added to non-Errors
|
// Verify that a stack property is not added to non-Errors
|
||||||
const obj = {};
|
const obj = {};
|
||||||
internalUtil.decorateErrorStack(obj);
|
decorateErrorStack(obj);
|
||||||
assert.strictEqual(obj.stack, undefined);
|
assert.strictEqual(obj.stack, undefined);
|
||||||
|
|
||||||
// Verify that the stack is decorated when possible
|
// Verify that the stack is decorated when possible
|
||||||
@ -43,8 +45,8 @@ assert(typeof err, 'object');
|
|||||||
checkStack(err.stack);
|
checkStack(err.stack);
|
||||||
|
|
||||||
// Verify that the stack is only decorated once
|
// Verify that the stack is only decorated once
|
||||||
internalUtil.decorateErrorStack(err);
|
decorateErrorStack(err);
|
||||||
internalUtil.decorateErrorStack(err);
|
decorateErrorStack(err);
|
||||||
checkStack(err.stack);
|
checkStack(err.stack);
|
||||||
|
|
||||||
// Verify that the stack is only decorated once for uncaught exceptions
|
// Verify that the stack is only decorated once for uncaught exceptions
|
||||||
@ -58,7 +60,7 @@ checkStack(result.stderr);
|
|||||||
// Verify that the stack is unchanged when there is no arrow message
|
// Verify that the stack is unchanged when there is no arrow message
|
||||||
err = new Error('foo');
|
err = new Error('foo');
|
||||||
let originalStack = err.stack;
|
let originalStack = err.stack;
|
||||||
internalUtil.decorateErrorStack(err);
|
decorateErrorStack(err);
|
||||||
assert.strictEqual(originalStack, err.stack);
|
assert.strictEqual(originalStack, err.stack);
|
||||||
|
|
||||||
// Verify that the arrow message is added to the start of the stack when it
|
// Verify that the arrow message is added to the start of the stack when it
|
||||||
@ -67,9 +69,9 @@ const arrowMessage = 'arrow_message';
|
|||||||
err = new Error('foo');
|
err = new Error('foo');
|
||||||
originalStack = err.stack;
|
originalStack = err.stack;
|
||||||
|
|
||||||
internalUtil.setHiddenValue(err, kArrowMessagePrivateSymbolIndex, arrowMessage);
|
binding.setHiddenValue(err, kArrowMessagePrivateSymbolIndex, arrowMessage);
|
||||||
internalUtil.decorateErrorStack(err);
|
decorateErrorStack(err);
|
||||||
|
|
||||||
assert.strictEqual(err.stack, `${arrowMessage}${originalStack}`);
|
assert.strictEqual(err.stack, `${arrowMessage}${originalStack}`);
|
||||||
assert.strictEqual(internalUtil
|
assert.strictEqual(
|
||||||
.getHiddenValue(err, kDecoratedPrivateSymbolIndex), true);
|
binding.getHiddenValue(err, kDecoratedPrivateSymbolIndex), true);
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const internalUtil = require('internal/util');
|
|
||||||
const spawnSync = require('child_process').spawnSync;
|
const spawnSync = require('child_process').spawnSync;
|
||||||
|
|
||||||
const binding = process.binding('util');
|
const binding = process.binding('util');
|
||||||
@ -12,13 +11,13 @@ const kArrowMessagePrivateSymbolIndex = binding['arrow_message_private_symbol'];
|
|||||||
|
|
||||||
function getHiddenValue(obj, index) {
|
function getHiddenValue(obj, index) {
|
||||||
return function() {
|
return function() {
|
||||||
internalUtil.getHiddenValue(obj, index);
|
binding.getHiddenValue(obj, index);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function setHiddenValue(obj, index, val) {
|
function setHiddenValue(obj, index, val) {
|
||||||
return function() {
|
return function() {
|
||||||
internalUtil.setHiddenValue(obj, index, val);
|
binding.setHiddenValue(obj, index, val);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +30,7 @@ assert.throws(getHiddenValue({}), /index must be an uint32/);
|
|||||||
assert.throws(getHiddenValue({}, null), /index must be an uint32/);
|
assert.throws(getHiddenValue({}, null), /index must be an uint32/);
|
||||||
assert.throws(getHiddenValue({}, []), /index must be an uint32/);
|
assert.throws(getHiddenValue({}, []), /index must be an uint32/);
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
internalUtil.getHiddenValue({}, kArrowMessagePrivateSymbolIndex),
|
binding.getHiddenValue({}, kArrowMessagePrivateSymbolIndex),
|
||||||
undefined);
|
undefined);
|
||||||
|
|
||||||
assert.throws(setHiddenValue(), /obj must be an object/);
|
assert.throws(setHiddenValue(), /obj must be an object/);
|
||||||
@ -44,10 +43,10 @@ assert.throws(setHiddenValue({}, null), /index must be an uint32/);
|
|||||||
assert.throws(setHiddenValue({}, []), /index must be an uint32/);
|
assert.throws(setHiddenValue({}, []), /index must be an uint32/);
|
||||||
const obj = {};
|
const obj = {};
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
internalUtil.setHiddenValue(obj, kArrowMessagePrivateSymbolIndex, 'bar'),
|
binding.setHiddenValue(obj, kArrowMessagePrivateSymbolIndex, 'bar'),
|
||||||
true);
|
true);
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
internalUtil.getHiddenValue(obj, kArrowMessagePrivateSymbolIndex),
|
binding.getHiddenValue(obj, kArrowMessagePrivateSymbolIndex),
|
||||||
'bar');
|
'bar');
|
||||||
|
|
||||||
let arrowMessage;
|
let arrowMessage;
|
||||||
@ -56,7 +55,7 @@ try {
|
|||||||
require(path.join(common.fixturesDir, 'syntax', 'bad_syntax'));
|
require(path.join(common.fixturesDir, 'syntax', 'bad_syntax'));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
arrowMessage =
|
arrowMessage =
|
||||||
internalUtil.getHiddenValue(err, kArrowMessagePrivateSymbolIndex);
|
binding.getHiddenValue(err, kArrowMessagePrivateSymbolIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(/bad_syntax\.js:1/.test(arrowMessage));
|
assert(/bad_syntax\.js:1/.test(arrowMessage));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user