jsre: bind the pretty printer to "inspect" in JS

pull/1667/head
Felix Lange 9 years ago
parent 5c5c3930b7
commit 49703bea0a
  1. 1
      jsre/jsre.go
  2. 8
      jsre/pretty.go

@ -66,6 +66,7 @@ func New(assetPath string) *JSRE {
re.loopWg.Add(1) re.loopWg.Add(1)
go re.runEventLoop() go re.runEventLoop()
re.Set("loadScript", re.loadScript) re.Set("loadScript", re.loadScript)
re.Set("inspect", prettyPrintJS)
return re return re
} }

@ -54,6 +54,14 @@ func prettyPrint(vm *otto.Otto, value otto.Value) {
ppctx{vm}.printValue(value, 0) ppctx{vm}.printValue(value, 0)
} }
func prettyPrintJS(call otto.FunctionCall) otto.Value {
for _, v := range call.ArgumentList {
prettyPrint(call.Otto, v)
fmt.Println()
}
return otto.UndefinedValue()
}
type ppctx struct{ vm *otto.Otto } type ppctx struct{ vm *otto.Otto }
func (ctx ppctx) indent(level int) string { func (ctx ppctx) indent(level int) string {

Loading…
Cancel
Save