• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 Huawei Device 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 
16 #include <cstddef>
17 #include "ecmascript/builtins/builtins.h"
18 #include "ecmascript/builtins/builtins_function.h"
19 #include "ecmascript/builtins/builtins_object.h"
20 #include "ecmascript/checkpoint/thread_state_transition.h"
21 #include "ecmascript/compiler/aot_file/an_file_data_manager.h"
22 #include "ecmascript/compiler/aot_file/aot_file_manager.h"
23 #include "ecmascript/compiler/circuit_builder_helper.h"
24 #include "ecmascript/deoptimizer/deoptimizer.h"
25 #include "ecmascript/ecma_global_storage.h"
26 #include "ecmascript/ecma_vm.h"
27 #include "ecmascript/global_env.h"
28 #include "ecmascript/js_api/js_api_tree_map.h"
29 #include "ecmascript/js_api/js_api_tree_set.h"
30 #include "ecmascript/js_api/js_api_vector.h"
31 #include "ecmascript/js_array.h"
32 #include "ecmascript/js_bigint.h"
33 #include "ecmascript/js_date_time_format.h"
34 #include "ecmascript/js_generator_object.h"
35 #include "ecmascript/js_map.h"
36 #include "ecmascript/js_map_iterator.h"
37 #include "ecmascript/js_object-inl.h"
38 #include "ecmascript/js_primitive_ref.h"
39 #include "ecmascript/js_regexp.h"
40 #include "ecmascript/js_runtime_options.h"
41 #include "ecmascript/js_set.h"
42 #include "ecmascript/js_set_iterator.h"
43 #include "ecmascript/js_tagged_value.h"
44 #include "ecmascript/js_typed_array.h"
45 #include "ecmascript/js_thread.h"
46 #include "ecmascript/js_weak_container.h"
47 #include "ecmascript/linked_hash_table.h"
48 #include "ecmascript/mem/mem_map_allocator.h"
49 #include "ecmascript/module/js_module_manager.h"
50 #include "ecmascript/module/js_module_source_text.h"
51 #include "ecmascript/napi/include/jsnapi.h"
52 #include "ecmascript/napi/include/jsnapi_internals.h"
53 #include "ecmascript/napi/jsnapi_helper.h"
54 #include "ecmascript/object_factory.h"
55 #include "ecmascript/pgo_profiler/pgo_profiler.h"
56 #include "ecmascript/pgo_profiler/pgo_profiler_decoder.h"
57 #include "ecmascript/pgo_profiler/pgo_profiler_encoder.h"
58 #include "ecmascript/pgo_profiler/pgo_profiler_manager.h"
59 #include "ecmascript/tagged_array.h"
60 #include "ecmascript/tests/test_helper.h"
61 #include "ecmascript/tagged_tree.h"
62 #include "ecmascript/weak_vector.h"
63 #include "gtest/gtest.h"
64 
65 using namespace panda;
66 using namespace panda::ecmascript;
67 using namespace panda::ecmascript::kungfu;
68 static const char *TEST_KEY = "TestKey";
69 static const char *TEST_VALUE = "TestValue";
70 static const char *TEST_NUM1 = "-3.14";
71 static const char *TEST_NUM2 = "-123.3";
72 static const int INT_ONE = 1;
73 static const int INT_MINUS_1 = -1;
74 static const char *STR_TEST = "Test";
75 static const char *STR_NUM = "123";
76 constexpr char ARK_DEBUGGER_LIB_PATH[] = "LIBRARYPATH";
77 
78 namespace panda::test {
79 using BuiltinsFunction = ecmascript::builtins::BuiltinsFunction;
80 using PGOProfilerManager = panda::ecmascript::pgo::PGOProfilerManager;
81 using FunctionForRef = Local<JSValueRef> (*)(JsiRuntimeCallInfo *);
82 class JSNApiTests : public testing::Test {
83 public:
SetUpTestCase()84     static void SetUpTestCase()
85     {
86         GTEST_LOG_(INFO) << "SetUpTestCase";
87     }
88 
TearDownTestCase()89     static void TearDownTestCase()
90     {
91         GTEST_LOG_(INFO) << "TearDownCase";
92     }
93 
SetUp()94     void SetUp() override
95     {
96         RuntimeOption option;
97         option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
98         vm_ = JSNApi::CreateJSVM(option);
99         ASSERT_TRUE(vm_ != nullptr) << "Cannot create Runtime";
100         thread_ = vm_->GetJSThread();
101         vm_->SetEnableForceGC(true);
102         thread_->ManagedCodeBegin();
103     }
104 
TearDown()105     void TearDown() override
106     {
107         thread_->ManagedCodeEnd();
108         vm_->SetEnableForceGC(false);
109         JSNApi::DestroyJSVM(vm_);
110     }
111 
TestNumberRef(T val,TaggedType expected)112     template <typename T> void TestNumberRef(T val, TaggedType expected)
113     {
114         LocalScope scope(vm_);
115         Local<NumberRef> obj = NumberRef::New(vm_, val);
116         ASSERT_TRUE(obj->IsNumber());
117         JSTaggedType res = JSNApiHelper::ToJSTaggedValue(*obj).GetRawData();
118         ASSERT_EQ(res, expected);
119         if constexpr (std::is_floating_point_v<T>) {
120             if (std::isnan(val)) {
121                 ASSERT_TRUE(std::isnan(obj->Value()));
122             } else {
123                 ASSERT_EQ(obj->Value(), val);
124             }
125         } else if constexpr (sizeof(T) >= sizeof(int32_t)) {
126             ASSERT_EQ(obj->IntegerValue(vm_), val);
127         } else if constexpr (std::is_signed_v<T>) {
128             ASSERT_EQ(obj->Int32Value(vm_), val);
129         } else {
130             ASSERT_EQ(obj->Uint32Value(vm_), val);
131         }
132     }
133 
ConvertDouble(double val)134     TaggedType ConvertDouble(double val)
135     {
136         return base::bit_cast<JSTaggedType>(val) + JSTaggedValue::DOUBLE_ENCODE_OFFSET;
137     }
138 
139 protected:
140     JSThread *thread_ = nullptr;
141     EcmaVM *vm_ = nullptr;
142 };
143 
FunctionCallback(JsiRuntimeCallInfo * info)144 Local<JSValueRef> FunctionCallback(JsiRuntimeCallInfo *info)
145 {
146     EscapeLocalScope scope(info->GetVM());
147     return scope.Escape(ArrayRef::New(info->GetVM(), info->GetArgsNumber()));
148 }
149 
WeakRefCallback(EcmaVM * vm)150 void WeakRefCallback(EcmaVM *vm)
151 {
152     LocalScope scope(vm);
153     Local<ObjectRef> object = ObjectRef::New(vm);
154     Global<ObjectRef> globalObject(vm, object);
155     globalObject.SetWeak();
156     Local<ObjectRef> object1 = ObjectRef::New(vm);
157     Global<ObjectRef> globalObject1(vm, object1);
158     globalObject1.SetWeak();
159     vm->CollectGarbage(TriggerGCType::YOUNG_GC);
160     vm->CollectGarbage(TriggerGCType::OLD_GC);
161     globalObject.FreeGlobalHandleAddr();
162 }
163 
ThreadCheck(const EcmaVM * vm)164 void ThreadCheck(const EcmaVM *vm)
165 {
166     EXPECT_TRUE(vm->GetJSThread()->GetThreadId() != JSThread::GetCurrentThreadId());
167 }
168 
CheckReject(JsiRuntimeCallInfo * info)169 void CheckReject(JsiRuntimeCallInfo *info)
170 {
171     ASSERT_EQ(info->GetArgsNumber(), 1U);
172     Local<JSValueRef> reason = info->GetCallArgRef(0);
173     ASSERT_TRUE(reason->IsString(info->GetVM()));
174     ASSERT_EQ(Local<StringRef>(reason)->ToString(info->GetVM()), "Reject");
175 }
176 
RejectCallback(JsiRuntimeCallInfo * info)177 Local<JSValueRef> RejectCallback(JsiRuntimeCallInfo *info)
178 {
179     LocalScope scope(info->GetVM());
180     CheckReject(info);
181     return JSValueRef::Undefined(info->GetVM());
182 }
183 
184 /**
185  * @tc.number: ffi_interface_api_054
186  * @tc.name: NumberRef_uint32_int64
187  * @tc.desc:Define the variable input of type uint32_t and int64_t to determine whether the object is of numerical type
188  * @tc.type: FUNC
189  * @tc.require:  parameter
190  */
HWTEST_F_L0(JSNApiTests,NumberRef_uint32_int64)191 HWTEST_F_L0(JSNApiTests, NumberRef_uint32_int64)
192 {
193     uint32_t input = 32;
194     int64_t input1 = 1;
195     Local<NumberRef> res = NumberRef::New(vm_, input);
196     Local<NumberRef> res1 = NumberRef::New(vm_, input1);
197     ASSERT_TRUE(res->IsNumber());
198     ASSERT_TRUE(res1->IsNumber());
199 }
200 
201 /**
202  * @tc.number: ffi_interface_api_055
203  * @tc.name: NumberRef_int32_t_double
204  * @tc.desc:Define the variable input of type int32 and double to determine whether the object is of numerical type
205  * @tc.type: FUNC
206  * @tc.require:  parameter
207  */
HWTEST_F_L0(JSNApiTests,NumberRef_int32_t_double)208 HWTEST_F_L0(JSNApiTests, NumberRef_int32_t_double)
209 {
210     int32_t input = -1;
211     double input1 = 1.1;
212     Local<NumberRef> res = NumberRef::New(vm_, input);
213     Local<NumberRef> res1 = NumberRef::New(vm_, input1);
214     ASSERT_TRUE(res->IsNumber());
215     ASSERT_TRUE(res1->IsNumber());
216 }
217 
218 /**
219  * @tc.number: ffi_interface_api_056
220  * @tc.name: ObjectRef_Freeze
221  * @tc.desc:Execute a Freeze operation and call the JSObject:: SetIntegrity Level method to achieve immutability
222  * @tc.type: FUNC
223  * @tc.require:  parameter
224  */
HWTEST_F_L0(JSNApiTests,ObjectRef_Freeze)225 HWTEST_F_L0(JSNApiTests, ObjectRef_Freeze)
226 {
227     LocalScope scope(vm_);
228     Local<ObjectRef> object = ObjectRef::New(vm_);
229     thread_ = vm_->GetJSThread();
230     JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
231     JSHandle<JSTaggedValue> set = env->GetBuiltinsSetFunction();
232     object->Freeze(vm_);
233     ecmascript::ThreadManagedScope managedScope(thread_);
234     bool status = JSObject::SetIntegrityLevel(thread_, JSHandle<JSObject>::Cast(set), IntegrityLevel::FROZEN);
235     ASSERT_TRUE(status);
236 }
237 
238 /**
239  * @tc.number: ffi_interface_api_057
240  * @tc.name: ObjectRef_Seal
241  * @tc.desc:The function is to perform a closed (Seal) operation by calling the JSObject::SetIntegrity Level method
242  * to ensure that its properties cannot be modified or deleted, and to set the integrity level of
243  * the object to SEALED
244  * @tc.type: FUNC
245  * @tc.require:  parameter
246  */
HWTEST_F_L0(JSNApiTests,ObjectRef_Seal)247 HWTEST_F_L0(JSNApiTests, ObjectRef_Seal)
248 {
249     LocalScope scope(vm_);
250     Local<ObjectRef> object = ObjectRef::New(vm_); // 创建一个新的空对象
251     thread_ = vm_->GetJSThread();
252     JSHandle<GlobalEnv> env = vm_->GetGlobalEnv();
253     JSHandle<JSTaggedValue> set = env->GetBuiltinsSetFunction();
254     object->Seal(vm_); // 尝试将对象封闭
255     ecmascript::ThreadManagedScope managedScope(thread_);
256     bool status = JSObject::SetIntegrityLevel(thread_, JSHandle<JSObject>::Cast(set), IntegrityLevel::SEALED);
257     ASSERT_TRUE(status);
258 }
259 
260 /**
261  * @tc.number: ffi_interface_api_058
262  * @tc.name: ObjectRef_GetAllPropertyNames
263  * @tc.desc:Use the GetAllPropertyNames method to obtain all property names of the object and return an ArrayRef object.
264  * @tc.type: FUNC
265  * @tc.require:  parameter
266  */
HWTEST_F_L0(JSNApiTests,ObjectRef_GetAllPropertyNames)267 HWTEST_F_L0(JSNApiTests, ObjectRef_GetAllPropertyNames)
268 {
269     LocalScope scope(vm_);
270     Local<ObjectRef> object = ObjectRef::New(vm_);
271     uint32_t filter = 3;
272     Local<ArrayRef> res = object->GetAllPropertyNames(vm_, filter);
273     ASSERT_FALSE(res->IsBigInt(vm_));
274     ASSERT_TRUE(res->IsArray(vm_));
275 }
276 
277 /**
278  * @tc.number: ffi_interface_api_059
279  * @tc.name: GetIndex
280  * @tc.desc:Call the GetIndex() function to obtain the index value and use EXCECT_ EQ()
281  * assertion is used to verify whether the result is 0, which is the initial index value.
282  * @tc.type: FUNC
283  * @tc.require:  parameter
284  */
HWTEST_F_L0(JSNApiTests,GetIndex)285 HWTEST_F_L0(JSNApiTests, GetIndex)
286 {
287     ecmascript::ThreadManagedScope managedScope(vm_->GetJSThread());
288     LocalScope scope(vm_);
289     JSThread *thread = vm_->GetJSThread();
290     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
291     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
292     JSHandle<JSTaggedValue> constructor = env->GetBuiltinsMapFunction();
293     JSHandle<JSMap> jsMap =
294         JSHandle<JSMap>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), constructor));
295     JSHandle<LinkedHashMap> hashMap = LinkedHashMap::Create(thread);
296     jsMap->SetLinkedMap(thread, hashMap);
297     JSHandle<JSTaggedValue> mapTag = JSHandle<JSTaggedValue>::Cast(jsMap);
298     JSHandle<JSTaggedValue> jsMapIteratorTag4 = JSMapIterator::CreateMapIterator(thread, mapTag, IterationKind::VALUE);
299     JSHandle<JSMapIterator> jsMapIterator4(jsMapIteratorTag4);
300     Local<MapIteratorRef> mapIterator4 = JSNApiHelper::ToLocal<MapIteratorRef>(jsMapIteratorTag4);
301     int32_t res4 = mapIterator4->GetIndex();
302     EXPECT_EQ(0, res4);
303 }
304 
305 /**
306  * @tc.number: ffi_interface_api_060
307  * @tc.name: GetKind_entries_values_keys
308  * @tc.desc:This test case is mainly used to verify whether the GetKind method of the JSMapIterator object can
309  * correctly return the expected type.
310  * @tc.type: FUNC
311  * @tc.require:  parameter
312  */
HWTEST_F_L0(JSNApiTests,GetKind_entries_values_keys)313 HWTEST_F_L0(JSNApiTests, GetKind_entries_values_keys)
314 {
315     LocalScope scope(vm_);
316     JSThread *thread = vm_->GetJSThread();
317     ecmascript::ThreadManagedScope managedScope(thread);
318     std::string expectedResult = "entries";
319     std::string valuesResult = "values";
320     std::string keysResult = "keys";
321     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
322     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
323     JSHandle<JSTaggedValue> constructor = env->GetBuiltinsMapFunction();
324     JSHandle<JSMap> jsMap =
325         JSHandle<JSMap>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), constructor));
326     JSHandle<LinkedHashMap> hashMap = LinkedHashMap::Create(thread);
327     jsMap->SetLinkedMap(thread, hashMap);
328     JSHandle<JSTaggedValue> mapTag = JSHandle<JSTaggedValue>::Cast(jsMap);
329     JSHandle<JSTaggedValue> jsMapIteratorTag =
330         JSMapIterator::CreateMapIterator(thread, mapTag, IterationKind::KEY_AND_VALUE);
331     JSHandle<JSMapIterator> jsMapIterator(jsMapIteratorTag);
332     EXPECT_EQ(JSTaggedValue::SameValue(jsMapIterator->GetIteratedMap(), jsMap->GetLinkedMap()), true);
333     Local<MapIteratorRef> mapIterator = JSNApiHelper::ToLocal<MapIteratorRef>(jsMapIteratorTag);
334     Local<JSValueRef> res = mapIterator->GetKind(vm_);
335     EXPECT_EQ(expectedResult, res->ToString(vm_)->ToString(vm_));
336     EXPECT_TRUE(mapIterator->IsMapIterator(vm_));
337     JSHandle<JSTaggedValue> jsMapIteratorTag1 = JSMapIterator::CreateMapIterator(thread, mapTag, IterationKind::KEY);
338     Local<MapIteratorRef> mapIterator1 = JSNApiHelper::ToLocal<MapIteratorRef>(jsMapIteratorTag1);
339     Local<JSValueRef> res1 = mapIterator1->GetKind(vm_);
340     EXPECT_EQ(keysResult, res1->ToString(vm_)->ToString(vm_));
341     JSHandle<JSTaggedValue> jsMapIteratorTag2 = JSMapIterator::CreateMapIterator(thread, mapTag, IterationKind::VALUE);
342     Local<MapIteratorRef> mapIterator2 = JSNApiHelper::ToLocal<MapIteratorRef>(jsMapIteratorTag2);
343     Local<JSValueRef> res2 = mapIterator2->GetKind(vm_);
344     EXPECT_EQ(valuesResult, res2->ToString(vm_)->ToString(vm_));
345 }
346 
347 /**
348  * @tc.number: ffi_interface_api_061
349  * @tc.name: GetKind_001
350  * @tc.desc:This test case is mainly used to verify whether the GetKind method of the JSMapIterator object can
351  * correctly return the expected type (in this example, the expected type is "keys").
352  * @tc.type: FUNC
353  * @tc.require:  parameter
354  */
HWTEST_F_L0(JSNApiTests,GetKind_001)355 HWTEST_F_L0(JSNApiTests, GetKind_001)
356 {
357     ecmascript::ThreadManagedScope managedScope(vm_->GetJSThread());
358     LocalScope scope(vm_);
359     JSThread *thread = vm_->GetJSThread();
360     std::string keysResult = "keys";
361     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
362     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
363     JSHandle<JSTaggedValue> constructor = env->GetBuiltinsMapFunction();
364     JSHandle<JSMap> jsMap =
365         JSHandle<JSMap>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), constructor));
366     JSHandle<LinkedHashMap> hashMap = LinkedHashMap::Create(thread);
367     jsMap->SetLinkedMap(thread, hashMap);
368     JSHandle<JSTaggedValue> mapTag = JSHandle<JSTaggedValue>::Cast(jsMap);
369     JSHandle<JSTaggedValue> jsMapIteratorTag1 = JSMapIterator::CreateMapIterator(thread, mapTag, IterationKind::KEY);
370     JSHandle<JSMapIterator> jsMapIterator1(jsMapIteratorTag1);
371     EXPECT_EQ(JSTaggedValue::SameValue(jsMapIterator1->GetIteratedMap(), jsMap->GetLinkedMap()), true);
372     Local<MapIteratorRef> mapIterator1 = JSNApiHelper::ToLocal<MapIteratorRef>(jsMapIteratorTag1);
373     Local<JSValueRef> res1 = mapIterator1->GetKind(vm_);
374     EXPECT_EQ(keysResult, res1->ToString(vm_)->ToString(vm_));
375 }
376 
377 /**
378  * @tc.number: ffi_interface_api_062
379  * @tc.name: GetKind_002
380  * @tc.desc:This test case is mainly used to verify whether the GetKind method of the JSMapIterator object can
381  * correctly return the expected type (in this example, the expected type is "values").
382  * @tc.type: FUNC
383  * @tc.require:  parameter
384  */
HWTEST_F_L0(JSNApiTests,GetKind_002)385 HWTEST_F_L0(JSNApiTests, GetKind_002)
386 {
387     ecmascript::ThreadManagedScope managedScope(vm_->GetJSThread());
388     LocalScope scope(vm_);
389     JSThread *thread = vm_->GetJSThread();
390     std::string valuesResult = "values";
391     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
392     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
393     JSHandle<JSTaggedValue> constructor = env->GetBuiltinsMapFunction();
394     JSHandle<JSMap> jsMap =
395         JSHandle<JSMap>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), constructor));
396     JSHandle<LinkedHashMap> hashMap = LinkedHashMap::Create(thread);
397     jsMap->SetLinkedMap(thread, hashMap);
398     JSHandle<JSTaggedValue> mapTag = JSHandle<JSTaggedValue>::Cast(jsMap);
399     JSHandle<JSTaggedValue> jsMapIteratorTag2 = JSMapIterator::CreateMapIterator(thread, mapTag, IterationKind::VALUE);
400     JSHandle<JSMapIterator> jsMapIterator2(jsMapIteratorTag2);
401     EXPECT_EQ(JSTaggedValue::SameValue(jsMapIterator2->GetIteratedMap(), jsMap->GetLinkedMap()), true);
402     Local<MapIteratorRef> mapIterator2 = JSNApiHelper::ToLocal<MapIteratorRef>(jsMapIteratorTag2);
403     Local<JSValueRef> res2 = mapIterator2->GetKind(vm_);
404     EXPECT_EQ(valuesResult, res2->ToString(vm_)->ToString(vm_));
405 }
406 
407 /**
408  * @tc.number: ffi_interface_api_063
409  * @tc.name: GetKind_003
410  * @tc.desc:Calling the GetKind method to obtain the iteration type KEY_AND_VALUE Compare with the string
411  * variable 'entries' to assert whether the expected result is the same as the actual result
412  * @tc.type: FUNC
413  * @tc.require:  parameter
414  */
HWTEST_F_L0(JSNApiTests,GetKind_003)415 HWTEST_F_L0(JSNApiTests, GetKind_003)
416 {
417     ecmascript::ThreadManagedScope managedScope(vm_->GetJSThread());
418     LocalScope scope(vm_);
419     JSThread *thread = vm_->GetJSThread();
420     std::string expectedResult = "entries";
421     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
422     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
423     // 从全局环境(GlobalEnv)中获取内置的Map构造函数
424     JSHandle<JSTaggedValue> constructor = env->GetBuiltinsMapFunction();
425     // 使用构造函数创建一个新的JSMap对象
426     JSHandle<JSMap> jsMap =
427         JSHandle<JSMap>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), constructor));
428     JSHandle<LinkedHashMap> hashMap = LinkedHashMap::Create(thread);
429     // 将创建的LinkedHashMap设置为JSMap的内部数据结构
430     jsMap->SetLinkedMap(thread, hashMap);
431     // 将jsMap转换为JSTaggedValue的句柄
432     JSHandle<JSTaggedValue> mapTag = JSHandle<JSTaggedValue>::Cast(jsMap);
433     // 创建一个新的JSMapIterator对象,并将其迭代方式设置为KEY_AND_VALUE
434     JSHandle<JSTaggedValue> jsMapIteratorTag =
435         JSMapIterator::CreateMapIterator(thread, mapTag, IterationKind::KEY_AND_VALUE);
436     JSHandle<JSMapIterator> jsMapIterator(jsMapIteratorTag);
437     EXPECT_EQ(JSTaggedValue::SameValue(jsMapIterator->GetIteratedMap(), jsMap->GetLinkedMap()), true);
438     // 将jsMapIteratorTag转换为本地代码可以使用的MapIteratorRef类型
439     Local<MapIteratorRef> mapIterator = JSNApiHelper::ToLocal<MapIteratorRef>(jsMapIteratorTag);
440     Local<JSValueRef> res = mapIterator->GetKind(vm_);
441     EXPECT_EQ(expectedResult, res->ToString(vm_)->ToString(vm_));
442     EXPECT_TRUE(mapIterator->IsMapIterator(vm_));
443 }
444 
445 /*
446  * @tc.number: ffi_interface_api_064
447  * @tc.name: GetProperty_IsFunction
448  * @tc.desc: Verify if the GetProperty function of the JavaScript virtual machine correctly returns a
449  * function as the property of the 'Number' key.
450  * @tc.type: FUNC
451  * @tc.require:  parameter
452  */
HWTEST_F_L0(JSNApiTests,GetProperty_IsFunction)453 HWTEST_F_L0(JSNApiTests, GetProperty_IsFunction)
454 {
455     LocalScope scope(vm_);
456     Local<ObjectRef> globalObject = JSNApi::GetGlobalObject(vm_);
457     ASSERT_FALSE(globalObject.IsEmpty());
458     ASSERT_TRUE(globalObject->IsObject(vm_));
459 
460     Local<ObjectRef> key = StringRef::NewFromUtf8(vm_, "Number");
461     Local<ObjectRef> property = globalObject->Get(vm_, key);
462     ASSERT_TRUE(property->IsFunction(vm_));
463 }
464 
465 /**
466  * @tc.number: ffi_interface_api_065
467  * @tc.name: NewClassFunction
468  * @tc.desc:Check if the function created through the NewClassFunction method meets the specifications of the class
469  * constructor, and obtain and verify the properties of the function.
470  * @tc.type: FUNC
471  * @tc.require:  parameter
472  */
HWTEST_F_L0(JSNApiTests,NewClassFunction)473 HWTEST_F_L0(JSNApiTests, NewClassFunction)
474 {
475     LocalScope scope(vm_);
476     Local<FunctionRef> cls = FunctionRef::NewClassFunction(vm_, FunctionCallback, nullptr, nullptr);
477 
478     JSHandle<JSTaggedValue> obj = JSNApiHelper::ToJSHandle(Local<JSValueRef>(cls));
479     // 断言obj是一个类构造函数
480     ASSERT_TRUE(obj->IsClassConstructor());
481     // GetPropertyInlinedProps方法获取内联属性的方法,CLASS_PROTOTYPE_INLINE_PROPERTY_INDEX类原型的内联属性索引
482     JSTaggedValue res =
483         JSHandle<JSFunction>(obj)->GetPropertyInlinedProps(JSFunction::CLASS_PROTOTYPE_INLINE_PROPERTY_INDEX);
484     // 断言获取的属性是一个内部访问器
485     ASSERT_TRUE(res.IsInternalAccessor());
486 }
487 
488 /**
489  * @tc.number: ffi_interface_api_066
490  * @tc.name: PromiseRef_Finally_IsPromise
491  * @tc.desc:FunctionRef:: New Create a reject callback function reject. The function of the code is to test the
492  * behavior of the Finally and Then methods of the Promise object
493  * in various situations, ensuring that they all return Promise objects and meet the expected behavior.
494  * @tc.type: FUNC
495  * @tc.require:  parameter
496  */
HWTEST_F_L0(JSNApiTests,PromiseRef_Finally_IsPromise)497 HWTEST_F_L0(JSNApiTests, PromiseRef_Finally_IsPromise)
498 {
499     LocalScope scope(vm_);
500     Local<PromiseCapabilityRef> capability = PromiseCapabilityRef::New(vm_);
501 
502     Local<PromiseRef> gitpromise = capability->GetPromise(vm_);
503     Local<FunctionRef> rejectcallback = FunctionRef::New(vm_, RejectCallback);
504     Local<PromiseRef> catchPromise = gitpromise->Finally(vm_, rejectcallback);
505     ASSERT_TRUE(gitpromise->IsPromise(vm_));
506     ASSERT_TRUE(catchPromise->IsPromise(vm_));
507     Local<PromiseRef> catchPromise2 = gitpromise->Then(vm_, rejectcallback, rejectcallback);
508     ASSERT_TRUE(catchPromise2->IsPromise(vm_));
509     Local<FunctionRef> functioncallback = FunctionRef::New(vm_, FunctionCallback);
510     ASSERT_TRUE(!functioncallback.IsEmpty());
511     Local<PromiseRef> catchPromise3 = gitpromise->Then(vm_, functioncallback);
512     ASSERT_TRUE(catchPromise3->IsPromise(vm_));
513 }
514 
515 /**
516  * @tc.number: ffi_interface_api_067
517  * @tc.name: IsBuffer
518  * @tc.desc: Construct a BufferRef function to determine whether it is a Buffer
519  * @tc.type: FUNC
520  * @tc.require:  parameter
521  */
HWTEST_F_L0(JSNApiTests,IsBuffer)522 HWTEST_F_L0(JSNApiTests, IsBuffer)
523 {
524     LocalScope scope(vm_);
525     const int32_t length = 15;
526     Local<BufferRef> buffer = BufferRef::New(vm_, length);
527     ASSERT_TRUE(buffer->IsBuffer(vm_));
528 }
529 
530 /**
531  * @tc.number: ffi_interface_api_068
532  * @tc.name: IsDataView
533  * @tc.desc: Construct a BufferRef function to determine whether it is a dataView
534  * @tc.type: FUNC
535  * @tc.require:  parameter
536  */
HWTEST_F_L0(JSNApiTests,IsDataView)537 HWTEST_F_L0(JSNApiTests, IsDataView)
538 {
539     LocalScope scope(vm_);
540     const int32_t length = 15;
541     Local<ArrayBufferRef> arrayBuffer = ArrayBufferRef::New(vm_, length);
542     Local<DataViewRef> dataView = DataViewRef::New(vm_, arrayBuffer, 5, 7);
543     ASSERT_TRUE(dataView->IsDataView(vm_));
544 }
545 
546 /**
547  * @tc.number: ffi_interface_api_071
548  * @tc.name: IsSharedArrayBuffer
549  * @tc.desc: Construct a BufferRef function to determine whether it is a SharedArrayBuffer
550  * @tc.type: FUNC
551  * @tc.require:  parameter
552  */
HWTEST_F_L0(JSNApiTests,IsSharedArrayBuffer)553 HWTEST_F_L0(JSNApiTests, IsSharedArrayBuffer)
554 {
555     LocalScope scope(vm_);
556     const int32_t length = 15;
557     Local<JSValueRef> sharedArrayBuffer = ArrayBufferRef::New(vm_, length);
558     ASSERT_FALSE(sharedArrayBuffer->IsSharedArrayBuffer(vm_));
559 }
560 
561 
562 /**
563  * @tc.number: ffi_interface_api_072
564  * @tc.name: IsTrue
565  * @tc.desc: Construct a BufferRef function to determine whether it is a IsTrue
566  * @tc.type: FUNC
567  * @tc.require:  parameter
568  */
HWTEST_F_L0(JSNApiTests,IsTrue)569 HWTEST_F_L0(JSNApiTests, IsTrue)
570 {
571     LocalScope scope(vm_);
572     Local<JSValueRef> b = JSValueRef::True(vm_);
573     ASSERT_TRUE(b->IsTrue());
574 }
575 
576 
577 /**
578  * @tc.number: ffi_interface_api_073
579  * @tc.name: IsFalse
580  * @tc.desc: Construct a BufferRef function to determine whether it is a IsFalse
581  * @tc.type: FUNC
582  * @tc.require:  parameter
583  */
HWTEST_F_L0(JSNApiTests,IsFalse)584 HWTEST_F_L0(JSNApiTests, IsFalse)
585 {
586     LocalScope scope(vm_);
587     Local<JSValueRef> c = JSValueRef::False(vm_);
588     ASSERT_TRUE(c->IsFalse());
589 }
590 
591 /**
592  * @tc.number: ffi_interface_api_074
593  * @tc.name: IsConstructor
594  * @tc.desc: Construct a BufferRef function to determine whether it is a Constructor
595  * @tc.require:  parameter
596  */
HWTEST_F_L0(JSNApiTests,IsConstructor)597 HWTEST_F_L0(JSNApiTests, IsConstructor)
598 {
599     LocalScope scope(vm_);
600     Local<FunctionRef> target = FunctionRef::New(vm_, FunctionCallback);
601     ASSERT_FALSE(target->IsConstructor(vm_));
602 }
603 
604 
605 /**
606  * @tc.number: ffi_interface_api_076
607  * @tc.name: GetOwnProperty
608  * @tc.desc: Construct a BufferRef function to determine whether it is a GetOwnProperty  not Construct function
609  * @tc.type: FUNC
610  * @tc.require:  parameter
611  */
HWTEST_F_L0(JSNApiTests,GetOwnProperty)612 HWTEST_F_L0(JSNApiTests, GetOwnProperty)
613 {
614     LocalScope scope(vm_);
615     Local<ObjectRef> object = ObjectRef::New(vm_);
616     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, TEST_KEY);
617     Local<JSValueRef> value = ObjectRef::New(vm_);
618     PropertyAttribute attribute(value, true, true, true);
619 
620     ASSERT_TRUE(object->DefineProperty(vm_, key, attribute));
621     Local<JSValueRef> value1 = object->Get(vm_, key);
622     ASSERT_TRUE(value->IsStrictEquals(vm_, value1));
623 }
624 
625 /**
626  * @tc.number: ffi_interface_api_078
627  * @tc.name: IsTreeMap
628  * @tc.desc: Used to verify whether the given object is a TreeMap.
629  * @tc.type: FUNC
630  * @tc.require:  parameter
631  */
HWTEST_F_L0(JSNApiTests,JSValueRef_IsTreeMap)632 HWTEST_F_L0(JSNApiTests, JSValueRef_IsTreeMap)
633 {
634     LocalScope scope(vm_);
635     JSThread *thread = vm_->GetJSThread();
636     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
637     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
638     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
639     JSHandle<JSHClass> mapClass = factory->NewEcmaHClass(JSAPITreeMap::SIZE, JSType::JS_API_TREE_MAP, proto);
640     JSHandle<JSAPITreeMap> jsTreeMap = JSHandle<JSAPITreeMap>::Cast(factory->NewJSObjectWithInit(mapClass));
641     JSHandle<TaggedTreeMap> treeMap(thread, TaggedTreeMap::Create(thread));
642     jsTreeMap->SetTreeMap(thread, treeMap);
643     JSHandle<JSTaggedValue> argumentTag = JSHandle<JSTaggedValue>::Cast(jsTreeMap);
644     Local<JSValueRef> TreeMap = JSNApiHelper::ToLocal<JSAPITreeSet>(argumentTag);
645     EXPECT_TRUE(TreeMap->IsTreeMap(vm_));
646 }
647 
648 /**
649  * @tc.number: ffi_interface_api_079
650  * @tc.name: IsTreeSet
651  * @tc.desc: Used to verify whether the given object is a TreeSet.
652  * @tc.type: FUNC
653  * @tc.require:  parameter
654  */
HWTEST_F_L0(JSNApiTests,JSValueRef_IsTreeSet)655 HWTEST_F_L0(JSNApiTests, JSValueRef_IsTreeSet)
656 {
657     LocalScope scope(vm_);
658     JSThread *thread = vm_->GetJSThread();
659     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
660     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
661     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
662     JSHandle<JSHClass> setClass = factory->NewEcmaHClass(JSAPITreeSet::SIZE, JSType::JS_API_TREE_SET, proto);
663     JSHandle<JSAPITreeSet> jsTreeSet = JSHandle<JSAPITreeSet>::Cast(factory->NewJSObjectWithInit(setClass));
664     JSHandle<TaggedTreeSet> treeSet(thread, TaggedTreeSet::Create(thread));
665     jsTreeSet->SetTreeSet(thread, treeSet);
666     JSHandle<JSTaggedValue> argumentTag = JSHandle<JSTaggedValue>::Cast(jsTreeSet);
667     Local<JSValueRef> TreeSet = JSNApiHelper::ToLocal<JSAPITreeSet>(argumentTag);
668     EXPECT_TRUE(TreeSet->IsTreeSet(vm_));
669 }
670 
671 /**
672  * @tc.number: ffi_interface_api_080
673  * @tc.name: IsVector
674  * @tc.desc: Used to verify whether the given object is a Vector.
675  * @tc.type: FUNC
676  * @tc.require:  parameter
677  */
HWTEST_F_L0(JSNApiTests,JSValueRef_IsVector)678 HWTEST_F_L0(JSNApiTests, JSValueRef_IsVector)
679 {
680     LocalScope scope(vm_);
681     JSThread *thread = vm_->GetJSThread();
682     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
683     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
684     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
685     JSHandle<JSHClass> vectorClass = factory->NewEcmaHClass(JSAPIVector::SIZE, JSType::JS_API_VECTOR, proto);
686     JSHandle<JSAPIVector> jsVector = JSHandle<JSAPIVector>::Cast(factory->NewJSObjectWithInit(vectorClass));
687     jsVector->SetLength(0);
688     JSHandle<JSTaggedValue> argumentTag = JSHandle<JSTaggedValue>::Cast(jsVector);
689     Local<JSValueRef> Vector = JSNApiHelper::ToLocal<JSAPIVector>(argumentTag);
690     EXPECT_TRUE(Vector->IsVector(vm_));
691 }
692 
693 /**
694  * @tc.number: ffi_interface_api_081
695  * @tc.name: IsJSArray
696  * @tc.desc: Used to verify whether the given object is a JSArray.
697  * @tc.type: FUNC
698  * @tc.require:  parameter
699  */
HWTEST_F_L0(JSNApiTests,JSValueRef_IsJSArray)700 HWTEST_F_L0(JSNApiTests, JSValueRef_IsJSArray)
701 {
702     LocalScope scope(vm_);
703     JSHandle<JSTaggedValue> jsArrayTag = JSArray::ArrayCreate(vm_->GetJSThread(), JSTaggedNumber(0));
704     Local<JSValueRef> jsArray = JSNApiHelper::ToLocal<JSTypedArray>(jsArrayTag);
705     EXPECT_TRUE(jsArray->IsJSArray(vm_));
706     Local<JSValueRef> array = JSNApiHelper::ToLocal<ArrayRef>(jsArrayTag);
707     EXPECT_TRUE(array->IsArray(vm_));
708 }
709 
710 /**
711  * @tc.number: ffi_interface_api_082
712  * @tc.name: IsMap
713  * @tc.desc: Used to verify whether the given object is a map container.
714  * @tc.type: FUNC
715  * @tc.require:  parameter
716  */
HWTEST_F_L0(JSNApiTests,JSValueRef_IsMap)717 HWTEST_F_L0(JSNApiTests, JSValueRef_IsMap)
718 {
719     LocalScope scope(vm_);
720     Local<MapRef> map = MapRef::New(vm_);
721     EXPECT_TRUE(map->IsMap(vm_));
722 }
723 
724 /**
725  * @tc.number: ffi_interface_api_083
726  * @tc.name: IsSet
727  * @tc.desc: Used to verify whether the given object is a Set container.
728  * @tc.type: FUNC
729  * @tc.require:  parameter
730  */
HWTEST_F_L0(JSNApiTests,SetRef_IsSet)731 HWTEST_F_L0(JSNApiTests, SetRef_IsSet)
732 {
733     LocalScope scope(vm_);
734     JSThread *thread = vm_->GetJSThread();
735     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
736     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
737     JSHandle<JSTaggedValue> constructor = env->GetBuiltinsSetFunction();
738     JSHandle<JSSet> set =
739         JSHandle<JSSet>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), constructor));
740     JSHandle<LinkedHashSet> hashSet = LinkedHashSet::Create(thread);
741     set->SetLinkedSet(thread, hashSet);
742     JSHandle<JSTaggedValue> setTag = JSHandle<JSTaggedValue>::Cast(set);
743     Local<SetRef> Set = JSNApiHelper::ToLocal<SetRef>(setTag);
744     EXPECT_TRUE(Set->IsSet(vm_));
745 }
746 
747 /**
748  * @tc.number: ffi_interface_api_084
749  * @tc.name: ObjectRef_NEW
750  * @tc.desc: Creating a new Object Ref object is not NULL if successfully created.
751  * @tc.type: FUNC
752  * @tc.require:  parameter
753  */
HWTEST_F_L0(JSNApiTests,ObjectRef_NEW)754 HWTEST_F_L0(JSNApiTests, ObjectRef_NEW)
755 {
756     LocalScope scope(vm_);
757     Local<ObjectRef> object = ObjectRef::New(vm_);
758     ASSERT_FALSE(object.IsNull());
759 }
760 
761 /**
762  * @tc.number: ffi_interface_api_085
763  * @tc.name: IsFalse
764  * @tc.desc: Used to verify whether the given object is false.
765  * @tc.type: FUNC
766  * @tc.require:  parameter
767  */
HWTEST_F_L0(JSNApiTests,JSNAPI_IsFalse)768 HWTEST_F_L0(JSNApiTests, JSNAPI_IsFalse)
769 {
770     LocalScope scope(vm_);
771     Local<PrimitiveRef> res = JSValueRef::False(vm_);
772     EXPECT_TRUE(res->IsFalse());
773 }
774 
775 /**
776  * @tc.number: ffi_interface_api_086
777  * @tc.name: GetDescription
778  * @tc.desc: Used to verify whether the object used to obtain descriptive information was successful.
779  * @tc.type: FUNC
780  * @tc.require:  parameter
781  */
HWTEST_F_L0(JSNApiTests,SymbolRef_GetDescription)782 HWTEST_F_L0(JSNApiTests, SymbolRef_GetDescription)
783 {
784     LocalScope scope(vm_);
785     Local<StringRef> description = StringRef::NewFromUtf8(vm_, "test");
786     Local<SymbolRef> symbol = SymbolRef::New(vm_, description);
787     Local<StringRef> desc = symbol->GetDescription(vm_);
788     EXPECT_EQ(description->ToString(vm_), desc->ToString(vm_));
789     EXPECT_FALSE(symbol.IsNull());
790     EXPECT_FALSE(description.IsEmpty());
791 }
792 
793 /**
794  * @tc.number: ffi_interface_api_087
795  * @tc.name: ArrayRefNew_uint32Length_SetValueAt_GetValueAt
796  * @tc.desc: Used to verify whether obtaining the length of the array, setting the value of the specified
797  * index position of the array, and obtaining the value of the specified index position of the
798  * array were successful
799  * @tc.type: FUNC
800  * @tc.require:  parameter
801  */
HWTEST_F_L0(JSNApiTests,ArrayRefNew_uint32Length_SetValueAt_GetValueAt)802 HWTEST_F_L0(JSNApiTests, ArrayRefNew_uint32Length_SetValueAt_GetValueAt)
803 {
804     LocalScope scope(vm_);
805     Local<ObjectRef> globalObject = JSNApi::GetGlobalObject(vm_);
806     ASSERT_FALSE(globalObject.IsEmpty());
807     ASSERT_TRUE(globalObject->IsObject(vm_));
808     Local<ArrayRef> property = ArrayRef::New(vm_, 3); // 3 : length
809     ASSERT_TRUE(property->IsArray(vm_));
810     ASSERT_EQ(property->Length(vm_), 3); // 3 : test case of input
811     uint32_t index = 1;
812     Local<JSValueRef> value = ObjectRef::New(vm_);
813     bool result = property->SetValueAt(vm_, globalObject, index, value);
814     ASSERT_TRUE(result);
815     Local<JSValueRef> value1 = property->GetValueAt(vm_, globalObject, index);
816     ASSERT_FALSE(value1.IsNull());
817 }
818 
819 /**
820  * @tc.number: ffi_interface_api_088
821  * @tc.name: WeakSetRef_GetSize_GetTotalElements_GetValue
822  * @tc.desc: Used to verify whether the size of the weakset for obtaining settings, the total number of
823  * elements obtained, and the value of the specified index position obtained were successful
824  * @tc.type: FUNC
825  * @tc.require:  parameter
826  */
HWTEST_F_L0(JSNApiTests,WeakSetRef_GetSize_GetTotalElements_GetValue)827 HWTEST_F_L0(JSNApiTests, WeakSetRef_GetSize_GetTotalElements_GetValue)
828 {
829     LocalScope scope(vm_);
830     JSThread *thread = vm_->GetJSThread();
831     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
832     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
833     JSHandle<JSTaggedValue> constructor = env->GetBuiltinsWeakSetFunction();
834     JSHandle<JSWeakSet> weakSet =
835         JSHandle<JSWeakSet>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), constructor));
836     JSHandle<LinkedHashSet> hashSet = LinkedHashSet::Create(thread);
837     weakSet->SetLinkedSet(thread, hashSet);
838     JSHandle<JSTaggedValue> weakSetTag = JSHandle<JSTaggedValue>::Cast(weakSet);
839     Local<JSValueRef> set1 = JSNApiHelper::ToLocal<WeakSetRef>(weakSetTag);
840     EXPECT_TRUE(set1->IsWeakSet(vm_));
841     Local<WeakSetRef> set = JSNApiHelper::ToLocal<WeakSetRef>(weakSetTag);
842     JSHandle<JSTaggedValue> value(factory->NewFromASCII("value"));
843     JSWeakSet::Add(thread, weakSet, value);
844     int32_t num = set->GetSize(vm_);
845     int32_t num1 = set->GetTotalElements(vm_);
846     ASSERT_EQ(num, 1);
847     ASSERT_EQ(num1, 1);
848     Local<JSValueRef> res2 = set->GetValue(vm_, 0);
849     ASSERT_EQ(res2->ToString(vm_)->ToString(vm_), "value");
850 }
851 
852 /**
853  * @tc.number: ffi_interface_api_089
854  * @tc.name: GetOwnPropertyNames
855  * @tc.desc: An array of self owned property names used to validate the acquisition of objects.
856  * @tc.type: FUNC
857  * @tc.require:  parameter
858  */
HWTEST_F_L0(JSNApiTests,ObjectRef_GetOwnPropertyNames)859 HWTEST_F_L0(JSNApiTests, ObjectRef_GetOwnPropertyNames)
860 {
861     LocalScope scope(vm_);
862     Local<ObjectRef> object = ObjectRef::New(vm_);
863     Local<ArrayRef> res = object->GetOwnPropertyNames(vm_);
864     EXPECT_TRUE(res->IsArray(vm_));
865 }
866 
867 /**
868  * @tc.number: ffi_interface_api_090
869  * @tc.name: SetBundle
870  * @tc.desc: Used to verify whether the initialization resource package was successfully set.
871  * @tc.type: FUNC
872  * @tc.require:  parameter
873  */
HWTEST_F_L0(JSNApiTests,SetBundle)874 HWTEST_F_L0(JSNApiTests, SetBundle)
875 {
876     LocalScope scope(vm_);
877     bool value = true;
878     JSNApi::SetBundle(vm_, value);
879     bool res = JSNApi::IsBundle(vm_);
880     EXPECT_TRUE(res);
881 }
882 
883 /**
884  * @tc.number: ffi_interface_api_091
885  * @tc.name: SetMockModuleList
886  * @tc.desc: Used to verify whether the function of setting the map container module was successful.
887  * @tc.type: FUNC
888  * @tc.require:  parameter
889  */
HWTEST_F_L0(JSNApiTests,JSNApi_SetMockModuleList)890 HWTEST_F_L0(JSNApiTests, JSNApi_SetMockModuleList)
891 {
892     LocalScope scope(vm_);
893     std::map<std::string, std::string> str = { { TEST_NUM1, TEST_NUM2 } };
894     JSNApi::SetMockModuleList(vm_, str);
895     ASSERT_EQ(std::string(vm_->GetMockModule(TEST_NUM1)), TEST_NUM2);
896 }
897 
898 /**
899  * @tc.number: ffi_interface_api_092
900  * @tc.name: SetSourceMapTranslateCallback
901  * @tc.desc: Whether the source mapping translation callback function used to verify the settings.
902  * was successfully set
903  * @tc.type: FUNC
904  * @tc.require:  parameter
905  */
HWTEST_F_L0(JSNApiTests,JSNAPI_SetSourceMapTranslateCallback)906 HWTEST_F_L0(JSNApiTests, JSNAPI_SetSourceMapTranslateCallback)
907 {
908     LocalScope scope(vm_);
909     SourceMapTranslateCallback tag { nullptr };
910     JSNApi::SetSourceMapTranslateCallback(vm_, tag);
911     SourceMapTranslateCallback cur = vm_->GetSourceMapTranslateCallback();
912     ASSERT_EQ(nullptr, cur);
913 }
914 
915 /**
916  * @tc.number: ffi_interface_api_093
917  * @tc.name: ExecutePendingJob
918  * @tc.desc: Used to verify whether the pending task has been successfully executed.
919  * @tc.type: FUNC
920  * @tc.require:  parameter
921  */
HWTEST_F_L0(JSNApiTests,JSNApi_ExecutePendingJob)922 HWTEST_F_L0(JSNApiTests, JSNApi_ExecutePendingJob)
923 {
924     LocalScope scope(vm_);
925     JSNApi::ExecutePendingJob(vm_);
926     bool res = EcmaVM::ConstCast(vm_)->GetJSThread()->GetCurrentEcmaContext()->ExecutePromisePendingJob();
927     EXPECT_TRUE(res);
928 }
929 
930 /**
931  * @tc.number: ffi_interface_api_096
932  * @tc.name: IsRegExp
933  * @tc.desc: Used to determine whether a given object is a regular expression.
934  * @tc.type: FUNC
935  * @tc.require:  parameter
936  */
HWTEST_F_L0(JSNApiTests,JSValueRef_IsRegExp)937 HWTEST_F_L0(JSNApiTests, JSValueRef_IsRegExp)
938 {
939     LocalScope scope(vm_);
940     JSThread *thread = vm_->GetJSThread();
941     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
942     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
943     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
944     JSHandle<JSHClass> jSRegExpClass = factory->NewEcmaHClass(JSRegExp::SIZE, JSType::JS_REG_EXP, proto);
945     JSHandle<JSRegExp> jSRegExp = JSHandle<JSRegExp>::Cast(factory->NewJSObject(jSRegExpClass));
946     jSRegExp->SetByteCodeBuffer(thread, JSTaggedValue::Undefined());
947     jSRegExp->SetOriginalSource(thread, JSTaggedValue::Undefined());
948     jSRegExp->SetGroupName(thread, JSTaggedValue::Undefined());
949     jSRegExp->SetOriginalFlags(thread, JSTaggedValue(0));
950     jSRegExp->SetLength(0);
951     JSHandle<JSTaggedValue> argumentTag = JSHandle<JSTaggedValue>::Cast(jSRegExp);
952     Local<JSValueRef> regexp = JSNApiHelper::ToLocal<JSRegExp>(argumentTag);
953     EXPECT_TRUE(regexp->IsRegExp(vm_));
954 }
955 
956 /**
957  * @tc.number: ffi_interface_api_097
958  * @tc.name: GetAndClearUncaughtException
959  * @tc.desc: Used to verify the success of obtaining and clearing uncaught exceptions
960  * @tc.type: FUNC
961  * @tc.require:  parameter
962  */
HWTEST_F_L0(JSNApiTests,GetAndClearUncaughtException)963 HWTEST_F_L0(JSNApiTests, GetAndClearUncaughtException)
964 {
965     LocalScope scope(vm_);
966     TryCatch tryCatch(vm_);
967     EXPECT_FALSE(tryCatch.HasCaught());
968     Local<StringRef> message = StringRef::NewFromUtf8(vm_, "ErrorTest");
969     Local<JSValueRef> error = Exception::Error(vm_, message);
970     EXPECT_TRUE(error->IsError(vm_));
971     JSNApi::ThrowException(vm_, error);
972     EXPECT_TRUE(vm_->GetJSThread()->HasPendingException());
973     JSNApi::GetAndClearUncaughtException(vm_);
974     EXPECT_FALSE(vm_->GetJSThread()->HasPendingException());
975 }
976 
977 /**
978  * @tc.number: ffi_interface_api_098
979  * @tc.name: IsJSPrimitiveNumber
980  * @tc.desc: Verify if the given JSValueRef object is a primativenumber.
981  * @tc.type: FUNC
982  * @tc.require:  parameter
983  */
HWTEST_F_L0(JSNApiTests,JSValueRef_IsJSPrimitiveNumber)984 HWTEST_F_L0(JSNApiTests, JSValueRef_IsJSPrimitiveNumber)
985 {
986     LocalScope scope(vm_);
987     ObjectFactory *factory = vm_->GetFactory();
988     JSHandle<JSTaggedValue> jstagvalue;
989     JSHandle<JSPrimitiveRef> jsprimitive = factory->NewJSPrimitiveRef(PrimitiveType::PRIMITIVE_NUMBER, jstagvalue);
990     JSHandle<JSTaggedValue> jspri = JSHandle<JSTaggedValue>::Cast(jsprimitive);
991     Local<JSValueRef> object = JSNApiHelper::ToLocal<JSValueRef>(jspri);
992     EXPECT_FALSE(object->IsJSPrimitiveNumber(vm_));
993 }
994 
995 
996 /**
997  * @tc.number: ffi_interface_api_099
998  * @tc.name: StringUtf16_NewFromUtf16_Length_WriteUtf16_01
999  * @tc.desc:
1000  * NewFromUtf16:Create StringRef in UTF8 format
1001  * WriteUtf16:Write the value of StringRef to char16_ T array buffer, testing Chinese
1002  * @tc.type: FUNC
1003  * @tc.require:  parameter
1004  */
HWTEST_F_L0(JSNApiTests,StringUtf16_NewFromUtf16_Length_WriteUtf16_01)1005 HWTEST_F_L0(JSNApiTests, StringUtf16_NewFromUtf16_Length_WriteUtf16_01)
1006 {
1007     LocalScope scope(vm_);
1008     const char16_t *test = u"年度";
1009     Local<StringRef> testString = StringRef::NewFromUtf16(vm_, test);
1010     EXPECT_EQ(testString->Length(vm_), 2);              // 2 : length of testString("年度")
1011     char16_t buffer[3];                              // 3 : length of testString + 1
1012     EXPECT_EQ(testString->WriteUtf16(vm_, buffer, 2), 2); // 2 : length of testString("年度")
1013     GTEST_LOG_(WARNING) << "年度test =" << buffer;
1014     ASSERT_EQ(buffer[0], u'年');
1015     ASSERT_EQ(buffer[1], u'度');
1016 }
1017 
1018 /**
1019  * @tc.number: ffi_interface_api_100
1020  * @tc.name: StringUtf16_NewFromUtf16_Length_WriteUtf16_01
1021  * @tc.desc: Write the value of StringRef to char16_ T array buffer, testing non Chinese
1022  * @tc.type: FUNC
1023  * @tc.require:  parameter
1024  */
HWTEST_F_L0(JSNApiTests,StringUtf16_NewFromUtf16_Length_WriteUtf16_02)1025 HWTEST_F_L0(JSNApiTests, StringUtf16_NewFromUtf16_Length_WriteUtf16_02)
1026 {
1027     LocalScope scope(vm_);
1028     const char16_t *test = u"hello world!0?";
1029     Local<StringRef> testString = StringRef::NewFromUtf16(vm_, test);
1030 
1031     EXPECT_EQ(testString->Length(vm_), 14);
1032     char16_t buffer[15];                               // 15 : length of testString + 1
1033     EXPECT_EQ(testString->WriteUtf16(vm_, buffer, 14), 14); // 14 : length of testString("hello world!!!")
1034     ASSERT_EQ(buffer[0], u'h');
1035     ASSERT_EQ(buffer[13], u'?');
1036 }
1037 
1038 /**
1039  * @tc.number: ffi_interface_api_101
1040  * @tc.name: SetRef_IsSet_GetSize_GetTotalElements_GetValue
1041  * @tc.desc:
1042  * IsSet:Determine if it is a set container object
1043  * GetSize:Get set length size
1044  * GetTotalElements:Get the total number of set elements
1045  * GetValue:Obtain the element values of the set container according to the following table
1046  * @tc.type: FUNC
1047  * @tc.require:  parameter
1048  */
HWTEST_F_L0(JSNApiTests,SetRef_IsSet_GetSize_GetTotalElements_GetValue)1049 HWTEST_F_L0(JSNApiTests, SetRef_IsSet_GetSize_GetTotalElements_GetValue)
1050 {
1051     LocalScope scope(vm_);
1052     JSThread *thread = vm_->GetJSThread();
1053     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1054     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
1055     JSHandle<JSTaggedValue> constructor = env->GetBuiltinsSetFunction();
1056     JSHandle<JSSet> jsSet =
1057         JSHandle<JSSet>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), constructor));
1058     JSHandle<LinkedHashSet> hashSet = LinkedHashSet::Create(thread);
1059     jsSet->SetLinkedSet(thread, hashSet);
1060     JSHandle<JSTaggedValue> setTag = JSHandle<JSTaggedValue>::Cast(jsSet);
1061     Local<SetRef> set = JSNApiHelper::ToLocal<SetRef>(setTag);
1062     EXPECT_TRUE(set->IsSet(vm_));
1063     JSHandle<JSTaggedValue> fristValue(factory->NewFromASCII("vlue1"));
1064     JSSet::Add(thread, jsSet, fristValue);
1065     JSSet::Add(thread, jsSet, fristValue);
1066     int32_t num = set->GetSize(vm_);
1067     int32_t num1 = set->GetTotalElements(vm_);
1068     ASSERT_EQ(num, 1);
1069     ASSERT_EQ(num1, 1);
1070     JSHandle<JSTaggedValue> secondValue(factory->NewFromASCII("vlue2"));
1071     JSSet::Add(thread, jsSet, secondValue);
1072     num = set->GetSize(vm_);
1073     num1 = set->GetTotalElements(vm_);
1074     ASSERT_EQ(num, 2);
1075     ASSERT_EQ(num1, 2);
1076     Local<JSValueRef> res1 = set->GetValue(vm_, 0);
1077     ASSERT_EQ(res1->ToString(vm_)->ToString(vm_), "vlue1");
1078     Local<JSValueRef> res2 = set->GetValue(vm_, 1);
1079     ASSERT_EQ(res2->ToString(vm_)->ToString(vm_), "vlue2");
1080 }
1081 
CreateJSSet(JSThread * thread)1082 static JSSet *CreateJSSet(JSThread *thread)
1083 {
1084     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1085     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
1086     JSHandle<JSTaggedValue> constructor = env->GetBuiltinsSetFunction();
1087     JSHandle<JSSet> set =
1088         JSHandle<JSSet>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), constructor));
1089     JSHandle<LinkedHashSet> hashSet = LinkedHashSet::Create(thread);
1090     set->SetLinkedSet(thread, hashSet);
1091     return JSSet::Cast(set.GetTaggedValue().GetTaggedObject());
1092 }
1093 
1094 /**
1095  * @tc.number: ffi_interface_api_102
1096  * @tc.name: JSSetIterator_IsSetIterator_GetIndex_GetKind
1097  * @tc.desc:
1098  * IsSetIterator:Determine if it is a set iterator
1099  * GetIndex:Gets the index of the subscript position currently pointed to by the set iterator
1100  * GetKind:Obtain the index type 'key/value/key_and_value' for the set iterator
1101  * @tc.type: FUNC
1102  * @tc.require:  parameter
1103  */
HWTEST_F_L0(JSNApiTests,JSSetIterator_IsSetIterator_GetIndex_GetKind)1104 HWTEST_F_L0(JSNApiTests, JSSetIterator_IsSetIterator_GetIndex_GetKind)
1105 {
1106     LocalScope scope(vm_);
1107     JSThread *thread = vm_->GetJSThread();
1108     JSHandle<JSSet> jsSet(thread, CreateJSSet(thread));
1109     EXPECT_TRUE(*jsSet != nullptr);
1110     JSHandle<JSTaggedValue> jsTagSetIterator =
1111         JSSetIterator::CreateSetIterator(thread, JSHandle<JSTaggedValue>(jsSet), IterationKind::KEY);
1112     JSHandle<JSSetIterator> jsSetIterator1(jsTagSetIterator);
1113     EXPECT_EQ(JSTaggedValue::SameValue(jsSetIterator1->GetIteratedSet(), jsSet->GetLinkedSet()), true);
1114     Local<SetIteratorRef> setIterator = JSNApiHelper::ToLocal<SetIteratorRef>(jsTagSetIterator);
1115     EXPECT_TRUE(setIterator->IsSetIterator(vm_));
1116     EXPECT_EQ(setIterator->GetIndex(), 0U);
1117     Local<JSValueRef> resultKey = StringRef::NewFromUtf8(vm_, "keys");
1118     EXPECT_EQ(setIterator->GetKind(vm_)->ToString(vm_)->ToString(vm_), resultKey->ToString(vm_)->ToString(vm_));
1119 }
1120 
1121 /**
1122  * @tc.number: ffi_interface_api_103
1123  * @tc.name: JSValueRef_IsMapIterator
1124  * @tc.desc: Determine if it is a Map iterator
1125  * @tc.type: FUNC
1126  * @tc.require:  parameter
1127  */
HWTEST_F_L0(JSNApiTests,JSValueRef_IsMapIterator)1128 HWTEST_F_L0(JSNApiTests, JSValueRef_IsMapIterator)
1129 {
1130     LocalScope scope(vm_);
1131     JSThread *thread = vm_->GetJSThread();
1132     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1133     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
1134     JSHandle<JSTaggedValue> constructor = env->GetBuiltinsMapFunction();
1135     JSHandle<JSMap> jsMap =
1136         JSHandle<JSMap>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), constructor));
1137     JSHandle<LinkedHashMap> hashMap = LinkedHashMap::Create(thread);
1138     jsMap->SetLinkedMap(thread, hashMap);
1139     JSHandle<JSTaggedValue> mapTag = JSHandle<JSTaggedValue>::Cast(jsMap);
1140     JSHandle<JSTaggedValue> jsMapIteratorTag =
1141         JSMapIterator::CreateMapIterator(thread, mapTag, IterationKind::KEY_AND_VALUE);
1142     JSHandle<JSMapIterator> jsMapIterator(jsMapIteratorTag);
1143     EXPECT_EQ(JSTaggedValue::SameValue(jsMapIterator->GetIteratedMap(), jsMap->GetLinkedMap()), true);
1144     Local<JSValueRef> mapIterator = JSNApiHelper::ToLocal<MapIteratorRef>(jsMapIteratorTag);
1145     EXPECT_TRUE(mapIterator->IsMapIterator(vm_));
1146 }
1147 
1148 /**
1149  * @tc.number: ffi_interface_api_104
1150  * @tc.name: JSValueRef_IsModuleNamespaceObject
1151  * @tc.desc: Determine if it is a module space object
1152  * @tc.type: FUNC
1153  * @tc.require:  parameter
1154  */
HWTEST_F_L0(JSNApiTests,JSValueRef_IsModuleNamespaceObject)1155 HWTEST_F_L0(JSNApiTests, JSValueRef_IsModuleNamespaceObject)
1156 {
1157     LocalScope scope(vm_);
1158     ObjectFactory *objectFactory = thread_->GetEcmaVM()->GetFactory();
1159     JSHandle<SourceTextModule> module = objectFactory->NewSourceTextModule();
1160     JSHandle<LocalExportEntry> localExportEntry1 = objectFactory->NewLocalExportEntry();
1161     SourceTextModule::AddLocalExportEntry(thread_, module, localExportEntry1, 0, 2);
1162     JSHandle<LocalExportEntry> localExportEntry2 = objectFactory->NewLocalExportEntry();
1163     SourceTextModule::AddLocalExportEntry(thread_, module, localExportEntry2, 1, 2);
1164     JSHandle<TaggedArray> localExportEntries(thread_, module->GetLocalExportEntries());
1165     CString baseFileName = "a.abc";
1166     module->SetEcmaModuleFilenameString(baseFileName);
1167     ModuleManager *moduleManager = thread_->GetCurrentEcmaContext()->GetModuleManager();
1168     moduleManager->AddResolveImportedModule(baseFileName, module.GetTaggedValue());
1169     JSHandle<ModuleNamespace> np =
1170         ModuleNamespace::ModuleNamespaceCreate(thread_, JSHandle<JSTaggedValue>::Cast(module), localExportEntries);
1171     EXPECT_TRUE(ModuleNamespace::PreventExtensions());
1172     JSHandle<JSTaggedValue> moduleNamespaceTag = JSHandle<JSTaggedValue>::Cast(np);
1173     Local<JSValueRef> moduleNamespace = JSNApiHelper::ToLocal<ModuleNamespace>(moduleNamespaceTag);
1174     ASSERT_TRUE(moduleNamespace->IsModuleNamespaceObject(vm_));
1175 }
1176 
1177 
1178 /**
1179  * @tc.number: ffi_interface_api_105
1180  * @tc.name: IsHole
1181  * @tc.desc: Determine if it is a hole
1182  * @tc.type: FUNC
1183  * @tc.require:  parameter
1184  */
HWTEST_F_L0(JSNApiTests,IsHole)1185 HWTEST_F_L0(JSNApiTests, IsHole)
1186 {
1187     LocalScope scope(vm_);
1188     Local<JSValueRef> b = JSValueRef::Hole(vm_);
1189     ASSERT_TRUE(b->IsHole());
1190 }
1191 
1192 
1193 /**
1194  * @tc.number: ffi_interface_api_106
1195  * @tc.name: GetValueDouble
1196  * @tc.desc: Get value double from isNumber
1197  * @tc.type: FUNC
1198  * @tc.require:  parameter
1199  */
HWTEST_F_L0(JSNApiTests,GetValueDouble)1200 HWTEST_F_L0(JSNApiTests, GetValueDouble)
1201 {
1202     LocalScope scope(vm_);
1203     bool isNumber = true;
1204     panda::JSValueRef* nativeValue = new JSValueRef();
1205     ASSERT_FALSE(nativeValue->GetValueDouble(isNumber));
1206     isNumber = false;
1207     ASSERT_FALSE(nativeValue->GetValueDouble(isNumber));
1208 
1209     delete nativeValue;
1210 }
1211 
1212 
1213 /**
1214  * @tc.number: ffi_interface_api_107
1215  * @tc.name: GetValueInt32
1216  * @tc.desc: Get value int32 from isNumber
1217  * @tc.type: FUNC
1218  * @tc.require:  parameter
1219  */
HWTEST_F_L0(JSNApiTests,GetValueInt32)1220 HWTEST_F_L0(JSNApiTests, GetValueInt32)
1221 {
1222     LocalScope scope(vm_);
1223     bool isNumber = true;
1224     panda::JSValueRef* nativeValue = new JSValueRef();
1225     ASSERT_FALSE(nativeValue->GetValueInt32(isNumber));
1226     isNumber = false;
1227     ASSERT_FALSE(nativeValue->GetValueInt32(isNumber));
1228 
1229     delete nativeValue;
1230 }
1231 
1232 
1233 /**
1234  * @tc.number: ffi_interface_api_108
1235  * @tc.name: GetValueUint32
1236  * @tc.desc: Get value uint32 from isNumber
1237  * @tc.type: FUNC
1238  * @tc.require:  parameter
1239  */
HWTEST_F_L0(JSNApiTests,GetValueUint32)1240 HWTEST_F_L0(JSNApiTests, GetValueUint32)
1241 {
1242     LocalScope scope(vm_);
1243     bool isNumber = true;
1244     panda::JSValueRef* nativeValue = new JSValueRef();
1245     ASSERT_FALSE(nativeValue->GetValueUint32(isNumber));
1246     isNumber = false;
1247     ASSERT_FALSE(nativeValue->GetValueUint32(isNumber));
1248 
1249     delete nativeValue;
1250 }
1251 
1252 
1253 /**
1254  * @tc.number: ffi_interface_api_109
1255  * @tc.name: GetValueInt64
1256  * @tc.desc: Get value int64 from isNumber
1257  * @tc.type: FUNC
1258  * @tc.require:  parameter
1259  */
HWTEST_F_L0(JSNApiTests,GetValueInt64)1260 HWTEST_F_L0(JSNApiTests, GetValueInt64)
1261 {
1262     LocalScope scope(vm_);
1263     bool isNumber = true;
1264     panda::JSValueRef* nativeValue = new JSValueRef();
1265     ASSERT_FALSE(nativeValue->GetValueInt64(isNumber));
1266     isNumber = false;
1267     ASSERT_FALSE(nativeValue->GetValueInt64(isNumber));
1268 
1269     delete nativeValue;
1270 }
1271 
1272 
1273 /**
1274  * @tc.number: ffi_interface_api_110
1275  * @tc.name: GetValueBool
1276  * @tc.desc: Get value bool from isNumber
1277  * @tc.type: FUNC
1278  * @tc.require:  parameter
1279  */
HWTEST_F_L0(JSNApiTests,GetValueBool)1280 HWTEST_F_L0(JSNApiTests, GetValueBool)
1281 {
1282     LocalScope scope(vm_);
1283     bool isNumber = true;
1284     panda::JSValueRef* nativeValue = new JSValueRef();
1285     ASSERT_FALSE(nativeValue->GetValueBool(isNumber));
1286     isNumber = false;
1287     ASSERT_FALSE(nativeValue->GetValueBool(isNumber));
1288 
1289     delete nativeValue;
1290 }
1291 
1292 
1293 /**
1294  * @tc.number: ffi_interface_api_111
1295  * @tc.name: ToBigInt
1296  * @tc.desc: String to big int
1297  * @tc.type: FUNC
1298  * @tc.require:  parameter
1299  */
HWTEST_F_L0(JSNApiTests,ToBigInt)1300 HWTEST_F_L0(JSNApiTests, ToBigInt)
1301 {
1302     LocalScope scope(vm_);
1303     Local<StringRef> toString = StringRef::NewFromUtf8(vm_, TEST_NUM2);
1304     Local<JSValueRef> toValue(toString);
1305     EXPECT_FALSE(toValue->ToBigInt(vm_)->IsBigInt(vm_));
1306 }
1307 
1308 
1309 /**
1310  * @tc.number: ffi_interface_api_112
1311  * @tc.name: IsInt && WithinInt32
1312  * @tc.desc: Determine if it is int && Within Int32
1313  * @tc.type: FUNC
1314  * @tc.require:  parameter
1315  */
HWTEST_F_L0(JSNApiTests,IsInt)1316 HWTEST_F_L0(JSNApiTests, IsInt)
1317 {
1318     LocalScope scope(vm_);
1319     bool input = true;
1320     Local<IntegerRef> res = IntegerRef::New(vm_, input);
1321     EXPECT_TRUE(res->IsInt());
1322     EXPECT_TRUE(res->WithinInt32());
1323 }
1324 
1325 
1326 /**
1327  * @tc.number: ffi_interface_api_113
1328  * @tc.name: IsJSFunction
1329  * @tc.desc: Determine if it is JSFunction
1330  * @tc.type: FUNC
1331  * @tc.require:  parameter
1332  */
HWTEST_F_L0(JSNApiTests,IsJSFunction)1333 HWTEST_F_L0(JSNApiTests, IsJSFunction)
1334 {
1335     LocalScope scope(vm_);
1336     bool input = true;
1337     Local<FunctionRef> res = IntegerRef::New(vm_, input);
1338     EXPECT_FALSE(res->IsJSFunction(vm_));
1339 }
1340 
1341 
1342 /**
1343  * @tc.number: ffi_interface_api_114
1344  * @tc.name: IsWeakRef
1345  * @tc.desc: Determine if it is JSFunction
1346  * @tc.type: FUNC
1347  * @tc.require:  parameter
1348  */
HWTEST_F_L0(JSNApiTests,IsWeakRef)1349 HWTEST_F_L0(JSNApiTests, IsWeakRef)
1350 {
1351     LocalScope scope(vm_);
1352     Local<JSValueRef> tag = BooleanRef::New(vm_, true);
1353     EXPECT_FALSE(tag->IsWeakRef(vm_));
1354 }
1355 
1356 
1357 /**
1358  * @tc.number: ffi_interface_api_115
1359  * @tc.name: IsArrayIterator
1360  * @tc.desc: Determine if it is arrayIterator
1361  * @tc.type: FUNC
1362  * @tc.require:  parameter
1363  */
HWTEST_F_L0(JSNApiTests,IsArrayIterator)1364 HWTEST_F_L0(JSNApiTests, IsArrayIterator)
1365 {
1366     LocalScope scope(vm_);
1367     Local<JSValueRef> tag = ArrayRef::New(vm_, true);
1368     EXPECT_FALSE(tag->IsArrayIterator(vm_));
1369 }
1370 
1371 
1372 /**
1373  * @tc.number: ffi_interface_api_116
1374  * @tc.name: IsStringIterator
1375  * @tc.desc: Determine if it is string Iterator
1376  * @tc.type: FUNC
1377  * @tc.require:  parameter
1378  */
HWTEST_F_L0(JSNApiTests,IsStringIterator)1379 HWTEST_F_L0(JSNApiTests, IsStringIterator)
1380 {
1381     LocalScope scope(vm_);
1382     Local<StringRef> toString = StringRef::NewFromUtf8(vm_, TEST_NUM2);
1383     EXPECT_FALSE(toString->IsStringIterator(vm_));
1384     std::string str = TEST_NUM2;
1385     EXPECT_EQ(toString->DebuggerToString(vm_), str);
1386 }
1387 
1388 
1389 /**
1390  * @tc.number: ffi_interface_api_116
1391  * @tc.name: IsJSSharedInt8Array
1392  * @tc.desc: Determine if it is JSSharedArray
1393  * @tc.type: FUNC
1394  * @tc.require:  parameter
1395  */
HWTEST_F_L0(JSNApiTests,IsJSSharedInt8Array)1396 HWTEST_F_L0(JSNApiTests, IsJSSharedInt8Array)
1397 {
1398     LocalScope scope(vm_);
1399     Local<JSValueRef> tag = ArrayRef::New(vm_, true);
1400     EXPECT_FALSE(tag->IsJSSharedInt8Array(vm_));
1401     EXPECT_FALSE(tag->IsJSSharedUint8Array(vm_));
1402     EXPECT_FALSE(tag->IsJSSharedUint8ClampedArray(vm_));
1403     EXPECT_FALSE(tag->IsJSSharedInt16Array(vm_));
1404     EXPECT_FALSE(tag->IsJSSharedUint16Array(vm_));
1405     EXPECT_FALSE(tag->IsJSSharedInt32Array(vm_));
1406     EXPECT_FALSE(tag->IsJSSharedFloat32Array(vm_));
1407     EXPECT_FALSE(tag->IsJSSharedUint32Array(vm_));
1408 }
1409 
1410 
1411 /**
1412  * @tc.number: ffi_interface_api_117
1413  * @tc.name: IsNativeModuleFailureInfoObject
1414  * @tc.desc: Determine if it is nativeModuleFailureInfoObject
1415  * @tc.type: FUNC
1416  * @tc.require:  parameter
1417  */
HWTEST_F_L0(JSNApiTests,IsNativeModuleFailureInfoObject)1418 HWTEST_F_L0(JSNApiTests, IsNativeModuleFailureInfoObject)
1419 {
1420     LocalScope scope(vm_);
1421     Local<JSValueRef> tag = ArrayRef::New(vm_, true);
1422     EXPECT_FALSE(tag->IsNativeModuleFailureInfoObject(vm_));
1423     EXPECT_FALSE(tag->IsSendableArrayBuffer(vm_));
1424     EXPECT_FALSE(tag->IsJSLocale(vm_));
1425     EXPECT_FALSE(tag->IsJSDateTimeFormat(vm_));
1426     EXPECT_FALSE(tag->IsJSRelativeTimeFormat(vm_));
1427     EXPECT_FALSE(tag->IsJSIntl(vm_));
1428     EXPECT_FALSE(tag->IsJSNumberFormat(vm_));
1429     EXPECT_FALSE(tag->IsJSCollator(vm_));
1430     EXPECT_FALSE(tag->IsJSPluralRules(vm_));
1431     EXPECT_FALSE(tag->IsJSListFormat(vm_));
1432     EXPECT_FALSE(tag->IsAsyncGeneratorObject(vm_));
1433 }
1434 
1435 
1436 /**
1437  * @tc.number: ffi_interface_api_118
1438  * @tc.name: IsAsyncGeneratorObject
1439  * @tc.desc: Determine if it is asyncGeneratorObject
1440  * @tc.type: FUNC
1441  * @tc.require:  parameter
1442  */
HWTEST_F_L0(JSNApiTests,IsAsyncGeneratorObject)1443 HWTEST_F_L0(JSNApiTests, IsAsyncGeneratorObject)
1444 {
1445     LocalScope scope(vm_);
1446     Local<JSValueRef> tag = ArrayRef::New(vm_, true);
1447     EXPECT_FALSE(tag->IsAsyncGeneratorObject(vm_));
1448     EXPECT_FALSE(tag->IsArrayList(vm_));
1449     EXPECT_FALSE(tag->IsDeque(vm_));
1450     EXPECT_FALSE(tag->IsHashMap(vm_));
1451     EXPECT_FALSE(tag->IsHashSet(vm_));
1452     EXPECT_FALSE(tag->IsLightWeightMap(vm_));
1453     EXPECT_FALSE(tag->IsLightWeightSet(vm_));
1454     EXPECT_FALSE(tag->IsLinkedList(vm_));
1455     EXPECT_FALSE(tag->IsLinkedListIterator(vm_));
1456     EXPECT_FALSE(tag->IsList(vm_));
1457     EXPECT_FALSE(tag->IsPlainArray(vm_));
1458     EXPECT_FALSE(tag->IsQueue(vm_));
1459     EXPECT_FALSE(tag->IsStack(vm_));
1460 }
1461 
1462 
1463 /**
1464  * @tc.number: ffi_interface_api_119
1465  * @tc.name: IsSendableObject
1466  * @tc.desc: Determine if it is sendableObject
1467  * @tc.type: FUNC
1468  * @tc.require:  parameter
1469  */
HWTEST_F_L0(JSNApiTests,IsSendableObject)1470 HWTEST_F_L0(JSNApiTests, IsSendableObject)
1471 {
1472     LocalScope scope(vm_);
1473     Local<JSValueRef> value = ObjectRef::New(vm_);
1474     EXPECT_FALSE(value->IsSendableObject(vm_));
1475     EXPECT_FALSE(value->IsJSShared(vm_));
1476     EXPECT_FALSE(value->IsSharedArray(vm_));
1477     EXPECT_FALSE(value->IsSharedTypedArray(vm_));
1478     EXPECT_FALSE(value->IsSharedSet(vm_));
1479     EXPECT_FALSE(value->IsSharedMap(vm_));
1480     EXPECT_FALSE(value->IsSharedMapIterator(vm_));
1481     EXPECT_TRUE(value->IsHeapObject());
1482 }
1483 
1484 
1485 /**
1486  * @tc.number: ffi_interface_api_120
1487  * @tc.name: GetNativePointerValue
1488  * @tc.desc: GetNativePointerValue
1489  * @tc.type: FUNC
1490  * @tc.require:  parameter
1491  */
HWTEST_F_L0(JSNApiTests,GetNativePointerValue)1492 HWTEST_F_L0(JSNApiTests, GetNativePointerValue)
1493 {
1494     LocalScope scope(vm_);
1495     Local<JSValueRef> value = ObjectRef::New(vm_);
1496     bool isNativePointer = true;
1497     EXPECT_FALSE(value->GetNativePointerValue(vm_, isNativePointer));
1498 }
1499 
1500 
1501 /**
1502  * @tc.number: ffi_interface_api_121
1503  * @tc.name: IsDetachedArraybuffer
1504  * @tc.desc: IsDetachedArraybuffer
1505  * @tc.type: FUNC
1506  * @tc.require:  parameter
1507  */
HWTEST_F_L0(JSNApiTests,IsDetachedArraybuffer)1508 HWTEST_F_L0(JSNApiTests, IsDetachedArraybuffer)
1509 {
1510     LocalScope scope(vm_);
1511     const int32_t length = 15;
1512     Local<JSValueRef> sharedArrayBuffer = ArrayBufferRef::New(vm_, length);
1513     bool isNativePointer = true;
1514     EXPECT_FALSE(sharedArrayBuffer->IsDetachedArraybuffer(vm_, isNativePointer));
1515     sharedArrayBuffer->DetachedArraybuffer(vm_, isNativePointer);
1516     EXPECT_TRUE(isNativePointer);
1517 }
1518 
1519 
1520 /**
1521  * @tc.number: ffi_interface_api_122
1522  * @tc.name: MapRefGet
1523  * @tc.desc: MapRef Get
1524  * @tc.type: FUNC
1525  * @tc.require:  parameter
1526  */
HWTEST_F_L0(JSNApiTests,MapRefGet)1527 HWTEST_F_L0(JSNApiTests, MapRefGet)
1528 {
1529     LocalScope scope(vm_);
1530     Local<MapRef> object = MapRef::New(vm_);
1531     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, TEST_KEY);
1532     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, TEST_VALUE);
1533     EXPECT_FALSE(object->Has(vm_, key));
1534     object->Set(vm_, key, value);
1535     EXPECT_TRUE(object->Has(vm_, key));
1536     Local<JSValueRef> mapRef = object->Get(vm_, TEST_KEY);
1537     EXPECT_FALSE(object->Has(vm_, mapRef));
1538     object->Delete(vm_, key);
1539     object->GetEntries(vm_);
1540     object->GetKeys(vm_);
1541     object->GetValues(vm_);
1542     EXPECT_FALSE(object->Has(vm_, TEST_KEY));
1543     object->Clear(vm_);
1544 }
1545 
1546 
1547 /**
1548  * @tc.number: ffi_interface_api_123
1549  * @tc.name: SendableMapRef
1550  * @tc.desc: SendableMapRef test
1551  * @tc.type: FUNC
1552  * @tc.require:  parameter
1553  */
HWTEST_F_L0(JSNApiTests,SendableMapRef)1554 HWTEST_F_L0(JSNApiTests, SendableMapRef)
1555 {
1556     LocalScope scope(vm_);
1557     Local<SendableMapRef> object = SendableMapRef::New(vm_);
1558     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, TEST_KEY);
1559     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, TEST_VALUE);
1560     EXPECT_FALSE(object->Has(vm_, key));
1561     object->Set(vm_, key, value);
1562     object->Set(vm_, TEST_KEY, value);
1563     EXPECT_TRUE(object->Has(vm_, key));
1564     Local<JSValueRef> sendableMapRef = object->Get(vm_, TEST_KEY);
1565     sendableMapRef = object->Get(vm_, key);
1566     EXPECT_FALSE(object->Has(vm_, sendableMapRef));
1567     Local<SendableMapIteratorRef> sendableMapIteratorRef = object->GetEntries(vm_);
1568     sendableMapIteratorRef->Next(vm_);
1569     object->GetKey(vm_, 0);
1570     object->GetKeys(vm_);
1571     object->GetValue(vm_, 0);
1572     object->GetValues(vm_);
1573     object->GetSize(vm_);
1574     object->GetTotalElements(vm_);
1575     EXPECT_TRUE(object->Has(vm_, TEST_KEY));
1576     object->Delete(vm_, key);
1577     object->Clear(vm_);
1578 }
1579 
1580 
1581 /**
1582  * @tc.number: ffi_interface_api_124
1583  * @tc.name: MapIteratorRef
1584  * @tc.desc: MapIteratorRef test
1585  * @tc.type: FUNC
1586  * @tc.require:  parameter
1587  */
HWTEST_F_L0(JSNApiTests,MapIteratorRef)1588 HWTEST_F_L0(JSNApiTests, MapIteratorRef)
1589 {
1590     LocalScope scope(vm_);
1591     Local<MapRef> mapRef = MapRef::New(vm_);
1592     Local<MapIteratorRef> object = MapIteratorRef::New(vm_, mapRef);
1593     Local<JSValueRef> key = StringRef::NewFromUtf8(vm_, TEST_KEY);
1594     Local<JSValueRef> value = StringRef::NewFromUtf8(vm_, TEST_VALUE);
1595     EXPECT_FALSE(object->Has(vm_, key));
1596     ecmascript::EcmaRuntimeCallInfo *ecmaRuntimeCallInfo = object->GetEcmaRuntimeCallInfo(vm_);
1597     object->Next(vm_, ecmaRuntimeCallInfo);
1598     object->Next(vm_);
1599     object->Set(vm_, key, value);
1600     object->Set(vm_, TEST_KEY, value);
1601     EXPECT_TRUE(object->Has(vm_, key));
1602     Local<JSValueRef> mapIteratorRef = object->Get(vm_, TEST_KEY);
1603     mapIteratorRef = object->Get(vm_, key);
1604     object->Delete(vm_, key);
1605     EXPECT_FALSE(object->Has(vm_, mapIteratorRef));
1606 }
1607 
1608 
1609 /**
1610  * @tc.number: ffi_interface_api_125
1611  * @tc.name: SetIteratorRef
1612  * @tc.desc: SetIteratorRef test
1613  * @tc.type: FUNC
1614  * @tc.require:  parameter
1615  */
HWTEST_F_L0(JSNApiTests,SetIteratorRef)1616 HWTEST_F_L0(JSNApiTests, SetIteratorRef)
1617 {
1618     LocalScope scope(vm_);
1619     JSThread *thread = vm_->GetJSThread();
1620     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1621     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
1622     JSHandle<JSTaggedValue> constructor = env->GetBuiltinsSetFunction();
1623     JSHandle<JSSet> set =
1624         JSHandle<JSSet>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), constructor));
1625     JSHandle<LinkedHashSet> hashSet = LinkedHashSet::Create(thread);
1626     set->SetLinkedSet(thread, hashSet);
1627     JSHandle<JSTaggedValue> setTag = JSHandle<JSTaggedValue>::Cast(set);
1628     Local<SetRef> setRef = JSNApiHelper::ToLocal<SetRef>(setTag);
1629     Local<MapIteratorRef> object = SetIteratorRef::New(vm_, setRef);
1630     EXPECT_TRUE(object->IsHeapObject());
1631 }
1632 
1633 
1634 /**
1635  * @tc.number: ffi_interface_api_126
1636  * @tc.name: PromiseRejectInfo
1637  * @tc.desc: PromiseRejectInfo test
1638  * @tc.type: FUNC
1639  * @tc.require:  parameter
1640  */
HWTEST_F_L0(JSNApiTests,PromiseRejectInfo)1641 HWTEST_F_L0(JSNApiTests, PromiseRejectInfo)
1642 {
1643     LocalScope scope(vm_);
1644     Local<StringRef> toStringPromise = StringRef::NewFromUtf8(vm_, TEST_NUM1);
1645     Local<JSValueRef> promise(toStringPromise);
1646     Local<StringRef> toStringReason = StringRef::NewFromUtf8(vm_, TEST_NUM1);
1647     Local<JSValueRef> reason(toStringReason);
1648     std::string* str = new std::string(TEST_VALUE);
1649     void *data = static_cast<void *>(str);
1650     PromiseRejectInfo promisereject(promise, reason, PromiseRejectInfo::PROMISE_REJECTION_EVENT::REJECT, data);
1651     EXPECT_EQ(promisereject.GetOperation(), PromiseRejectInfo::PROMISE_REJECTION_EVENT::REJECT);
1652 
1653     delete str;
1654 }
1655 
1656 /**
1657  * @tc.number: ffi_interface_api_127
1658  * @tc.name: ObjectRef
1659  * @tc.desc: ObjectRef test
1660  * @tc.type: FUNC
1661  * @tc.require:  parameter
1662  */
HWTEST_F_L0(JSNApiTests,ObjectRef)1663 HWTEST_F_L0(JSNApiTests, ObjectRef)
1664 {
1665     LocalScope scope(vm_);
1666     Local<ObjectRef> object = ObjectRef::New(vm_);
1667     object = ObjectRef::NewS(vm_);
1668     std::string str = TEST_VALUE;
1669     object->CreateNativeModuleFailureInfo(vm_, str);
1670     bool input = true;
1671     Local<FunctionRef> res = IntegerRef::New(vm_, input);
1672     object->CreateAccessorData(vm_, res, res);
1673     uintptr_t addr = ObjectRef::NewObject(vm_);
1674     Local<StringRef> key = StringRef::NewFromUtf8(vm_, TEST_VALUE);
1675     Local<JSValueRef> value = ObjectRef::New(vm_);
1676     PropertyAttribute property(value, true, true, true);
1677     object->SetConcurrentNativePointerField(vm_, 0);
1678     EXPECT_FALSE(object->SetPrototype(vm_, object));
1679     EXPECT_FALSE(object->HasOwnProperty(vm_, key));
1680     EXPECT_FALSE(object->GetOwnProperty(vm_, key, property));
1681     EXPECT_NE(addr, 1);
1682 }
1683 
1684 /**
1685  * @tc.number: ffi_interface_api_128
1686  * @tc.name: SendableArrayBufferRef
1687  * @tc.desc: SendableArrayBufferRef test
1688  * @tc.type: FUNC
1689  * @tc.require:  parameter
1690  */
HWTEST_F_L0(JSNApiTests,SendableArrayBufferRef)1691 HWTEST_F_L0(JSNApiTests, SendableArrayBufferRef)
1692 {
1693     LocalScope scope(vm_);
1694     Local<SendableArrayBufferRef> res = SendableArrayBufferRef::New(vm_, 0);
1695     const int32_t length = 33;
1696     res->GetBuffer(vm_);
1697     EXPECT_NE(res->ByteLength(vm_), length);
1698     res->Detach(vm_);
1699     EXPECT_NE(res->IsDetach(vm_), length);
1700 }
1701 
1702 /**
1703  * @tc.number: ffi_interface_api_129
1704  * @tc.name: JSNApiSetPkgAliasList
1705  * @tc.desc: Used to verify whether the function of setting the map container module was successful.
1706  * @tc.type: FUNC
1707  * @tc.require:  parameter
1708  */
HWTEST_F_L0(JSNApiTests,JSNApiSetPkgAliasList)1709 HWTEST_F_L0(JSNApiTests, JSNApiSetPkgAliasList)
1710 {
1711     LocalScope scope(vm_);
1712     std::map<std::string, std::string> str = { { TEST_NUM1, TEST_NUM2 } };
1713     JSNApi::SetPkgAliasList(vm_, str);
1714     std::string moduleName = TEST_NUM1;
1715     EXPECT_EQ(std::string(vm_->GetPkgNameWithAlias(TEST_NUM1)), TEST_NUM2);
1716 }
1717 
1718 /**
1719  * @tc.number: ffi_interface_api_130
1720  * @tc.name: InitForConcurrentFunction
1721  * @tc.desc: Used to verify whether the function of setting the map container module was successful.
1722  * @tc.type: FUNC
1723  * @tc.require:  parameter
1724  */
HWTEST_F_L0(JSNApiTests,JSNApiInitForConcurrentFunction)1725 HWTEST_F_L0(JSNApiTests, JSNApiInitForConcurrentFunction)
1726 {
1727     LocalScope scope(vm_);
1728     void *taskInfo = reinterpret_cast<void *>(BuiltinsFunction::FunctionPrototypeInvokeSelf);
1729     Local<JSValueRef> function = FunctionRef::New(vm_, FunctionCallback);
1730     EXPECT_FALSE(JSNApi::InitForConcurrentFunction(vm_, function, taskInfo));
1731 }
1732 
1733 /**
1734  * @tc.number: ffi_interface_api_131
1735  * @tc.name: GetStackBeforeCallNapiSuccess
1736  * @tc.desc: Used to verify whether the function of setting the map container module was successful.
1737  * @tc.type: FUNC
1738  * @tc.require:  parameter
1739  */
HWTEST_F_L0(JSNApiTests,GetStackBeforeCallNapiSuccess)1740 HWTEST_F_L0(JSNApiTests, GetStackBeforeCallNapiSuccess)
1741 {
1742     LocalScope scope(vm_);
1743     SourceMapCallback callback { nullptr };
1744     JSNApi::SetSourceMapCallback(vm_, callback);
1745     vm_->GetJSThread()->SetIsProfiling(false);
1746     bool getStackBeforeCallNapiSuccess = false;
1747     JSNApi::GetStackBeforeCallNapiSuccess(vm_, getStackBeforeCallNapiSuccess);
1748     JSNApi::GetStackAfterCallNapi(vm_);
1749     EXPECT_FALSE(getStackBeforeCallNapiSuccess);
1750 }
1751 
1752 /*
1753  * @tc.number: ffi_interface_api_132
1754  * @tc.name: PrintExceptionInfo
1755  * @tc.desc: Obtain and print abnormal information correctly.
1756  * @tc.type: FUNC
1757  * @tc.require:  parameter
1758  */
HWTEST_F_L0(JSNApiTests,PrintExceptionInfo)1759 HWTEST_F_L0(JSNApiTests, PrintExceptionInfo)
1760 {
1761     LocalScope scope(vm_);
1762     std::thread t1([&]() {
1763         RuntimeOption option;
1764         option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
1765         auto *vm2 = JSNApi::CreateJSVM(option);
1766         auto *thread = vm2->GetJSThread();
1767         thread->SetException(JSTaggedValue::Exception());
1768         EXPECT_NE(vm2, nullptr) << "Cannot create Runtime";
1769         JSNApi::PrintExceptionInfo(vm2);
1770         JSNApi::DestroyJSVM(vm2);
1771     });
1772     {
1773         ThreadSuspensionScope suspensionScope(thread_);
1774         t1.join();
1775     }
1776 }
1777 
1778 /**
1779  * @tc.number: ffi_interface_api_133
1780  * @tc.name: StartDebugger
1781  * @tc.desc: StartDebugger test
1782  * @tc.type: FUNC
1783  * @tc.require:  parameter
1784  */
HWTEST_F_L0(JSNApiTests,JSNApi_StartDebugger)1785 HWTEST_F_L0(JSNApiTests, JSNApi_StartDebugger)
1786 {
1787     EcmaVM *vm = nullptr;
1788     JSNApi::DebugOption *option = new JSNApi::DebugOption();
1789 
1790     EXPECT_FALSE(JSNApi::StartDebugger(vm, *option));
1791 
1792     option->port = INT_MINUS_1;
1793     EXPECT_FALSE(JSNApi::StartDebugger(vm_, *option));
1794 
1795     option->port = INT_ONE;
1796     option->libraryPath = nullptr;
1797     EXPECT_FALSE(JSNApi::StartDebugger(vm_, *option));
1798 
1799     option->libraryPath = ARK_DEBUGGER_LIB_PATH;
1800     EXPECT_FALSE(JSNApi::StartDebugger(vm_, *option));
1801 
1802     delete option;
1803 }
1804 
1805 /**
1806  * @tc.number: ffi_interface_api_134
1807  * @tc.name: StartDebuggerForOldProcess
1808  * @tc.desc: StartDebuggerForOldProcess test
1809  * @tc.type: FUNC
1810  * @tc.require:  parameter
1811  */
HWTEST_F_L0(JSNApiTests,JSNApi_StartDebuggerForOldProcess)1812 HWTEST_F_L0(JSNApiTests, JSNApi_StartDebuggerForOldProcess)
1813 {
1814     EcmaVM *vm = nullptr;
1815     JSNApi::DebugOption *option = new JSNApi::DebugOption();
1816     DebuggerPostTask debuggerPostTask = {};
1817 
1818     EXPECT_FALSE(JSNApi::StartDebuggerForOldProcess(vm, *option, 1, debuggerPostTask));
1819 
1820     option->libraryPath = ARK_DEBUGGER_LIB_PATH;
1821     EXPECT_FALSE(JSNApi::StartDebuggerForOldProcess(vm_, *option, 1, debuggerPostTask));
1822 
1823     delete option;
1824 }
1825 
1826 /**
1827  * @tc.number: ffi_interface_api_135
1828  * @tc.name: StartDebuggerForSocketPair
1829  * @tc.desc: StartDebuggerForSocketPair test
1830  * @tc.type: FUNC
1831  * @tc.require:  parameter
1832  */
HWTEST_F_L0(JSNApiTests,JSNApi_StartDebuggerForSocketPair)1833 HWTEST_F_L0(JSNApiTests, JSNApi_StartDebuggerForSocketPair)
1834 {
1835     int tid = INT_MINUS_1;
1836     int socketfd = 0;
1837 
1838     EXPECT_FALSE(JSNApi::StartDebuggerForSocketPair(tid, socketfd));
1839 
1840     tid = 0;
1841     ecmascript::tooling::JsDebuggerManager *jsDebuggerManager = new ecmascript::tooling::JsDebuggerManager(vm_);
1842     ecmascript::tooling::JsDebuggerManager::AddJsDebuggerManager(tid, jsDebuggerManager);
1843     EXPECT_FALSE(JSNApi::StartDebuggerForSocketPair(tid, socketfd));
1844 
1845     delete jsDebuggerManager;
1846 }
1847 
1848 /**
1849  * @tc.number: ffi_interface_api_136
1850  * @tc.name: NotifyDebugMode
1851  * @tc.desc: NotifyDebugMode test
1852  * @tc.type: FUNC
1853  * @tc.require:  parameter
1854  */
HWTEST_F_L0(JSNApiTests,JSNApi_NotifyDebugMode)1855 HWTEST_F_L0(JSNApiTests, JSNApi_NotifyDebugMode)
1856 {
1857     int tid = INT_MINUS_1;
1858     EcmaVM *vm = nullptr;
1859     JSNApi::DebugOption *option = new JSNApi::DebugOption();
1860     int32_t instanceId = 0;
1861     DebuggerPostTask debuggerPostTask = {};
1862     bool debugApp = false;
1863 
1864     EXPECT_FALSE(JSNApi::NotifyDebugMode(tid, vm, *option));
1865     EXPECT_TRUE(JSNApi::NotifyDebugMode(tid, vm_, *option));
1866 
1867     debugApp = true;
1868     EXPECT_FALSE(JSNApi::NotifyDebugMode(tid, vm_, *option, instanceId, debuggerPostTask, debugApp));
1869 
1870     option->libraryPath = ARK_DEBUGGER_LIB_PATH;
1871     EXPECT_FALSE(JSNApi::NotifyDebugMode(tid, vm_, *option, instanceId, debuggerPostTask, debugApp));
1872 
1873     delete option;
1874 }
1875 
1876 /**
1877  * @tc.number: ffi_interface_api_137
1878  * @tc.name: StoreDebugInfo
1879  * @tc.desc: StoreDebugInfo test
1880  * @tc.type: FUNC
1881  * @tc.require:  parameter
1882  */
HWTEST_F_L0(JSNApiTests,JSNApi_StoreDebugInfo)1883 HWTEST_F_L0(JSNApiTests, JSNApi_StoreDebugInfo)
1884 {
1885     int tid = INT_MINUS_1;
1886     EcmaVM *vm = nullptr;
1887     JSNApi::DebugOption *option = new JSNApi::DebugOption();
1888     DebuggerPostTask debuggerPostTask = {};
1889     bool debugApp = false;
1890 
1891     EXPECT_FALSE(JSNApi::StoreDebugInfo(tid, vm, *option, debuggerPostTask, debugApp));
1892     EXPECT_FALSE(JSNApi::StoreDebugInfo(tid, vm_, *option, debuggerPostTask, debugApp));
1893 
1894     option->libraryPath = ARK_DEBUGGER_LIB_PATH;
1895     EXPECT_FALSE(JSNApi::StoreDebugInfo(tid, vm_, *option, debuggerPostTask, debugApp));
1896 
1897     delete option;
1898 }
1899 
1900 /**
1901  * @tc.number: ffi_interface_api_138
1902  * @tc.name: StopDebugger
1903  * @tc.desc: StopDebugger test
1904  * @tc.type: FUNC
1905  * @tc.require:  parameter
1906  */
HWTEST_F_L0(JSNApiTests,JSNApi_StopDebugger)1907 HWTEST_F_L0(JSNApiTests, JSNApi_StopDebugger)
1908 {
1909     int tid = INT_MINUS_1;
1910     EcmaVM *vm = nullptr;
1911 
1912     EXPECT_FALSE(JSNApi::StopDebugger(vm));
1913 
1914     EXPECT_FALSE(JSNApi::StopDebugger(tid));
1915 }
1916 
1917 /**
1918  * @tc.number: ffi_interface_api_138
1919  * @tc.name: KeyIsNumber
1920  * @tc.desc: KeyIsNumber test
1921  * @tc.type: FUNC
1922  * @tc.require:  parameter
1923  */
HWTEST_F_L0(JSNApiTests,JSNApi_KeyIsNumber)1924 HWTEST_F_L0(JSNApiTests, JSNApi_KeyIsNumber)
1925 {
1926     EXPECT_TRUE(JSNApi::KeyIsNumber(STR_NUM));
1927     EXPECT_FALSE(JSNApi::KeyIsNumber(STR_TEST));
1928 }
1929 } // namespace panda::test