• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ArkTs使用JSVM-API接口进行primitive类相关开发
2
3### 介绍
4
5在使用JSVM-API接口时,开发人员可以实现在JSVM模块中与JavaScript对象的交互,并进行数据转换和获取特定对象的操作,它们在不同的场景中发挥着重要的作用,使开发人员能够更灵活地处理JavaScript值和对象。
6
7该工程中展示的代码详细描述可查如下链接:
8
9- [使用JSVM-API接口进行primitive类相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-primitive.md)
10
11### 效果预览
12
13|                                  首页                                  |                           执行及结果即时反馈                           |
14| :--------------------------------------------------------------------: | :--------------------------------------------------------------------: |
15| <img src="./screenshots/JsvmAboutPrimitive_1.png" style="zoom:33%;" /> | <img src="./screenshots/JsvmAboutPrimitive_2.png" style="zoom:33%;" /> |
16
17### 使用说明
18
191. 在主界面,可以点击Hello World,开始执行。
202. 执行结果会即时反馈在屏幕中央,并在控制台打印log。
21
22### 工程目录
23
24```
25coercetobool/src/
26 ├── main
27 │   ├── cpp
28 │   │   ├── types
29 │   │   │   ├── libentry
30 │   │   │   │   ├── Index.d.ts          // 提供JS侧的接口方法
31 │   │   │   │   ├── oh-package.json5 	 // 将index.d.ts与cpp文件关联
32 │   │   ├── CMakeLists.txt              // 配置CMake打包参数
33 │   │   ├── hello.cpp                   // 实现Native侧的runTest接口
34 │   ├── ets
35 │   │   ├── entryability
36 │   │   ├── entrybackupability
37 │   │   ├── pages
38 │   │       ├── Index.ets               // ArkTS侧调用C/C++方法实现
39 │   ├── module.json5
40 │   └── resources
41 ├── ohosTest
42 │   ├── ets
43 │   │   ├── test
44 │   │       ├── Ability.test.ets        // 自动化测试代码
45coercetonumber/src/
46 ├── main
47 │   ├── cpp
48 │   │   ├── types
49 │   │   │   ├── libcoercetonumber
50 │   │   │   │   ├── Index.d.ts          // 提供JS侧的接口方法
51 │   │   │   │   ├── oh-package.json5 	 // 将index.d.ts与cpp文件关联
52 │   │   ├── CMakeLists.txt              // 配置CMake打包参数
53 │   │   ├── hello.cpp                   // 实现Native侧的runTest接口
54 │   ├── ets
55 │   │   ├── coercetonumberability
56 │   │   ├── pages
57 │   │       ├── Index.ets               // ArkTS侧调用C/C++方法实现
58 │   ├── module.json5
59 │   └── resources
60 ├── ohosTest
61 │   ├── ets
62 │   │   ├── test
63 │   │       ├── Ability.test.ets        // 自动化测试代码
64coercetoobject/src/
65 ├── main
66 │   ├── cpp
67 │   │   ├── types
68 │   │   │   ├── libcoercetoobject
69 │   │   │   │   ├── Index.d.ts          // 提供JS侧的接口方法
70 │   │   │   │   ├── oh-package.json5 	 // 将index.d.ts与cpp文件关
71 │   │   ├── CMakeLists.txt              // 配置CMake打包参数
72 │   │   ├── hello.cpp                   // 实现Native侧的runTest接
73 │   ├── ets
74 │   │   ├── coercetoobjectability
75 │   │   ├── pages
76 │   │       ├── Index.ets               // ArkTS侧调用C/C++方法实现
77 │   ├── module.json5
78 │   └── resources
79 ├── ohosTest
80 │   ├── ets
81 │   │   ├── test
82 │   │       ├── Ability.test.ets        // 自动化测试代码
83coercetostring/src/
84 ├── main
85 │   ├── cpp
86 │   │   ├── types
87 │   │   │   ├── libcoercetostring
88 │   │   │   │   ├── Index.d.ts          // 提供JS侧的接口方法
89 │   │   │   │   ├── oh-package.json5 	 // 将index.d.ts与cpp文件关
90 │   │   ├── CMakeLists.txt              // 配置CMake打包参数
91 │   │   ├── hello.cpp                   // 实现Native侧的runTest接
92 │   ├── ets
93 │   │   ├── coercetostringability
94 │   │   ├── pages
95 │   │       ├── Index.ets               // ArkTS侧调用C/C++方法实现
96 │   ├── module.json5
97 │   └── resources
98 ├── ohosTest
99 │   ├── ets
100 │   │   ├── test
101 │   │       ├── Ability.test.ets        // 自动化测试代码
102getboolean/src/
103 ├── main
104 │   ├── cpp
105 │   │   ├── types
106 │   │   │   ├── libgetboolean
107 │   │   │   │   ├── Index.d.ts          // 提供JS侧的接口方法
108 │   │   │   │   ├── oh-package.json5 	 // 将index.d.ts与cpp文件关
109 │   │   ├── CMakeLists.txt              // 配置CMake打包参数
110 │   │   ├── hello.cpp                   // 实现Native侧的runTest接
111 │   ├── ets
112 │   │   ├── getbooleanability
113 │   │   ├── pages
114 │   │       ├── Index.ets               // ArkTS侧调用C/C++方法实现
115 │   ├── module.json5
116 │   └── resources
117 ├── ohosTest
118 │   ├── ets
119 │   │   ├── test
120 │   │       ├── Ability.test.ets        // 自动化测试代码
121getglobal/src/
122 ├── main
123 │   ├── cpp
124 │   │   ├── types
125 │   │   │   ├── libgetglobal
126 │   │   │   │   ├── Index.d.ts          // 提供JS侧的接口方法
127 │   │   │   │   ├── oh-package.json5 	 // 将index.d.ts与cpp文件关
128 │   │   ├── CMakeLists.txt              // 配置CMake打包参数
129 │   │   ├── hello.cpp                   // 实现Native侧的runTest接
130 │   ├── ets
131 │   │   ├── getglobalability
132 │   │   ├── pages
133 │   │       ├── Index.ets               // ArkTS侧调用C/C++方法实现
134 │   ├── module.json5
135 │   └── resources
136 ├── ohosTest
137 │   ├── ets
138 │   │   ├── test
139 │   │       ├── Ability.test.ets        // 自动化测试代码
140getnull/src/
141 ├── main
142 │   ├── cpp
143 │   │   ├── types
144 │   │   │   ├── libgetnull
145 │   │   │   │   ├── Index.d.ts          // 提供JS侧的接口方法
146 │   │   │   │   ├── oh-package.json5 	 // 将index.d.ts与cpp文件关
147 │   │   ├── CMakeLists.txt              // 配置CMake打包参数
148 │   │   ├── hello.cpp                   // 实现Native侧的runTest接
149 │   ├── ets
150 │   │   ├── getnullability
151 │   │   ├── pages
152 │   │       ├── Index.ets               // ArkTS侧调用C/C++方法实现
153 │   ├── module.json5
154 │   └── resources
155 ├── ohosTest
156 │   ├── ets
157 │   │   ├── test
158 │   │       ├── Ability.test.ets        // 自动化测试代码
159getundefined/src/
160 ├── main
161 │   ├── cpp
162 │   │   ├── types
163 │   │   │   ├── libgetundefined
164 │   │   │   │   ├── Index.d.ts          // 提供JS侧的接口方法
165 │   │   │   │   ├── oh-package.json5 	 // 将index.d.ts与cpp文件关
166 │   │   ├── CMakeLists.txt              // 配置CMake打包参数
167 │   │   ├── hello.cpp                   // 实现Native侧的runTest接
168 │   ├── ets
169 │   │   ├── getundefinedability
170 │   │   ├── pages
171 │   │       ├── Index.ets               // ArkTS侧调用C/C++方法实现
172 │   ├── module.json5
173 │   └── resources
174 ├── ohosTest
175 │   ├── ets
176 │   │   ├── test
177 │   │       ├── Ability.test.ets        // 自动化测试代码
178getvaluebool/src/
179 ├── main
180 │   ├── cpp
181 │   │   ├── types
182 │   │   │   ├── libgetvaluebool
183 │   │   │   │   ├── Index.d.ts          // 提供JS侧的接口方法
184 │   │   │   │   ├── oh-package.json5 	 // 将index.d.ts与cpp文件关
185 │   │   ├── CMakeLists.txt              // 配置CMake打包参数
186 │   │   ├── hello.cpp                   // 实现Native侧的runTest接
187 │   ├── ets
188 │   │   ├── getvalueboolability
189 │   │   ├── pages
190 │   │       ├── Index.ets               // ArkTS侧调用C/C++方法实现
191 │   ├── module.json5
192 │   └── resources
193 ├── ohosTest
194 │   ├── ets
195 │   │   ├── test
196 │   │       ├── Ability.test.ets        // 自动化测试代码
197```
198
199### 相关权限
200
201不涉及。
202
203### 依赖
204
205不涉及。
206
207### 约束与限制
208
2091.本示例仅支持标准系统上运行, 支持设备:Phone。
210
2112.本示例为Stage模型,支持API15版本SDK,版本号:5.0.3.135,镜像版本号:HarmonyOS NEXT_5.0.3.135。
212
2133.本示例需要使用DevEco Studio 5.0.3 Release (Build Version: 5.0.9.300, built on March 13, 2025)及以上版本才可编译运行。
214
215### 下载
216
217如需单独下载本工程,执行如下命令:
218
219```
220git init
221git config core.sparsecheckout true
222echo code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutPrimitive > .git/info/sparse-checkout
223git remote add origin https://gitee.com/openharmony/applications_app_samples.git
224git pull origin master
225```
226