Documentation
¶
Overview ¶
Package jsrt provides a goja-based JavaScript implementation of script.Runtime.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrVMPoolBusy = errdefs.NotAvailable(errors.New("jsrt: VM pool exhausted"))
ErrVMPoolBusy is returned by nested execution when no VM is immediately available. Nested scripts must not wait on the same pool their parent holds.
var ErrVMPoolExhausted = errdefs.NotAvailable(errors.New("jsrt: VM pool exhausted, context cancelled while waiting"))
ErrVMPoolExhausted is returned when all VMs are in use and the context is cancelled before one becomes available.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Runtime)
Option configures a Runtime.
func WithMaxCallStackSize ¶ added in v0.2.6
WithMaxCallStackSize bounds the maximum call-stack depth a script may reach. Hits raise a goja runtime error and abort the script. Zero / negative leaves goja's default in place.
func WithMaxExecTime ¶ added in v0.2.6
WithMaxExecTime sets a runtime-enforced wall-clock ceiling on each Exec call. The ceiling is independent of the caller's context: even if the caller passes context.Background(), no script may run longer than d. The shorter of (caller deadline, d) wins. Zero disables the extra cap (caller ctx alone applies).
On expiry the script is interrupted via goja's Interrupt mechanism and Exec returns a context-deadline error classified by sdk/errdefs.IsTimeout.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime manages a pool of goja VMs for JS script execution. It implements script.Runtime.
func (*Runtime) Exec ¶
func (r *Runtime) Exec(ctx context.Context, name, source string, env *script.Env) (*script.Signal, error)
Exec implements script.Runtime. It runs a JS script in a pooled VM with the given environment (config + bindings) injected as globals. A built-in "signal" global is always injected, providing interrupt/error/done control flow back to the host.
func (*Runtime) ExecNested ¶ added in v0.4.5
func (r *Runtime) ExecNested(ctx context.Context, name, source string, env *script.Env) (*script.Signal, error)
ExecNested runs a child script only when another VM is immediately available. It is used by runtime.execScript to avoid parent scripts deadlocking each other while they still hold their own VMs.
func (*Runtime) SupportsNestedExec ¶ added in v0.4.5
SupportsNestedExec reports whether runtime.execScript has any chance of acquiring a second VM while a parent script is still holding one. Runtime bindings still use ExecNested so they can fail fast when the pool is busy.