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 ¶
- Variables
- func Shutdown()
- type HostOption
- type ScriptEngineConfigurer
- type V8Error
- func (v V8Error) AsFunction() (jsFunction, bool)
- func (v V8Error) AsObject() (jsObject, bool)
- func (v V8Error) Boolean() bool
- func (v V8Error) Int32() int32
- func (v V8Error) IsBoolean() bool
- func (v V8Error) IsFunction() bool
- func (v V8Error) IsNull() bool
- func (v V8Error) IsObject() bool
- func (v V8Error) IsString() bool
- func (v V8Error) IsUndefined() bool
- func (v V8Error) Self() *v8Value
- func (v V8Error) StrictEquals(other jsValue) bool
- func (v V8Error) String() string
- func (v V8Error) Uint32() uint32
- type V8Module
- type V8Script
- type V8ScriptContext
- func (ctx *V8ScriptContext) Clock() html.Clock
- func (ctx *V8ScriptContext) Close()
- func (ctx *V8ScriptContext) Compile(script string) (html.Script, error)
- func (c *V8ScriptContext) Constructor(name string) js.Constructor[jsTypeParam]
- func (ctx *V8ScriptContext) DownloadModule(url string) (html.Script, error)
- func (ctx *V8ScriptContext) DownloadScript(url string) (html.Script, error)
- func (ctx *V8ScriptContext) Eval(script string) (any, error)
- func (c *V8ScriptContext) GetValue(entity entity.ObjectIder) (jsValue, bool)
- func (ctx *V8ScriptContext) Run(script string) error
- func (c *V8ScriptContext) SetValue(entity entity.ObjectIder, value jsValue)
- func (c *V8ScriptContext) Window() html.Window
- type V8ScriptHost
- func (host *V8ScriptHost) Close()
- func (host *V8ScriptHost) CreateClass(name string, extends js.Class[jsTypeParam], ...) js.Class[jsTypeParam]
- func (host *V8ScriptHost) CreateFunction(name string, callback js.FunctionCallback[jsTypeParam])
- func (host *V8ScriptHost) Logger() log.Logger
- func (host *V8ScriptHost) NewContext(w html.Window) html.ScriptContext
- func (host *V8ScriptHost) RunScript(script, src string)
Constants ¶
This section is empty.
Variables ¶
var (
ErrWrongNoOfArguments = errors.New("Not enough arguments passed")
)
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 ¶
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) IsFunction ¶ added in v0.8.0
func (v V8Error) IsFunction() bool
func (V8Error) IsUndefined ¶ added in v0.8.0
func (v V8Error) IsUndefined() bool
func (V8Error) StrictEquals ¶ added in v0.8.0
func (v V8Error) StrictEquals( other jsValue, ) bool
type V8Module ¶ added in v0.8.0
type V8Module struct {
// contains filtered or unexported fields
}
V8Module represents a compiled ECMAScript module
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) 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)