util: move getConstructorOf() to internal

PR-URL: https://github.com/nodejs/node/pull/12526
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Timothy Gu 2017-04-19 23:07:39 -07:00
parent b2870a4f8c
commit 3c0dd45c88
2 changed files with 17 additions and 17 deletions

View File

@ -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,

View File

@ -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) {