Documentation
¶
Index ¶
- func NewFactory(options ...jsexecutor.JsEngineOption) jsexecutor.JsEngineFactory
- func WithCanBlock(canBlock bool) jsexecutor.JsEngineOption
- func WithEnableModuleImport(enable bool) jsexecutor.JsEngineOption
- func WithGCThreshold(threshold int64) jsexecutor.JsEngineOption
- func WithMaxStackSize(size uint64) jsexecutor.JsEngineOption
- func WithMemoryLimit(limit uint64) jsexecutor.JsEngineOption
- func WithRpcScript(script string) jsexecutor.JsEngineOption
- func WithStrip(strip int) jsexecutor.JsEngineOption
- func WithTimeout(timeout uint64) jsexecutor.JsEngineOption
- type Engine
- type EngineOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewFactory ¶
func NewFactory(options ...jsexecutor.JsEngineOption) jsexecutor.JsEngineFactory
NewFactory returns a JsEngineFactory that creates QuickJS engines with the given options.
func WithCanBlock ¶
func WithCanBlock(canBlock bool) jsexecutor.JsEngineOption
WithCanBlock enables or disables blocking operations in the runtime. Enabling this may affect performance and security.
func WithEnableModuleImport ¶
func WithEnableModuleImport(enable bool) jsexecutor.JsEngineOption
WithEnableModuleImport enables or disables ES6 module import support. Enabling this may have security implications.
func WithGCThreshold ¶
func WithGCThreshold(threshold int64) jsexecutor.JsEngineOption
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 ¶
func WithMaxStackSize(size uint64) jsexecutor.JsEngineOption
WithMaxStackSize sets the stack size for the JavaScript runtime in bytes. If size is 0, the default stack size is used.
func WithMemoryLimit ¶
func WithMemoryLimit(limit uint64) jsexecutor.JsEngineOption
WithMemoryLimit sets the memory limit for the JavaScript runtime in bytes. If limit is 0, there is no memory limit.
func WithRpcScript ¶
func WithRpcScript(script string) jsexecutor.JsEngineOption
WithRpcScript sets the RPC script for the engine. The script must not be empty.
func WithStrip ¶
func WithStrip(strip int) jsexecutor.JsEngineOption
WithStrip sets the strip level for bytecode compilation. 0 = no stripping, higher values strip more debug information.
func WithTimeout ¶
func WithTimeout(timeout uint64) jsexecutor.JsEngineOption
WithTimeout sets the script execution timeout in seconds. If timeout is 0, there is no timeout.
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 // contains filtered or unexported fields }
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.
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.