Help us shape the future of Go! Take the 2026 Go Developer Survey

script

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Paths such as response.users[*].id are evaluated in Go. They are not JavaScript. Object literals and #? predicates run in Sobek.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSONPath

func JSONPath(data any, path string) (any, error)

Types

type Bindings

type Bindings struct {
	Config     func() map[string]any
	Driver     func(string, []any) (any, error)
	Call       func(Call) (any, error)
	Env        string
	Root       string
	FeatureDir string
	Configure  func(key string, val any) error
	CallSingle func(path string, arg any) (any, error)
	Setup      func(name string, once bool) (any, error)
	Channel    func(kind string, spec map[string]any) (any, error)
	PageText   func(selector string) (string, error)
	Abort      func()
	Sleep      func(time.Duration, <-chan struct{}) error
	Log        func(string) error
	Info       func() map[string]any
	Scenario   func() map[string]any
	Feature    func() map[string]any
	Write      func(any, string) (string, error)
	WaitHTTP   func(string, time.Duration, time.Duration, <-chan struct{}) error
	WaitPort   func(string, int, time.Duration, time.Duration, <-chan struct{}) error
	Signal     func(any) error
	Listen     func(time.Duration, <-chan struct{}) (any, error)
	Embed      func(any, string, string) error
	Helpers    map[string]func([]any) (any, error)
}

type Call

type Call struct {
	Path   string
	Arg    any
	Once   bool
	Shared bool
}

Call describes a feature or JavaScript file invocation.

type Configuration

type Configuration struct {
	// contains filtered or unexported fields
}

Configuration keeps live callbacks within their owning scenario runtime. A cache keeps a sealed function, which still calls that runtime.

func (Configuration) Portable

func (c Configuration) Portable() (Configuration, error)

Portable copies data and sealed callbacks. A sealed callback keeps the runtime and lexical bindings it closed over. Source is only the fallback.

type Element

type Element struct{ Locator string }

Element is a locator, not a DOM node or a cross-runtime browser handle.

type FailureDecision

type FailureDecision struct {
	Override bool
	Continue bool
}

type VM

type VM struct {
	// contains filtered or unexported fields
}

func New

func New() *VM

func (*VM) ApplyConfiguration

func (v *VM) ApplyConfiguration(c Configuration) error

func (*VM) Bind

func (v *VM) Bind(b Bindings) error

func (*VM) Bridge

func (v *VM) Bridge(methods map[string]func([]any) (any, error)) sobek.Value

func (*VM) Bytes

func (v *VM) Bytes(ref string) ([]byte, error)

func (*VM) CallFile

func (v *VM) CallFile(ref string, arg any) (any, error)

CallFile evaluates a JS helper once, invoking it if it returns a function. An object-valued helper is returned as data.

func (*VM) CallHook

func (v *VM) CallHook(name string) (bool, error)

func (*VM) Configuration

func (v *VM) Configuration() Configuration

func (*VM) ConfigureHeaders

func (v *VM) ConfigureHeaders(expr string) error

func (*VM) ConfigureHook

func (v *VM) ConfigureHook(name, expr string) error

func (*VM) ConfigureRetry

func (v *VM) ConfigureRetry(val any) error

func (*VM) Eval

func (v *VM) Eval(expr string) (out any, err error)

func (*VM) EvalConfig

func (v *VM) EvalConfig(src string) error

func (*VM) Get

func (v *VM) Get(name string) (any, bool)

func (*VM) HeaderOverlay

func (v *VM) HeaderOverlay() (map[string]any, error)

func (*VM) Invoke

func (v *VM) Invoke(expr string, arg any) (any, error)

func (*VM) IsFunction

func (v *VM) IsFunction(expr string) bool

func (*VM) Isolated added in v0.3.0

func (v *VM) Isolated(ctx context.Context) (*VM, func(), error)

Isolated seeds a new realm with this VM's variables and callbacks. Declarations and built-in changes in the child stay there. stop ends its lease.

func (*VM) Park

func (v *VM) Park(step func(wake <-chan struct{}) (bool, error)) error

Park lets other retained calls run on this goroutine while it is blocked in listen or pause. Sobek cannot execute on two goroutines at once.

func (*VM) RemovePath

func (v *VM) RemovePath(path string) error

func (*VM) Seal

func (v *VM) Seal(val any) any

Seal captures callable and null bindings along with data, retaining their native values so sibling functions and object identity survive scope restore.

func (*VM) SealConfiguration

func (v *VM) SealConfiguration(c Configuration) Configuration

func (*VM) Set

func (v *VM) Set(name string, val any)

func (*VM) SetFunction

func (v *VM) SetFunction(name string, fn func(call sobek.FunctionCall) sobek.Value)

func (*VM) SetPath

func (v *VM) SetPath(path string, val any) error

func (*VM) SetRetryUntil

func (v *VM) SetRetryUntil(expr string)

func (*VM) SharedScope added in v0.3.0

func (v *VM) SharedScope() func()

SharedScope restores call arguments and helpers while preserving shared variables.

func (*VM) StepFailure

func (v *VM) StepFailure(info map[string]any) (FailureDecision, error)

func (*VM) TakeRetryUntil

func (v *VM) TakeRetryUntil() (expr string, count int, every time.Duration)

func (*VM) ToValue

func (v *VM) ToValue(val any) sobek.Value

func (*VM) Truthy

func (v *VM) Truthy(expr string, self, root any) (bool, error)

_ is the current value. $ is the match root.

func (*VM) Try added in v0.3.0

func (v *VM) Try(fn func() error) error

Try converts JavaScript exceptions from property access and export into errors. The caller must own the runtime, just as for Eval and Get.

func (*VM) Vars

func (v *VM) Vars() map[string]any

func (*VM) Watch

func (v *VM) Watch(ctx context.Context) (func(), error)

Watch leases this VM for one scenario or retained-function execution. All runtime operations, including cleanup and exports, must finish before stop.

Jump to

Keyboard shortcuts

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