gojaengine

package
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

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) Close

func (e *Engine) Close() error

Close stops the event loop and releases associated resources.

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

type Option func(*Engine) error

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

func WithMaxCallStackSize(size int) Option

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL