2022-07-08 06:04:42 +00:00
# ArkCompiler JS Runtime
2021-09-01 06:28:24 +00:00
2022-07-08 06:04:42 +00:00
### Introduction
2021-09-01 06:28:24 +00:00
2022-07-08 06:04:42 +00:00
ArkCompiler JS Runtime is the default JS runtime on OpenHarmony. It supports ECMAScript libraries and efficient container libraries. It also provides a set of native APIs for C++ and JS interaction and a variety of garbage collectors that features high performance.
2021-09-01 06:28:24 +00:00
2022-07-08 06:04:42 +00:00
For more information, see [ArkCompiler JS Runtime ](https://gitee.com/openharmony/docs/blob/master/en/readme/ARK-Runtime-Subsystem.md ).
2021-09-01 06:28:24 +00:00
2022-07-08 06:04:42 +00:00
**ArkCompiler JS Runtime architecture**
2021-09-11 09:29:08 +00:00
2022-07-08 06:04:42 +00:00
![](/docs/figures/en-us_image_ark-js-arch.png)
2021-09-01 06:28:24 +00:00
2022-07-08 06:04:42 +00:00
## Directory Structure
2021-09-01 06:28:24 +00:00
2021-09-04 08:06:49 +00:00
```
2022-07-12 03:01:25 +00:00
/arkcompiler/ets_runtime
2022-07-08 06:04:42 +00:00
├─ ecmascript # Implementation of ArkCompiler JS Runtime, including the ECMAScript library, interpreter, and memory management
2021-09-04 08:06:49 +00:00
│ ├─ base # Base helper class
2022-07-08 06:04:42 +00:00
│ ├─ builtins # ECMAScript libraries
2021-09-04 08:06:49 +00:00
│ ├─ compiler # JS compiler
2022-07-08 06:04:42 +00:00
│ ├─ containers # Non-ECMAScript containers
│ ├─ dfx # Memory and profiling tool
2021-09-04 08:06:49 +00:00
│ ├─ ic # Inline cache module
│ ├─ interpreter # JS interpreter
│ ├─ jobs # Queue of jobs
2022-07-08 06:04:42 +00:00
│ ├─ js_vm # Command line tool
│ ├─ jspandafile # abc file management module
2021-09-04 08:06:49 +00:00
│ ├─ mem # Memory management module
2022-07-08 06:04:42 +00:00
│ ├─ module # ECMAScript module
│ ├─ napi # C++ API module
│ ├─ taskpool # Task pool
2021-09-04 08:06:49 +00:00
│ ├─ regexp # Regular expression engine module
2022-07-08 06:04:42 +00:00
│ ├─ snapshot # Snapshot module
│ ├─ stubs # Runtime stub functions
2021-09-04 08:06:49 +00:00
│ ├─ tests # Unit test cases
2022-09-20 11:25:15 +00:00
│ ├─ debugger # JS debugger
2022-07-08 06:04:42 +00:00
│ ├─ trampoline # Trampoline function
│ ├─ ts_type # TS type management module
└─ test # Module test cases
2021-09-04 08:06:49 +00:00
```
2021-09-01 06:28:24 +00:00
2022-07-08 06:04:42 +00:00
## Constraints
2021-09-01 06:28:24 +00:00
2022-07-08 06:04:42 +00:00
* Only the ArkCompiler bytecode files generated by ts2abc, which is the ArkCompiler JS frontend toolchain, can be run.
2022-11-09 09:56:50 +00:00
* Only the ES2021 standard and strict modes are supported.
2022-07-08 06:04:42 +00:00
* Functions cannot be dynamically created using strings, such as new Function("console.log(1);")).
2021-09-01 06:28:24 +00:00
2022-07-08 06:04:42 +00:00
## Building
2021-09-04 08:06:49 +00:00
2021-09-11 09:29:08 +00:00
```
2022-07-08 06:04:42 +00:00
$./build.sh --product-name hispark_taurus_standard --build-target ark_js_host_linux_tools_packages
2021-09-11 09:29:08 +00:00
```
2021-09-04 08:06:49 +00:00
2022-07-08 06:04:42 +00:00
### Available APIs
2021-09-04 08:06:49 +00:00
2023-05-09 07:05:35 +00:00
See [NAPI ](https://gitee.com/openharmony/arkui_napi/blob/master/README.md ).
2021-09-04 08:06:49 +00:00
2022-07-08 06:04:42 +00:00
### Usage
2021-09-04 08:06:49 +00:00
2022-07-08 06:04:42 +00:00
For details about how to generate JS bytecodes, see [Using the Toolchain ](docs/using-the-toolchain.md ).
2021-09-04 08:06:49 +00:00
To run bytecodes:
2021-09-11 09:29:08 +00:00
```
2022-10-13 08:09:55 +00:00
LD_LIBRARY_PATH=out/hispark_taurus/clang_x64/arkcompiler/ets_runtime:out/hispark_taurus/clang_x64/thirdparty/icu:prebuilts/clang/ohos/linux-x86_64/llvm/lib ./out/hispark_taurus/clang_x64/arkcompiler/ets_runtime/ark_js_vm helloworld.abc
2022-07-08 06:04:42 +00:00
2021-09-11 09:29:08 +00:00
```
2021-09-04 08:06:49 +00:00
2022-07-12 03:01:25 +00:00
For more information, see [ARK Runtime Usage Guide](https://gitee.com/openharmony/arkcompiler_ets_runtime/blob/master/
docs/ARK-Runtime-Usage-Guide.md).
2021-09-04 08:06:49 +00:00
2022-07-08 06:04:42 +00:00
## Repositories Involved
2021-09-04 08:06:49 +00:00
2022-07-12 03:01:25 +00:00
[arkcompiler\_runtime\_core ](https://gitee.com/openharmony/arkcompiler_runtime_core )
2021-09-04 08:06:49 +00:00
2022-07-12 03:01:25 +00:00
**[arkcompiler\_ets\_runtime](https://gitee.com/openharmony/arkcompiler_ets_runtime)**
2021-09-01 06:28:24 +00:00
2022-07-12 03:01:25 +00:00
[arkcompiler\_ets\_frontend ](https://gitee.com/openharmony/arkcompiler_ets_frontend )