mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
internal/jsre: fix pretty-printing of floats
This commit is contained in:
parent
71b70f2eea
commit
3fdc0937eb
1 changed files with 15 additions and 22 deletions
|
|
@ -84,30 +84,23 @@ func (ctx ppctx) indent(level int) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctx ppctx) printValue(v goja.Value, level int, inArray bool) {
|
func (ctx ppctx) printValue(v goja.Value, level int, inArray bool) {
|
||||||
|
if goja.IsNull(v) || goja.IsUndefined(v) {
|
||||||
|
fmt.Fprint(ctx.w, SpecialColor(v.String()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
kind := v.ExportType().Kind()
|
||||||
switch {
|
switch {
|
||||||
case goja.IsNull(v):
|
case kind == reflect.Bool:
|
||||||
fmt.Fprint(ctx.w, SpecialColor("null"))
|
fmt.Fprint(ctx.w, SpecialColor("%t", v.ToBoolean()))
|
||||||
case goja.IsUndefined(v):
|
case kind == reflect.String:
|
||||||
fmt.Fprint(ctx.w, SpecialColor("undefined"))
|
fmt.Fprint(ctx.w, StringColor("%q", v.String()))
|
||||||
case goja.IsNaN(v):
|
case kind >= reflect.Int && kind <= reflect.Complex128:
|
||||||
fmt.Fprint(ctx.w, NumberColor("NaN"))
|
fmt.Fprint(ctx.w, NumberColor("%s", v.String()))
|
||||||
default:
|
|
||||||
switch v.ExportType().Kind() {
|
|
||||||
case reflect.String:
|
|
||||||
s := v.ToString().String()
|
|
||||||
fmt.Fprint(ctx.w, StringColor("%q", s))
|
|
||||||
case reflect.Bool:
|
|
||||||
b := v.ToBoolean()
|
|
||||||
fmt.Fprint(ctx.w, SpecialColor("%t", b))
|
|
||||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
|
||||||
s := v.ToString().String()
|
|
||||||
fmt.Fprint(ctx.w, NumberColor("%s", s))
|
|
||||||
default:
|
default:
|
||||||
if obj, ok := v.(*goja.Object); ok {
|
if obj, ok := v.(*goja.Object); ok {
|
||||||
ctx.printObject(obj, level, inArray)
|
ctx.printObject(obj, level, inArray)
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprint(ctx.w, "<unprintable>")
|
fmt.Fprintf(ctx.w, "<unprintable %T>", v)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue