Documentation ¶
Overview ¶
Package jsre provides execution environment for JavaScript.
Index ¶
- Variables
- func MakeCallback(vm *goja.Runtime, fn func(Call) (goja.Value, error)) goja.Value
- func SafeGet(obj *goja.Object, key string) (ret goja.Value)
- type Call
- type JSRE
- func (re *JSRE) Compile(filename string, src string) (err error)
- func (jsre *JSRE) CompleteKeywords(line string) []string
- func (re *JSRE) Do(fn func(*goja.Runtime))
- func (re *JSRE) Evaluate(code string, w io.Writer)
- func (re *JSRE) Exec(file string) error
- func (re *JSRE) Run(code string) (v goja.Value, err error)
- func (re *JSRE) Set(ns string, v any) (err error)
- func (re *JSRE) Stop(waitForCallbacks bool)
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func MakeCallback ¶ added in v1.10.8
MakeCallback turns the given function into a function that's callable by JS.
Types ¶
type Call ¶ added in v1.10.7
type Call struct { goja.FunctionCall VM *goja.Runtime }
Call is the argument type of Go functions which are callable from JS.
type JSRE ¶
type JSRE struct {
// contains filtered or unexported fields
}
JSRE is a JS runtime environment embedding the goja interpreter. It provides helper functions to load code from files, run code snippets and bind native go objects to JS.
The runtime runs all code on a dedicated event loop and does not expose the underlying goja runtime directly. To use the runtime, call JSRE.Do. When binding a Go function, use the Call type to gain access to the runtime.
func (*JSRE) CompleteKeywords ¶
CompleteKeywords returns potential continuations for the given line. Since line is evaluated, callers need to make sure that evaluating line does not have side effects.
func (*JSRE) Evaluate ¶
Evaluate executes code and pretty prints the result to the specified output stream.
func (*JSRE) Exec ¶
Exec(file) loads and runs the contents of a file if a relative path is given, the jsre's assetPath is used