v8go: rogchap.com/v8go Index | Files

package v8go

import "rogchap.com/v8go"

Package v8go provides an API to execute JavaScript.

Index

Package Files

cgo.go context.go errors.go isolate.go v8go.go value.go

func Version Uses

func Version() string

Version returns the version of the V8 Engine with the -v8go suffix

type Context Uses

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

Context is a global root execution environment that allows separate, unrelated, JavaScript applications to run in a single instance of V8.

func NewContext Uses

func NewContext(iso *Isolate) (*Context, error)

NewContext creates a new JavaScript context for a given isoltate; if isolate is `nil` than a new isolate will be created.

func (*Context) Isolate Uses

func (c *Context) Isolate() (*Isolate, error)

Isolate gets the current context's parent isolate.An error is returned if the isolate has been terninated.

func (*Context) RunScript Uses

func (c *Context) RunScript(source string, origin string) (*Value, error)

RunScript executes the source JavaScript; origin or filename provides a reference for the script and used in the stack trace if there is an error. error will be of type `JSError` of not nil.

type HeapStatistics Uses

type HeapStatistics struct {
    TotalHeapSize            uint64
    TotalHeapSizeExecutable  uint64
    TotalPhysicalSize        uint64
    TotalAvailableSize       uint64
    UsedHeapSize             uint64
    HeapSizeLimit            uint64
    MallocedMemory           uint64
    ExternalMemory           uint64
    PeakMallocedMemory       uint64
    NumberOfNativeContexts   uint64
    NumberOfDetachedContexts uint64
}

HeapStatistics represents V8 isolate heap statistics

type Isolate Uses

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

Isolate is a JavaScript VM instance with its own heap and garbage collector. Most applications will create one isolate with many V8 contexts for execution.

func NewIsolate Uses

func NewIsolate() (*Isolate, error)

NewIsolate creates a new V8 isolate. Only one thread may access a given isolate at a time, but different threads may access different isolates simultaneously.

func (*Isolate) GetHeapStatistics Uses

func (i *Isolate) GetHeapStatistics() HeapStatistics

GetHeapStatistics returns heap statistics for an isolate.

func (*Isolate) TerminateExecution Uses

func (i *Isolate) TerminateExecution()

TerminateExecution terminates forcefully the current thread of JavaScript execution in the given isolate.

type JSError Uses

type JSError struct {
    Message    string
    Location   string
    StackTrace string
}

JSError is an error that is returned if there is are any JavaScript exceptions handled in the context. When used with the fmt verb `%+v`, will output the JavaScript stack trace, if available.

func (*JSError) Error Uses

func (e *JSError) Error() string

func (*JSError) Format Uses

func (e *JSError) Format(s fmt.State, verb rune)

Format implements the fmt.Formatter interface to provide a custom formatter primarily to output the javascript stack trace with %+v

type Value Uses

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

Value represents all Javascript values and objects

func (*Value) String Uses

func (v *Value) String() string

String will return the string representation of the value. Primitive values are returned as-is, objects will return `[object Object]` and functions will print their definition.

Package v8go imports 6 packages (graph). Updated 2019-11-28. Refresh now. Tools for package owners.