JsEngine class

QuickJS 的公开 Dart 入口。

这个类只负责管理请求队列和 runtime 生命周期;真正的执行发生在平台 backend 里,native 侧是 Dart isolate + FFI,web 侧是 Web Worker + WASM。

Implemented types

Properties

engineVersion String
当前打包进插件的 QuickJS 版本号。
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state JsRuntimeState
当前 runtime 生命周期状态。
no setter

Methods

bindFunction(String code, {Duration? timeout, String name = '<handle>'}) Future<JsFunctionHandle>
Evaluates code and stores the resulting JavaScript function as a handle.
bindStream(String name) Future<Stream<Object?>>
Binds a JS { emit, close, error } sink and returns its Dart stream.
call(String method, List<Object?> args, {Duration? timeout}) Future<Object?>
Calls a function stored on globalThis and returns its awaited result as a structured Dart value.
callModule(String module, String method, List<Object?> args, {Duration? timeout}) Future<Object?>
Calls a function export from an ES module and converts its awaited result.
callPlugin(String method, List<Object?> args, {String? pluginId, Duration? timeout}) Future<Object?>
Calls a plugin export by method name from the plugins loaded in this runtime.
callPluginExport(JsPlugin plugin, String method, List<Object?> args, {Duration? timeout}) Future<Object?>
Calls a declared function from a plugin entry module.
override
callRaw(String method, List<Object?> args, {Duration? timeout}) Future<String>
Calls a function stored on globalThis and returns QuickJS's raw bridge string after awaiting its result.
clearSourceMaps() → void
Removes all source maps registered on this runtime wrapper.
debugEvaluateValue(String expression, {Duration? timeout, String name = '<inspector>'}) Future<Object?>
Evaluates a debug expression and converts its result to Dart values.
debugInspect({bool includeGlobals = false}) Future<JsInspectorSnapshot>
Captures a lightweight inspector snapshot.
dispose() Future<void>
释放当前实例持有的 runtime。
disposePlugin(JsPlugin plugin, {Duration? timeout}) Future<Object?>
Calls the plugin's optional dispose lifecycle export.
override
eval(String code, {Duration? timeout, String name = '<eval>', Map<String, Object?> tempGlobals = const {}}) Future<Object?>
在当前 runtime 中执行 code,并把基础 JS 值转换成 Dart 值。
evalRaw(String code, {Duration? timeout, String name = '<eval>', Map<String, Object?> tempGlobals = const {}}) Future<String>
在当前 runtime 中执行 code
initPlugin(JsPlugin plugin, {Map<String, Object?> context = const <String, Object?>{}, Duration? timeout}) Future<Object?>
Calls the plugin's optional init lifecycle export.
override
injectClass<T extends Object>(String name, JsClass<T> definition) Future<JsClassHandle>
Injects an explicit Dart class as a JavaScript constructor.
injectFunction(String name, JsCallback callback) Future<void>
Temporarily injects a Dart function on JavaScript globalThis.
injectObject<T extends Object>(String name, JsObject<T> object) Future<JsObjectHandle>
在 JS globalThis 上绑定 { emit, close, error },并返回 Dart Stream
injectStream<T>(String name, Stream<T> stream) Future<void>
Injects stream on JS globalThis as an async iterable.
loadFeatures(JsFeatures features, {JsFeaturesConflictPolicy conflictPolicy = JsFeaturesConflictPolicy.reject}) Future<void>
Loads a capability bundle and rebuilds the current runtime when required.
loadPlugin(JsPlugin plugin, {bool initialize = true, Map<String, Object?> context = const <String, Object?>{}, Duration? timeout, JsFeaturesConflictPolicy conflictPolicy = JsFeaturesConflictPolicy.reject}) Future<void>
Loads, validates and optionally initializes a plugin at runtime.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pumpTimers() Future<Duration?>
Advances the JavaScript event loop once.
registerSourceMap(String sourceName, JsSourceMap sourceMap) → void
Registers a source map for generated JavaScript sourceName.
restart() Future<void>
中止当前任务、取消等待队列并重建底层 runtime。
run(String code, {Duration? timeout, String name = '<run>', Map<String, Object?> tempGlobals = const {}}) Future<Object?>
Executes an async JavaScript function body and returns a Dart value.
runCommonJs(String source, {String name = '<commonjs>', Duration? timeout}) Future<String>
Executes a minimal CommonJS module in the current runtime.
runModule(String source, {String name = '<module>', Duration? timeout}) Future<String>
在当前 runtime 中执行 ES module source
runRaw(String code, {Duration? timeout, String name = '<run>', Map<String, Object?> tempGlobals = const {}}) Future<String>
在当前 runtime 中执行异步 JavaScript 函数体,并等待返回的 Promise。
sourceMapFor(String sourceName) JsSourceMap?
Returns the source map registered for sourceName, if any.
toString() String
A string representation of this object.
inherited
unregisterSourceMap(String sourceName) → void
Removes the source map registered for sourceName.
validatePlugin(JsPlugin plugin, {Duration? timeout}) Future<void>
Validates that a plugin entry module exposes every declared function.
override

Operators

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

Static Methods

create({JsOptions options = const JsOptions(), JsModuleLoader? moduleLoader, List<JsScript> scripts = const <JsScript>[], List<JsModule> modules = const <JsModule>[], List<JsHostMethod> methods = const <JsHostMethod>[], List<JsFeatures> features = const <JsFeatures>[], List<JsPlugin> plugins = const <JsPlugin>[], JsConsoleSink? onConsole}) Future<JsEngine>
为当前平台创建一个独立的 QuickJS runtime。