• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 SwanLink (Jiangsu) Technology Development Co., LTD.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "jsvm.h"
16 #include "jsvm_types.h"
17 #include "napi_datatype_test.h"
18 const size_t NUM_SIZE_2 = 2;
TestFunction(JSVM_Env env,JSVM_CallbackInfo info)19 JSVM_Value TestFunction(JSVM_Env env, JSVM_CallbackInfo info)
20 {
21     JSVM_Value output;
22     void *data = nullptr;
23     OH_JSVM_GetCbInfo(env, info, nullptr, nullptr, nullptr, &data);
24     OH_JSVM_CreateStringUtf8(env, (char *)data, strlen((char *)data), &output);
25     return output;
26 }
27 JSVM_CallbackStruct hello_cb = {TestFunction, (void *)"Hello"};
28 int g_iFlag = 0;
29 intptr_t g_externals[] = {
30     (intptr_t)&hello_cb,
31     (intptr_t)&g_iFlag,
32 };
33 //JSVM_Status OH_JSVM_Init
TestInitTest1(JSVM_Env env,JSVM_CallbackInfo info)34 [[maybe_unused]] JSVM_Value TestInitTest1(JSVM_Env env, JSVM_CallbackInfo info)
35 {
36     size_t argc = 1;
37     JSVM_Value args[1] = {nullptr};
38     JSVM_Value thisVar = nullptr;
39     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
40 
41     JSVM_InitOptions initOpt;
42     memset_s(&initOpt, sizeof(JSVM_InitOptions), 0, sizeof(JSVM_InitOptions));
43     JSVM_Status status = OH_JSVM_Init(nullptr);
44     if (status == JSVM_OK) {
45         OH_JSVM_ThrowError(env, nullptr, "TestInitTest2: OH_JSVM_Init Failed");
46         return nullptr;
47     }
48 
49     bool result = true;
50     JSVM_Value value = nullptr;
51     OH_JSVM_GetBoolean(env, result, &value);
52     return value;
53 }
54 //CreateVM
TestCreateVMTest1(JSVM_Env env,JSVM_CallbackInfo info)55 [[maybe_unused]] JSVM_Value TestCreateVMTest1(JSVM_Env env, JSVM_CallbackInfo info)
56 {
57     size_t argc = 1;
58     JSVM_Value args[1] = {nullptr};
59     JSVM_Value thisVar = nullptr;
60     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
61     // create vm
62     JSVM_VM vm;
63     JSVM_CreateVMOptions options;
64     if (memset_s(&options, sizeof(options), 0, sizeof(options)) != EOK) {
65         OH_JSVM_ThrowError(env, nullptr, "TestCreateVMTest1: OH_JSVM_Init Failed");
66         return nullptr;
67     }
68     options.isForSnapshotting = true;
69     JSVM_Status status = OH_JSVM_CreateVM(&options, &vm);
70     if (status != JSVM_OK) {
71         OH_JSVM_ThrowError(env, nullptr, "TestCreateVMTest1: OH_JSVM_CreateVM Failed");
72         return nullptr;
73     }
74     if (vm == nullptr) {
75         OH_JSVM_ThrowError(env, nullptr, "TestCreateVMTest1: OH_JSVM_CreateVM Failed");
76         return nullptr;
77     }
78     status = OH_JSVM_DestroyVM(vm);
79     if (status != JSVM_OK) {
80         OH_JSVM_ThrowError(env, nullptr, "TestCreateVMTest1: OH_JSVM_DestroyVM Failed");
81         return nullptr;
82     }
83 
84     bool result = true;
85     JSVM_Value value = nullptr;
86     OH_JSVM_GetBoolean(env, result, &value);
87     return value;
88 }
TestCreateVMTest2(JSVM_Env env,JSVM_CallbackInfo info)89 [[maybe_unused]] JSVM_Value TestCreateVMTest2(JSVM_Env env, JSVM_CallbackInfo info)
90 {
91     size_t argc = 1;
92     JSVM_Value args[1] = {nullptr};
93     JSVM_Value thisVar = nullptr;
94     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
95     // create vm
96     JSVM_VM vm;
97     JSVM_Status status = OH_JSVM_CreateVM(nullptr, &vm);
98     if (status != JSVM_OK) {
99         OH_JSVM_ThrowError(env, nullptr, "TestCreateVMTest2: OH_JSVM_CreateVM Failed");
100         return nullptr;
101     }
102     JSVM_VMScope rstVmScope = nullptr;
103     status = OH_JSVM_OpenVMScope(vm, &rstVmScope);
104     if (status != JSVM_OK) {
105         OH_JSVM_ThrowError(env, nullptr, "TestCreateVMTest2: OH_JSVM_OpenVMScope Failed");
106         return nullptr;
107     }
108     status = OH_JSVM_CloseVMScope(vm, rstVmScope);
109     if (status != JSVM_OK) {
110         OH_JSVM_ThrowError(env, nullptr, "TestCreateVMTest2: OH_JSVM_DestroyVM Failed");
111         return nullptr;
112     }
113     status = OH_JSVM_DestroyVM(vm);
114     if (status != JSVM_OK) {
115         OH_JSVM_ThrowError(env, nullptr, "TestCreateVMTest2: OH_JSVM_DestroyVM Failed");
116         return nullptr;
117     }
118 
119     bool result = true;
120     JSVM_Value value = nullptr;
121     OH_JSVM_GetBoolean(env, result, &value);
122     return value;
123 }
124 //DestroyVM
TestDestroyVMTest1(JSVM_Env env,JSVM_CallbackInfo info)125 [[maybe_unused]] JSVM_Value TestDestroyVMTest1(JSVM_Env env, JSVM_CallbackInfo info)
126 {
127     size_t argc = 1;
128     JSVM_Value args[1] = {nullptr};
129     JSVM_Value thisVar = nullptr;
130     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
131     // create vm
132     JSVM_VM vm;
133     JSVM_CreateVMOptions options;
134     if (memset_s(&options, sizeof(options), 0, sizeof(options)) != EOK) {
135         OH_JSVM_ThrowError(env, nullptr, "TestDestroyVMTest1: OH_JSVM_Init Failed");
136         return nullptr;
137     }
138     options.isForSnapshotting = true;
139     JSVM_Status status = OH_JSVM_CreateVM(&options, &vm);
140     if (status != JSVM_OK) {
141         OH_JSVM_ThrowError(env, nullptr, "TestDestroyVMTest1: OH_JSVM_CreateVM Failed");
142         return nullptr;
143     }
144     status = OH_JSVM_DestroyVM(vm);
145     if (status != JSVM_OK) {
146         OH_JSVM_ThrowError(env, nullptr, "TestDestroyVMTest1: OH_JSVM_DestroyVM Failed");
147         return nullptr;
148     }
149 
150     bool result = true;
151     JSVM_Value value = nullptr;
152     OH_JSVM_GetBoolean(env, result, &value);
153     return value;
154 }
TestDestroyVMTest2(JSVM_Env env,JSVM_CallbackInfo info)155 [[maybe_unused]] JSVM_Value TestDestroyVMTest2(JSVM_Env env, JSVM_CallbackInfo info)
156 {
157     size_t argc = 1;
158     JSVM_Value args[1] = {nullptr};
159     JSVM_Value thisVar = nullptr;
160     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
161     // create vm
162     JSVM_VM vm;
163     JSVM_CreateVMOptions options;
164     if (memset_s(&options, sizeof(options), 0, sizeof(options)) != EOK) {
165         OH_JSVM_ThrowError(env, nullptr, "TestDestroyVMTest2: OH_JSVM_Init Failed");
166         return nullptr;
167     }
168     options.isForSnapshotting = true;
169     JSVM_Status status = OH_JSVM_CreateVM(&options, &vm);
170     if (status != JSVM_OK) {
171         OH_JSVM_ThrowError(env, nullptr, "TestDestroyVMTest2: OH_JSVM_CreateVM Failed");
172         return nullptr;
173     }
174     status = OH_JSVM_DestroyVM(nullptr);
175     if (status == JSVM_OK) {
176         OH_JSVM_ThrowError(env, nullptr, "TestDestroyVMTest2: OH_JSVM_DestroyVM Failed");
177         return nullptr;
178     }
179 
180     bool result = true;
181     JSVM_Value value = nullptr;
182     OH_JSVM_GetBoolean(env, result, &value);
183     return value;
184 }
185 //OpenVMScope
TestOpenVMScopeTest1(JSVM_Env env,JSVM_CallbackInfo info)186 [[maybe_unused]] JSVM_Value TestOpenVMScopeTest1(JSVM_Env env, JSVM_CallbackInfo info)
187 {
188     size_t argc = 1;
189     JSVM_Value args[1] = {nullptr};
190     JSVM_Value thisVar = nullptr;
191     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
192     // create vm
193     JSVM_VM vm;
194     JSVM_CreateVMOptions options;
195     if (memset_s(&options, sizeof(options), 0, sizeof(options)) != EOK) {
196         OH_JSVM_ThrowError(env, nullptr, "TestOpenVMScopeTest1: OH_JSVM_Init Failed");
197         return nullptr;
198     }
199     options.isForSnapshotting = true;
200     JSVM_Status status = OH_JSVM_CreateVM(&options, &vm);
201     if (status != JSVM_OK) {
202         OH_JSVM_ThrowError(env, nullptr, "TestOpenVMScopeTest1: OH_JSVM_CreateVM Failed");
203         return nullptr;
204     }
205     // open vm scope
206     JSVM_VMScope vmScope;
207     status = OH_JSVM_OpenVMScope(vm, &vmScope);
208     if (status != JSVM_OK) {
209         OH_JSVM_ThrowError(env, nullptr, "TestOpenVMScopeTest1: OH_JSVM_OpenVMScope Failed");
210         return nullptr;
211     }
212     if (vmScope == nullptr) {
213         OH_JSVM_ThrowError(env, nullptr, "TestOpenVMScopeTest1: OH_JSVM_OpenVMScope Failed");
214         return nullptr;
215     }
216     //close
217     status = OH_JSVM_CloseVMScope(vm, vmScope);
218     if (status != JSVM_OK) {
219         OH_JSVM_ThrowError(env, nullptr, "TestOpenVMScopeTest1: OH_JSVM_CloseVMScope Failed");
220         return nullptr;
221     }
222     status = OH_JSVM_DestroyVM(vm);
223     if (status != JSVM_OK) {
224         OH_JSVM_ThrowError(env, nullptr, "TestOpenVMScopeTest1: OH_JSVM_DestroyVM Failed");
225         return nullptr;
226     }
227 
228     bool result = true;
229     JSVM_Value value = nullptr;
230     OH_JSVM_GetBoolean(env, result, &value);
231     return value;
232 }
TestOpenVMScopeTest2(JSVM_Env env,JSVM_CallbackInfo info)233 [[maybe_unused]] JSVM_Value TestOpenVMScopeTest2(JSVM_Env env, JSVM_CallbackInfo info)
234 {
235     // create vm
236     JSVM_VM vm;
237     JSVM_CreateVMOptions options;
238     memset_s(&options, sizeof(options), 0, sizeof(options));
239     options.isForSnapshotting = true;
240     JSVM_Status status = OH_JSVM_CreateVM(&options, &vm);
241     if (status != JSVM_OK) {
242         OH_JSVM_ThrowError(env, nullptr, "TestOpenVMScopeTest2: OH_JSVM_CreateVM Failed");
243         return nullptr;
244     }
245     // open vm scope first
246     JSVM_VMScope vmScope1;
247     status = OH_JSVM_OpenVMScope(vm, &vmScope1);
248     if (status != JSVM_OK) {
249         OH_JSVM_ThrowError(env, nullptr, "TestOpenVMScopeTest2: OH_JSVM_OpenVMScope Failed");
250         return nullptr;
251     }
252     if (vmScope1 == nullptr) {
253         OH_JSVM_ThrowError(env, nullptr, "TestOpenVMScopeTest2: OH_JSVM_OpenVMScope Failed");
254         return nullptr;
255     }
256     // open vm scope second
257     JSVM_VMScope vmScope2;
258     status = OH_JSVM_OpenVMScope(vm, &vmScope2);
259     if (status != JSVM_OK) {
260         OH_JSVM_ThrowError(env, nullptr, "TestOpenVMScopeTest2: OH_JSVM_OpenVMScope Failed");
261         return nullptr;
262     }
263     if (vmScope2 == nullptr) {
264         OH_JSVM_ThrowError(env, nullptr, "TestOpenVMScopeTest2: OH_JSVM_OpenVMScope Failed");
265         return nullptr;
266     }
267     //close scope1
268     status = OH_JSVM_CloseVMScope(vm, vmScope1);
269     if (status != JSVM_OK) {
270         OH_JSVM_ThrowError(env, nullptr, "TestOpenVMScopeTest2: OH_JSVM_CloseVMScope Failed");
271         return nullptr;
272     }
273     //close scope2
274     status = OH_JSVM_CloseVMScope(vm, vmScope2);
275     if (status != JSVM_OK) {
276         OH_JSVM_ThrowError(env, nullptr, "TestOpenVMScopeTest2: OH_JSVM_CloseVMScope Failed");
277         return nullptr;
278     }
279     status = OH_JSVM_DestroyVM(vm);
280     if (status != JSVM_OK) {
281         OH_JSVM_ThrowError(env, nullptr, "TestOpenVMScopeTest2: OH_JSVM_DestroyVM Failed");
282         return nullptr;
283     }
284 
285     bool result = true;
286     JSVM_Value value = nullptr;
287     OH_JSVM_GetBoolean(env, result, &value);
288     return value;
289 }
290 //CloseVMScope
TestCloseVMScopeTest1(JSVM_Env env,JSVM_CallbackInfo info)291 [[maybe_unused]] JSVM_Value TestCloseVMScopeTest1(JSVM_Env env, JSVM_CallbackInfo info)
292 {
293     size_t argc = 1;
294     JSVM_Value args[1] = {nullptr};
295     JSVM_Value thisVar = nullptr;
296     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
297     // create vm
298     JSVM_VM vm;
299     JSVM_CreateVMOptions options;
300     if (memset_s(&options, sizeof(options), 0, sizeof(options)) != EOK) {
301         OH_JSVM_ThrowError(env, nullptr, "TestCloseVMScopeTest1: OH_JSVM_Init Failed");
302         return nullptr;
303     }
304     options.isForSnapshotting = true;
305     JSVM_Status status = OH_JSVM_CreateVM(&options, &vm);
306     if (status != JSVM_OK) {
307         OH_JSVM_ThrowError(env, nullptr, "TestCloseVMScopeTest1: OH_JSVM_CreateVM Failed");
308         return nullptr;
309     }
310     // open vm scope
311     JSVM_VMScope vmScope;
312     status = OH_JSVM_OpenVMScope(vm, &vmScope);
313     if (status != JSVM_OK) {
314         OH_JSVM_ThrowError(env, nullptr, "TestCloseVMScopeTest1: OH_JSVM_OpenVMScope Failed");
315         return nullptr;
316     }
317     // close vm scope
318     status = OH_JSVM_CloseVMScope(vm, vmScope);
319     if (status != JSVM_OK) {
320         OH_JSVM_ThrowError(env, nullptr, "TestCloseVMScopeTest1: OH_JSVM_CloseVMScope Failed");
321         return nullptr;
322     }
323     //destroy vm
324     status = OH_JSVM_DestroyVM(vm);
325     if (status != JSVM_OK) {
326         OH_JSVM_ThrowError(env, nullptr, "TestCloseVMScopeTest1: OH_JSVM_DestroyVM Failed");
327         return nullptr;
328     }
329 
330     bool result = true;
331     JSVM_Value value = nullptr;
332     OH_JSVM_GetBoolean(env, result, &value);
333     return value;
334 }
TestCloseVMScopeTest2(JSVM_Env env,JSVM_CallbackInfo info)335 [[maybe_unused]] JSVM_Value TestCloseVMScopeTest2(JSVM_Env env, JSVM_CallbackInfo info)
336 {
337     size_t argc = 1;
338     JSVM_Value args[1] = {nullptr};
339     JSVM_Value thisVar = nullptr;
340     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
341     // create vm
342     JSVM_VM vm;
343     JSVM_CreateVMOptions options;
344     if (memset_s(&options, sizeof(options), 0, sizeof(options)) != EOK) {
345         OH_JSVM_ThrowError(env, nullptr, "TestCloseVMScopeTest2: OH_JSVM_Init Failed");
346         return nullptr;
347     }
348     options.isForSnapshotting = true;
349     JSVM_Status status = OH_JSVM_CreateVM(&options, &vm);
350     if (status != JSVM_OK) {
351         OH_JSVM_ThrowError(env, nullptr, "TestCloseVMScopeTest2: OH_JSVM_CreateVM Failed");
352         return nullptr;
353     }
354     // open vm scope
355     JSVM_VMScope vmScope;
356     status = OH_JSVM_OpenVMScope(vm, &vmScope);
357     if (status != JSVM_OK) {
358         OH_JSVM_ThrowError(env, nullptr, "TestCloseVMScopeTest2: OH_JSVM_OpenVMScope Failed");
359         return nullptr;
360     }
361     // close vm scope
362     status = OH_JSVM_CloseVMScope(vm, vmScope);
363     if (status != JSVM_OK) {
364         OH_JSVM_ThrowError(env, nullptr, "TestCloseVMScopeTest2: OH_JSVM_CloseVMScope Failed");
365         return nullptr;
366     }
367     //destroy vm
368     status = OH_JSVM_DestroyVM(vm);
369     if (status != JSVM_OK) {
370         OH_JSVM_ThrowError(env, nullptr, "TestCloseVMScopeTest3: OH_JSVM_DestroyVM Failed");
371         return nullptr;
372     }
373 
374     bool result = true;
375     JSVM_Value value = nullptr;
376     OH_JSVM_GetBoolean(env, result, &value);
377     return value;
378 }
379 // CreateEnv
assertEqual(JSVM_Env env,JSVM_CallbackInfo info)380 JSVM_Value assertEqual(JSVM_Env env, JSVM_CallbackInfo info)
381 {
382     size_t argc = NUM_SIZE_2;
383     JSVM_Value args[NUM_SIZE_2];
384     JSVM_CALL(env, OH_JSVM_GetCbInfo(env, info, &argc, args, NULL, NULL));
385 
386     bool isStrictEquals = false;
387     OH_JSVM_StrictEquals(env, args[0], args[1], &isStrictEquals);
388     return nullptr;
389 }
TestCreateEnvTest1(JSVM_Env env,JSVM_CallbackInfo info)390 [[maybe_unused]] JSVM_Value TestCreateEnvTest1(JSVM_Env env, JSVM_CallbackInfo info)
391 {
392     // create vm
393     JSVM_VM vm;
394     JSVM_CreateVMOptions options;
395     memset_s(&options, sizeof(options), 0, sizeof(options));
396     options.isForSnapshotting = true;
397     JSVM_Status status = OH_JSVM_CreateVM(&options, &vm);
398     if (status != JSVM_OK) {
399         OH_JSVM_ThrowError(env, nullptr, "TestCreateEnvTest1: OH_JSVM_CreateVM Failed");
400         return nullptr;
401     }
402     // open vm scope
403     JSVM_VMScope vmScope;
404     status = OH_JSVM_OpenVMScope(vm, &vmScope);
405     if (status != JSVM_OK) {
406         OH_JSVM_ThrowError(env, nullptr, "TestCreateEnvTest1: OH_JSVM_OpenVMScope Failed");
407         return nullptr;
408     }
409     // create env
410     JSVM_Env envTest;
411     JSVM_CallbackStruct param[1];
412     param[0].data = nullptr;
413     param[0].callback = assertEqual;
414     JSVM_PropertyDescriptor descriptor[] = {
415         {"assertEqual", NULL, &param[0], NULL, NULL, NULL, JSVM_DEFAULT},
416     };
417     // propertycount = 0
418     status = OH_JSVM_CreateEnv(vm, 0, descriptor, &envTest);
419     if (status != JSVM_OK) {
420         OH_JSVM_ThrowError(env, nullptr, "TestCreateEnvTest1: OH_JSVM_CreateEnv Failed");
421         return nullptr;
422     }
423     //destroy env
424     status = OH_JSVM_DestroyEnv(envTest);
425     if (status != JSVM_OK) {
426         OH_JSVM_ThrowError(env, nullptr, "TestCreateEnvTest1: OH_JSVM_DestroyEnv Failed");
427         return nullptr;
428     }
429     // close vm scope
430     status = OH_JSVM_CloseVMScope(vm, vmScope);
431     if (status != JSVM_OK) {
432         OH_JSVM_ThrowError(env, nullptr, "TestCreateEnvTest1: OH_JSVM_CloseVMScope Failed");
433         return nullptr;
434     }
435     //destroy vm
436     status = OH_JSVM_DestroyVM(vm);
437     if (status != JSVM_OK) {
438         OH_JSVM_ThrowError(env, nullptr, "TestCreateEnvTest1: OH_JSVM_DestroyVM Failed");
439         return nullptr;
440     }
441 
442     bool result = true;
443     JSVM_Value value = nullptr;
444     OH_JSVM_GetBoolean(env, result, &value);
445     return value;
446 }
TestCreateEnvTest2(JSVM_Env env,JSVM_CallbackInfo info)447 [[maybe_unused]] JSVM_Value TestCreateEnvTest2(JSVM_Env env, JSVM_CallbackInfo info)
448 {
449     // create vm
450     JSVM_VM vm;
451     JSVM_CreateVMOptions options;
452     memset_s(&options, sizeof(options), 0, sizeof(options));
453     options.isForSnapshotting = true;
454     JSVM_Status status = OH_JSVM_CreateVM(&options, &vm);
455     if (status != JSVM_OK) {
456         OH_JSVM_ThrowError(env, nullptr, "TestCreateEnvTest2: OH_JSVM_CreateVM Failed");
457         return nullptr;
458     }
459     // open vm scope
460     JSVM_VMScope vmScope;
461     status = OH_JSVM_OpenVMScope(vm, &vmScope);
462     if (status != JSVM_OK) {
463         OH_JSVM_ThrowError(env, nullptr, "TestCreateEnvTest2: OH_JSVM_OpenVMScope Failed");
464         return nullptr;
465     }
466     // create env
467     JSVM_Env envTest;
468     JSVM_CallbackStruct param[1];
469     param[0].data = nullptr;
470     param[0].callback = assertEqual;
471     JSVM_PropertyDescriptor descriptor[] = {
472         {"assertEqual", NULL, &param[0], NULL, NULL, NULL, JSVM_DEFAULT},
473     };
474     status = OH_JSVM_CreateEnv(vm, sizeof(descriptor) / sizeof(descriptor[0]), descriptor, &envTest);
475     if (status != JSVM_OK) {
476         OH_JSVM_ThrowError(env, nullptr, "TestCreateEnvTest2: OH_JSVM_CreateEnv Failed");
477         return nullptr;
478     }
479     //destroy env
480     status = OH_JSVM_DestroyEnv(envTest);
481     if (status != JSVM_OK) {
482         OH_JSVM_ThrowError(env, nullptr, "TestCreateEnvTest2: OH_JSVM_DestroyEnv Failed");
483         return nullptr;
484     }
485     // close vm scope
486     status = OH_JSVM_CloseVMScope(vm, vmScope);
487     if (status != JSVM_OK) {
488         OH_JSVM_ThrowError(env, nullptr, "TestCreateEnvTest2: OH_JSVM_CloseVMScope Failed");
489         return nullptr;
490     }
491     //destroy vm
492     status = OH_JSVM_DestroyVM(vm);
493     if (status != JSVM_OK) {
494         OH_JSVM_ThrowError(env, nullptr, "TestCreateEnvTest2: OH_JSVM_DestroyVM Failed");
495         return nullptr;
496     }
497 
498     bool result = true;
499     JSVM_Value value = nullptr;
500     OH_JSVM_GetBoolean(env, result, &value);
501     return value;
502 }
503 //DestroyEnv
TestDestroyEnvTest1(JSVM_Env env,JSVM_CallbackInfo info)504 [[maybe_unused]] JSVM_Value TestDestroyEnvTest1(JSVM_Env env, JSVM_CallbackInfo info)
505 {
506     // create vm
507     JSVM_VM vm;
508     JSVM_CreateVMOptions options;
509     memset_s(&options, sizeof(options), 0, sizeof(options));
510     options.isForSnapshotting = true;
511     JSVM_Status status = OH_JSVM_CreateVM(&options, &vm);
512     if (status != JSVM_OK) {
513         OH_JSVM_ThrowError(env, nullptr, "TestDestroyEnvTest1: OH_JSVM_CreateVM Failed");
514         return nullptr;
515     }
516     // open vm scope
517     JSVM_VMScope vmScope;
518     status = OH_JSVM_OpenVMScope(vm, &vmScope);
519     if (status != JSVM_OK) {
520         OH_JSVM_ThrowError(env, nullptr, "TestDestroyEnvTest1: OH_JSVM_OpenVMScope Failed");
521         return nullptr;
522     }
523     // create env
524     JSVM_Env envTest;
525     JSVM_CallbackStruct param[1];
526     param[0].data = nullptr;
527     param[0].callback = assertEqual;
528     JSVM_PropertyDescriptor descriptor[] = {
529         {"assertEqual", NULL, &param[0], NULL, NULL, NULL, JSVM_DEFAULT},
530     };
531     status = OH_JSVM_CreateEnv(vm, sizeof(descriptor) / sizeof(descriptor[0]), descriptor, &envTest);
532     if (status != JSVM_OK) {
533         OH_JSVM_ThrowError(env, nullptr, "TestDestroyEnvTest1: OH_JSVM_CreateEnv Failed");
534         return nullptr;
535     }
536     //destroy env
537     status = OH_JSVM_DestroyEnv(envTest);
538     if (status != JSVM_OK) {
539         OH_JSVM_ThrowError(env, nullptr, "TestDestroyEnvTest1: OH_JSVM_DestroyEnv Failed");
540         return nullptr;
541     }
542     // close vm scope
543     status = OH_JSVM_CloseVMScope(vm, vmScope);
544     if (status != JSVM_OK) {
545         OH_JSVM_ThrowError(env, nullptr, "TestDestroyEnvTest1: OH_JSVM_CloseVMScope Failed");
546         return nullptr;
547     }
548     //destroy vm
549     status = OH_JSVM_DestroyVM(vm);
550     if (status != JSVM_OK) {
551         OH_JSVM_ThrowError(env, nullptr, "TestDestroyEnvTest1: OH_JSVM_DestroyVM Failed");
552         return nullptr;
553     }
554 
555     bool result = true;
556     JSVM_Value value = nullptr;
557     OH_JSVM_GetBoolean(env, result, &value);
558     return value;
559 }
TestDestroyEnvTest2(JSVM_Env env,JSVM_CallbackInfo info)560 [[maybe_unused]] JSVM_Value TestDestroyEnvTest2(JSVM_Env env, JSVM_CallbackInfo info)
561 {
562     size_t argc = 1;
563     JSVM_Value args[1] = {nullptr};
564     JSVM_Value thisVar = nullptr;
565     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
566     // create vm
567     JSVM_VM vm;
568     JSVM_CreateVMOptions options;
569     if (memset_s(&options, sizeof(options), 0, sizeof(options)) != EOK) {
570         OH_JSVM_ThrowError(env, nullptr, "TestDestroyEnvTest2: OH_JSVM_Init Failed");
571         return nullptr;
572     }
573     options.isForSnapshotting = true;
574     JSVM_Status status = OH_JSVM_CreateVM(&options, &vm);
575     if (status != JSVM_OK) {
576         OH_JSVM_ThrowError(env, nullptr, "TestDestroyEnvTest2: OH_JSVM_CreateVM Failed");
577         return nullptr;
578     }
579     // open vm scope
580     JSVM_VMScope vmScope;
581     status = OH_JSVM_OpenVMScope(vm, &vmScope);
582     if (status != JSVM_OK) {
583         OH_JSVM_ThrowError(env, nullptr, "TestDestroyEnvTest2: OH_JSVM_OpenVMScope Failed");
584         return nullptr;
585     }
586     // env is null
587     JSVM_Env envTest = nullptr;
588     // close vm scope
589     status = OH_JSVM_CloseVMScope(vm, vmScope);
590     if (status != JSVM_OK) {
591         OH_JSVM_ThrowError(env, nullptr, "TestDestroyEnvTest2: OH_JSVM_CloseVMScope Failed");
592         return nullptr;
593     }
594     //destroy vm
595     status = OH_JSVM_DestroyVM(vm);
596     if (status != JSVM_OK) {
597         OH_JSVM_ThrowError(env, nullptr, "TestDestroyEnvTest2: OH_JSVM_DestroyVM Failed");
598         return nullptr;
599     }
600 
601     bool result = true;
602     JSVM_Value value = nullptr;
603     OH_JSVM_GetBoolean(env, result, &value);
604     return value;
605 }
606 //OpenEnvScope
TestOpenEnvScopeTest1(JSVM_Env env,JSVM_CallbackInfo info)607 [[maybe_unused]] JSVM_Value TestOpenEnvScopeTest1(JSVM_Env env, JSVM_CallbackInfo info)
608 {
609     size_t argc = 1;
610     JSVM_Value args[1] = {nullptr};
611     JSVM_Value thisVar = nullptr;
612     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
613     // create vm
614     JSVM_VM vm;
615     JSVM_CreateVMOptions options;
616     if (memset_s(&options, sizeof(options), 0, sizeof(options)) != EOK) {
617         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest1: OH_JSVM_Init Failed");
618         return nullptr;
619     }
620     options.isForSnapshotting = true;
621     JSVM_Status status = OH_JSVM_CreateVM(&options, &vm);
622     if (status != JSVM_OK) {
623         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest1: OH_JSVM_CreateVM Failed");
624         return nullptr;
625     }
626     // open vm scope
627     JSVM_VMScope vmScope;
628     status = OH_JSVM_OpenVMScope(vm, &vmScope);
629     if (status != JSVM_OK) {
630         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest1: OH_JSVM_OpenVMScope Failed");
631         return nullptr;
632     }
633     // env is null
634     JSVM_Env envTest = nullptr;
635     // close vm scope
636     status = OH_JSVM_CloseVMScope(vm, vmScope);
637     if (status != JSVM_OK) {
638         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest1: OH_JSVM_CloseVMScope Failed");
639         return nullptr;
640     }
641     //destroy vm
642     status = OH_JSVM_DestroyVM(vm);
643     if (status != JSVM_OK) {
644         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest1: OH_JSVM_DestroyVM Failed");
645         return nullptr;
646     }
647 
648     bool result = true;
649     JSVM_Value value = nullptr;
650     OH_JSVM_GetBoolean(env, result, &value);
651     return value;
652 }
TestOpenEnvScopeTest2(JSVM_Env env,JSVM_CallbackInfo info)653 [[maybe_unused]] JSVM_Value TestOpenEnvScopeTest2(JSVM_Env env, JSVM_CallbackInfo info)
654 {
655     size_t argc = 1;
656     JSVM_Value args[1] = {nullptr};
657     JSVM_Value thisVar = nullptr;
658     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
659     // create vm
660     JSVM_VM vm = nullptr;
661     JSVM_CreateVMOptions options;
662     if (memset_s(&options, sizeof(options), 0, sizeof(options)) != EOK) {
663         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest2: OH_JSVM_Init Failed");
664         return nullptr;
665     }
666     options.isForSnapshotting = true;
667     JSVM_Status status = OH_JSVM_CreateVM(&options, &vm);
668     if (status != JSVM_OK) {
669         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest2: OH_JSVM_CreateVM Failed");
670         return nullptr;
671     }
672     // open vm scope
673     JSVM_VMScope vmScope;
674     status = OH_JSVM_OpenVMScope(vm, &vmScope);
675     if (status != JSVM_OK) {
676         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest2: OH_JSVM_OpenVMScope Failed");
677         return nullptr;
678     }
679     // create env
680     JSVM_Env envTest;
681     JSVM_CallbackStruct param[1];
682     param[0].data = nullptr;
683     param[0].callback = assertEqual;
684     JSVM_PropertyDescriptor descriptor[] = {
685         {"assertEqual", NULL, &param[0], NULL, NULL, NULL, JSVM_DEFAULT},
686     };
687     status = OH_JSVM_CreateEnv(vm, sizeof(descriptor) / sizeof(descriptor[0]), descriptor, &envTest);
688     if (status != JSVM_OK) {
689         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest2: OH_JSVM_CreateEnv Failed");
690         return nullptr;
691     }
692     // open env scope
693     JSVM_EnvScope envScope;
694     status = OH_JSVM_OpenEnvScope(envTest, &envScope);
695     if (status != JSVM_OK) {
696         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest2: OH_JSVM_OpenEnvScope Failed");
697         return nullptr;
698     }
699     //close env scope
700     status = OH_JSVM_CloseEnvScope(envTest, envScope);
701     if (status != JSVM_OK) {
702         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest2: OH_JSVM_CloseEnvScope Failed");
703         return nullptr;
704     }
705     //destroy env
706     status = OH_JSVM_DestroyEnv(envTest);
707     if (status != JSVM_OK) {
708         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest2: OH_JSVM_DestroyEnv Failed");
709         return nullptr;
710     }
711     // close vm scope
712     status = OH_JSVM_CloseVMScope(vm, vmScope);
713     if (status != JSVM_OK) {
714         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest2: OH_JSVM_CloseVMScope Failed");
715         return nullptr;
716     }
717     //destroy vm
718     status = OH_JSVM_DestroyVM(vm);
719     if (status != JSVM_OK) {
720         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest2: OH_JSVM_DestroyVM Failed");
721         return nullptr;
722     }
723 
724     bool result = true;
725     JSVM_Value value = nullptr;
726     OH_JSVM_GetBoolean(env, result, &value);
727     return value;
728 }
TestOpenEnvScopeTest3(JSVM_Env env,JSVM_CallbackInfo info)729 [[maybe_unused]] JSVM_Value TestOpenEnvScopeTest3(JSVM_Env env, JSVM_CallbackInfo info)
730 {
731     size_t argc = 1;
732     JSVM_Value args[1] = {nullptr};
733     JSVM_Value thisVar = nullptr;
734     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
735     // create vm
736     JSVM_VM vm;
737     JSVM_CreateVMOptions options;
738     if (memset_s(&options, sizeof(options), 0, sizeof(options)) != EOK) {
739         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest3: OH_JSVM_Init Failed");
740         return nullptr;
741     }
742     options.isForSnapshotting = true;
743     JSVM_Status status = OH_JSVM_CreateVM(&options, &vm);
744     if (status != JSVM_OK) {
745         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest3: OH_JSVM_CreateVM Failed");
746         return nullptr;
747     }
748     // open vm scope
749     JSVM_VMScope vmScope;
750     status = OH_JSVM_OpenVMScope(vm, &vmScope);
751     if (status != JSVM_OK) {
752         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest3: OH_JSVM_OpenVMScope Failed");
753         return nullptr;
754     }
755     // create env
756     JSVM_Env envTest;
757     JSVM_CallbackStruct param[1];
758     param[0].data = nullptr;
759     param[0].callback = assertEqual;
760     JSVM_PropertyDescriptor descriptor[] = {
761         {"assertEqual", NULL, &param[0], NULL, NULL, NULL, JSVM_DEFAULT},
762     };
763     status = OH_JSVM_CreateEnv(vm, sizeof(descriptor) / sizeof(descriptor[0]), descriptor, &envTest);
764     if (status != JSVM_OK) {
765         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest3: OH_JSVM_CreateEnv Failed");
766         return nullptr;
767     }
768     //first open env scope
769     JSVM_EnvScope envScope1;
770     status = OH_JSVM_OpenEnvScope(envTest, &envScope1);
771     if (status != JSVM_OK) {
772         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest3: OH_JSVM_OpenEnvScope Failed");
773         return nullptr;
774     }
775     //second open env scope
776     JSVM_EnvScope envScope2;
777     status = OH_JSVM_OpenEnvScope(envTest, &envScope2);
778     if (status != JSVM_OK) {
779         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest3: OH_JSVM_OpenEnvScope second Failed");
780         return nullptr;
781     }
782     //close env scope1
783     status = OH_JSVM_CloseEnvScope(envTest, envScope1);
784     if (status != JSVM_OK) {
785         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest3: OH_JSVM_CloseEnvScope Failed");
786         return nullptr;
787     }
788     //close env scope2
789     status = OH_JSVM_CloseEnvScope(envTest, envScope2);
790     if (status != JSVM_OK) {
791         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest3: OH_JSVM_CloseEnvScope Failed");
792         return nullptr;
793     }
794     //destroy env
795     status = OH_JSVM_DestroyEnv(envTest);
796     if (status != JSVM_OK) {
797         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest3: OH_JSVM_DestroyEnv Failed");
798         return nullptr;
799     }
800     // close vm scope
801     status = OH_JSVM_CloseVMScope(vm, vmScope);
802     if (status != JSVM_OK) {
803         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest3: OH_JSVM_CloseVMScope Failed");
804         return nullptr;
805     }
806     //destroy vm
807     status = OH_JSVM_DestroyVM(vm);
808     if (status != JSVM_OK) {
809         OH_JSVM_ThrowError(env, nullptr, "TestOpenEnvScopeTest3: OH_JSVM_DestroyVM Failed");
810         return nullptr;
811     }
812 
813     bool result = true;
814     JSVM_Value value = nullptr;
815     OH_JSVM_GetBoolean(env, result, &value);
816     return value;
817 }
818 // CloseEnvScope
TestCloseEnvScopeTest1(JSVM_Env env,JSVM_CallbackInfo info)819 [[maybe_unused]] JSVM_Value TestCloseEnvScopeTest1(JSVM_Env env, JSVM_CallbackInfo info)
820 {
821     size_t argc = 1;
822     JSVM_Value args[1] = {nullptr};
823     JSVM_Value thisVar = nullptr;
824     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
825     // create vm
826     JSVM_VM vm;
827     JSVM_CreateVMOptions options;
828     if (memset_s(&options, sizeof(options), 0, sizeof(options)) != EOK) {
829         OH_JSVM_ThrowError(env, nullptr, "TestCloseEnvScopeTest1: OH_JSVM_Init Failed");
830         return nullptr;
831     }
832     options.isForSnapshotting = true;
833     JSVM_Status status = OH_JSVM_CreateVM(&options, &vm);
834     if (status != JSVM_OK) {
835         OH_JSVM_ThrowError(env, nullptr, "TestCloseEnvScopeTest1: OH_JSVM_CreateVM Failed");
836         return nullptr;
837     }
838     // open vm scope
839     JSVM_VMScope vmScope;
840     status = OH_JSVM_OpenVMScope(vm, &vmScope);
841     if (status != JSVM_OK) {
842         OH_JSVM_ThrowError(env, nullptr, "TestCloseEnvScopeTest1: OH_JSVM_OpenVMScope Failed");
843         return nullptr;
844     }
845     // create env
846     JSVM_Env envTest;
847     JSVM_CallbackStruct param[1];
848     param[0].data = nullptr;
849     param[0].callback = assertEqual;
850     JSVM_PropertyDescriptor descriptor[] = {
851         {"assertEqual", NULL, &param[0], NULL, NULL, NULL, JSVM_DEFAULT},
852     };
853     status = OH_JSVM_CreateEnv(vm, sizeof(descriptor) / sizeof(descriptor[0]), descriptor, &envTest);
854     if (status != JSVM_OK) {
855         OH_JSVM_ThrowError(env, nullptr, "TestCloseEnvScopeTest1: OH_JSVM_CreateEnv Failed");
856         return nullptr;
857     }
858     //open env scope
859     JSVM_EnvScope envScope;
860     status = OH_JSVM_OpenEnvScope(envTest, &envScope);
861     if (status != JSVM_OK) {
862         OH_JSVM_ThrowError(env, nullptr, "TestCloseEnvScopeTest1: OH_JSVM_OpenEnvScope Failed");
863         return nullptr;
864     }
865     //close env scope
866     status = OH_JSVM_CloseEnvScope(envTest, envScope);
867     if (status != JSVM_OK) {
868         OH_JSVM_ThrowError(env, nullptr, "TestCloseEnvScopeTest1: OH_JSVM_CloseEnvScope Failed");
869         return nullptr;
870     }
871     //destroy env
872     status = OH_JSVM_DestroyEnv(envTest);
873     if (status != JSVM_OK) {
874         OH_JSVM_ThrowError(env, nullptr, "TestCloseEnvScopeTest1: OH_JSVM_DestroyEnv Failed");
875         return nullptr;
876     }
877     // close vm scope
878     status = OH_JSVM_CloseVMScope(vm, vmScope);
879     if (status != JSVM_OK) {
880         OH_JSVM_ThrowError(env, nullptr, "TestCloseEnvScopeTest1: OH_JSVM_CloseVMScope Failed");
881         return nullptr;
882     }
883     //destroy vm
884     status = OH_JSVM_DestroyVM(vm);
885     if (status != JSVM_OK) {
886         OH_JSVM_ThrowError(env, nullptr, "TestCloseEnvScopeTest1: OH_JSVM_DestroyVM Failed");
887         return nullptr;
888     }
889 
890     bool result = true;
891     JSVM_Value value = nullptr;
892     OH_JSVM_GetBoolean(env, result, &value);
893     return value;
894 }
TestCloseEnvScopeTest2(JSVM_Env env,JSVM_CallbackInfo info)895 [[maybe_unused]] JSVM_Value TestCloseEnvScopeTest2(JSVM_Env env, JSVM_CallbackInfo info)
896 {
897     size_t argc = 1;
898     JSVM_Value args[1] = {nullptr};
899     JSVM_Value thisVar = nullptr;
900     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
901     // create vm
902     JSVM_VM vm;
903     JSVM_CreateVMOptions options;
904     if (memset_s(&options, sizeof(options), 0, sizeof(options)) != EOK) {
905         OH_JSVM_ThrowError(env, nullptr, "TestCloseEnvScopeTest2: OH_JSVM_Init Failed");
906         return nullptr;
907     }
908     options.isForSnapshotting = true;
909     JSVM_Status status = OH_JSVM_CreateVM(&options, &vm);
910     if (status != JSVM_OK) {
911         OH_JSVM_ThrowError(env, nullptr, "TestCloseEnvScopeTest2: OH_JSVM_CreateVM Failed");
912         return nullptr;
913     }
914     // open vm scope
915     JSVM_VMScope vmScope;
916     status = OH_JSVM_OpenVMScope(vm, &vmScope);
917     if (status != JSVM_OK) {
918         OH_JSVM_ThrowError(env, nullptr, "TestCloseEnvScopeTest2: OH_JSVM_OpenVMScope Failed");
919         return nullptr;
920     }
921     // create env
922     JSVM_Env envTest;
923     JSVM_CallbackStruct param[1];
924     param[0].data = nullptr;
925     param[0].callback = assertEqual;
926     JSVM_PropertyDescriptor descriptor[] = {
927         {"assertEqual", NULL, &param[0], NULL, NULL, NULL, JSVM_DEFAULT},
928     };
929     status = OH_JSVM_CreateEnv(vm, sizeof(descriptor) / sizeof(descriptor[0]), descriptor, &envTest);
930     if (status != JSVM_OK) {
931         OH_JSVM_ThrowError(env, nullptr, "TestCloseEnvScopeTest2: OH_JSVM_CreateEnv Failed");
932         return nullptr;
933     }
934     //open env scope
935     JSVM_EnvScope envScope;
936     status = OH_JSVM_OpenEnvScope(envTest, &envScope);
937     if (status != JSVM_OK) {
938         OH_JSVM_ThrowError(env, nullptr, "TestCloseEnvScopeTest2: OH_JSVM_OpenEnvScope Failed");
939         return nullptr;
940     }
941     //first close env scope
942     status = OH_JSVM_CloseEnvScope(envTest, envScope);
943     if (status != JSVM_OK) {
944         OH_JSVM_ThrowError(env, nullptr, "TestCloseEnvScopeTest2: OH_JSVM_CloseEnvScope first Failed");
945         return nullptr;
946     }
947     //destroy env
948     status = OH_JSVM_DestroyEnv(envTest);
949     if (status != JSVM_OK) {
950         OH_JSVM_ThrowError(env, nullptr, "TestCloseEnvScopeTest2: OH_JSVM_DestroyEnv Failed");
951         return nullptr;
952     }
953     // close vm scope
954     status = OH_JSVM_CloseVMScope(vm, vmScope);
955     if (status != JSVM_OK) {
956         OH_JSVM_ThrowError(env, nullptr, "TestCloseEnvScopeTest2: OH_JSVM_CloseVMScope Failed");
957         return nullptr;
958     }
959     //destroy vm
960     status = OH_JSVM_DestroyVM(vm);
961     if (status != JSVM_OK) {
962         OH_JSVM_ThrowError(env, nullptr, "TestCloseEnvScopeTest4: OH_JSVM_DestroyVM Failed");
963         return nullptr;
964     }
965 
966     bool result = true;
967     JSVM_Value value = nullptr;
968     OH_JSVM_GetBoolean(env, result, &value);
969     return value;
970 }
971 //Init-- create vm -- open vm scope -- create env -- open env scope -- open handlescope
972 //   -- close handlescope -- close env scope -- destroy env -- close vm scope -- destroy vm
TestDataTypeCombinationTest1(JSVM_Env env,JSVM_CallbackInfo info)973 [[maybe_unused]] JSVM_Value TestDataTypeCombinationTest1(JSVM_Env env, JSVM_CallbackInfo info)
974 {
975     size_t argc = 1;
976     JSVM_Value args[1] = {nullptr};
977     JSVM_Value thisVar = nullptr;
978     OH_JSVM_GetCbInfo(env, info, &argc, args, &thisVar, nullptr);
979     // create vm
980     JSVM_VM vm;
981     JSVM_CreateVMOptions options;
982     if (memset_s(&options, sizeof(options), 0, sizeof(options)) != EOK) {
983         OH_JSVM_ThrowError(env, nullptr, "TestDataTypeCombinationTest1: OH_JSVM_Init Failed");
984         return nullptr;
985     }
986     options.isForSnapshotting = true;
987     JSVM_Status status = OH_JSVM_CreateVM(&options, &vm);
988     if (status != JSVM_OK) {
989         OH_JSVM_ThrowError(env, nullptr, "TestDataTypeCombinationTest1: OH_JSVM_CreateVM Failed");
990         return nullptr;
991     }
992     // open vm scope
993     JSVM_VMScope vmScope;
994     status = OH_JSVM_OpenVMScope(vm, &vmScope);
995     if (status != JSVM_OK) {
996         OH_JSVM_ThrowError(env, nullptr, "TestDataTypeCombinationTest1: OH_JSVM_OpenVMScope Failed");
997         return nullptr;
998     }
999     // create env
1000     JSVM_Env envTest;
1001     JSVM_CallbackStruct param[1];
1002     param[0].data = nullptr;
1003     param[0].callback = assertEqual;
1004     JSVM_PropertyDescriptor descriptor[] = {
1005         {"assertEqual", NULL, &param[0], NULL, NULL, NULL, JSVM_DEFAULT},
1006     };
1007     status = OH_JSVM_CreateEnv(vm, sizeof(descriptor) / sizeof(descriptor[0]), descriptor, &envTest);
1008     if (status != JSVM_OK) {
1009         OH_JSVM_ThrowError(env, nullptr, "TestDataTypeCombinationTest1: OH_JSVM_CreateEnv Failed");
1010         return nullptr;
1011     }
1012     //open env scope
1013     JSVM_EnvScope envScope;
1014     status = OH_JSVM_OpenEnvScope(envTest, &envScope);
1015     if (status != JSVM_OK) {
1016         OH_JSVM_ThrowError(env, nullptr, "TestDataTypeCombinationTest1: OH_JSVM_OpenEnvScope Failed");
1017         return nullptr;
1018     }
1019     //open handlescope
1020     JSVM_HandleScope handlescope;
1021     status = OH_JSVM_OpenHandleScope(envTest, &handlescope);
1022     if (status != JSVM_OK) {
1023         OH_JSVM_ThrowError(env, nullptr, "TestDataTypeCombinationTest1: OH_JSVM_OpenHandleScope Failed");
1024         return nullptr;
1025     }
1026     //close handlescope
1027     status = OH_JSVM_CloseHandleScope(envTest, handlescope);
1028     if (status != JSVM_OK) {
1029         OH_JSVM_ThrowError(env, nullptr, "TestDataTypeCombinationTest1: OH_JSVM_CloseHandleScope Failed");
1030         return nullptr;
1031     }
1032     //close env scope
1033     status = OH_JSVM_CloseEnvScope(envTest, envScope);
1034     if (status != JSVM_OK) {
1035         OH_JSVM_ThrowError(env, nullptr, "TestDataTypeCombinationTest1: OH_JSVM_CloseEnvScope Failed");
1036         return nullptr;
1037     }
1038     //destroy env
1039     status = OH_JSVM_DestroyEnv(envTest);
1040     if (status != JSVM_OK) {
1041         OH_JSVM_ThrowError(env, nullptr, "TestDataTypeCombinationTest1: OH_JSVM_DestroyEnv Failed");
1042         return nullptr;
1043     }
1044     // close vm scope
1045     status = OH_JSVM_CloseVMScope(vm, vmScope);
1046     if (status != JSVM_OK) {
1047         OH_JSVM_ThrowError(env, nullptr, "TestDataTypeCombinationTest1: OH_JSVM_CloseVMScope Failed");
1048         return nullptr;
1049     }
1050     //destroy vm
1051     status = OH_JSVM_DestroyVM(vm);
1052     if (status != JSVM_OK) {
1053         OH_JSVM_ThrowError(env, nullptr, "TestDataTypeCombinationTest1: OH_JSVM_DestroyVM Failed");
1054         return nullptr;
1055     }
1056 
1057     bool result = true;
1058     JSVM_Value value = nullptr;
1059     OH_JSVM_GetBoolean(env, result, &value);
1060     return value;
1061 }
1062