script

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTimeout = errors.New("script execution timeout")

Functions

func Check

func Check(src string) error

Check compiles the source without running it.

func Normalize

func Normalize(value any, maxBytes int) (any, error)

Normalize converts a Go value into its JSON form and enforces maxBytes if positive.

func Truthy

func Truthy(value any) (bool, error)

Truthy reports whether a condition result selects a sequence flow; only booleans are accepted.

Types

type Assignment

type Assignment struct {
	Name  string
	Value any
}

type Error

type Error struct {
	Err  error
	Logs []string
}

Error is a script failure; Logs holds what the script wrote before it failed.

func (*Error) Error

func (this *Error) Error() string

func (*Error) Unwrap

func (this *Error) Unwrap() error

type Result

type Result struct {
	// JSON compatible value: nil, bool, float64, string, []any or map[string]any (EXPR-05)
	Value       any
	Logs        []string
	Assignments []Assignment
}

type Sandbox

type Sandbox struct {
	Timeout        time.Duration
	MaxResultBytes int
	MaxLogEntries  int
	MaxCallStack   int
}

Sandbox evaluates JavaScript, the only expression and script language of the engine (EXPR-01). Scripts see the variables as globals plus log(...) and setVariable(name, value) (EXPR-04). They have no access to engine internals, the file system or the network, because goja provides none of these by default and nothing else is registered (EXPR-03).

goja has no memory limit. The timeout and the result size limit bound what a script can do, but a script can allocate memory until the timeout interrupts it.

func NewSandbox

func NewSandbox() *Sandbox

func (*Sandbox) Run

func (this *Sandbox) Run(src string, variables map[string]any) (result Result, err error)

Run evaluates src; the value of the last expression statement is the result.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL