Documentation
¶
Index ¶
- func NewFactory(options ...Option) jsexecutor.JsEngineFactory
- type Engine
- type EngineOption
- type Option
- func WithCanBlock(canBlock bool) Option
- func WithEnableModuleImport(enable bool) Option
- func WithGCThreshold(threshold int64) Option
- func WithMaxStackSize(size uint64) Option
- func WithMemoryLimit(limit uint64) Option
- func WithRpcScript(script string) Option
- func WithStrip(strip int) Option
- func WithTimeout(timeout uint64) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewFactory ¶
func NewFactory(options ...Option) jsexecutor.JsEngineFactory
NewFactory returns a JsEngineFactory that creates QuickJS engines with the given options.
Types ¶
type Engine ¶
type Engine struct { Runtime *quickjs.Runtime // QuickJS runtime instance Ctx *quickjs.Context // QuickJS context instance Option *EngineOption // Engine configuration options RpcScript string // Embedded RPC script for executing requests }
Engine represents a QuickJS engine instance with its runtime, context, and options.
func (*Engine) Close ¶
Close releases all resources associated with the engine, including context and runtime.
func (*Engine) Execute ¶
func (e *Engine) Execute(req *jsexecutor.JsRequest) (*jsexecutor.JsResponse, error)
Execute runs a JavaScript request using the embedded RPC script as the entry point. The request is marshaled to JS, passed to the RPC function, and the response is unmarshaled back to Go.
func (*Engine) Init ¶
func (e *Engine) Init(scripts []*jsexecutor.InitScript) error
Init executes the provided initialization scripts in the engine context. Each script is evaluated in order. If any script fails, an error is returned.
func (*Engine) Reload ¶
func (e *Engine) Reload(scripts []*jsexecutor.InitScript) error
Reload resets the engine context and re-initializes it with the provided scripts. The old context is closed and a new one is created.
type EngineOption ¶
type EngineOption struct { Timeout uint64 `json:"timeout"` // Script execution timeout in seconds (0 = no timeout) MemoryLimit uint64 `json:"memoryLimit"` // Memory limit in bytes (0 = no limit) GCThreshold int64 `json:"gcThreshold"` // GC threshold in bytes (-1 = disable, 0 = default) MaxStackSize uint64 `json:"maxStackSize"` // Stack size in bytes (0 = default) CanBlock bool `json:"canBlock"` // Whether the runtime can block (for async operations) EnableModuleImport bool `json:"enableModuleImport"` // Enable ES6 module import support Strip int `json:"strip"` // Strip level for bytecode compilation }
EngineOption holds configuration options for a QuickJS engine instance.
type Option ¶
Option is a function that applies a configuration to an Engine instance.
func WithCanBlock ¶
WithCanBlock enables or disables blocking operations in the runtime. Enabling this may affect performance and security.
func WithEnableModuleImport ¶
WithEnableModuleImport enables or disables ES6 module import support. Enabling this may have security implications.
func WithGCThreshold ¶
WithGCThreshold sets the garbage collection threshold for the engine. Use -1 to disable automatic GC, 0 for default, or a positive value for a custom threshold.
func WithMaxStackSize ¶
WithMaxStackSize sets the stack size for the JavaScript runtime in bytes. If size is 0, the default stack size is used.
func WithMemoryLimit ¶
WithMemoryLimit sets the memory limit for the JavaScript runtime in bytes. If limit is 0, there is no memory limit.
func WithRpcScript ¶
WithRpcScript sets the RPC script for the engine. The script must not be empty.
func WithStrip ¶
WithStrip sets the strip level for bytecode compilation. 0 = no stripping, higher values strip more debug information.
func WithTimeout ¶
WithTimeout sets the script execution timeout in seconds. If timeout is 0, there is no timeout.