gojaengine

package
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 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

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) 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) Load added in v0.1.11

func (e *Engine) Load(scripts []*jsexecutor.JsScript) error

Load loads scripts on the engine's event loop.

type EngineOption

type EngineOption struct {
	MaxCallStackSize int
	EnableConsole    bool
	EnableRequire    bool
	FieldNameMapper  goja.FieldNameMapper
}

EngineOption holds configuration for a Goja engine instance.

Jump to

Keyboard shortcuts

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