vm

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2020 License: MIT Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrExecutionCancelled = errors.New("execution cancelled")

Functions

func Initialize

func Initialize(m *plugin.Manager) (plugin.Plugin, error)

Types

type AsyncResult

type AsyncResult struct {
	// Closed when the result is ready. Read from this channel to detect when
	// the result has been populated and is safe to inspect.
	Ready chan struct{}
	// Error associated with the result, if any. Only read from this after
	// the result is ready.
	Error error
	// Value associated with the result if there is no error. Only read from
	// this after the result is ready.
	Value goja.Value
	// contains filtered or unexported fields
}

AsyncResult handles invocations of asynchronous code that returns promises. An AsyncResult accepts any goja.Value; non-promises are supported so this is safe (if maybe a bit inefficient) to wrap all results produced by using one of the Run* methods on a VM.

func (*AsyncResult) Await

func (r *AsyncResult) Await() (goja.Value, error)

Await blocks until the result is ready and returns the result or error.

func (*AsyncResult) Cancel

func (r *AsyncResult) Cancel()

Cancel the result to halt execution.

type Module

type Module struct {
	Name string
	Path string
	Main string
	Body string
	// contains filtered or unexported fields
}

A Module is a javascript module identified by a name and full path.

func (*Module) FullPath

func (m *Module) FullPath() string

func (*Module) Require

func (m *Module) Require(name string) (*Module, error)

func (*Module) String

func (m *Module) String() string

type PrependRuntimeInitHandler

type PrependRuntimeInitHandler interface {
	PrependRuntimeInitHandler() bool
}

type Registry

type Registry struct {
	Transform func(in string) (string, error)
	// contains filtered or unexported fields
}

func NewRegistry

func NewRegistry(basePath string) *Registry

func (*Registry) Enable

func (r *Registry) Enable(runtime *goja.Runtime)

func (*Registry) SetModule

func (r *Registry) SetModule(module *Module)

type Result

type Result struct {
	// Closed when the result is ready. Read from this channel to detect when
	// the result has been populated and is safe to inspect.
	Ready chan struct{}
	// Error associated with the result, if any. Only read from this after
	// the result is ready.
	Error error
	// Value associated with the result if there is no error. Only read from
	// this after the result is ready.
	Value goja.Value
	// contains filtered or unexported fields
}

A Result is the output from executing synchronous code on a VM.

func (*Result) Await

func (r *Result) Await() (goja.Value, error)

Await blocks until the result is ready and returns the result or error.

func (*Result) Cancel

func (r *Result) Cancel()

Cancel the result to halt execution.

type RuntimeInitHandler

type RuntimeInitHandler interface {
	HandleRuntimeInit(r *goja.Runtime)
}

type VM

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

func FromPlugins

func FromPlugins(m *plugin.Manager) (*VM, error)

func New

func New(registry *Registry) (*VM, error)

func (*VM) Compile

func (vm *VM) Compile(name, in string) (*goja.Program, error)

func (*VM) Do

func (vm *VM) Do(fn func(*goja.Runtime))

func (*VM) OnRuntimeInit

func (vm *VM) OnRuntimeInit(h func(*goja.Runtime))

func (*VM) PrependRuntimeInit

func (vm *VM) PrependRuntimeInit(h func(*goja.Runtime))

func (*VM) RunProgram

func (vm *VM) RunProgram(p *goja.Program) *AsyncResult

func (*VM) RunScript

func (vm *VM) RunScript(name, in string) *AsyncResult

func (*VM) RunString

func (vm *VM) RunString(in string) *AsyncResult

func (*VM) SetModule

func (vm *VM) SetModule(module *Module)

func (*VM) SetTransformer

func (vm *VM) SetTransformer(fn func(in string) (string, error))

func (*VM) Shutdown

func (vm *VM) Shutdown() error

func (*VM) Start

func (vm *VM) Start() error

Jump to

Keyboard shortcuts

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