v8

package
v0.0.0-...-376a440 Latest Latest
Warning

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

Go to latest
Published: May 10, 2020 License: LGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CompileVMPool maintains a pool of compile vm instance
	CompileVMPool vmPoolType = iota
	// RunVMPool maintains a pool of run vm instance
	RunVMPool
)

Variables

View Source
var (
	ErrConsoleNoLogger        = errors.New("no logger error")
	ErrConsoleInvalidLogLevel = errors.New("log invalid level")
)

Error message

View Source
var CVMInitOnce = sync.Once{}

CVMInitOnce vm init once

View Source
var (
	// ErrGetSandbox error when GetSandbox failed.
	ErrGetSandbox = errors.New("get sandbox failed")
)
View Source
var ErrInvalidDbValType = errors.New("invalid db value type")

ErrInvalidDbValType error

View Source
var (
	ErrResultTooLong = errors.New("result too long")
)

Error message

Functions

This section is empty.

Types

type Module

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

Module JavaScript module.

func NewModule

func NewModule(id, code string) *Module

NewModule create new Module.

type Modules

type Modules map[string]*Module

Modules module map.

func NewModules

func NewModules() Modules

NewModules create new Modules.

func (Modules) Del

func (ms Modules) Del(id string)

Del del module with specified id.

func (Modules) Get

func (ms Modules) Get(id string) *Module

Get get module with specified id.

func (Modules) Set

func (ms Modules) Set(m *Module)

Set set module to modules.

type Sandbox

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

Sandbox is an execution environment that allows separate, unrelated, JavaScript code to run in a single instance of IVM.

func GetSandbox

func GetSandbox(cSbx C.SandboxPtr) (*Sandbox, bool)

GetSandbox from sandbox map by sandbox ptr

func NewSandbox

func NewSandbox(e *VM, flags int64) *Sandbox

NewSandbox generate new sandbox for VM and insert into sandbox map

func (*Sandbox) Compile

func (sbx *Sandbox) Compile(contract *contract.Contract) (string, error)

Compile contract before execution, return compiled code

func (*Sandbox) Execute

func (sbx *Sandbox) Execute(preparedCode string) (string, int64, error)

Execute prepared code, return results, gasUsed

func (*Sandbox) GetFlags

func (sbx *Sandbox) GetFlags() int64

GetFlags ...

func (*Sandbox) Init

func (sbx *Sandbox) Init(vmType vmPoolType)

Init add system functions

func (*Sandbox) Prepare

func (sbx *Sandbox) Prepare(contract *contract.Contract, function string, args []interface{}) (string, error)

Prepare for contract, inject code

func (*Sandbox) Release

func (sbx *Sandbox) Release()

Release release sandbox and delete from map

func (*Sandbox) SetGasLimit

func (sbx *Sandbox) SetGasLimit(limit int64)

SetGasLimit set gas limit in context

func (*Sandbox) SetHost

func (sbx *Sandbox) SetHost(host *host.Host)

SetHost set host in sandbox and set gas limit

func (*Sandbox) SetJSPath

func (sbx *Sandbox) SetJSPath(path string, vmType vmPoolType)

SetJSPath set js path and ReloadVM

func (*Sandbox) Validate

func (sbx *Sandbox) Validate(contract *contract.Contract) error

Validate contract before save, return err if invalid

type VM

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

VM contains isolate instance, which is a v8 VM with its own heap.

func NewVM

func NewVM(poolType vmPoolType, jsPath string) *VM

NewVM return new vm with isolate and sandbox

func NewVMWithChannel

func NewVMWithChannel(vmType vmPoolType, jsPath string, releaseChannel chan *VM) *VM

NewVMWithChannel return new vm with release channel

func (*VM) EnsureFlags

func (e *VM) EnsureFlags(flags int64)

EnsureFlags make sandbox flag is same with input

type VMPool

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

VMPool manage all V8VM instance.

func NewVMPool

func NewVMPool(compilePoolSize, runPoolSize int) *VMPool

NewVMPool create new VMPool instance.

func (*VMPool) Compile

func (vmp *VMPool) Compile(contract *contract.Contract) (string, error)

Compile compile js code to binary.

func (*VMPool) Init

func (vmp *VMPool) Init() error

Init init VMPool.

func (*VMPool) LoadAndCall

func (vmp *VMPool) LoadAndCall(host *host.Host, contract *contract.Contract, api string, args ...interface{}) (rtn []interface{}, cost contract.Cost, err error)

LoadAndCall load compiled Javascript code and run code with specified api and args

func (*VMPool) Release

func (vmp *VMPool) Release()

Release release all V8VM instance in VMPool

func (*VMPool) SetJSPath

func (vmp *VMPool) SetJSPath(path string)

SetJSPath set standard Javascript library path.

func (*VMPool) Validate

func (vmp *VMPool) Validate(contract *contract.Contract) error

Validate js code and abi.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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