From cd0d9ba8242a45285d47307d47a33572f26cb363 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Fri, 17 Feb 2017 16:49:38 -0800 Subject: [PATCH] util: eliminate unnecessary exports The getHiddenValue and setHiddenValue functions are exported from internalUtil for no really good reason --- lib/internal/util.js | 9 +++---- ...test-internal-util-decorate-error-stack.js | 26 ++++++++++--------- test/parallel/test-util-internal.js | 13 +++++----- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/lib/internal/util.js b/lib/internal/util.js index 76ef759cefbc83..0a3cbe0232fb02 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -6,9 +6,6 @@ const prefix = `(${process.release.name}:${process.pid}) `; const kArrowMessagePrivateSymbolIndex = binding['arrow_message_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 // `util` module makes it accessible without having to `require('util')` there. exports.customInspectSymbol = Symbol('util.inspect.custom'); @@ -84,14 +81,14 @@ exports._deprecate = function(fn, msg, code) { exports.decorateErrorStack = function decorateErrorStack(err) { if (!(exports.isError(err) && err.stack) || - exports.getHiddenValue(err, kDecoratedPrivateSymbolIndex) === true) + binding.getHiddenValue(err, kDecoratedPrivateSymbolIndex) === true) return; - const arrow = exports.getHiddenValue(err, kArrowMessagePrivateSymbolIndex); + const arrow = binding.getHiddenValue(err, kArrowMessagePrivateSymbolIndex); if (arrow) { err.stack = arrow + err.stack; - exports.setHiddenValue(err, kDecoratedPrivateSymbolIndex, true); + binding.setHiddenValue(err, kDecoratedPrivateSymbolIndex, true); } }; diff --git a/test/parallel/test-internal-util-decorate-error-stack.js b/test/parallel/test-internal-util-decorate-error-stack.js index caf31cb2650f17..7028188f6cd4bf 100644 --- a/test/parallel/test-internal-util-decorate-error-stack.js +++ b/test/parallel/test-internal-util-decorate-error-stack.js @@ -10,16 +10,18 @@ const path = require('path'); const kArrowMessagePrivateSymbolIndex = binding['arrow_message_private_symbol']; const kDecoratedPrivateSymbolIndex = binding['decorated_private_symbol']; +const decorateErrorStack = internalUtil.decorateErrorStack; + assert.doesNotThrow(function() { - internalUtil.decorateErrorStack(); - internalUtil.decorateErrorStack(null); - internalUtil.decorateErrorStack(1); - internalUtil.decorateErrorStack(true); + decorateErrorStack(); + decorateErrorStack(null); + decorateErrorStack(1); + decorateErrorStack(true); }); // Verify that a stack property is not added to non-Errors const obj = {}; -internalUtil.decorateErrorStack(obj); +decorateErrorStack(obj); assert.strictEqual(obj.stack, undefined); // Verify that the stack is decorated when possible @@ -43,8 +45,8 @@ assert(typeof err, 'object'); checkStack(err.stack); // Verify that the stack is only decorated once -internalUtil.decorateErrorStack(err); -internalUtil.decorateErrorStack(err); +decorateErrorStack(err); +decorateErrorStack(err); checkStack(err.stack); // 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 err = new Error('foo'); let originalStack = err.stack; -internalUtil.decorateErrorStack(err); +decorateErrorStack(err); assert.strictEqual(originalStack, err.stack); // 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'); originalStack = err.stack; -internalUtil.setHiddenValue(err, kArrowMessagePrivateSymbolIndex, arrowMessage); -internalUtil.decorateErrorStack(err); +binding.setHiddenValue(err, kArrowMessagePrivateSymbolIndex, arrowMessage); +decorateErrorStack(err); assert.strictEqual(err.stack, `${arrowMessage}${originalStack}`); -assert.strictEqual(internalUtil - .getHiddenValue(err, kDecoratedPrivateSymbolIndex), true); +assert.strictEqual( + binding.getHiddenValue(err, kDecoratedPrivateSymbolIndex), true); diff --git a/test/parallel/test-util-internal.js b/test/parallel/test-util-internal.js index aa475db4a1b7a7..9be642a8ffe715 100644 --- a/test/parallel/test-util-internal.js +++ b/test/parallel/test-util-internal.js @@ -4,7 +4,6 @@ const common = require('../common'); const path = require('path'); const assert = require('assert'); -const internalUtil = require('internal/util'); const spawnSync = require('child_process').spawnSync; const binding = process.binding('util'); @@ -12,13 +11,13 @@ const kArrowMessagePrivateSymbolIndex = binding['arrow_message_private_symbol']; function getHiddenValue(obj, index) { return function() { - internalUtil.getHiddenValue(obj, index); + binding.getHiddenValue(obj, index); }; } function setHiddenValue(obj, index, val) { 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({}, []), /index must be an uint32/); assert.deepStrictEqual( - internalUtil.getHiddenValue({}, kArrowMessagePrivateSymbolIndex), + binding.getHiddenValue({}, kArrowMessagePrivateSymbolIndex), undefined); 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/); const obj = {}; assert.strictEqual( - internalUtil.setHiddenValue(obj, kArrowMessagePrivateSymbolIndex, 'bar'), + binding.setHiddenValue(obj, kArrowMessagePrivateSymbolIndex, 'bar'), true); assert.strictEqual( - internalUtil.getHiddenValue(obj, kArrowMessagePrivateSymbolIndex), + binding.getHiddenValue(obj, kArrowMessagePrivateSymbolIndex), 'bar'); let arrowMessage; @@ -56,7 +55,7 @@ try { require(path.join(common.fixturesDir, 'syntax', 'bad_syntax')); } catch (err) { arrowMessage = - internalUtil.getHiddenValue(err, kArrowMessagePrivateSymbolIndex); + binding.getHiddenValue(err, kArrowMessagePrivateSymbolIndex); } assert(/bad_syntax\.js:1/.test(arrowMessage));