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‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,21 @@ function convertToValidSignal(signal){
180180
thrownewError('Unknown signal: '+signal);
181181
}
182182

183+
functiongetConstructorOf(obj){
184+
while(obj){
185+
vardescriptor=Object.getOwnPropertyDescriptor(obj,'constructor');
186+
if(descriptor!==undefined&&
187+
typeofdescriptor.value==='function'&&
188+
descriptor.value.name!==''){
189+
returndescriptor.value;
190+
}
191+
192+
obj=Object.getPrototypeOf(obj);
193+
}
194+
195+
returnnull;
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‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -278,22 +278,6 @@ function arrayToHash(array){
278278
}
279279

280280

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

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

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

0 commit comments

Comments
(0)