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 form, 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 V8Script
- type V8ScriptContext
- func (ctx *V8ScriptContext) Clock() html.Clock
- func (ctx *V8ScriptContext) Close()
- func (ctx *V8ScriptContext) Compile(script string) (V8Script, error)
- func (c *V8ScriptContext) Constructor(name string) js.Constructor[jsTypeParam]
- 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
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 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 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) (V8Script, 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) 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.