engine

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2020 License: AGPL-3.0 Imports: 13 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HijackConsoleLogging added in v0.1.1

func HijackConsoleLogging(e *Engine) error

HijackConsoleLogging intercepts the javascript runtimes console logging functions (i.e. console.log) and dynamically generates new native function implementations of those build ins that use the engine object's Logger interface

Types

type Engine

type Engine struct {
	// javascript V8 runtime
	VM *otto.Otto

	// logger interface for any output
	Logger logger.Logger

	// maps the asset names to the functions that return their bytes
	Imports map[string]func() []byte

	// maps the namespaces to native packages created by the compiler
	Packages map[string]*NativePackage

	// plaintext name of the VM - usually the script file basename
	Name string

	// unique identifier for this VM (unique per build)
	ID string

	// flag to denote whether the debugger is enabled
	DebuggerEnabled bool

	// timeout in seconds
	Timeout int

	// is the genesis VM halted
	Halted bool

	// is the genesis VM paused
	Paused bool

	// backwards compatibility to tell the planner whether to execute the before hook
	BeforeHook bool

	// backwards compatibility option to tell the planner whether to execute the after hook
	AfterHook bool

	// defines the entry point function for execution of the script
	EntryPoint string
	// contains filtered or unexported fields
}

Engine defines the virtual machine type for the genesis scripting engine

func New

func New(name, id string, timeout int, entrypoint string) *Engine

New returns a new genesis virtual machine with the given parameters (does not run, just returns the container object)

func (*Engine) AddImport

func (e *Engine) AddImport(filename string, loader func() []byte)

AddImport maps an asset to a filename in the VMs virtual file system

func (*Engine) CallFunctionWithTimeout added in v0.1.1

func (e *Engine) CallFunctionWithTimeout(fn string) (otto.Value, error)

CallFunctionWithTimeout calls a given top level function in the VM that honors the VMs timeout setting

func (*Engine) DeclareNamespace added in v0.1.1

func (e *Engine) DeclareNamespace(namespace string) (*otto.Object, error)

DeclareNamespace adds an empty namespace to the virtual machine. Caution! will overwrite any values at existing namespace.

func (*Engine) EnableAssets added in v0.1.1

func (e *Engine) EnableAssets() error

EnableAssets injects the core asset handling functions into the engine's runtime TODO (gen0cide): Fix asset retrieval to call from vm functions, not the raw translations

func (*Engine) Exec added in v0.1.1

func (e *Engine) Exec(fn string) (otto.Value, error)

Exec takes a single string of javascript and evaluates it within the VMs current context. It will return both a javascript value object as well as an error if one was encountered

func (*Engine) ImportNativePackage added in v0.1.1

func (e *Engine) ImportNativePackage(namespace string, pkg *NativePackage) error

ImportNativePackage adds a golang native package to the virtual machine's runtime at a specified namespace

func (*Engine) ImportStandardLibrary added in v0.1.1

func (e *Engine) ImportStandardLibrary(pkgs []*NativePackage) error

ImportStandardLibrary injects all provided native packages into the standard libraries namespace within the engine

func (*Engine) InitVM added in v0.1.1

func (e *Engine) InitVM() error

InitVM initializes the Engine's javascript virtual machine

func (*Engine) LoadScript

func (e *Engine) LoadScript(filename string, source []byte) error

LoadScript takes a script (source) with a corrasponding filename for debugging purposes and checks it for syntax errors before evaluating the script within the virtual machine's current scope

func (*Engine) LoadScriptWithTimeout added in v0.1.1

func (e *Engine) LoadScriptWithTimeout(script *ast.Program) (otto.Value, error)

LoadScriptWithTimeout evaluates an expression in the VM that honors the VMs timeout setting

func (*Engine) Raise added in v0.1.1

func (e *Engine) Raise(name string, format string, args ...interface{}) otto.Value

Raise is a convenience method for throwing a javascript runtime error from go space

func (*Engine) SetConst added in v0.1.1

func (e *Engine) SetConst(name string, value interface{}) error

SetConst defines a const value within the virtual machine

func (*Engine) SetEntryPoint added in v0.1.1

func (e *Engine) SetEntryPoint(fnName string)

SetEntryPoint sets the function name of the entry point function for the script

func (*Engine) SetID added in v0.1.1

func (e *Engine) SetID(id string)

SetID sets the VM's unique ID

func (*Engine) SetLogger

func (e *Engine) SetLogger(l logger.Logger) error

SetLogger overrides the logging interface for this virtual machine.

func (*Engine) SetName

func (e *Engine) SetName(n string)

SetName sets the VM's human readable name

func (*Engine) SetTimeout added in v0.0.10

func (e *Engine) SetTimeout(t int)

SetTimeout sets the timeout in seconds for the virtual machine

type NativeConst added in v0.1.1

type NativeConst struct {
	Name  string
	Value interface{}
}

NativeConst defines a golang const declared within a given library

type NativeField added in v0.1.1

type NativeField struct {
	Label     string
	Signature string
}

NativeField expresses a struct field within a Go native type within the engine

type NativeFunc added in v0.1.1

type NativeFunc struct {
	Name      string
	Signature string
	Func      func(call otto.FunctionCall) otto.Value
}

NativeFunc defines a golang library function that is callable from within the genesis VM

type NativePackage added in v0.1.1

type NativePackage struct {
	ImportPath  string
	Name        string
	SymbolTable map[string]*NativeFunc
	Types       map[string]*NativeType
	Consts      map[string]*NativeConst
	Vars        map[string]*NativeVar
}

NativePackage defines a golang library that is being imported into the genesis VM

type NativeType added in v0.1.1

type NativeType struct {
	Name    string
	Factory func(call otto.FunctionCall) otto.Value
	Fields  map[string]*NativeField
}

NativeType expresses a native Golang type definition that can be used within the engine

type NativeVar added in v0.1.1

type NativeVar struct {
	Name      string
	Signature string
	Value     interface{}
}

NativeVar defines a golang top level var declaration within a given library

type ParamDef added in v0.1.1

type ParamDef struct {
	Name   string
	GoType string
	JSType string
}

ParamDef defines basic information about either an argument or return value for NativeFunc

Jump to

Keyboard shortcuts

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