vm

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package vm provides a wrapper around the goja runtime.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCompilation is returned when a script fails to compile.
	ErrCompilation = errors.New("script compilation failed")
	// ErrRuntime is returned when a script fails to run.
	ErrRuntime = errors.New("script runtime failure")
	// ErrFunctionNotFound Function does not exist in script.
	ErrFunctionNotFound = errors.New("failed to find function")
)

Functions

This section is empty.

Types

type Option added in v0.7.1

type Option func(*Options)

Option represents an option for running a script.

func WithStartingLineNumber added in v0.7.3

func WithStartingLineNumber(lineNumber int) Option

WithStartingLineNumber sets the starting line number for the script.

type Options added in v0.7.1

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

Options represents options for running a script.

type VM

type VM struct {
	*goja.Runtime
	// contains filtered or unexported fields
}

VM is a wrapper around the goja runtime.

func New

func New() (*VM, error)

New creates a new VM.

func (*VM) Run

func (v *VM) Run(ctx context.Context, name string, src string, opts ...Option) (goja.Value, error)

Run runs a script in the VM.

func (*VM) RunFunction added in v0.11.0

func (v *VM) RunFunction(ctx context.Context, fnName string, args ...any) (goja.Value, error)

RunFunction will run the named function if it already exists within the environment, for example if it was defined in a script run by RunScript. The provided args will be passed to the function, and the result will be returned.

func (*VM) ToObject

func (v *VM) ToObject(val goja.Value) *goja.Object

ToObject converts a value to an object.

Jump to

Keyboard shortcuts

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