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) {
|
||||
if goja.IsNull(v) || goja.IsUndefined(v) {
|
||||
fmt.Fprint(ctx.w, SpecialColor(v.String()))
|
||||
return
|
||||
}
|
||||
kind := v.ExportType().Kind()
|
||||
switch {
|
||||
case goja.IsNull(v):
|
||||
fmt.Fprint(ctx.w, SpecialColor("null"))
|
||||
case goja.IsUndefined(v):
|
||||
fmt.Fprint(ctx.w, SpecialColor("undefined"))
|
||||
case goja.IsNaN(v):
|
||||
fmt.Fprint(ctx.w, NumberColor("NaN"))
|
||||
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))
|
||||
case kind == reflect.Bool:
|
||||
fmt.Fprint(ctx.w, SpecialColor("%t", v.ToBoolean()))
|
||||
case kind == reflect.String:
|
||||
fmt.Fprint(ctx.w, StringColor("%q", v.String()))
|
||||
case kind >= reflect.Int && kind <= reflect.Complex128:
|
||||
fmt.Fprint(ctx.w, NumberColor("%s", v.String()))
|
||||
default:
|
||||
if obj, ok := v.(*goja.Object); ok {
|
||||
ctx.printObject(obj, level, inArray)
|
||||
} else {
|
||||
fmt.Fprint(ctx.w, "<unprintable>")
|
||||
}
|
||||
fmt.Fprintf(ctx.w, "<unprintable %T>", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue