Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewFactory ¶
func NewFactory(opts ...Option) jsexecutor.JsEngineFactory
NewFactory returns a jsexecutor.JsEngineFactory for creating Goja engines. The factory is configured with the provided options.
Types ¶
type Engine ¶
type Engine struct {
Loop *eventloop.EventLoop // The event loop that owns and serializes access to the runtime.
Option *EngineOption // Engine configuration options.
// contains filtered or unexported fields
}
Engine implements the jsexecutor.JsEngine interface using the Goja JS engine. It uses an event loop to ensure thread-safe execution of JavaScript.
func (*Engine) Execute ¶
func (e *Engine) Execute(req *jsexecutor.JsRequest) (*jsexecutor.JsResponse, error)
Execute runs a JavaScript request and returns the response. It schedules the execution on the event loop and handles async results.
func (*Engine) Init ¶
func (e *Engine) Init(scripts []*jsexecutor.InitScript) error
Init runs initialization scripts on the engine's event loop.
func (*Engine) Reload ¶
func (e *Engine) Reload(scripts []*jsexecutor.InitScript) error
Reload creates a new event loop and re-initializes the engine. This is a "hard" reload, replacing the entire JS environment.
type EngineOption ¶
type EngineOption struct {
MaxCallStackSize int
EnableConsole bool
EnableRequire bool
FieldNameMapper goja.FieldNameMapper
}
EngineOption holds configuration for a Goja engine instance.
type Option ¶
Option is a function that applies a configuration to an Engine instance.
func WithEnableConsole ¶
func WithEnableConsole() Option
WithEnableConsole enables the console object (console.log, etc.) in the JS runtime.
func WithFieldNameMapper ¶
func WithFieldNameMapper(mapper goja.FieldNameMapper) Option
WithFieldNameMapper sets the field name mapper for Go-to-JS struct conversions. This controls how Go struct field names are exposed in JavaScript.
func WithMaxCallStackSize ¶
WithMaxCallStackSize sets the maximum call stack size for the runtime. A value of 0 or less means no limit.
func WithRequire ¶
func WithRequire() Option
WithRequire enables the require() function for loading CommonJS modules.