compiler

package
v3.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 41 Imported by: 14

Documentation

Overview

Package compiler provides a compiler for the goja runtime.

Index

Constants

This section is empty.

Variables

View Source
var (
	PoolingJsVmConcurrency  = 100
	NonPoolingVMConcurrency = 20
)
View Source
var (
	// ErrJSExecDeadline is the error returned when alloted time for script execution exceeds
	ErrJSExecDeadline = errkit.New("js engine execution deadline exceeded").SetKind(errkit.ErrKindDeadline).Build()
)

Functions

func ExecuteProgram added in v3.1.9

func ExecuteProgram(p *goja.Program, args *ExecuteArgs, opts *ExecuteOptions) (result goja.Value, err error)

ExecuteProgram executes a compiled program with the default options. it deligates if a particular program should run in a pooled or non-pooled runtime

func Init added in v3.1.6

func Init(opts *types.Options) error

Init initializes the javascript protocol

func InternalGetGeneratorRuntime added in v3.1.8

func InternalGetGeneratorRuntime() *goja.Runtime

Internal purposes i.e generating bindings

func WrapScriptNCompile added in v3.1.9

func WrapScriptNCompile(script string, strict bool) (*goja.Program, error)

Wraps a script in a function and compiles it.

Types

type Compiler

type Compiler struct{}

Compiler provides a runtime to execute goja runtime based javascript scripts efficiently while also providing them access to custom modules defined in libs/.

func New

func New() *Compiler

New creates a new compiler for the goja runtime.

func (*Compiler) ExecuteWithOptions

func (c *Compiler) ExecuteWithOptions(program *goja.Program, args *ExecuteArgs, opts *ExecuteOptions) (ExecuteResult, error)

ExecuteWithOptions executes a script with the provided options.

type ExecuteArgs

type ExecuteArgs struct {
	Args        map[string]interface{} //these are protocol variables
	TemplateCtx map[string]interface{} // templateCtx contains template scoped variables
}

ExecuteArgs is the arguments to pass to the script.

func NewExecuteArgs

func NewExecuteArgs() *ExecuteArgs

NewExecuteArgs returns a new execute arguments.

func (*ExecuteArgs) Map added in v3.3.1

func (e *ExecuteArgs) Map() map[string]interface{}

Map returns a merged map of the TemplateCtx and Args fields.

type ExecuteOptions

type ExecuteOptions struct {
	// Callback can be used to register new runtime helper functions
	// ex: export etc
	Callback func(runtime *goja.Runtime) error

	// Cleanup is extra cleanup function to be called after execution
	Cleanup func(runtime *goja.Runtime)

	// Source is original source of the script
	Source *string

	Context context.Context

	TimeoutVariants *types.Timeouts
	// contains filtered or unexported fields
}

ExecuteOptions provides options for executing a script.

type ExecuteResult

type ExecuteResult map[string]interface{}

ExecuteResult is the result of executing a script.

func NewExecuteResult

func NewExecuteResult() ExecuteResult

NewExecuteResult returns a new execute result instance

func (ExecuteResult) GetSuccess

func (e ExecuteResult) GetSuccess() bool

GetSuccess returns whether the script was successful or not.

func (ExecuteResult) Map added in v3.3.1

func (e ExecuteResult) Map() map[string]interface{}

Map returns the map representation of the ExecuteResult

Jump to

Keyboard shortcuts

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