mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
eth/tracers/js: avoid compiling js bigint when not needed
This commit is contained in:
parent
48d05c43c9
commit
717fc2b063
1 changed files with 13 additions and 4 deletions
|
|
@ -22,6 +22,7 @@ import (
|
|||
"fmt"
|
||||
"math/big"
|
||||
"slices"
|
||||
"sync"
|
||||
|
||||
"github.com/dop251/goja"
|
||||
"github.com/ethereum/go-ethereum/core/tracing"
|
||||
|
|
@ -59,9 +60,17 @@ func init() {
|
|||
tracers.DefaultDirectory.RegisterJSEval(newJsTracer)
|
||||
}
|
||||
|
||||
// bigIntProgram is compiled once and the exported function mostly invoked to convert
|
||||
// hex strings into big ints.
|
||||
var bigIntProgram = goja.MustCompile("bigInt", bigIntegerJS, false)
|
||||
var compiledBigInt *goja.Program
|
||||
var compileOnce sync.Once
|
||||
|
||||
// getBigIntProgram compiles the bigint library, if needed, and returns the compiled
|
||||
// goja program.
|
||||
func getBigIntProgram() *goja.Program {
|
||||
compileOnce.Do(func() {
|
||||
compiledBigInt = goja.MustCompile("bigInt", bigIntegerJS, false)
|
||||
})
|
||||
return compiledBigInt
|
||||
}
|
||||
|
||||
type toBigFn = func(vm *goja.Runtime, val string) (goja.Value, error)
|
||||
type toBufFn = func(vm *goja.Runtime, val []byte) (goja.Value, error)
|
||||
|
|
@ -567,7 +576,7 @@ func (t *jsTracer) setBuiltinFunctions() {
|
|||
func (t *jsTracer) setTypeConverters() error {
|
||||
// Inject bigint logic.
|
||||
// TODO: To be replaced after goja adds support for native JS bigint.
|
||||
toBigCode, err := t.vm.RunProgram(bigIntProgram)
|
||||
toBigCode, err := t.vm.RunProgram(getBigIntProgram())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue