v8engine

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

The v8host packages provides functionality to execute client-side scripts in gost-dom. The engine uses v8, and requires cgo.

This engine is based on tommie's v8go fork, which automatically pulls the latest v8 changes from the chromium repo.

An alternate script engine that is implemented in pure go is found in the gojahost package

See also: https://github.com/tommie/v8go

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWrongNoOfArguments = errors.New("Not enough arguments passed")
)
View Source
var MAX_POOL_SIZE = runtime.NumCPU() * 2

MAX_POOL_SIZE sets a limit to the number of script hosts that will be pooled for reuse. By default Go will run as many tests in parallel as you have CPU cores, so there shouldn't be a reason for a larger pool, but this provides a bit of flexibility.

Functions

func DefaultEngine

func DefaultEngine() html.ScriptEngine

Types

type HostOption

type HostOption func(o *hostOptions)

func WithHTTPClient

func WithHTTPClient(client *http.Client) HostOption

func WithLogger

func WithLogger(logger log.Logger) HostOption

type V8Error

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

func (V8Error) AsFunction

func (v V8Error) AsFunction() (jsFunction, bool)

func (V8Error) AsObject

func (v V8Error) AsObject() (jsObject, bool)

func (V8Error) Boolean

func (v V8Error) Boolean() bool

func (V8Error) Int32

func (v V8Error) Int32() int32

func (V8Error) IsBoolean

func (v V8Error) IsBoolean() bool

func (V8Error) IsFunction

func (v V8Error) IsFunction() bool

func (V8Error) IsNull

func (v V8Error) IsNull() bool

func (V8Error) IsObject

func (v V8Error) IsObject() bool

func (V8Error) IsString

func (v V8Error) IsString() bool

func (V8Error) IsUndefined

func (v V8Error) IsUndefined() bool

func (V8Error) Self

func (v V8Error) Self() *v8Value

func (V8Error) StrictEquals

func (v V8Error) StrictEquals(
	other jsValue,
) bool

func (V8Error) String

func (v V8Error) String() string

func (V8Error) Uint32

func (v V8Error) Uint32() uint32

type V8Module

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

V8Module represents a compiled ECMAScript module

func (V8Module) Eval

func (mod V8Module) Eval() (any, error)

func (V8Module) Run

func (mod V8Module) Run() error

type V8Script

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

func (V8Script) Eval

func (s V8Script) Eval() (any, error)

func (V8Script) Run

func (s V8Script) Run() error

type V8ScriptContext

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

func (*V8ScriptContext) Clock

func (ctx *V8ScriptContext) Clock() html.Clock

func (*V8ScriptContext) Close

func (ctx *V8ScriptContext) Close()

func (*V8ScriptContext) Compile

func (ctx *V8ScriptContext) Compile(script string) (html.Script, error)

func (*V8ScriptContext) Constructor

func (c *V8ScriptContext) Constructor(name string) js.Constructor[jsTypeParam]

Constructor returns the V8 FunctionTemplate with the specified name. Panics if the name is not one registered as a constructor. The name should not originate from client code, only from this library, so it should be guaranteed that this function is only called with valid values.

func (*V8ScriptContext) DownloadModule

func (ctx *V8ScriptContext) DownloadModule(url string) (html.Script, error)

func (*V8ScriptContext) DownloadScript

func (ctx *V8ScriptContext) DownloadScript(url string) (html.Script, error)

func (*V8ScriptContext) Eval

func (ctx *V8ScriptContext) Eval(script string) (any, error)

func (*V8ScriptContext) GetValue

func (c *V8ScriptContext) GetValue(entity entity.ObjectIder) (jsValue, bool)

func (*V8ScriptContext) Run

func (ctx *V8ScriptContext) Run(script string) error

func (*V8ScriptContext) SetValue

func (c *V8ScriptContext) SetValue(entity entity.ObjectIder, value jsValue)

func (*V8ScriptContext) Window

func (c *V8ScriptContext) Window() html.Window

type V8ScriptHost

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

func New deprecated

func New(opts ...HostOption) *V8ScriptHost

New returns a new initialized V8ScriptHost

Deprecated: Obtain V8ScriptHost instances from a script engine which will handle caching of unused isolates

func (*V8ScriptHost) Close

func (host *V8ScriptHost) Close()

Close informs that client code is done using this script host. The host will be placed into a pool;

func (*V8ScriptHost) CreateClass

func (host *V8ScriptHost) CreateClass(
	name string,
	extends js.Class[jsTypeParam],
	callback js.FunctionCallback[jsTypeParam],
) js.Class[jsTypeParam]

func (*V8ScriptHost) CreateFunction

func (host *V8ScriptHost) CreateFunction(
	name string,
	callback js.FunctionCallback[jsTypeParam],
)

func (*V8ScriptHost) CreateGlobalObject

func (h *V8ScriptHost) CreateGlobalObject(name string) js.GlobalObject[jsTypeParam]

CreateGlobalObject implements js/ScriptEngine.CreateGlobalObject

func (*V8ScriptHost) Dispose

func (host *V8ScriptHost) Dispose()

func (*V8ScriptHost) Logger

func (host *V8ScriptHost) Logger() log.Logger

func (*V8ScriptHost) NewContext

func (host *V8ScriptHost) NewContext(w html.Window) html.ScriptContext

NewContext creates a new script context using w as the global window object.

func (*V8ScriptHost) RunScript

func (host *V8ScriptHost) RunScript(script, src string)

Jump to

Keyboard shortcuts

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