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:
parent
b2870a4f8c
commit
3c0dd45c88
@ -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,
|
||||
|
18
lib/util.js
18
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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user