JsScript class final
安装到每个新建 runtime 的启动/引导 JavaScript 脚本描述。
宿主脚本在内置 console 与显式宿主能力安装之后执行;runtime 在 restart()
后重建时也会重新执行。适用于注入可选全局对象或 polyfill,例如 crypto、
Buffer、location 或应用自定义对象。
Constructors
-
JsScript({required String name, required String? source, List<
String> globals = const <String>[]}) -
使用内联 JavaScript 源码创建宿主脚本。
const
-
JsScript.asset({required String name, required String? path, AssetBundle? bundle, List<
String> globals = const <String>[]}) -
使用 Flutter asset 创建宿主脚本描述(同步构造)。
const
-
JsScript.methodGlobals({required String name, required Map<
String, String> globals}) -
Creates a startup script that exposes persistent host methods as globals.
factory
Properties
- bundle → AssetBundle?
-
解析 path 时使用的 asset bundle。
final
-
globals
→ List<
String> -
本脚本安装到
globalThis的全局变量名列表。final - hashCode → int
-
The hash code for this object.
no setterinherited
- name → String
-
QuickJS 堆栈中使用的脚本 source 名称。
final
- path → String?
-
包含 JavaScript 源码的 Flutter asset 路径。
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- source → String?
-
内联 JavaScript 源码;与 path 二选一。
final
Methods
-
loadSource(
) → Future< String> - 加载脚本源码:优先返回内联 source,否则从 path 读取 asset。
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited