Documentation
¶
Index ¶
- func NewFactory(opts ...jsexecutor.JsEngineOption) jsexecutor.JsEngineFactory
- func WithEnableConsole() jsexecutor.JsEngineOption
- func WithFieldNameMapper(mapper goja.FieldNameMapper) jsexecutor.JsEngineOption
- func WithMaxCallStackSize(size int) jsexecutor.JsEngineOption
- func WithRequire() jsexecutor.JsEngineOption
- type Engine
- type EngineOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewFactory ¶
func NewFactory(opts ...jsexecutor.JsEngineOption) jsexecutor.JsEngineFactory
NewFactory returns a jsexecutor.JsEngineFactory for creating Goja engines. The factory is configured with the provided options.
func WithEnableConsole ¶
func WithEnableConsole() jsexecutor.JsEngineOption
WithEnableConsole enables the console object (console.log, etc.) in the JS runtime.
func WithFieldNameMapper ¶
func WithFieldNameMapper(mapper goja.FieldNameMapper) jsexecutor.JsEngineOption
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 ¶
func WithMaxCallStackSize(size int) jsexecutor.JsEngineOption
WithMaxCallStackSize sets the maximum call stack size for the runtime. A value of 0 or less means no limit.
func WithRequire ¶
func WithRequire() jsexecutor.JsEngineOption
WithRequire enables the require() function for loading CommonJS modules.
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.
type EngineOption ¶
type EngineOption struct {
MaxCallStackSize int
EnableConsole bool
EnableRequire bool
FieldNameMapper goja.FieldNameMapper
}
EngineOption holds configuration for a Goja engine instance.