v8

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: Apache-2.0 Imports: 20 Imported by: 8

Documentation

Index

Constants

View Source
const (

	// IsoReady isolate is ready
	IsoReady uint8 = 0

	// IsoBusy isolate is in used
	IsoBusy uint8 = 1
)

Variables

View Source
var RootScripts = map[string]*Script{}

RootScripts the scripts for studio

View Source
var Scripts = map[string]*Script{}

Scripts loaded scripts

View Source
var WidgetScripts = map[string]*Script{}

WidgetScripts the scripts for widget

Functions

func DisablePrecompile

func DisablePrecompile()

DisablePrecompile disable the precompile

func EnablePrecompile

func EnablePrecompile()

EnablePrecompile enable the precompile feature

func SetHeapAvailableSize

func SetHeapAvailableSize(size uint)

SetHeapAvailableSize set runtime Available

func Start

func Start(option *Option) error

Start v8 runtime

func Stop

func Stop()

Stop v8 runtime

Types

type Context

type Context struct {
	ID      string                 // the script id
	SID     string                 // set the session id
	Data    map[string]interface{} // set the global data
	Timeout time.Duration          // terminate the execution after this time
	Iso     *Isolate
	Root    bool
	*v8go.Context
}

Context v8 Context

func (*Context) Call

func (ctx *Context) Call(method string, args ...interface{}) (interface{}, error)

Call call the script function

func (*Context) Close

func (ctx *Context) Close() error

Close Context

type Isolate

type Isolate struct {
	*v8go.Isolate
	// contains filtered or unexported fields
}

Isolate v8 Isolate

func NewIsolate

func NewIsolate() (*Isolate, error)

NewIsolate create a new Isolate

func SelectIso

func SelectIso(timeout time.Duration) (*Isolate, error)

SelectIso one ready isolate

func (*Isolate) Lock

func (iso *Isolate) Lock() error

Lock the isolate

func (Isolate) Locked

func (iso Isolate) Locked() bool

Locked check if the isolate is locked

func (*Isolate) Precompile

func (iso *Isolate) Precompile()

Precompile compile the loaded scirpts

func (*Isolate) Unlock

func (iso *Isolate) Unlock() error

Unlock the isolate

type Isolates

type Isolates struct {
	Len  int
	Data *sync.Map
}

Isolates loaded isolate

func (*Isolates) Add

func (list *Isolates) Add(iso *Isolate)

Add a isolate

func (*Isolates) Range

func (list *Isolates) Range(callback func(iso *Isolate) bool)

Range traverse isolates

func (*Isolates) Remove

func (list *Isolates) Remove(iso *Isolate)

Remove a isolate

func (*Isolates) Resize

func (list *Isolates) Resize(minSize, maxSize int) error

Resize set the maxSize

type Option

type Option struct {
	MinSize           int    `json:"minSize,omitempty"`           // the number of V8 VM when runtime start. max value is 100, the default value is 2
	MaxSize           int    `json:"maxSize,omitempty"`           // the maximum of V8 VM should be smaller than minSize, the default value is 10
	HeapSizeLimit     uint64 `json:"heapSizeLimit,omitempty"`     // the isolate heap size limit should be smaller than 1.5G, and the default value is 1518338048 (1.5G)
	HeapSizeRelease   uint64 `json:"heapSizeRelease,omitempty"`   // the isolate will be re-created when reaching this value, and the default value is 52428800 (50M)
	HeapAvailableSize uint64 `json:"heapAvailableSize,omitempty"` // the isolate will be re-created when the available size is smaller than this value, and the default value is 524288000 (500M)
	Precompile        bool   `json:"precompile,omitempty"`        // if true compile scripts when the VM is created. this will increase the load time, but the script will run faster. the default value is false
	DataRoot          string `json:"dataRoot,omitempty"`          // the data root path
}

Option runtime option

func (*Option) Validate

func (option *Option) Validate()

Validate the option

type Script

type Script struct {
	ID      string
	File    string
	Source  string
	Root    bool
	Timeout time.Duration
}

Script v8 scripts

func Load

func Load(file string, id string) (*Script, error)

Load load the script

func LoadRoot

func LoadRoot(file string, id string) (*Script, error)

LoadRoot load the script with root privileges

func LoadWidget

func LoadWidget(file string, id string) (*Script, error)

LoadWidget load the script for custom widgets

func NewScript

func NewScript(file string, id string, timeout ...time.Duration) *Script

NewScript create a new script

func Select

func Select(id string) (*Script, error)

Select a script

func SelectRoot

func SelectRoot(id string) (*Script, error)

SelectRoot a script with root privileges

func SelectWidget

func SelectWidget(id string) (*Script, error)

SelectWidget a custom widget script

func (*Script) Compile

func (script *Script) Compile(iso *Isolate, timeout time.Duration) (*v8go.Context, error)

Compile the javascript

func (*Script) NewContext

func (script *Script) NewContext(sid string, global map[string]interface{}) (*Context, error)

NewContext create a new context

Directories

Path Synopsis
functions
objects
fs
log

Jump to

Keyboard shortcuts

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