go-json/internal/encoder/vm_indent/debug_vm.go

36 lines
841 B
Go
Raw Normal View History

2021-05-18 08:48:13 +03:00
package vm_indent
import (
"fmt"
"github.com/goccy/go-json/internal/encoder"
)
2021-05-31 16:25:33 +03:00
func DebugRun(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]byte, error) {
2021-05-31 19:25:05 +03:00
var code *encoder.Opcode
2021-06-01 07:40:15 +03:00
if (ctx.Option.Flag & encoder.HTMLEscapeOption) != 0 {
2021-05-31 19:25:05 +03:00
code = codeSet.EscapeKeyCode
} else {
code = codeSet.NoescapeKeyCode
}
2021-05-18 08:48:13 +03:00
defer func() {
if err := recover(); err != nil {
2022-03-24 23:09:22 +03:00
w := ctx.Option.DebugOut
fmt.Fprintln(w, "=============[DEBUG]===============")
fmt.Fprintln(w, "* [TYPE]")
fmt.Fprintln(w, codeSet.Type)
fmt.Fprintf(w, "\n")
fmt.Fprintln(w, "* [ALL OPCODE]")
fmt.Fprintln(w, code.Dump())
fmt.Fprintf(w, "\n")
fmt.Fprintln(w, "* [CONTEXT]")
fmt.Fprintf(w, "%+v\n", ctx)
fmt.Fprintln(w, "===================================")
2021-05-18 08:48:13 +03:00
panic(err)
}
}()
2021-05-31 16:25:33 +03:00
return Run(ctx, b, codeSet)
2021-05-18 08:48:13 +03:00
}