QuickJsRuntime2 class

Quickjs engine for flutter.

Inheritance
Available extensions

Constructors

QuickJsRuntime2({_JsModuleHandler? moduleHandler, int stackSize = 1024 * 1024, int? timeout, int? memoryLimit = kDefaultJsMemoryLimit, _JsHostPromiseRejectionHandler? hostPromiseRejectionHandler, bool autoExecutePendingJobs = true})

Properties

autoExecutePendingJobs bool
When true (default), evaluate / evaluateJson / callFunction drain Promise microtasks via executePendingJobs after the call.
getter/setter pair
dartContext Map<String, dynamic>
getter/setter pairinherited
debugReferenceCount int
no setter
hashCode int
The hash code for this object.
no setterinherited
hasPendingJobs bool
True if QuickJS has at least one pending job (Promise reactions, etc.).
no setter
hostPromiseRejectionHandler → _JsHostPromiseRejectionHandler?
Handler function to manage js module.
final
localContext Map<String, dynamic>
getter/setter pairinherited
memoryLimit int?
Heap limit bytes (null/0 = unlimited).
final
moduleHandler → _JsModuleHandler?
Handler function to manage js module.
final
port ReceivePort
Message Port for event loop. Close it to stop dispatching event loop.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stackSize int
Max stack size for quickjs.
getter/setter pair
timeout int?
Interrupt after this many ms of wall-clock JS work (null/0 = off).
final

Methods

callFunction(Pointer<NativeType> fn, Pointer<NativeType> obj) JsEvalResult
override
close() → void
Free Runtime and Context. After dispose, the engine cannot be reopened. After close without dispose, the next evaluate recreates the engine.
compile(String script, String fileName) Uint8List
override
convertValue<T>(JsEvalResult jsValue) → T?
override
dispatch() Future<void>
Dispatch JavaScript Event loop.
dispose() → void
override
disposeChannelFunctions() → void
Removes channel registrations for this engine (call from dispose).
inherited
enableHandlePromises() → void

Available on JavascriptRuntime, provided by the HandlePromises extension

Optional no-op friendly setup for callers that still invoke this.
evaluate(String command, {String? name, int? evalFlags, String? sourceUrl}) JsEvalResult
Evaluate js script.
override
evaluateAsync(String code, {String? sourceUrl}) Future<JsEvalResult>
override
evaluateAsyncBytecode(Uint8List bytecode) Future<JsEvalResult>
override
evaluateBytecode(Uint8List bytecode) JsEvalResult
override
evaluateJson(String command, {String? sourceUrl}) → dynamic
Evaluate js script and decode the result via a single JSON.stringify round-trip instead of recursive per-element FFI marshaling.
override
evaluateJsonBatch(Iterable<String> expressions, {String? sourceUrl}) List
Evaluate multiple JavaScript expressions and decode the results through one JSON round-trip. Expressions must be JSON-serializable and are evaluated in order in the same runtime.
inherited
executePendingJob() int
override
executePendingJobs({int maxJobs = 10000}) int
Drain the QuickJS job queue until empty or maxJobs jobs run. Returns the number of jobs executed, or stops early on error (-1 job).
inherited
getEngineInstanceId() String
override
getMemoryUsage() JsMemoryUsage?
QuickJS heap usage snapshot, or null if unavailable.
override
handlePromise(JsEvalResult value, {Duration? timeout}) Future<JsEvalResult>

Available on JavascriptRuntime, provided by the HandlePromises extension

init() JavascriptRuntime
inherited
initChannelFunctions() → void
override
jsonStringify(JsEvalResult jsValue) String
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onMessage(String channelName, dynamic fn(dynamic args)) → void
inherited
reinitialize() → void
Drop native heap + channels and re-run init (console, setTimeout, bridges). Used by JsEnginePool when EngineResetMode.hard / resetOnRelease: true.
override
releaseHostCaches() → void
Free Dart-side JS refs that must not outlive close; call before native free.
inherited
runGC() → void
Force a QuickJS GC pass. No-op if the engine is not ready / disposed.
override
sendMessage({required String channelName, required List<String> args, String? uuid}) → void
Dart → JS message helper. Prefer not to inject untrusted strings into evaluate; use registered bridges + sendMessage from JS instead.
inherited
setInspectable(bool inspectable) → void
override
setupBridge(String channelName, void fn(dynamic args)) bool
override
softReset() → void
Wipe tenant state while keeping the same native engine and instance id. Used by JsEnginePool with EngineResetMode.soft.
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited