v8host

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: MIT Imports: 25 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 Shutdown added in v0.7.1

func Shutdown()

Dispose all pooled isolates

Types

type HostOption added in v0.5.1

type HostOption func(o *hostOptions)

func WithHTTPClient added in v0.8.0

func WithHTTPClient(client *http.Client) HostOption

func WithLogger added in v0.5.1

func WithLogger(logger log.Logger) HostOption

type ScriptEngineConfigurer added in v0.7.2

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

func (*ScriptEngineConfigurer) AddConfigurator added in v0.7.2

func (c *ScriptEngineConfigurer) AddConfigurator(configurer js.Configurator[jsTypeParam])

type V8Error added in v0.8.0

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

func (V8Error) AsFunction added in v0.8.0

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

func (V8Error) AsObject added in v0.8.0

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

func (V8Error) Boolean added in v0.8.0

func (v V8Error) Boolean() bool

func (V8Error) Int32 added in v0.8.0

func (v V8Error) Int32() int32

func (V8Error) IsBoolean added in v0.8.0

func (v V8Error) IsBoolean() bool

func (V8Error) IsFunction added in v0.8.0

func (v V8Error) IsFunction() bool

func (V8Error) IsNull added in v0.8.0

func (v V8Error) IsNull() bool

func (V8Error) IsObject added in v0.8.0

func (v V8Error) IsObject() bool

func (V8Error) IsString added in v0.8.0

func (v V8Error) IsString() bool

func (V8Error) IsUndefined added in v0.8.0

func (v V8Error) IsUndefined() bool

func (V8Error) Self added in v0.8.0

func (v V8Error) Self() *v8Value

func (V8Error) StrictEquals added in v0.8.0

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

func (V8Error) String added in v0.8.0

func (v V8Error) String() string

func (V8Error) Uint32 added in v0.8.0

func (v V8Error) Uint32() uint32

type V8Module added in v0.8.0

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

V8Module represents a compiled ECMAScript module

func (V8Module) Eval added in v0.8.0

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

func (V8Module) Run added in v0.8.0

func (mod V8Module) Run() error

type V8Script added in v0.7.0

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

func (V8Script) Eval added in v0.7.0

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

func (V8Script) Run added in v0.7.0

func (s V8Script) Run() error

type V8ScriptContext

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

func (*V8ScriptContext) Clock added in v0.3.0

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

func (*V8ScriptContext) Close

func (ctx *V8ScriptContext) Close()

func (*V8ScriptContext) Compile added in v0.7.0

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

func (*V8ScriptContext) Constructor added in v0.7.2

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 added in v0.8.0

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

func (*V8ScriptContext) DownloadScript added in v0.8.0

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

func (*V8ScriptContext) Eval

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

func (*V8ScriptContext) GetValue added in v0.7.2

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

func (*V8ScriptContext) Run

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

func (*V8ScriptContext) SetValue added in v0.7.2

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

func (*V8ScriptContext) Window added in v0.7.2

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

type V8ScriptHost

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

func New

func New(opts ...HostOption) *V8ScriptHost

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 added in v0.7.2

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

func (*V8ScriptHost) CreateFunction added in v0.7.2

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

func (*V8ScriptHost) Logger added in v0.5.1

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. Calling with a nil value for w is allowed, but not supported; and any attempt to access the DOM will result in a runtime error.

func (*V8ScriptHost) RunScript added in v0.8.0

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