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 DefaultEngine() html.ScriptEngine
- type HostOption
- 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 (h *V8ScriptHost) CreateGlobalObject(name string) js.GlobalObject[jsTypeParam]
- func (host *V8ScriptHost) Dispose()
- 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 ¶
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) IsFunction ¶
func (v V8Error) IsFunction() bool
func (V8Error) IsUndefined ¶
func (v V8Error) IsUndefined() bool
func (V8Error) StrictEquals ¶
func (v V8Error) StrictEquals( other jsValue, ) bool
type V8Module ¶
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 ¶
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) 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)