Documentation
¶
Index ¶
- func HijackConsoleLogging(e *Engine) error
- type Engine
- func (e *Engine) AddImport(filename string, loader func() []byte)
- func (e *Engine) CallFunctionWithTimeout(fn string) (otto.Value, error)
- func (e *Engine) DeclareNamespace(namespace string) (*otto.Object, error)
- func (e *Engine) EnableAssets() error
- func (e *Engine) Exec(fn string) (otto.Value, error)
- func (e *Engine) ImportNativePackage(namespace string, pkg *NativePackage) error
- func (e *Engine) ImportStandardLibrary(pkgs []*NativePackage) error
- func (e *Engine) InitVM() error
- func (e *Engine) LoadScript(filename string, source []byte) error
- func (e *Engine) LoadScriptWithTimeout(script *ast.Program) (otto.Value, error)
- func (e *Engine) Raise(name string, format string, args ...interface{}) otto.Value
- func (e *Engine) SetConst(name string, value interface{}) error
- func (e *Engine) SetEntryPoint(fnName string)
- func (e *Engine) SetID(id string)
- func (e *Engine) SetLogger(l logger.Logger) error
- func (e *Engine) SetName(n string)
- func (e *Engine) SetTimeout(t int)
- type NativeConst
- type NativeField
- type NativeFunc
- type NativePackage
- type NativeType
- type NativeVar
- type ParamDef
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HijackConsoleLogging ¶ added in v0.1.1
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 ¶
New returns a new genesis virtual machine with the given parameters (does not run, just returns the container object)
func (*Engine) CallFunctionWithTimeout ¶ added in v0.1.1
CallFunctionWithTimeout calls a given top level function in the VM that honors the VMs timeout setting
func (*Engine) DeclareNamespace ¶ added in v0.1.1
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
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
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) LoadScript ¶
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
LoadScriptWithTimeout evaluates an expression in the VM that honors the VMs timeout setting
func (*Engine) Raise ¶ added in v0.1.1
Raise is a convenience method for throwing a javascript runtime error from go space
func (*Engine) SetEntryPoint ¶ added in v0.1.1
SetEntryPoint sets the function name of the entry point function for the script
func (*Engine) SetTimeout ¶ added in v0.0.10
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
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