compiler

package
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: MIT Imports: 32 Imported by: 3 modules, 14 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

Overview

Package compiler provides a compiler for the goja runtime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Compiler

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

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) Execute

func (c *Compiler) Execute(code string, args *ExecuteArgs) (ExecuteResult, error)

Execute executes a script with the default options.

func (*Compiler) ExecuteWithOptions

func (c *Compiler) ExecuteWithOptions(code string, args *ExecuteArgs, opts *ExecuteOptions) (ExecuteResult, error)

ExecuteWithOptions executes a script with the provided options.

func (*Compiler) VM

func (c *Compiler) VM() *goja.Runtime

VM returns a new goja runtime for the compiler.

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.

type ExecuteOptions

type ExecuteOptions struct {
	// Pool specifies whether to use a pool of goja runtimes
	// Can be used to speedup execution but requires
	// the script to not make any global changes.
	Pool bool

	// CaptureOutput specifies whether to capture the output
	// of the script execution.
	CaptureOutput bool

	// CaptureVariables specifies the variables to capture
	// from the script execution.
	CaptureVariables []string

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

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

func (ExecuteResult) GetSuccess

func (e ExecuteResult) GetSuccess() bool

GetSuccess returns whether the script was successful or not.

Jump to

Keyboard shortcuts

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