详谈鸿蒙系统的方舟JS运行时组件

风在云颠
发布于 2021-9-14 18:01
浏览
0收藏

简介

**方舟JS运行时(ARK JavaScript Runtime)**是OpenHarmony上JS应用使用的运行时。包含JS对象的分配器以及垃圾回收器(GC)、符合ECMAScript规范的标准库、用于运行ARK前端组件生成的方舟字节码(ARK Bytecode,abc)的解释器、用于存储隐藏类的内联缓存、方舟JS运行时对外的函数接口(AFFI)等模块。

方舟JS运行时组件架构图:

详谈鸿蒙系统的方舟JS运行时组件-鸿蒙开发者社区

目录

/ark/js_runtime
├─ ecmascript             # 方舟JS运行时实现,包括ECMAScript标准库、解释器、内存管理等
│   ├─ base               # 基础帮助类
│   ├─ builtins           # ECMAScript标准库
│   ├─ class_linker       # 字节码预处理模块
│   ├─ compiler           # JS编译器
│   ├─ hprof              # 内存分析工具
│   ├─ ic                 # 内联缓存模块
│   ├─ interpreter        # JS解释器
│   ├─ jobs               # 微任务队列
│   ├─ js_vm              # 命令行工具
│   ├─ mem                # 内存管理模块
│   ├─ napi               # C++接口模块
│   ├─ regexp             # 正则引擎模块
│   ├─ snapshot           # 快照模块
│   ├─ tests              # 单元测试用例
│   ├─ thread             # 线程池
│   ├─ tooling            # JS调试器
│   └─ vmstat             # 运行时profiling工具
└─ test                   # 模块测试用例

约束

  • 仅支持运行方舟JS前端工具链(ts2abc)生成的方舟字节码文件
  • 只支持ES2015标准和严格模式(use strict)
  • 不支持通过字符串动态创建函数(比如new Function(“console.log(1);”))

编译构建

./build.sh --product-name Hi3516DV300 --build-target ark_js_runtime

接口说明

NAPI接口说明参考NAPI组件

使用说明

JS生成字节码参考工具链使用

字节码执行

cd out/release

LD_LIBRARY_PATH=clang_x64/ark/ark:clang_x64/global/i18n:…/…/prebuilts/clang/ohos/linux-x86_64/llvm/lib/ ./clang_x64/ark/ark_js_runtime/ark_js_vm helloworld.abc _GLOBAL::func_main_0

相关仓

方舟运行时子系统

ark/runtime_core

ark/js_runtime

ark/ts2abc

ark_js_runtime-master.zip 1.37M 19次下载
已于2021-9-14 18:01:50修改
收藏
回复
举报
回复
    相关推荐