Skip to content
Permalink
Browse files

util: move getConstructorOf() to internal

PR-URL: #12526
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
TimothyGu committed Apr 20, 2017
1 parent b2870a4 commit 3c0dd45c882b8c84ec244d3a5635302fb4875d81
Showing with 17 additions and 17 deletions.
  1. +16 −0 lib/internal/util.js
  2. +1 −17 lib/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,
@@ -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) {

0 comments on commit 3c0dd45

Please sign in to comment.
You can’t perform that action at this time.