Imported from eclipse-oniro-mirrors/arkcompiler_runtime_core (
static_core/plugins/ets/stdlib/AGENTS.md). Install upstream withnpx skills add eclipse-oniro-mirrors/arkcompiler_runtime_core --skill stdlib. Copyright stays with the author.
ETS Standard Library Guide
Project Overview
This directory contains the ArkTS-Sta standard library within ArkCompiler Runtime Core, located at static_core/plugins/ets/stdlib/.
Directory Routing
| Directory | Responsibility | Implicit Import | Special Constraints |
|---|---|---|---|
std/core/ |
Core types: Array, String, Promise, Error, TypedArrays, Functions, Global, primitive wrappers, reflection, JsonElement | Yes | Most native/intrinsic-dense area |
std/concurrency/ |
Concurrency primitives: taskpool, workers, AsyncLock, Atomics, SyncPrimitives | Yes | Concurrency primitives involve lock semantics, task scheduling, and memory ordering — high-risk area |
std/containers/ |
Data structures: HashMap, TreeMap (AVL tree), TreeSet, HashSet, Queue, LinkedList | Yes | TreeMap/TreeSet are generated from Jinja2 templates for generics |
std/interop/ |
JS-ETS interoperability: JSValue, JSRuntime, serialization, Promise interop | Yes | InteropTransferHelper is generated from templates (see code_generation.md) |
std/testing/ |
ArkTest unit testing framework | Yes | |
std/debug/ |
Debugging tools, logging | Yes | |
std/math/consts/ |
Mathematical constants | No | Requires explicit import |
arkruntime/ |
ArkRuntime API | No | Requires explicit import |
native/core/ |
C++ native implementations: Intl (ICU4C), RegExp (PCRE2), Process | N/A | Connected to ETS layer via ANI |
Module configuration: stdconfig.json (defines the "std" to "ets/stdlib/std" path mapping)
Build and Verification
For build commands, test framework usage, and urunner invocation, see docs/knowledge/build_and_test.md. Build commands are executed from static_core/ (i.e., ../../../), not from this subdirectory.
Verification by Task Type
| Task Type | Verification Method |
|---|---|
| Modifying Intl behavior | Build, then run ets_func_tests with --filter "**/intl/**" |
| Modifying RegExp behavior | Build, then run ets_func_tests with --filter "**/regexp/**" |
| Modifying Map/Set behavior | Build, then run ets_func_tests with --filter "**/*Map*" and --filter "**/*Set*" |
| Modifying JsonElement/Json behavior | Build, then run ets_func_tests with --filter "**/json/**" and --filter "**/Json*" |
| Modifying Proxy behavior | Build, then run ets_func_tests with --filter "**/Proxy*" |
| Modifying Reflect behavior | Build, then run ets_func_tests with --filter "**/Reflect*" |
| Adding/modifying mirror class fields | Build, then run corresponding offset tests in static_core/plugins/ets/tests/runtime/types/ |
Completion Criteria
A task is considered complete when:
- The behavior has been implemented
- Relevant builds and tests have passed, or reasons for inability to verify have been documented
- Test cases in the ignore list are allowed to fail if they have known issues
- The final response includes: list of changed files, verification commands and results, and remaining risks
For behaviors involving real hardware, devices, display, or service integration, board-side evidence must be provided.
Knowledge Routing
Before making changes, locate the relevant code paths by scenario and read the corresponding knowledge documents. Before making changes, you must declare in your response: the task category, the knowledge documents you have read, and the constraints extracted from them.
| Scenario | Code Path | Read First |
|---|---|---|
| Types, primitives, boxed types, int/Int, type conversion | std/core/ |
docs/knowledge/type_system.md |
| Templates, Jinja2, codegen, autogenerated, genlib | Generated files in std/containers/, std/interop/ |
docs/knowledge/code_generation.md |
| Build, CMake, GN, testing, urunner, ArkTest | ../../../ (build root), static_core/tests/ |
docs/knowledge/build_and_test.md |
| Performance, intrinsics, safepoint | static_core/plugins/ets/runtime/intrinsics/ |
docs/knowledge/performance.md |
| Performance, irtoc, managed-first | static_core/irtoc/, static_core/plugins/ets/irtoc_scripts/ |
docs/knowledge/performance.md |
| Regex, RegExp, PCRE2, matching, replace, split | native/core/regexp/, std/core/RegExp.ets |
docs/knowledge/regexp.md |
| Internationalization, Intl, ICU4C, Locale, NumberFormat, DateTimeFormat, Collator | native/core/intl/, std/core/ |
docs/knowledge/intl.md |
| Proxy, ReflectProxy, InvocationHandler, dynamic proxy, assembly bridge | std/core/ReflectProxy.ets |
docs/knowledge/proxy.md |
| Map, Set, Record, hash table, double array, tombstone, resizing | std/core/Map.ets, std/core/Set.ets |
docs/knowledge/map_set_record.md |
| Reflection, Class, Method, Field, Constructor | std/core/Reflect*.ets |
docs/knowledge/reflection.md |
| Deep copy, DeepCloner, Cloneable, circular references, deep cloning | escompat/deepcopy.ets |
docs/knowledge/deepcopy.md |
| JsonElement, JsonType, jsonx, JSON deserialization, BigIntMode | std/core/Jsonx.ets, std/core/json.ets |
docs/knowledge/json_element.md |
Project Constraints
Architectural Invariants
- With the exception of
arkruntime/andstd/math/consts/, allstd/directories are implicitly imported. The frontend compiler automatically inserts import directives, allowing user code to use them directly — do not change implicitly imported modules to explicit imports or vice versa - Native calls involving third-party C libraries (PCRE2, ICU4C, etc.) must go through ANI bindings to
native/core/— third-party library execution times are unpredictable and their source code cannot be modified, so they cannot use intrinsics - High-frequency hot-path native calls use intrinsics (YAML bindings), but the intrinsic execution time must be reasonable — see
docs/knowledge/performance.mdfor rationale - The declaration order of fields in an ETS class does not necessarily match the actual memory layout of the corresponding native mirror class (
EtsType*) — the frontend compiler and runtime reorder and align fields for layout optimization. When adding or modifying mirror class fields, you must verify the field offsets match between the managed class and the C++ mirror class via offset tests. Reference:static_core/plugins/ets/tests/runtime/types/contains mirror class offset self-tests (e.g.,ets_map_test.cpp— seeMapMemoryLayouttest usingMirrorFieldInfo::CompareMemberOffsets)
Do Not
- All
.etsfiles must include the Apache 2.0 license header (year2021-2026). Shell scripts use the#prefix - Do not directly edit files that begin with
// NOTE: autogenerated file— you must modify the corresponding template instead (seedocs/knowledge/code_generation.md) - Do not
returnfrom afinallyblock - Do not return a constant from
main()— you must returnmyTestsuite.run() - Do not unconditionally promote frequently called APIs to C++ intrinsics or irtoc implementations (see
docs/knowledge/performance.md) - After modifying
.etsfiles, you must rebuild before running tests - Template changes and generated files must be committed together
- Do not add or modify mirror class fields without adding/updating corresponding field offset tests — see Architectural Invariants above; reference tests are in
static_core/plugins/ets/tests/runtime/types/(e.g.,ets_map_test.cppMapMemoryLayoutusingMirrorFieldInfo::CompareMemberOffsets)
Ask Before
- Modifying the public API signatures or semantics of implicitly imported modules (std/core, std/containers, etc.) — this affects all ArkTS users and downstream impact cannot be fully assessed
- Deleting or renaming exported APIs — these may be compile-time dependencies for other modules or external code
- Adding or modifying intrinsic registrations (
ets_compiler_intrinsics.yaml, etc.) — this affects safepoint/GC behavior and requires performance evaluation - Adding third-party library dependencies — not all third-party libraries are approved for use; license, security, and size impact must be reviewed