diff --git a/lib/internal/util.js b/lib/internal/util.js index 48036148b97..8b2148fd6a0 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -180,6 +180,21 @@ function convertToValidSignal(signal) { throw new Error('Unknown signal: ' + signal); } +function getConstructorOf(obj) { + while (obj) { + var descriptor = Object.getOwnPropertyDescriptor(obj, 'constructor'); + if (descriptor !== undefined && + typeof descriptor.value === 'function' && + descriptor.value.name !== '') { + return descriptor.value; + } + + obj = Object.getPrototypeOf(obj); + } + + return null; +} + module.exports = exports = { assertCrypto, cachedResult, @@ -188,6 +203,7 @@ module.exports = exports = { decorateErrorStack, deprecate, filterDuplicateStrings, + getConstructorOf, isError, normalizeEncoding, objectToString, diff --git a/lib/util.js b/lib/util.js index 2631f0a2c3e..ddf43a760c2 100644 --- a/lib/util.js +++ b/lib/util.js @@ -278,22 +278,6 @@ function arrayToHash(array) { } -function getConstructorOf(obj) { - while (obj) { - var descriptor = Object.getOwnPropertyDescriptor(obj, 'constructor'); - if (descriptor !== undefined && - typeof descriptor.value === 'function' && - descriptor.value.name !== '') { - return descriptor.value; - } - - obj = Object.getPrototypeOf(obj); - } - - return null; -} - - function ensureDebugIsInitialized() { if (Debug === undefined) { const runInDebugContext = require('vm').runInDebugContext; @@ -410,7 +394,7 @@ function formatValue(ctx, value, recurseTimes) { }); } - var constructor = getConstructorOf(value); + var constructor = internalUtil.getConstructorOf(value); // Some type of object without properties can be shortcutted. if (keys.length === 0) {