@ -239,6 +239,28 @@ function formatValue(ctx, value, recurseTimes) {
keys = Object . getOwnPropertyNames ( value ) ;
keys = Object . getOwnPropertyNames ( value ) ;
}
}
// This could be a boxed primitive (new String(), etc.), check valueOf()
// NOTE: Avoid calling `valueOf` on `Date` instance because it will return
// a number which, when object has some additional user-stored `keys`,
// will be printed out.
var formatted ;
var raw = value ;
try {
// the .valueOf() call can fail for a multitude of reasons
if ( ! isDate ( value ) )
raw = value . valueOf ( ) ;
} catch ( e ) {
// ignore...
}
if ( isString ( raw ) ) {
// for boxed Strings, we have to remove the 0-n indexed entries,
// since they just noisey up the output and are redundant
keys = keys . filter ( function ( key ) {
return ! ( key >= 0 && key < raw . length ) ;
} ) ;
}
// Some type of object without properties can be shortcutted.
// Some type of object without properties can be shortcutted.
if ( keys . length === 0 ) {
if ( keys . length === 0 ) {
if ( isFunction ( value ) ) {
if ( isFunction ( value ) ) {
@ -254,6 +276,19 @@ function formatValue(ctx, value, recurseTimes) {
if ( isError ( value ) ) {
if ( isError ( value ) ) {
return formatError ( value ) ;
return formatError ( value ) ;
}
}
// now check the `raw` value to handle boxed primitives
if ( isString ( raw ) ) {
formatted = formatPrimitiveNoColor ( ctx , raw ) ;
return ctx . stylize ( '[String: ' + formatted + ']' , 'string' ) ;
}
if ( isNumber ( raw ) ) {
formatted = formatPrimitiveNoColor ( ctx , raw ) ;
return ctx . stylize ( '[Number: ' + formatted + ']' , 'number' ) ;
}
if ( isBoolean ( raw ) ) {
formatted = formatPrimitiveNoColor ( ctx , raw ) ;
return ctx . stylize ( '[Boolean: ' + formatted + ']' , 'boolean' ) ;
}
}
}
var base = '' , array = false , braces = [ '{' , '}' ] ;
var base = '' , array = false , braces = [ '{' , '}' ] ;
@ -285,6 +320,24 @@ function formatValue(ctx, value, recurseTimes) {
base = ' ' + formatError ( value ) ;
base = ' ' + formatError ( value ) ;
}
}
// Make boxed primitive Strings look like such
if ( isString ( raw ) ) {
formatted = formatPrimitiveNoColor ( ctx , raw ) ;
base = ' ' + '[String: ' + formatted + ']' ;
}
// Make boxed primitive Numbers look like such
if ( isNumber ( raw ) ) {
formatted = formatPrimitiveNoColor ( ctx , raw ) ;
base = ' ' + '[Number: ' + formatted + ']' ;
}
// Make boxed primitive Booleans look like such
if ( isBoolean ( raw ) ) {
formatted = formatPrimitiveNoColor ( ctx , raw ) ;
base = ' ' + '[Boolean: ' + formatted + ']' ;
}
if ( keys . length === 0 && ( ! array || value . length == 0 ) ) {
if ( keys . length === 0 && ( ! array || value . length == 0 ) ) {
return braces [ 0 ] + base + braces [ 1 ] ;
return braces [ 0 ] + base + braces [ 1 ] ;
}
}
@ -338,6 +391,15 @@ function formatPrimitive(ctx, value) {
}
}
function formatPrimitiveNoColor ( ctx , value ) {
var stylize = ctx . stylize ;
ctx . stylize = stylizeNoColor ;
var str = formatPrimitive ( ctx , value ) ;
ctx . stylize = stylize ;
return str ;
}
function formatError ( value ) {
function formatError ( value ) {
return '[' + Error . prototype . toString . call ( value ) + ']' ;
return '[' + Error . prototype . toString . call ( value ) + ']' ;
}
}