Documentation
¶
Index ¶
- Constants
- Variables
- func Call(runtime *goja.Runtime, function any, this any, arguments ...any) (value any, err error)
- func CallExported(runtime *goja.Runtime, function ExportedJavaScriptFunc, this any, ...) (value any, err error)
- func CallValue(runtime *goja.Runtime, function goja.Value, this any, arguments ...any) (any, error)
- func GetAndCall(runtime *goja.Runtime, object *goja.Object, name string, this any, ...) (value any, err error)
- func HandleJavaScriptPanic(r any) error
- func NewObject(runtime *goja.Runtime, value any) *goja.Object
- func UnwrapJavaScriptException(err error) error
- type Bind
- type BindFunc
- type Context
- func (self *Context) AppendExtension(extension Extension)
- func (self *Context) CreateExtension(extension Extension) goja.Value
- func (self *Context) NewEarlyBind(id string, exportName string) (EarlyBind, error)
- func (self *Context) NewLateBind(id string, exportName string) (LateBind, error)
- func (self *Context) NewRequire() *goja.Object
- func (self *Context) Require(context contextpkg.Context, url exturl.URL, childEnvironment bool, ...) (*goja.Object, *Context, error)
- func (self *Context) RequireAndExport(context contextpkg.Context, url exturl.URL, childEnvironment bool, ...) (value any, jsContext *Context, err error)
- func (self *Context) ResolveAndRequire(context contextpkg.Context, id string, bareId bool, childEnvironment bool, ...) (*goja.Object, *Context, error)
- func (self *Context) ResolveAndWatch(context contextpkg.Context, id string, bareId bool) (exturl.URL, error)
- type CreateExtensionFunc
- type CreateResolverFunc
- type EarlyBind
- type Environment
- func (self *Environment) AddModule(url exturl.URL, module *Module)
- func (self *Environment) Call(function any, this any, arguments ...any) (any, error)
- func (self *Environment) ClearCache()
- func (self *Environment) GetAndCall(object *goja.Object, name string, this any, arguments ...any) (any, error)
- func (self *Environment) NewChild() *Environment
- func (self *Environment) NewContext(url exturl.URL, parent *Context, userContext any) *Context
- func (self *Environment) NewModule() *Module
- func (self *Environment) NewTimeoutContext() (contextpkg.Context, contextpkg.CancelFunc)
- func (self *Environment) Release() error
- func (self *Environment) Require(id string, bareId bool, userContext any) (*goja.Object, error)
- func (self *Environment) RequireURL(url exturl.URL, userContext any) (*goja.Object, error)
- func (self *Environment) StartWatcher() error
- func (self *Environment) StopWatcher() error
- func (self *Environment) Watch(path string) error
- type ExportedJavaScriptFunc
- type Extension
- type JavaScriptConstructorFunc
- type LateBind
- type Module
- type OnFileModifiedFunc
- type PrecompileFunc
- type ResolveFunc
- type ThreadSafeObject
- func (self *ThreadSafeObject) Delete(key string) bool
- func (self *ThreadSafeObject) Get(key string) goja.Value
- func (self *ThreadSafeObject) Has(key string) bool
- func (self *ThreadSafeObject) Keys() []string
- func (self *ThreadSafeObject) NewDynamicObject(runtime *goja.Runtime) *goja.Object
- func (self *ThreadSafeObject) Set(key string, value goja.Value) bool
Constants ¶
const DEFAULT_TIMEOUT = time.Second * 5
Variables ¶
var DromedaryCaseMapper dromedaryCaseMapper
Functions ¶
func Call ¶
The function argument can be a ExportedJavaScriptFunc or a goja.Value representing a function.
func CallExported ¶ added in v0.2.3
func GetAndCall ¶ added in v0.1.10
func HandleJavaScriptPanic ¶ added in v0.2.0
Call with a recover() value. If it's an error, then it will be unwrapped and returned.
Otherwise, will re-panic the value.
This function is useful for cases in which Goja indicates errors by panicking instead of returning an error.
Usage:
func MyFunc() (err error) { defer func() { if err_ := HandleJavaScriptPanic(recover()); err_ != nil { err = err_ } }() // do something that can panic }
func UnwrapJavaScriptException ¶ added in v0.2.0
Types ¶
type Context ¶
type Context struct { Environment *Environment Parent *Context UserContext any Module *Module Resolve ResolveFunc Extensions []goja.Value }
func Unbind ¶ added in v0.2.0
If value is a Bind will unbind it, recursively, and return the bound value and Context.
Otherwise will return the provided value and Context as is.
func (*Context) AppendExtension ¶ added in v0.2.0
func (*Context) CreateExtension ¶ added in v0.2.0
func (*Context) NewEarlyBind ¶ added in v0.2.0
Will attempt to immediately require the id and export the result, storing the result in an EarlyBind.
func (*Context) NewLateBind ¶ added in v0.2.0
Will resolve the id and store the URL and exportName in a LateBind. Only when LateBind.Unbind is called will require the URL and export the result (and cache the return values).
func (*Context) NewRequire ¶ added in v0.2.4
func (*Context) RequireAndExport ¶ added in v0.2.0
func (*Context) ResolveAndRequire ¶ added in v0.2.4
func (*Context) ResolveAndWatch ¶ added in v0.2.0
type CreateExtensionFunc ¶
Can return a goja.Value, nil, or other values, which will be converted to a goja.Value.
type CreateResolverFunc ¶
type CreateResolverFunc func(fromUrl exturl.URL, jsContext *Context) ResolveFunc
type Environment ¶
type Environment struct { Runtime *goja.Runtime URLContext *exturl.Context BasePaths []exturl.URL Extensions []Extension Modules *goja.Object Precompile PrecompileFunc CreateResolver CreateResolverFunc OnFileModified OnFileModifiedFunc Timeout time.Duration Strict bool Log commonlog.Logger Lock sync.Mutex // contains filtered or unexported fields }
func NewEnvironment ¶
func NewEnvironment(urlContext *exturl.Context, basePaths ...exturl.URL) *Environment
func (*Environment) ClearCache ¶
func (self *Environment) ClearCache()
func (*Environment) GetAndCall ¶ added in v0.1.10
func (*Environment) NewChild ¶
func (self *Environment) NewChild() *Environment
func (*Environment) NewContext ¶
func (*Environment) NewModule ¶
func (self *Environment) NewModule() *Module
func (*Environment) NewTimeoutContext ¶ added in v0.2.0
func (self *Environment) NewTimeoutContext() (contextpkg.Context, contextpkg.CancelFunc)
func (*Environment) Release ¶
func (self *Environment) Release() error
func (*Environment) RequireURL ¶
func (*Environment) StartWatcher ¶ added in v0.1.10
func (self *Environment) StartWatcher() error
func (*Environment) StopWatcher ¶
func (self *Environment) StopWatcher() error
func (*Environment) Watch ¶
func (self *Environment) Watch(path string) error
type ExportedJavaScriptFunc ¶ added in v0.2.3
type ExportedJavaScriptFunc = func(functionCall goja.FunctionCall) goja.Value
This is the returned type when calling Export() on a goja.FunctionCall.
type Extension ¶
type Extension struct { Name string Create CreateExtensionFunc }
func NewExtensions ¶ added in v0.2.0
func NewExtensions(extensions map[string]CreateExtensionFunc) []Extension
type JavaScriptConstructorFunc ¶ added in v0.2.0
type JavaScriptConstructorFunc = func(constructor goja.ConstructorCall) *goja.Object
func NewConstructor ¶ added in v0.2.0
func NewConstructor(runtime *goja.Runtime, f func(constructor goja.ConstructorCall) (any, error)) JavaScriptConstructorFunc
type OnFileModifiedFunc ¶ added in v0.1.10
type PrecompileFunc ¶
type ResolveFunc ¶
type ThreadSafeObject ¶
type ThreadSafeObject struct {
// contains filtered or unexported fields
}
func NewThreadSafeObject ¶
func NewThreadSafeObject() *ThreadSafeObject
func (*ThreadSafeObject) Delete ¶
func (self *ThreadSafeObject) Delete(key string) bool
(goja.DynamicObject interface)
func (*ThreadSafeObject) Get ¶
func (self *ThreadSafeObject) Get(key string) goja.Value
(goja.DynamicObject interface)
func (*ThreadSafeObject) Has ¶
func (self *ThreadSafeObject) Has(key string) bool
(goja.DynamicObject interface)
func (*ThreadSafeObject) Keys ¶
func (self *ThreadSafeObject) Keys() []string
(goja.DynamicObject interface)
func (*ThreadSafeObject) NewDynamicObject ¶
func (self *ThreadSafeObject) NewDynamicObject(runtime *goja.Runtime) *goja.Object
func (*ThreadSafeObject) Set ¶
func (self *ThreadSafeObject) Set(key string, value goja.Value) bool
(goja.DynamicObject interface)