Skip to content

Commit

Permalink
util: move getConstructorOf() to internal
Browse files Browse the repository at this point in the history
PR-URL: #12526
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
TimothyGu committed Apr 24, 2017
1 parent b2870a4 commit 3c0dd45
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
16 changes: 16 additions & 0 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -188,6 +203,7 @@ module.exports = exports = {
decorateErrorStack,
deprecate,
filterDuplicateStrings,
getConstructorOf,
isError,
normalizeEncoding,
objectToString,
Expand Down
18 changes: 1 addition & 17 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3c0dd45

Please sign in to comment.