js

package
v0.0.0-...-3b91d86 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPathEscapes = errors.New("given path would escape")

ErrPathEscapes is returns when a given path would escape, that is, when joined with a path, something outside that path may be accessed.

Functions

func PathsFileReader

func PathsFileReader(paths ...string) func(filename string) ([]byte, error)

PathsFileReader returns a function which searches a list of paths in order, returning the first accessible file, or an error.

func PathsModuleLoader

func PathsModuleLoader(paths ...string) func(name string) ([]byte, error)

PathsModuleLoader returns a function which searches a list of paths in order, returning the first accessible JS module's source code, or an error.

Types

type Options

type Options struct {
	// Stdout is where the console writes.
	// If nil, then the console writes nowhere.
	Stdout io.Writer

	// ModuleLoader is a function which loads JS source by name.
	// If nil, then then no modules can be loaded (other than embedded ones,
	// see DisableLibs).
	ModuleLoader func(name string) ([]byte, error)

	// FileReader is a function which reads a file into the runtime. If not nil,
	// then this function is accessible through the name "readFile".
	FileReader func(filename string) ([]byte, error)

	// DisableLibs controls access to embedded libraries (lodash, etc).
	// If false, then they will not be accessible.
	DisableLibs bool
}

Options is provided to NewRuntime to construct a new Runtime.

type Runtime

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

Runtime wraps a goja runtime.

func NewRuntime

func NewRuntime(options Options) *Runtime

NewRuntime creates a new js runtime. Once the runtime is no longer needed, call Destroy.

func (*Runtime) Destroy

func (r *Runtime) Destroy()

Destroy cleans up the runtime. After calling Destrory, the runtime may not be usable.

func (*Runtime) Run

func (r *Runtime) Run(ctx context.Context, program string, out interface{}) error

Run runs a program in the runtime, and exports the result to out via JSON. If the context is cancelled, then the runtime is interrupted, and the output is undefined.

func (*Runtime) Set

func (r *Runtime) Set(name string, value interface{})

Set sets a variable to the specified value in the runtime.

Directories

Path Synopsis
Package console implements the global JS console object, in the same fashion as in the goja_node repo.
Package console implements the global JS console object, in the same fashion as in the goja_node repo.

Jump to

Keyboard shortcuts

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