@@ -15,10 +15,13 @@ const {
1515} = require ( 'internal/errors' ) ;
1616const { previewEntries } = internalBinding ( 'util' ) ;
1717const { Buffer : { isBuffer } } = require ( 'buffer' ) ;
18- const util = require ( 'util' ) ;
18+ const {
19+ inspect,
20+ formatWithOptions
21+ } = require ( 'internal/util/inspect' ) ;
1922const {
2023 isTypedArray, isSet, isMap, isSetIterator, isMapIterator,
21- } = util . types ;
24+ } = require ( 'internal/ util/ types' ) ;
2225const kCounts = Symbol ( 'counts' ) ;
2326
2427const kTraceConsoleCategory = 'node,node.console' ;
@@ -271,12 +274,12 @@ Console.prototype[kGetInspectOptions] = function(stream) {
271274
272275Console . prototype [ kFormatForStdout ] = function ( args ) {
273276 const opts = this [ kGetInspectOptions ] ( this . _stdout ) ;
274- return util . formatWithOptions ( opts , ...args ) ;
277+ return formatWithOptions ( opts , ...args ) ;
275278} ;
276279
277280Console . prototype [ kFormatForStderr ] = function ( args ) {
278281 const opts = this [ kGetInspectOptions ] ( this . _stderr ) ;
279- return util . formatWithOptions ( opts , ...args ) ;
282+ return formatWithOptions ( opts , ...args ) ;
280283} ;
281284
282285const consoleMethods = {
@@ -290,7 +293,7 @@ const consoleMethods = {
290293 } ,
291294
292295 dir ( object , options ) {
293- this [ kWriteToConsole ] ( kUseStdout , util . inspect ( object , {
296+ this [ kWriteToConsole ] ( kUseStdout , inspect ( object , {
294297 customInspect : false ,
295298 ...this [ kGetInspectOptions ] ( this . _stdout ) ,
296299 ...options
@@ -404,7 +407,7 @@ const consoleMethods = {
404407 if ( cliTable === undefined ) cliTable = require ( 'internal/cli_table' ) ;
405408 const final = ( k , v ) => this . log ( cliTable ( k , v ) ) ;
406409
407- const inspect = ( v ) => {
410+ const _inspect = ( v ) => {
408411 const depth = v !== null &&
409412 typeof v === 'object' &&
410413 ! isArray ( v ) &&
@@ -414,10 +417,10 @@ const consoleMethods = {
414417 maxArrayLength : 3 ,
415418 ...this [ kGetInspectOptions ] ( this . _stdout )
416419 } ;
417- return util . inspect ( v , opt ) ;
420+ return inspect ( v , opt ) ;
418421 } ;
419422 const getIndexArray = ( length ) => ArrayFrom (
420- { length } , ( _ , i ) => inspect ( i ) ) ;
423+ { length } , ( _ , i ) => _inspect ( i ) ) ;
421424
422425 const mapIter = isMapIterator ( tabularData ) ;
423426 let isKeyValue = false ;
@@ -434,14 +437,14 @@ const consoleMethods = {
434437 let length = 0 ;
435438 if ( mapIter ) {
436439 for ( ; i < tabularData . length / 2 ; ++ i ) {
437- keys . push ( inspect ( tabularData [ i * 2 ] ) ) ;
438- values . push ( inspect ( tabularData [ i * 2 + 1 ] ) ) ;
440+ keys . push ( _inspect ( tabularData [ i * 2 ] ) ) ;
441+ values . push ( _inspect ( tabularData [ i * 2 + 1 ] ) ) ;
439442 length ++ ;
440443 }
441444 } else {
442445 for ( const [ k , v ] of tabularData ) {
443- keys . push ( inspect ( k ) ) ;
444- values . push ( inspect ( v ) ) ;
446+ keys . push ( _inspect ( k ) ) ;
447+ values . push ( _inspect ( v ) ) ;
445448 length ++ ;
446449 }
447450 }
@@ -463,7 +466,7 @@ const consoleMethods = {
463466 const values = [ ] ;
464467 let length = 0 ;
465468 for ( const v of tabularData ) {
466- values . push ( inspect ( v ) ) ;
469+ values . push ( _inspect ( v ) ) ;
467470 length ++ ;
468471 }
469472 return final ( [ iterKey , valuesKey ] , [ getIndexArray ( length ) , values ] ) ;
@@ -480,7 +483,7 @@ const consoleMethods = {
480483 ( typeof item !== 'function' && typeof item !== 'object' ) ;
481484 if ( properties === undefined && primitive ) {
482485 hasPrimitives = true ;
483- valuesKeyArray [ i ] = inspect ( item ) ;
486+ valuesKeyArray [ i ] = _inspect ( item ) ;
484487 } else {
485488 const keys = properties || ObjectKeys ( item ) ;
486489 for ( const key of keys ) {
@@ -489,7 +492,7 @@ const consoleMethods = {
489492 if ( ( primitive && properties ) || ! hasOwnProperty ( item , key ) )
490493 map [ key ] [ i ] = '' ;
491494 else
492- map [ key ] [ i ] = item == null ? item : inspect ( item [ key ] ) ;
495+ map [ key ] [ i ] = item == null ? item : _inspect ( item [ key ] ) ;
493496 }
494497 }
495498 }
0 commit comments