Skip to content

Commit 3c0dd45

Browse files
committed
util: move getConstructorOf() to internal
PR-URL: #12526 Reviewed-By: James M Snell <[email protected]>
1 parent b2870a4 commit 3c0dd45

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

lib/internal/util.js

+16
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,21 @@ function convertToValidSignal(signal) {
180180
throw new Error('Unknown signal: ' + signal);
181181
}
182182

183+
function getConstructorOf(obj) {
184+
while (obj) {
185+
var descriptor = Object.getOwnPropertyDescriptor(obj, 'constructor');
186+
if (descriptor !== undefined &&
187+
typeof descriptor.value === 'function' &&
188+
descriptor.value.name !== '') {
189+
return descriptor.value;
190+
}
191+
192+
obj = Object.getPrototypeOf(obj);
193+
}
194+
195+
return null;
196+
}
197+
183198
module.exports = exports = {
184199
assertCrypto,
185200
cachedResult,
@@ -188,6 +203,7 @@ module.exports = exports = {
188203
decorateErrorStack,
189204
deprecate,
190205
filterDuplicateStrings,
206+
getConstructorOf,
191207
isError,
192208
normalizeEncoding,
193209
objectToString,

lib/util.js

+1-17
Original file line numberDiff line numberDiff line change
@@ -278,22 +278,6 @@ function arrayToHash(array) {
278278
}
279279

280280

281-
function getConstructorOf(obj) {
282-
while (obj) {
283-
var descriptor = Object.getOwnPropertyDescriptor(obj, 'constructor');
284-
if (descriptor !== undefined &&
285-
typeof descriptor.value === 'function' &&
286-
descriptor.value.name !== '') {
287-
return descriptor.value;
288-
}
289-
290-
obj = Object.getPrototypeOf(obj);
291-
}
292-
293-
return null;
294-
}
295-
296-
297281
function ensureDebugIsInitialized() {
298282
if (Debug === undefined) {
299283
const runInDebugContext = require('vm').runInDebugContext;
@@ -410,7 +394,7 @@ function formatValue(ctx, value, recurseTimes) {
410394
});
411395
}
412396

413-
var constructor = getConstructorOf(value);
397+
var constructor = internalUtil.getConstructorOf(value);
414398

415399
// Some type of object without properties can be shortcutted.
416400
if (keys.length === 0) {

0 commit comments

Comments
 (0)