• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "ecmascript/accessor_data.h"
17 #include "ecmascript/dfx/hprof/heap_profiler.h"
18 #include "ecmascript/dfx/hprof/heap_profiler_interface.h"
19 #include "ecmascript/dfx/hprof/heap_snapshot.h"
20 #include "ecmascript/dfx/hprof/heap_snapshot_json_serializer.h"
21 #include "ecmascript/dfx/hprof/string_hashmap.h"
22 #include "ecmascript/dfx/native_module_failure_info.h"
23 #include "ecmascript/ecma_vm.h"
24 #include "ecmascript/global_dictionary-inl.h"
25 #include "ecmascript/global_env.h"
26 #include "ecmascript/ic/ic_handler.h"
27 #include "ecmascript/ic/property_box.h"
28 #include "ecmascript/ic/proto_change_details.h"
29 #include "ecmascript/jobs/micro_job_queue.h"
30 #include "ecmascript/jobs/pending_job.h"
31 #include "ecmascript/jspandafile/class_info_extractor.h"
32 #include "ecmascript/jspandafile/class_literal.h"
33 #include "ecmascript/jspandafile/program_object.h"
34 #include "ecmascript/js_api/js_api_arraylist.h"
35 #include "ecmascript/js_api/js_api_arraylist_iterator.h"
36 #include "ecmascript/js_api/js_api_deque.h"
37 #include "ecmascript/js_api/js_api_deque_iterator.h"
38 #include "ecmascript/js_api/js_api_lightweightmap.h"
39 #include "ecmascript/js_api/js_api_lightweightmap_iterator.h"
40 #include "ecmascript/js_api/js_api_lightweightset.h"
41 #include "ecmascript/js_api/js_api_lightweightset_iterator.h"
42 #include "ecmascript/js_api/js_api_linked_list.h"
43 #include "ecmascript/js_api/js_api_linked_list_iterator.h"
44 #include "ecmascript/js_api/js_api_list.h"
45 #include "ecmascript/js_api/js_api_list_iterator.h"
46 #include "ecmascript/js_api/js_api_plain_array.h"
47 #include "ecmascript/js_api/js_api_plain_array_iterator.h"
48 #include "ecmascript/js_api/js_api_queue.h"
49 #include "ecmascript/js_api/js_api_queue_iterator.h"
50 #include "ecmascript/js_api/js_api_stack.h"
51 #include "ecmascript/js_api/js_api_stack_iterator.h"
52 #include "ecmascript/js_api/js_api_tree_map.h"
53 #include "ecmascript/js_api/js_api_tree_map_iterator.h"
54 #include "ecmascript/js_api/js_api_tree_set.h"
55 #include "ecmascript/js_api/js_api_tree_set_iterator.h"
56 #include "ecmascript/js_api/js_api_vector.h"
57 #include "ecmascript/js_api/js_api_vector_iterator.h"
58 #include "ecmascript/js_arguments.h"
59 #include "ecmascript/js_array.h"
60 #include "ecmascript/js_array_iterator.h"
61 #include "ecmascript/js_arraybuffer.h"
62 #include "ecmascript/js_async_from_sync_iterator.h"
63 #include "ecmascript/js_async_function.h"
64 #include "ecmascript/js_async_generator_object.h"
65 #include "ecmascript/js_bigint.h"
66 #include "ecmascript/js_collator.h"
67 #include "ecmascript/js_dataview.h"
68 #include "ecmascript/js_date.h"
69 #include "ecmascript/js_date_time_format.h"
70 #include "ecmascript/js_finalization_registry.h"
71 #include "ecmascript/js_for_in_iterator.h"
72 #include "ecmascript/js_function.h"
73 #include "ecmascript/js_generator_object.h"
74 #include "ecmascript/js_global_object.h"
75 #include "ecmascript/js_handle.h"
76 #include "ecmascript/js_api/js_api_hashmap.h"
77 #include "ecmascript/js_api/js_api_hashmap_iterator.h"
78 #include "ecmascript/js_api/js_api_hashset.h"
79 #include "ecmascript/js_api/js_api_hashset_iterator.h"
80 #include "ecmascript/js_intl.h"
81 #include "ecmascript/js_locale.h"
82 #include "ecmascript/js_map.h"
83 #include "ecmascript/js_map_iterator.h"
84 #include "ecmascript/js_number_format.h"
85 #include "ecmascript/js_object-inl.h"
86 #include "ecmascript/js_plural_rules.h"
87 #include "ecmascript/js_displaynames.h"
88 #include "ecmascript/js_list_format.h"
89 #include "ecmascript/js_primitive_ref.h"
90 #include "ecmascript/js_promise.h"
91 #include "ecmascript/js_realm.h"
92 #include "ecmascript/js_regexp.h"
93 #include "ecmascript/js_regexp_iterator.h"
94 #include "ecmascript/js_relative_time_format.h"
95 #include "ecmascript/js_segmenter.h"
96 #include "ecmascript/js_segments.h"
97 #include "ecmascript/js_segment_iterator.h"
98 #include "ecmascript/js_set.h"
99 #include "ecmascript/js_set_iterator.h"
100 #include "ecmascript/js_string_iterator.h"
101 #include "ecmascript/js_tagged_number.h"
102 #include "ecmascript/js_tagged_value-inl.h"
103 #include "ecmascript/js_thread.h"
104 #include "ecmascript/js_typed_array.h"
105 #include "ecmascript/js_weak_container.h"
106 #include "ecmascript/js_weak_ref.h"
107 #include "ecmascript/layout_info-inl.h"
108 #include "ecmascript/lexical_env.h"
109 #include "ecmascript/linked_hash_table.h"
110 #include "ecmascript/marker_cell.h"
111 #include "ecmascript/mem/assert_scope.h"
112 #include "ecmascript/mem/c_containers.h"
113 #include "ecmascript/mem/machine_code.h"
114 #include "ecmascript/module/js_module_source_text.h"
115 #include "ecmascript/object_factory.h"
116 #include "ecmascript/shared_objects/js_shared_array.h"
117 #include "ecmascript/shared_objects/js_sendable_arraybuffer.h"
118 #include "ecmascript/shared_objects/js_shared_array_iterator.h"
119 #include "ecmascript/shared_objects/js_shared_map.h"
120 #include "ecmascript/shared_objects/js_shared_map_iterator.h"
121 #include "ecmascript/shared_objects/js_shared_set.h"
122 #include "ecmascript/shared_objects/js_shared_set_iterator.h"
123 #include "ecmascript/shared_objects/js_shared_typed_array.h"
124 #include "ecmascript/stubs/runtime_stubs.h"
125 #include "ecmascript/tagged_array.h"
126 #include "ecmascript/tagged_dictionary.h"
127 #include "ecmascript/tagged_hash_array.h"
128 #include "ecmascript/tagged_list.h"
129 #include "ecmascript/tagged_node.h"
130 #include "ecmascript/tagged_tree.h"
131 #include "ecmascript/template_map.h"
132 #include "ecmascript/tests/test_helper.h"
133 #include "ecmascript/transitions_dictionary.h"
134 #include "ecmascript/require/js_cjs_module.h"
135 #include "ecmascript/require/js_cjs_require.h"
136 #include "ecmascript/require/js_cjs_exports.h"
137 
138 using namespace panda::ecmascript;
139 using namespace panda::ecmascript::base;
140 
141 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
142 #define CHECK_DUMP_FIELDS(begin, end, num);                                                                     \
143     LOG_ECMA_IF((num) != ((end) - (begin)) / JSTaggedValue::TaggedTypeSize() && sizeof(uintptr_t) == 8, FATAL)  \
144         << "Fields in obj are not in dump list. "
145 
146 namespace panda::test {
147 class EcmaDumpTest : public BaseTestWithScope<false> {
148 };
149 
150 #ifndef NDEBUG
HWTEST_F_L0(EcmaDumpTest,Dump)151 HWTEST_F_L0(EcmaDumpTest, Dump)
152 {
153     std::ostringstream os;
154 
155     JSTaggedValue value1(100);
156     value1.Dump(os);
157 
158     JSTaggedValue value2(100.0);
159     JSTaggedValue(value2.GetRawData()).Dump(os);
160 
161     JSTaggedValue::Undefined().Dump(os);
162     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
163     env.GetTaggedValue().Dump(os);
164 
165     JSHandle<JSFunction> objFunc(env->GetObjectFunction());
166     objFunc.GetTaggedValue().Dump(os);
167 }
168 #endif  // #ifndef NDEBUG
169 
NewJSMap(JSThread * thread,ObjectFactory * factory,JSHandle<JSTaggedValue> proto)170 static JSHandle<JSMap> NewJSMap(JSThread *thread, ObjectFactory *factory, JSHandle<JSTaggedValue> proto)
171 {
172     JSHandle<JSHClass> mapClass = factory->NewEcmaHClass(JSMap::SIZE, JSType::JS_MAP, proto);
173     JSHandle<JSMap> jsMap = JSHandle<JSMap>::Cast(factory->NewJSObjectWithInit(mapClass));
174     JSHandle<LinkedHashMap> linkedMap(LinkedHashMap::Create(thread));
175     jsMap->SetLinkedMap(thread, linkedMap);
176     return jsMap;
177 }
178 
NewJSSharedMap(JSThread * thread,ObjectFactory * factory)179 static JSHandle<JSSharedMap> NewJSSharedMap(JSThread *thread, ObjectFactory *factory)
180 {
181     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
182     JSHandle<JSTaggedValue> proto = globalEnv->GetSFunctionPrototype();
183     auto emptySLayout = thread->GlobalConstants()->GetHandledEmptySLayoutInfo();
184     JSHandle<JSHClass> mapClass = factory->NewSEcmaHClass(JSSharedMap::SIZE, 0,
185         JSType::JS_SHARED_MAP, proto, emptySLayout);
186     JSHandle<JSSharedMap> jsMap = JSHandle<JSSharedMap>::Cast(factory->NewJSObjectWithInit(mapClass));
187     JSHandle<LinkedHashMap> linkedMap(
188         LinkedHashMap::Create(thread, LinkedHashMap::MIN_CAPACITY, MemSpaceKind::SHARED));
189     jsMap->SetLinkedMap(thread, linkedMap);
190     jsMap->SetModRecord(0);
191     return jsMap;
192 }
193 
NewJSSet(JSThread * thread,ObjectFactory * factory,JSHandle<JSTaggedValue> proto)194 static JSHandle<JSSet> NewJSSet(JSThread *thread, ObjectFactory *factory, JSHandle<JSTaggedValue> proto)
195 {
196     JSHandle<JSHClass> setClass = factory->NewEcmaHClass(JSSet::SIZE, JSType::JS_SET, proto);
197     JSHandle<JSSet> jsSet = JSHandle<JSSet>::Cast(factory->NewJSObjectWithInit(setClass));
198     JSHandle<LinkedHashSet> linkedSet(LinkedHashSet::Create(thread));
199     jsSet->SetLinkedSet(thread, linkedSet);
200     return jsSet;
201 }
202 
NewJSSharedSet(JSThread * thread,ObjectFactory * factory)203 static JSHandle<JSSharedSet> NewJSSharedSet(JSThread *thread, ObjectFactory *factory)
204 {
205     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
206     JSHandle<JSTaggedValue> proto = globalEnv->GetSFunctionPrototype();
207     auto emptySLayout = thread->GlobalConstants()->GetHandledEmptySLayoutInfo();
208     JSHandle<JSHClass> setClass = factory->NewSEcmaHClass(JSSharedSet::SIZE, 0,
209         JSType::JS_SHARED_SET, proto, emptySLayout);
210     JSHandle<JSSharedSet> jsSet = JSHandle<JSSharedSet>::Cast(factory->NewJSObjectWithInit(setClass));
211     JSHandle<LinkedHashSet> linkedSet(
212         LinkedHashSet::Create(thread, LinkedHashSet::MIN_CAPACITY, MemSpaceKind::SHARED));
213     jsSet->SetLinkedSet(thread, linkedSet);
214     jsSet->SetModRecord(0);
215     return jsSet;
216 }
217 
NewJSAPIHashMap(JSThread * thread,ObjectFactory * factory)218 static JSHandle<JSAPIHashMap> NewJSAPIHashMap(JSThread *thread, ObjectFactory *factory)
219 {
220     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
221     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
222     JSHandle<JSHClass> mapClass = factory->NewEcmaHClass(JSAPIHashMap::SIZE, JSType::JS_API_HASH_MAP, proto);
223     JSHandle<JSAPIHashMap> jsHashMap = JSHandle<JSAPIHashMap>::Cast(factory->NewJSObjectWithInit(mapClass));
224     jsHashMap->SetTable(thread, TaggedHashArray::Create(thread));
225     jsHashMap->SetSize(0);
226     return jsHashMap;
227 }
228 
NewJSAPIHashSet(JSThread * thread,ObjectFactory * factory)229 static JSHandle<JSAPIHashSet> NewJSAPIHashSet(JSThread *thread, ObjectFactory *factory)
230 {
231     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
232     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
233     JSHandle<JSHClass> setClass = factory->NewEcmaHClass(JSAPIHashSet::SIZE, JSType::JS_API_HASH_SET, proto);
234     JSHandle<JSAPIHashSet> jsHashSet = JSHandle<JSAPIHashSet>::Cast(factory->NewJSObjectWithInit(setClass));
235     jsHashSet->SetTable(thread, TaggedHashArray::Create(thread));
236     jsHashSet->SetSize(0);
237     return jsHashSet;
238 }
239 
NewJSAPITreeMap(JSThread * thread,ObjectFactory * factory)240 static JSHandle<JSAPITreeMap> NewJSAPITreeMap(JSThread *thread, ObjectFactory *factory)
241 {
242     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
243     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
244     JSHandle<JSHClass> mapClass = factory->NewEcmaHClass(JSAPITreeMap::SIZE, JSType::JS_API_TREE_MAP, proto);
245     JSHandle<JSAPITreeMap> jsTreeMap = JSHandle<JSAPITreeMap>::Cast(factory->NewJSObjectWithInit(mapClass));
246     JSHandle<TaggedTreeMap> treeMap(thread, TaggedTreeMap::Create(thread));
247     jsTreeMap->SetTreeMap(thread, treeMap);
248     return jsTreeMap;
249 }
250 
NewJSAPITreeSet(JSThread * thread,ObjectFactory * factory)251 static JSHandle<JSAPITreeSet> NewJSAPITreeSet(JSThread *thread, ObjectFactory *factory)
252 {
253     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
254     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
255     JSHandle<JSHClass> setClass = factory->NewEcmaHClass(JSAPITreeSet::SIZE, JSType::JS_API_TREE_SET, proto);
256     JSHandle<JSAPITreeSet> jsTreeSet = JSHandle<JSAPITreeSet>::Cast(factory->NewJSObjectWithInit(setClass));
257     JSHandle<TaggedTreeSet> treeSet(thread, TaggedTreeSet::Create(thread));
258     jsTreeSet->SetTreeSet(thread, treeSet);
259     return jsTreeSet;
260 }
261 
NewJSAPIPlainArray(JSThread * thread,ObjectFactory * factory)262 static JSHandle<JSAPIPlainArray> NewJSAPIPlainArray(JSThread *thread, ObjectFactory *factory)
263 {
264     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
265     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
266     JSHandle<JSHClass> mapClass = factory->NewEcmaHClass(JSAPIPlainArray::SIZE, JSType::JS_API_PLAIN_ARRAY, proto);
267     JSHandle<JSAPIPlainArray> jSAPIPlainArray = JSHandle<JSAPIPlainArray>::Cast(factory->NewJSObjectWithInit(mapClass));
268     JSHandle<TaggedArray> keys =
269             JSAPIPlainArray::CreateSlot(thread, JSAPIPlainArray::DEFAULT_CAPACITY_LENGTH);
270     JSHandle<TaggedArray> values =
271             JSAPIPlainArray::CreateSlot(thread, JSAPIPlainArray::DEFAULT_CAPACITY_LENGTH);
272     jSAPIPlainArray->SetKeys(thread, keys);
273     jSAPIPlainArray->SetValues(thread, values);
274     jSAPIPlainArray->SetLength(0);
275     return jSAPIPlainArray;
276 }
277 
NewJSAPIList(JSThread * thread,ObjectFactory * factory)278 static JSHandle<JSAPIList> NewJSAPIList(JSThread *thread, ObjectFactory *factory)
279 {
280     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
281     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
282     JSHandle<JSHClass> listClass = factory->NewEcmaHClass(JSAPIList::SIZE, JSType::JS_API_LIST, proto);
283     JSHandle<JSAPIList> jsAPIList = JSHandle<JSAPIList>::Cast(factory->NewJSObjectWithInit(listClass));
284     JSHandle<JSTaggedValue> taggedSingleList(thread, TaggedSingleList::Create(thread));
285     jsAPIList->SetSingleList(thread, taggedSingleList);
286     return jsAPIList;
287 }
288 
NewJSAPILinkedList(JSThread * thread,ObjectFactory * factory)289 static JSHandle<JSAPILinkedList> NewJSAPILinkedList(JSThread *thread, ObjectFactory *factory)
290 {
291     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
292     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
293     JSHandle<JSHClass> mapClass = factory->NewEcmaHClass(JSAPILinkedList::SIZE, JSType::JS_API_LINKED_LIST, proto);
294     JSHandle<JSAPILinkedList> jsAPILinkedList = JSHandle<JSAPILinkedList>::Cast(factory->NewJSObjectWithInit(mapClass));
295     JSHandle<JSTaggedValue> linkedlist(thread, TaggedDoubleList::Create(thread));
296     jsAPILinkedList->SetDoubleList(thread, linkedlist);
297     return jsAPILinkedList;
298 }
299 
NewJSObject(JSThread * thread,ObjectFactory * factory,JSHandle<GlobalEnv> globalEnv)300 static JSHandle<JSObject> NewJSObject(JSThread *thread, ObjectFactory *factory, JSHandle<GlobalEnv> globalEnv)
301 {
302     JSFunction *jsFunc = globalEnv->GetObjectFunction().GetObject<JSFunction>();
303     JSHandle<JSTaggedValue> jsFunc1(thread, jsFunc);
304     JSHandle<JSObject> jsObj = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(jsFunc1), jsFunc1);
305     return jsObj;
306 }
307 
NewJSAPIArrayList(JSThread * thread,ObjectFactory * factory,JSHandle<JSTaggedValue> proto)308 static JSHandle<JSAPIArrayList> NewJSAPIArrayList(JSThread *thread, ObjectFactory *factory,
309                                                   JSHandle<JSTaggedValue> proto)
310 {
311     JSHandle<JSHClass> arrayListClass =
312         factory->NewEcmaHClass(JSAPIArrayList::SIZE, JSType::JS_API_ARRAY_LIST, proto);
313     JSHandle<JSAPIArrayList> jsArrayList = JSHandle<JSAPIArrayList>::Cast(factory->NewJSObjectWithInit(arrayListClass));
314     jsArrayList->SetLength(thread, JSTaggedValue(0));
315     return jsArrayList;
316 }
317 
NewJSAPIStack(ObjectFactory * factory,JSHandle<JSTaggedValue> proto)318 static JSHandle<JSAPIStack> NewJSAPIStack(ObjectFactory *factory, JSHandle<JSTaggedValue> proto)
319 {
320     JSHandle<JSHClass> stackClass = factory->NewEcmaHClass(JSAPIStack::SIZE, JSType::JS_API_STACK, proto);
321     JSHandle<JSAPIStack> jsStack = JSHandle<JSAPIStack>::Cast(factory->NewJSObjectWithInit(stackClass));
322     jsStack->SetTop(0);
323     return jsStack;
324 }
325 
NewJSRegExp(JSThread * thread,ObjectFactory * factory,JSHandle<JSTaggedValue> proto)326 static JSHandle<JSRegExp> NewJSRegExp(JSThread *thread, ObjectFactory *factory, JSHandle<JSTaggedValue> proto)
327 {
328     JSHandle<JSHClass> jSRegExpClass =
329         factory->NewEcmaHClass(JSRegExp::SIZE, JSType::JS_REG_EXP, proto);
330     JSHandle<JSRegExp> jSRegExp = JSHandle<JSRegExp>::Cast(factory->NewJSObject(jSRegExpClass));
331     jSRegExp->SetByteCodeBuffer(thread, JSTaggedValue::Undefined());
332     jSRegExp->SetOriginalSource(thread, JSTaggedValue::Undefined());
333     jSRegExp->SetGroupName(thread, JSTaggedValue::Undefined());
334     jSRegExp->SetOriginalFlags(thread, JSTaggedValue(0));
335     jSRegExp->SetLength(0);
336     return jSRegExp;
337 }
338 
NewJSAPILightWeightMap(JSThread * thread,ObjectFactory * factory)339 static JSHandle<JSAPILightWeightMap> NewJSAPILightWeightMap(JSThread *thread, ObjectFactory *factory)
340 {
341     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
342     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
343     JSHandle<JSHClass> lwmapClass =
344         factory->NewEcmaHClass(JSAPILightWeightMap::SIZE, JSType::JS_API_LIGHT_WEIGHT_MAP, proto);
345     JSHandle<JSAPILightWeightMap> jSAPILightWeightMap =
346         JSHandle<JSAPILightWeightMap>::Cast(factory->NewJSObjectWithInit(lwmapClass));
347     JSHandle<JSTaggedValue> hashArray =
348         JSHandle<JSTaggedValue>(factory->NewTaggedArray(JSAPILightWeightMap::DEFAULT_CAPACITY_LENGTH));
349     JSHandle<JSTaggedValue> keyArray =
350         JSHandle<JSTaggedValue>(factory->NewTaggedArray(JSAPILightWeightMap::DEFAULT_CAPACITY_LENGTH));
351     JSHandle<JSTaggedValue> valueArray =
352         JSHandle<JSTaggedValue>(factory->NewTaggedArray(JSAPILightWeightMap::DEFAULT_CAPACITY_LENGTH));
353     jSAPILightWeightMap->SetHashes(thread, hashArray);
354     jSAPILightWeightMap->SetKeys(thread, keyArray);
355     jSAPILightWeightMap->SetValues(thread, valueArray);
356     jSAPILightWeightMap->SetLength(0);
357     return jSAPILightWeightMap;
358 }
359 
NewJSAPILightWeightSet(JSThread * thread,ObjectFactory * factory)360 static JSHandle<JSAPILightWeightSet> NewJSAPILightWeightSet(JSThread *thread, ObjectFactory *factory)
361 {
362     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
363     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
364     JSHandle<JSHClass> setClass =
365         factory->NewEcmaHClass(JSAPILightWeightSet::SIZE, JSType::JS_API_LIGHT_WEIGHT_SET, proto);
366     JSHandle<JSAPILightWeightSet> jSAPILightWeightSet =
367         JSHandle<JSAPILightWeightSet>::Cast(factory->NewJSObjectWithInit(setClass));
368     JSHandle<TaggedArray> hashes =
369         JSAPILightWeightSet::CreateSlot(thread, JSAPILightWeightSet::DEFAULT_CAPACITY_LENGTH);
370     JSHandle<TaggedArray> values =
371         JSAPILightWeightSet::CreateSlot(thread, JSAPILightWeightSet::DEFAULT_CAPACITY_LENGTH);
372     jSAPILightWeightSet->SetHashes(thread, hashes);
373     jSAPILightWeightSet->SetValues(thread, values);
374     jSAPILightWeightSet->SetLength(0);
375     return jSAPILightWeightSet;
376 }
377 
NewJSAPIQueue(JSThread * thread,ObjectFactory * factory,JSHandle<JSTaggedValue> proto)378 static JSHandle<JSAPIQueue> NewJSAPIQueue(JSThread *thread, ObjectFactory *factory, JSHandle<JSTaggedValue> proto)
379 {
380     JSHandle<JSHClass> queueClass = factory->NewEcmaHClass(JSAPIQueue::SIZE, JSType::JS_API_QUEUE, proto);
381     JSHandle<JSAPIQueue> jsQueue = JSHandle<JSAPIQueue>::Cast(factory->NewJSObjectWithInit(queueClass));
382     JSHandle<TaggedArray> newElements = factory->NewTaggedArray(JSAPIQueue::DEFAULT_CAPACITY_LENGTH);
383     jsQueue->SetLength(thread, JSTaggedValue(0));
384     jsQueue->SetFront(0);
385     jsQueue->SetTail(0);
386     jsQueue->SetElements(thread, newElements);
387     return jsQueue;
388 }
389 
NewJSAPIDeque(JSThread * thread,ObjectFactory * factory,JSHandle<JSTaggedValue> proto)390 static JSHandle<JSAPIDeque> NewJSAPIDeque(JSThread *thread, ObjectFactory *factory, JSHandle<JSTaggedValue> proto)
391 {
392     JSHandle<JSHClass> dequeClass = factory->NewEcmaHClass(JSAPIDeque::SIZE, JSType::JS_API_DEQUE, proto);
393     JSHandle<JSAPIDeque> jsDeque = JSHandle<JSAPIDeque>::Cast(factory->NewJSObjectWithInit(dequeClass));
394     JSHandle<TaggedArray> newElements = factory->NewTaggedArray(JSAPIDeque::DEFAULT_CAPACITY_LENGTH);
395     jsDeque->SetFirst(0);
396     jsDeque->SetLast(0);
397     jsDeque->SetElements(thread, newElements);
398     return jsDeque;
399 }
400 
NewJSAPIVector(ObjectFactory * factory,JSHandle<JSTaggedValue> proto)401 static JSHandle<JSAPIVector> NewJSAPIVector(ObjectFactory *factory, JSHandle<JSTaggedValue> proto)
402 {
403     JSHandle<JSHClass> vectorClass = factory->NewEcmaHClass(JSAPIVector::SIZE, JSType::JS_API_VECTOR, proto);
404     JSHandle<JSAPIVector> jsVector = JSHandle<JSAPIVector>::Cast(factory->NewJSObjectWithInit(vectorClass));
405     jsVector->SetLength(0);
406     return jsVector;
407 }
408 
HWTEST_F_L0(EcmaDumpTest,HeapProfileDump)409 HWTEST_F_L0(EcmaDumpTest, HeapProfileDump)
410 {
411     [[maybe_unused]] ecmascript::EcmaHandleScope scope(thread);
412     auto factory = thread->GetEcmaVM()->GetFactory();
413     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
414     auto globalConst = const_cast<GlobalEnvConstants *>(thread->GlobalConstants());
415     JSHandle<JSTaggedValue> proto = globalEnv->GetFunctionPrototype();
416     std::vector<Reference> snapshotVector;
417     std::ostringstream os;
418 
419 #define DUMP_FOR_HANDLE(dumpHandle)                                                     \
420     do {                                                                                \
421         JSTaggedValue dumpValue = (dumpHandle).GetTaggedValue();                         \
422         dumpValue.Dump(os);                                                             \
423         dumpValue.DumpForSnapshot(snapshotVector);                                      \
424         /* Testing runtime stubs: */                                                    \
425         JSTaggedType dumpRawData = dumpValue.GetRawData();                              \
426         uintptr_t hintStr = reinterpret_cast<uintptr_t>("Testing with: " #dumpHandle);  \
427         RuntimeStubs::Dump(dumpRawData);                                                \
428         RuntimeStubs::DebugDump(dumpRawData);                                           \
429         RuntimeStubs::DumpWithHint(hintStr, dumpRawData);                               \
430         RuntimeStubs::DebugDumpWithHint(hintStr, dumpRawData);                          \
431     } while (false)
432 
433 #define NEW_OBJECT_AND_DUMP(ClassName, TypeName)                                                \
434     do {                                                                                        \
435         JSHandle<JSHClass> class##ClassName =                                                   \
436             factory->NewEcmaHClass(ClassName::SIZE, JSType::TypeName, proto);                   \
437         JSHandle<JSObject> object##ClassName = factory->NewJSObjectWithInit(class##ClassName);  \
438         DUMP_FOR_HANDLE(object##ClassName);                                                     \
439     } while (false)
440 
441     for (JSType type = JSType::JS_OBJECT; type <= JSType::TYPE_LAST; type = JSType(static_cast<int>(type) + 1)) {
442         switch (type) {
443             case JSType::JS_ERROR:
444             case JSType::JS_EVAL_ERROR:
445             case JSType::JS_RANGE_ERROR:
446             case JSType::JS_TYPE_ERROR:
447             case JSType::JS_AGGREGATE_ERROR:
448             case JSType::JS_REFERENCE_ERROR:
449             case JSType::JS_URI_ERROR:
450             case JSType::JS_ARGUMENTS:
451             case JSType::JS_SYNTAX_ERROR:
452             case JSType::JS_OOM_ERROR:
453             case JSType::JS_TERMINATION_ERROR:
454             case JSType::JS_OBJECT:
455             case JSType::JS_SHARED_OBJECT: {
456                 CHECK_DUMP_FIELDS(ECMAObject::SIZE, JSObject::SIZE, 2U);
457                 JSHandle<JSObject> jsObj = NewJSObject(thread, factory, globalEnv);
458                 DUMP_FOR_HANDLE(jsObj);
459                 break;
460             }
461             case JSType::JS_REALM: {
462                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSRealm::SIZE, 2U);
463                 JSHandle<JSRealm> jsRealm = factory->NewJSRealm();
464                 DUMP_FOR_HANDLE(jsRealm);
465                 break;
466             }
467             case JSType::METHOD: {
468 #ifdef PANDA_TARGET_64
469                 CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), Method::SIZE, 6U);
470 #else
471                 CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), Method::SIZE, 5U);
472 #endif
473                 break;
474             }
475             case JSType::JS_FUNCTION_BASE: {
476                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSFunctionBase::SIZE, 3U);
477                 break;
478             }
479             case JSType::JS_FUNCTION:
480             case JSType::JS_SHARED_FUNCTION: {
481                 CHECK_DUMP_FIELDS(JSFunctionBase::SIZE, JSFunction::SIZE, 9U);
482                 JSHandle<JSTaggedValue> jsFunc = globalEnv->GetFunctionFunction();
483                 DUMP_FOR_HANDLE(jsFunc);
484                 break;
485             }
486             case JSType::JS_PROXY_REVOC_FUNCTION: {
487                 CHECK_DUMP_FIELDS(JSFunction::SIZE, JSProxyRevocFunction::SIZE, 1U);
488                 JSHandle<JSHClass> proxyRevocClass =
489                     JSHandle<JSHClass>::Cast(globalEnv->GetProxyRevocFunctionClass());
490                 JSHandle<JSObject> proxyRevocFunc = factory->NewJSObjectWithInit(proxyRevocClass);
491                 DUMP_FOR_HANDLE(proxyRevocFunc);
492                 break;
493             }
494             case JSType::JS_PROMISE_REACTIONS_FUNCTION: {
495                 CHECK_DUMP_FIELDS(JSFunction::SIZE, JSPromiseReactionsFunction::SIZE, 2U);
496                 JSHandle<JSHClass> promiseReactClass =
497                     JSHandle<JSHClass>::Cast(globalEnv->GetPromiseReactionFunctionClass());
498                 JSHandle<JSObject> promiseReactFunc = factory->NewJSObjectWithInit(promiseReactClass);
499                 DUMP_FOR_HANDLE(promiseReactFunc);
500                 break;
501             }
502             case JSType::JS_PROMISE_EXECUTOR_FUNCTION: {
503                 CHECK_DUMP_FIELDS(JSFunction::SIZE, JSPromiseExecutorFunction::SIZE, 1U);
504                 JSHandle<JSHClass> promiseExeClass =
505                     JSHandle<JSHClass>::Cast(globalEnv->GetPromiseExecutorFunctionClass());
506                 JSHandle<JSObject> promiseExeFunc = factory->NewJSObjectWithInit(promiseExeClass);
507                 DUMP_FOR_HANDLE(promiseExeFunc);
508                 break;
509             }
510             case JSType::JS_ASYNC_MODULE_FULFILLED_FUNCTION: {
511                 CHECK_DUMP_FIELDS(JSFunction::SIZE, JSAsyncModuleFulfilledFunction::SIZE, 0U);
512                 JSHandle<JSHClass> moduleFulfilledClass =
513                     JSHandle<JSHClass>::Cast(globalEnv->GetAsyncModuleFulfilledFunctionClass());
514                 JSHandle<JSObject> moduleFulfilledFunc = factory->NewJSObjectWithInit(moduleFulfilledClass);
515                 DUMP_FOR_HANDLE(moduleFulfilledFunc);
516                 break;
517             }
518             case JSType::JS_ASYNC_MODULE_REJECTED_FUNCTION: {
519                 CHECK_DUMP_FIELDS(JSFunction::SIZE, JSAsyncModuleRejectedFunction::SIZE, 0U);
520                 JSHandle<JSHClass> moduleRejectedClass =
521                     JSHandle<JSHClass>::Cast(globalEnv->GetAsyncModuleRejectedFunctionClass());
522                 JSHandle<JSObject> moduleRejectedFunc = factory->NewJSObjectWithInit(moduleRejectedClass);
523                 DUMP_FOR_HANDLE(moduleRejectedFunc);
524                 break;
525             }
526             case JSType::JS_PROMISE_ALL_RESOLVE_ELEMENT_FUNCTION: {
527                 CHECK_DUMP_FIELDS(JSFunction::SIZE, JSPromiseAllResolveElementFunction::SIZE, 5U);
528                 JSHandle<JSHClass> promiseAllClass =
529                     JSHandle<JSHClass>::Cast(globalEnv->GetPromiseAllResolveElementFunctionClass());
530                 JSHandle<JSObject> promiseAllFunc = factory->NewJSObjectWithInit(promiseAllClass);
531                 DUMP_FOR_HANDLE(promiseAllFunc);
532                 break;
533             }
534             case JSType::JS_PROMISE_ANY_REJECT_ELEMENT_FUNCTION: {
535                 CHECK_DUMP_FIELDS(JSFunction::SIZE, JSPromiseAnyRejectElementFunction::SIZE, 5U);
536                 JSHandle<JSHClass> promiseAnyClass =
537                     JSHandle<JSHClass>::Cast(globalEnv->GetPromiseAnyRejectElementFunctionClass());
538                 JSHandle<JSObject> promiseAnyFunc = factory->NewJSObjectWithInit(promiseAnyClass);
539                 DUMP_FOR_HANDLE(promiseAnyFunc);
540                 break;
541             }
542             case JSType::JS_PROMISE_ALL_SETTLED_ELEMENT_FUNCTION: {
543                 CHECK_DUMP_FIELDS(JSFunction::SIZE, JSPromiseAllSettledElementFunction::SIZE, 5U);
544                 JSHandle<JSHClass> promiseAllSettledClass =
545                     JSHandle<JSHClass>::Cast(globalEnv->GetPromiseAllSettledElementFunctionClass());
546                 JSHandle<JSObject> promiseAllSettledFunc = factory->NewJSObjectWithInit(promiseAllSettledClass);
547                 DUMP_FOR_HANDLE(promiseAllSettledFunc);
548                 break;
549             }
550             case JSType::JS_PROMISE_FINALLY_FUNCTION: {
551                 CHECK_DUMP_FIELDS(JSFunction::SIZE, JSPromiseFinallyFunction::SIZE, 2U);
552                 JSHandle<JSHClass> promiseFinallyClass =
553                     JSHandle<JSHClass>::Cast(globalEnv->GetPromiseFinallyFunctionClass());
554                 JSHandle<JSObject> promiseFinallyFunc = factory->NewJSObjectWithInit(promiseFinallyClass);
555                 DUMP_FOR_HANDLE(promiseFinallyFunc);
556                 break;
557             }
558             case JSType::JS_PROMISE_VALUE_THUNK_OR_THROWER_FUNCTION: {
559                 CHECK_DUMP_FIELDS(JSFunction::SIZE, JSPromiseValueThunkOrThrowerFunction::SIZE, 1U);
560                 JSHandle<JSHClass> promiseValueClass =
561                     JSHandle<JSHClass>::Cast(globalEnv->GetPromiseValueThunkOrThrowerFunctionClass());
562                 JSHandle<JSObject> promiseValueFunc = factory->NewJSObjectWithInit(promiseValueClass);
563                 DUMP_FOR_HANDLE(promiseValueFunc);
564                 break;
565             }
566             case JSType::JS_ASYNC_GENERATOR_FUNCTION: {
567                 CHECK_DUMP_FIELDS(JSFunction::SIZE, JSAsyncGeneratorFunction::SIZE, 0U);
568                 break;
569             }
570             case JSType::JS_GENERATOR_FUNCTION: {
571                 CHECK_DUMP_FIELDS(JSFunction::SIZE, JSGeneratorFunction::SIZE, 0U);
572                 break;
573             }
574             case JSType::JS_ASYNC_FUNCTION:
575             case JSType::JS_SHARED_ASYNC_FUNCTION: {
576                 CHECK_DUMP_FIELDS(JSFunction::SIZE, JSAsyncFunction::SIZE, 0U);
577                 break;
578             }
579             case JSType::JS_INTL_BOUND_FUNCTION: {
580                 CHECK_DUMP_FIELDS(JSFunction::SIZE, JSIntlBoundFunction::SIZE, 3U);
581                 JSHandle<JSIntlBoundFunction> intlBoundFunc = factory->NewJSIntlBoundFunction(
582                     MethodIndex::BUILTINS_NUMBER_FORMAT_NUMBER_FORMAT_INTERNAL_FORMAT_NUMBER);
583                 DUMP_FOR_HANDLE(intlBoundFunc);
584                 break;
585             }
586             case JSType::JS_ASYNC_AWAIT_STATUS_FUNCTION: {
587                 CHECK_DUMP_FIELDS(JSFunction::SIZE, JSAsyncAwaitStatusFunction::SIZE, 1U);
588                 JSHandle<JSAsyncAwaitStatusFunction> asyncAwaitFunc = factory->NewJSAsyncAwaitStatusFunction(
589                     MethodIndex::BUILTINS_PROMISE_HANDLER_ASYNC_AWAIT_FULFILLED);
590                 DUMP_FOR_HANDLE(asyncAwaitFunc);
591                 break;
592             }
593             case JSType::JS_BOUND_FUNCTION: {
594                 CHECK_DUMP_FIELDS(JSFunctionBase::SIZE, JSBoundFunction::SIZE, 3U);
595                 NEW_OBJECT_AND_DUMP(JSBoundFunction, JS_BOUND_FUNCTION);
596                 break;
597             }
598             case JSType::JS_REG_EXP: {
599                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSRegExp::SIZE, 5U);
600                 NEW_OBJECT_AND_DUMP(JSRegExp, JS_REG_EXP);
601                 break;
602             }
603             case JSType::JS_SET: {
604                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSSet::SIZE, 1U);
605                 JSHandle<JSSet> jsSet = NewJSSet(thread, factory, proto);
606                 DUMP_FOR_HANDLE(jsSet);
607                 break;
608             }
609             case JSType::JS_SHARED_SET: {
610                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSSharedSet::SIZE, 2U);
611                 JSHandle<JSSharedSet> jsSet = NewJSSharedSet(thread, factory);
612                 DUMP_FOR_HANDLE(jsSet);
613                 break;
614             }
615             case JSType::JS_MAP: {
616                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSMap::SIZE, 1U);
617                 JSHandle<JSMap> jsMap = NewJSMap(thread, factory, proto);
618                 DUMP_FOR_HANDLE(jsMap);
619                 break;
620             }
621             case JSType::JS_SHARED_MAP: {
622                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSSharedMap::SIZE, 2U);
623                 JSHandle<JSSharedMap> jsMap = NewJSSharedMap(thread, factory);
624                 DUMP_FOR_HANDLE(jsMap);
625                 break;
626             }
627             case JSType::JS_WEAK_MAP: {
628                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSWeakMap::SIZE, 1U);
629                 JSHandle<JSHClass> weakMapClass = factory->NewEcmaHClass(JSWeakMap::SIZE, JSType::JS_WEAK_MAP, proto);
630                 JSHandle<JSWeakMap> jsWeakMap = JSHandle<JSWeakMap>::Cast(factory->NewJSObjectWithInit(weakMapClass));
631                 JSHandle<LinkedHashMap> weakLinkedMap(LinkedHashMap::Create(thread));
632                 jsWeakMap->SetLinkedMap(thread, weakLinkedMap);
633                 DUMP_FOR_HANDLE(jsWeakMap);
634                 break;
635             }
636             case JSType::JS_WEAK_SET: {
637                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSWeakSet::SIZE, 1U);
638                 JSHandle<JSHClass> weakSetClass = factory->NewEcmaHClass(JSWeakSet::SIZE, JSType::JS_WEAK_SET, proto);
639                 JSHandle<JSWeakSet> jsWeakSet = JSHandle<JSWeakSet>::Cast(factory->NewJSObjectWithInit(weakSetClass));
640                 JSHandle<LinkedHashSet> weakLinkedSet(LinkedHashSet::Create(thread));
641                 jsWeakSet->SetLinkedSet(thread, weakLinkedSet);
642                 DUMP_FOR_HANDLE(jsWeakSet);
643                 break;
644             }
645             case JSType::JS_WEAK_REF: {
646                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSWeakRef::SIZE, 1U);
647                 JSHandle<JSHClass> weakRefClass = factory->NewEcmaHClass(JSWeakRef::SIZE, JSType::JS_WEAK_REF, proto);
648                 JSHandle<JSWeakRef> jsWeakRef = JSHandle<JSWeakRef>::Cast(factory->NewJSObjectWithInit(weakRefClass));
649                 jsWeakRef->SetWeakObject(thread, JSTaggedValue::Undefined());
650                 DUMP_FOR_HANDLE(jsWeakRef);
651                 break;
652             }
653             case JSType::JS_FINALIZATION_REGISTRY: {
654                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSFinalizationRegistry::SIZE, 5U);
655                 JSHandle<JSHClass> finalizationRegistryClass =
656                     factory->NewEcmaHClass(JSFinalizationRegistry::SIZE, JSType::JS_FINALIZATION_REGISTRY, proto);
657                 JSHandle<JSFinalizationRegistry> jsFinalizationRegistry =
658                     JSHandle<JSFinalizationRegistry>::Cast(factory->NewJSObjectWithInit(finalizationRegistryClass));
659                 JSHandle<LinkedHashMap> weakLinkedMap(LinkedHashMap::Create(thread));
660                 jsFinalizationRegistry->SetMaybeUnregister(thread, weakLinkedMap);
661                 DUMP_FOR_HANDLE(jsFinalizationRegistry);
662                 break;
663             }
664             case JSType::CELL_RECORD: {
665                 CHECK_DUMP_FIELDS(Record::SIZE, CellRecord::SIZE, 2U);
666                 JSHandle<CellRecord> cellRecord = factory->NewCellRecord();
667                 DUMP_FOR_HANDLE(cellRecord);
668                 break;
669             }
670             case JSType::JS_DATE: {
671                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSDate::SIZE, 2U);
672                 JSHandle<JSHClass> dateClass = factory->NewEcmaHClass(JSDate::SIZE, JSType::JS_DATE, proto);
673                 JSHandle<JSDate> date = JSHandle<JSDate>::Cast(factory->NewJSObjectWithInit(dateClass));
674                 date->SetTimeValue(thread, JSTaggedValue(0.0));
675                 date->SetLocalOffset(thread, JSTaggedValue(0.0));
676                 DUMP_FOR_HANDLE(date);
677                 break;
678             }
679             case JSType::JS_FORIN_ITERATOR: {
680                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSForInIterator::SIZE, 4U);
681                 JSHandle<JSTaggedValue> array(thread, factory->NewJSArray().GetTaggedValue());
682                 JSHandle<JSTaggedValue> keys(thread, factory->EmptyArray().GetTaggedValue());
683                 JSHandle<JSTaggedValue> hclass(thread, JSTaggedValue::Undefined());
684                 JSHandle<JSForInIterator> forInIter = factory->NewJSForinIterator(array, keys, hclass);
685                 DUMP_FOR_HANDLE(forInIter);
686                 break;
687             }
688             case JSType::JS_MAP_ITERATOR: {
689                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSMapIterator::SIZE, 2U);
690                 JSHandle<JSMapIterator> jsMapIter =
691                     factory->NewJSMapIterator(NewJSMap(thread, factory, proto), IterationKind::KEY);
692                 DUMP_FOR_HANDLE(jsMapIter);
693                 break;
694             }
695             case JSType::JS_SHARED_MAP_ITERATOR: {
696                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSSharedMapIterator::SIZE, 2U);
697                 JSHandle<JSSharedMapIterator> jsMapIter =
698                     factory->NewJSMapIterator(NewJSSharedMap(thread, factory), IterationKind::KEY);
699                 DUMP_FOR_HANDLE(jsMapIter);
700                 break;
701             }
702             case JSType::JS_SET_ITERATOR: {
703                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSSetIterator::SIZE, 2U);
704                 JSHandle<JSSetIterator> jsSetIter =
705                     factory->NewJSSetIterator(NewJSSet(thread, factory, proto), IterationKind::KEY);
706                 DUMP_FOR_HANDLE(jsSetIter);
707                 break;
708             }
709             case JSType::JS_SHARED_SET_ITERATOR: {
710                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSSharedSetIterator::SIZE, 2U);
711                 JSHandle<JSSharedSetIterator> jsSetIter =
712                     factory->NewJSSetIterator(NewJSSharedSet(thread, factory), IterationKind::KEY);
713                 DUMP_FOR_HANDLE(jsSetIter);
714                 break;
715             }
716             case JSType::JS_REG_EXP_ITERATOR: {
717                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSRegExpIterator::SIZE, 3U);
718                 JSHandle<EcmaString> emptyString(thread->GlobalConstants()->GetHandledEmptyString());
719                 JSHandle<JSTaggedValue> jsRegExp(NewJSRegExp(thread, factory, proto));
720                 JSHandle<JSRegExpIterator> jsRegExpIter =
721                     factory->NewJSRegExpIterator(jsRegExp, emptyString, false, false);
722                 DUMP_FOR_HANDLE(jsRegExpIter);
723                 break;
724             }
725             case JSType::JS_ARRAY_ITERATOR: {
726                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSArrayIterator::SIZE, 2U);
727                 JSHandle<JSArrayIterator> arrayIter =
728                     factory->NewJSArrayIterator(JSHandle<JSObject>::Cast(factory->NewJSArray()), IterationKind::KEY);
729                 DUMP_FOR_HANDLE(arrayIter);
730                 break;
731             }
732             case JSType::JS_SHARED_ARRAY_ITERATOR: {
733                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSArrayIterator::SIZE, 2U);
734                 JSHandle<JSSharedArrayIterator> arrayIter = factory->NewJSSharedArrayIterator(
735                     JSHandle<JSObject>::Cast(factory->NewJSSArray()), IterationKind::KEY);
736                 DUMP_FOR_HANDLE(arrayIter);
737                 break;
738             }
739             case JSType::JS_STRING_ITERATOR: {
740                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSStringIterator::SIZE, 2U);
741                 JSHandle<JSTaggedValue> stringIter = globalEnv->GetStringIterator();
742                 DUMP_FOR_HANDLE(stringIter);
743                 break;
744             }
745             case JSType::JS_INTL: {
746                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSIntl::SIZE, 1U);
747                 NEW_OBJECT_AND_DUMP(JSIntl, JS_INTL);
748                 break;
749             }
750             case JSType::JS_LOCALE: {
751                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSLocale::SIZE, 1U);
752                 NEW_OBJECT_AND_DUMP(JSLocale, JS_LOCALE);
753                 break;
754             }
755             case JSType::JS_DATE_TIME_FORMAT: {
756                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSDateTimeFormat::SIZE, 9U);
757                 NEW_OBJECT_AND_DUMP(JSDateTimeFormat, JS_DATE_TIME_FORMAT);
758                 break;
759             }
760             case JSType::JS_RELATIVE_TIME_FORMAT: {
761                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSRelativeTimeFormat::SIZE, 4U);
762                 NEW_OBJECT_AND_DUMP(JSRelativeTimeFormat, JS_RELATIVE_TIME_FORMAT);
763                 break;
764             }
765             case JSType::JS_NUMBER_FORMAT: {
766                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSNumberFormat::SIZE, 13U);
767                 NEW_OBJECT_AND_DUMP(JSNumberFormat, JS_NUMBER_FORMAT);
768                 break;
769             }
770             case JSType::JS_COLLATOR: {
771                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSCollator::SIZE, 5U);
772                 NEW_OBJECT_AND_DUMP(JSCollator, JS_COLLATOR);
773                 break;
774             }
775             case JSType::JS_PLURAL_RULES: {
776                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSPluralRules::SIZE, 9U);
777                 NEW_OBJECT_AND_DUMP(JSPluralRules, JS_PLURAL_RULES);
778                 break;
779             }
780             case JSType::JS_DISPLAYNAMES: {
781                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSDisplayNames::SIZE, 3U);
782                 NEW_OBJECT_AND_DUMP(JSDisplayNames, JS_DISPLAYNAMES);
783                 break;
784             }
785             case JSType::JS_SEGMENTER: {
786                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSSegmenter::SIZE, 3U);
787                 NEW_OBJECT_AND_DUMP(JSSegmenter, JS_SEGMENTER);
788                 break;
789             }
790             case JSType::JS_SEGMENTS: {
791                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSSegments::SIZE, 4U);
792                 NEW_OBJECT_AND_DUMP(JSSegments, JS_SEGMENTS);
793                 break;
794             }
795             case JSType::JS_SEGMENT_ITERATOR: {
796                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSSegmentIterator::SIZE, 4U);
797                 NEW_OBJECT_AND_DUMP(JSSegmentIterator, JS_SEGMENTS);
798                 break;
799             }
800             case JSType::JS_LIST_FORMAT: {
801                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSListFormat::SIZE, 3U);
802                 NEW_OBJECT_AND_DUMP(JSListFormat, JS_LIST_FORMAT);
803                 break;
804             }
805             case JSType::JS_SHARED_ARRAY_BUFFER:
806             case JSType::JS_ARRAY_BUFFER: {
807                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSArrayBuffer::SIZE, 2U);
808                 NEW_OBJECT_AND_DUMP(JSArrayBuffer, JS_ARRAY_BUFFER);
809                 break;
810             }
811             case JSType::JS_SENDABLE_ARRAY_BUFFER: {
812                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSSendableArrayBuffer::SIZE, 2U);
813                 NEW_OBJECT_AND_DUMP(JSSendableArrayBuffer, JS_SENDABLE_ARRAY_BUFFER);
814                 break;
815             }
816             case JSType::JS_PROMISE: {
817                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSPromise::SIZE, 4U);
818                 NEW_OBJECT_AND_DUMP(JSPromise, JS_PROMISE);
819                 break;
820             }
821             case JSType::JS_DATA_VIEW: {
822                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSDataView::SIZE, 3U);
823                 NEW_OBJECT_AND_DUMP(JSDataView, JS_DATA_VIEW);
824                 break;
825             }
826             case JSType::JS_GENERATOR_OBJECT: {
827                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSGeneratorObject::SIZE, 4U);
828                 NEW_OBJECT_AND_DUMP(JSGeneratorObject, JS_GENERATOR_OBJECT);
829                 break;
830             }
831             case JSType::JS_ASYNC_GENERATOR_OBJECT: {
832                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAsyncGeneratorObject::SIZE, 5U);
833                 NEW_OBJECT_AND_DUMP(JSAsyncGeneratorObject, JS_ASYNC_GENERATOR_OBJECT);
834                 break;
835             }
836             case JSType::JS_ASYNC_FUNC_OBJECT: {
837                 CHECK_DUMP_FIELDS(JSGeneratorObject::SIZE, JSAsyncFuncObject::SIZE, 1U);
838                 JSHandle<JSAsyncFuncObject> asyncFuncObject = factory->NewJSAsyncFuncObject();
839                 DUMP_FOR_HANDLE(asyncFuncObject);
840                 break;
841             }
842             case JSType::JS_ARRAY: {
843                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSArray::SIZE, 2U);
844                 JSHandle<JSArray> jsArray = factory->NewJSArray();
845                 DUMP_FOR_HANDLE(jsArray);
846                 break;
847             }
848             case JSType::JS_SHARED_ARRAY: {
849                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSArray::SIZE, 2U);
850                 JSHandle<JSSharedArray> jsArray = factory->NewJSSArray();
851                 DUMP_FOR_HANDLE(jsArray);
852                 break;
853             }
854             case JSType::JS_TYPED_ARRAY:
855             case JSType::JS_INT8_ARRAY:
856             case JSType::JS_UINT8_ARRAY:
857             case JSType::JS_UINT8_CLAMPED_ARRAY:
858             case JSType::JS_INT16_ARRAY:
859             case JSType::JS_UINT16_ARRAY:
860             case JSType::JS_INT32_ARRAY:
861             case JSType::JS_UINT32_ARRAY:
862             case JSType::JS_FLOAT32_ARRAY:
863             case JSType::JS_FLOAT64_ARRAY:
864             case JSType::JS_BIGINT64_ARRAY:
865             case JSType::JS_BIGUINT64_ARRAY: {
866                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSTypedArray::SIZE, 4U);
867                 NEW_OBJECT_AND_DUMP(JSTypedArray, JS_TYPED_ARRAY);
868                 break;
869             }
870             case JSType::JS_SHARED_TYPED_ARRAY:
871             case JSType::JS_SHARED_INT8_ARRAY:
872             case JSType::JS_SHARED_UINT8_ARRAY:
873             case JSType::JS_SHARED_UINT8_CLAMPED_ARRAY:
874             case JSType::JS_SHARED_INT16_ARRAY:
875             case JSType::JS_SHARED_UINT16_ARRAY:
876             case JSType::JS_SHARED_INT32_ARRAY:
877             case JSType::JS_SHARED_UINT32_ARRAY:
878             case JSType::JS_SHARED_FLOAT32_ARRAY:
879             case JSType::JS_SHARED_FLOAT64_ARRAY:
880             case JSType::JS_SHARED_BIGINT64_ARRAY:
881             case JSType::JS_SHARED_BIGUINT64_ARRAY: {
882                 // Fixme(Gymee) Add test later
883                 break;
884             }
885             case JSType::JS_PRIMITIVE_REF: {
886                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSPrimitiveRef::SIZE, 1U);
887                 NEW_OBJECT_AND_DUMP(JSPrimitiveRef, JS_PRIMITIVE_REF);
888                 break;
889             }
890             case JSType::JS_GLOBAL_OBJECT: {
891                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSGlobalObject::SIZE, 0U);
892                 JSHandle<JSTaggedValue> globalObject = globalEnv->GetJSGlobalObject();
893                 DUMP_FOR_HANDLE(globalObject);
894                 break;
895             }
896             case JSType::JS_PROXY: {
897                 CHECK_DUMP_FIELDS(ECMAObject::SIZE, JSProxy::SIZE, 5U);
898                 JSHandle<JSTaggedValue> emptyObj(thread, NewJSObject(thread, factory, globalEnv).GetTaggedValue());
899                 JSHandle<JSProxy> proxy = factory->NewJSProxy(emptyObj, emptyObj);
900                 DUMP_FOR_HANDLE(proxy);
901                 break;
902             }
903             case JSType::HCLASS: {
904                 CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), JSHClass::SIZE, 9U);
905                 JSHandle<JSHClass> hclass = factory->NewEcmaHClass(JSHClass::SIZE, JSType::HCLASS, proto);
906                 DUMP_FOR_HANDLE(hclass);
907                 break;
908             }
909             case JSType::LINE_STRING:
910             case JSType::CONSTANT_STRING:
911             case JSType::TREE_STRING:
912             case JSType::SLICED_STRING: {
913                 DUMP_FOR_HANDLE(globalEnv->GetObjectFunction());
914                 break;
915             }
916             case JSType::BIGINT: {
917                 DUMP_FOR_HANDLE(globalEnv->GetBigIntFunction());
918                 break;
919             }
920             case JSType::PROFILE_TYPE_INFO_CELL_0:
921             case JSType::PROFILE_TYPE_INFO_CELL_1:
922             case JSType::PROFILE_TYPE_INFO_CELL_N: {
923                 JSHandle<JSTaggedValue> handleUndefined(thread, JSTaggedValue::Undefined());
924                 JSHandle<ProfileTypeInfoCell> profileTypeInfoCell = factory->NewProfileTypeInfoCell(handleUndefined);
925                 DUMP_FOR_HANDLE(profileTypeInfoCell);
926                 break;
927             }
928             case JSType::FUNCTION_TEMPLATE: {
929                 auto method = JSFunction::Cast(globalEnv->GetTaggedObjectFunction())->GetMethod();
930                 JSHandle<Method> methodHandle(thread, method);
931                 JSHandle<JSTaggedValue> handleUndefined(thread, JSTaggedValue::Undefined());
932                 JSHandle<FunctionTemplate> funcTemp = factory->NewFunctionTemplate(methodHandle, handleUndefined, 0);
933                 DUMP_FOR_HANDLE(funcTemp);
934                 break;
935             }
936             case JSType::TAGGED_ARRAY:
937             case JSType::VTABLE:
938             case JSType::LEXICAL_ENV:
939             case JSType::SENDABLE_ENV:
940             case JSType::AOT_LITERAL_INFO: {
941                 JSHandle<TaggedArray> taggedArray = factory->NewTaggedArray(4);
942                 DUMP_FOR_HANDLE(taggedArray);
943                 break;
944             }
945             case JSType::CONSTANT_POOL: {
946                 JSHandle<ConstantPool> constantPool = factory->NewConstantPool(4);
947                 DUMP_FOR_HANDLE(constantPool);
948                 break;
949             }
950             case JSType::PROFILE_TYPE_INFO: {
951                 JSHandle<ProfileTypeInfo> info = factory->NewProfileTypeInfo(4);
952                 DUMP_FOR_HANDLE(info);
953                 break;
954             }
955             case JSType::EXTRA_PROFILE_TYPE_INFO: {
956                 JSHandle<ExtraProfileTypeInfo> info = factory->NewExtraProfileTypeInfo();
957                 DUMP_FOR_HANDLE(info);
958                 break;
959             }
960             case JSType::TAGGED_DICTIONARY: {
961                 JSHandle<TaggedArray> dict = factory->NewDictionaryArray(4);
962                 DUMP_FOR_HANDLE(dict);
963                 break;
964             }
965             case JSType::BYTE_ARRAY: {
966                 JSHandle<ByteArray> byteArray = factory->NewByteArray(4, 8);
967                 DUMP_FOR_HANDLE(byteArray);
968                 break;
969             }
970             case JSType::COW_TAGGED_ARRAY: {
971                 JSHandle<COWTaggedArray> dict = factory->NewCOWTaggedArray(4);
972                 DUMP_FOR_HANDLE(dict);
973                 break;
974             }
975             case JSType::MUTANT_TAGGED_ARRAY: {
976                 JSHandle<MutantTaggedArray> array = factory->NewMutantTaggedArray(4);
977                 DUMP_FOR_HANDLE(array);
978                 break;
979             }
980             case JSType::COW_MUTANT_TAGGED_ARRAY: {
981                 JSHandle<COWMutantTaggedArray> array = factory->NewCOWMutantTaggedArray(4);
982                 DUMP_FOR_HANDLE(array);
983                 break;
984             }
985             case JSType::GLOBAL_ENV: {
986                 DUMP_FOR_HANDLE(globalEnv);
987                 break;
988             }
989             case JSType::ACCESSOR_DATA:
990             case JSType::INTERNAL_ACCESSOR: {
991                 CHECK_DUMP_FIELDS(Record::SIZE, AccessorData::SIZE, 2U);
992                 JSHandle<AccessorData> accessor = factory->NewAccessorData();
993                 DUMP_FOR_HANDLE(accessor);
994                 break;
995             }
996             case JSType::SYMBOL: {
997                 CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), JSSymbol::SIZE, 3U);
998                 JSHandle<JSSymbol> symbol = factory->NewJSSymbol();
999                 DUMP_FOR_HANDLE(symbol);
1000                 break;
1001             }
1002             case JSType::JS_GENERATOR_CONTEXT: {
1003                 CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), GeneratorContext::SIZE, 7U);
1004                 JSHandle<GeneratorContext> genContext = factory->NewGeneratorContext();
1005                 DUMP_FOR_HANDLE(genContext);
1006                 break;
1007             }
1008             case JSType::PROTOTYPE_HANDLER: {
1009                 CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), PrototypeHandler::SIZE, 5U);
1010                 JSHandle<PrototypeHandler> protoHandler = factory->NewPrototypeHandler();
1011                 DUMP_FOR_HANDLE(protoHandler);
1012                 break;
1013             }
1014             case JSType::TRANSITION_HANDLER: {
1015                 CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TransitionHandler::SIZE, 2U);
1016                 JSHandle<TransitionHandler> transitionHandler = factory->NewTransitionHandler();
1017                 DUMP_FOR_HANDLE(transitionHandler);
1018                 break;
1019             }
1020             case JSType::TRANS_WITH_PROTO_HANDLER: {
1021                 CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TransWithProtoHandler::SIZE, 3U);
1022                 JSHandle<TransWithProtoHandler> transWithProtoHandler = factory->NewTransWithProtoHandler();
1023                 DUMP_FOR_HANDLE(transWithProtoHandler);
1024                 break;
1025             }
1026             case JSType::STORE_TS_HANDLER: {
1027                 CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), StoreTSHandler::SIZE, 3U);
1028                 JSHandle<StoreTSHandler> storeTSHandler = factory->NewStoreTSHandler();
1029                 DUMP_FOR_HANDLE(storeTSHandler);
1030                 break;
1031             }
1032             case JSType::PROPERTY_BOX: {
1033                 CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), PropertyBox::SIZE, 1U);
1034                 JSHandle<PropertyBox> PropertyBox = factory->NewPropertyBox(globalConst->GetHandledEmptyArray());
1035                 DUMP_FOR_HANDLE(PropertyBox);
1036                 break;
1037             }
1038             case JSType::PROTO_CHANGE_MARKER: {
1039                 CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), ProtoChangeMarker::SIZE, 1U);
1040                 JSHandle<ProtoChangeMarker> protoMaker = factory->NewProtoChangeMarker();
1041                 DUMP_FOR_HANDLE(protoMaker);
1042                 break;
1043             }
1044             case JSType::MARKER_CELL: {
1045                 CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), MarkerCell::SIZE, 1U);
1046                 JSHandle<MarkerCell> markerCell = factory->NewMarkerCell();
1047                 DUMP_FOR_HANDLE(markerCell);
1048                 break;
1049             }
1050             case JSType::TRACK_INFO: {
1051                 CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TrackInfo::SIZE, 3U);
1052                 break;
1053             }
1054             case JSType::PROTOTYPE_INFO: {
1055                 CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), ProtoChangeDetails::SIZE, 2U);
1056                 JSHandle<ProtoChangeDetails> protoDetails = factory->NewProtoChangeDetails();
1057                 DUMP_FOR_HANDLE(protoDetails);
1058                 break;
1059             }
1060             case JSType::TEMPLATE_MAP: {
1061                 JSHandle<JSTaggedValue> templateMap = globalEnv->GetTemplateMap();
1062                 DUMP_FOR_HANDLE(templateMap);
1063                 break;
1064             }
1065             case JSType::PROGRAM: {
1066                 CHECK_DUMP_FIELDS(ECMAObject::SIZE, Program::SIZE, 1U);
1067                 JSHandle<Program> program = factory->NewProgram();
1068                 DUMP_FOR_HANDLE(program);
1069                 break;
1070             }
1071             case JSType::PROMISE_CAPABILITY: {
1072                 CHECK_DUMP_FIELDS(Record::SIZE, PromiseCapability::SIZE, 3U);
1073                 JSHandle<PromiseCapability> promiseCapa = factory->NewPromiseCapability();
1074                 DUMP_FOR_HANDLE(promiseCapa);
1075                 break;
1076             }
1077             case JSType::PROMISE_RECORD: {
1078                 CHECK_DUMP_FIELDS(Record::SIZE, PromiseRecord::SIZE, 1U);
1079                 JSHandle<PromiseRecord> promiseRecord = factory->NewPromiseRecord();
1080                 DUMP_FOR_HANDLE(promiseRecord);
1081                 break;
1082             }
1083             case JSType::RESOLVING_FUNCTIONS_RECORD: {
1084                 CHECK_DUMP_FIELDS(Record::SIZE, ResolvingFunctionsRecord::SIZE, 2U);
1085                 JSHandle<ResolvingFunctionsRecord> ResolvingFunc = factory->NewResolvingFunctionsRecord();
1086                 DUMP_FOR_HANDLE(ResolvingFunc);
1087                 break;
1088             }
1089             case JSType::ASYNC_GENERATOR_REQUEST: {
1090                 CHECK_DUMP_FIELDS(Record::SIZE, AsyncGeneratorRequest::SIZE, 2U);
1091                 JSHandle<AsyncGeneratorRequest> asyncGeneratorRequest = factory->NewAsyncGeneratorRequest();
1092                 DUMP_FOR_HANDLE(asyncGeneratorRequest);
1093                 break;
1094             }
1095             case JSType::ASYNC_ITERATOR_RECORD: {
1096                 CHECK_DUMP_FIELDS(Record::SIZE, AsyncIteratorRecord::SIZE, 3U);
1097                 JSHandle<JSTaggedValue> emptyObj(thread, NewJSObject(thread, factory, globalEnv).GetTaggedValue());
1098                 JSHandle<JSTaggedValue> emptyMethod(thread, NewJSObject(thread, factory, globalEnv).GetTaggedValue());
1099                 JSHandle<AsyncIteratorRecord> asyncIteratorRecord =
1100                     factory->NewAsyncIteratorRecord(emptyObj, emptyMethod, false);
1101                 DUMP_FOR_HANDLE(asyncIteratorRecord);
1102                 break;
1103             }
1104             case JSType::JS_ASYNC_FROM_SYNC_ITERATOR: {
1105                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAsyncFromSyncIterator::SIZE, 1U);
1106                 NEW_OBJECT_AND_DUMP(JSAsyncFromSyncIterator, JS_ASYNC_FROM_SYNC_ITERATOR);
1107                 break;
1108             }
1109             case JSType::JS_ASYNC_FROM_SYNC_ITER_UNWARP_FUNCTION: {
1110                 CHECK_DUMP_FIELDS(JSFunction::SIZE, JSAsyncFromSyncIterUnwarpFunction::SIZE, 1U);
1111                 break;
1112             }
1113             case JSType::PROMISE_REACTIONS: {
1114                 CHECK_DUMP_FIELDS(Record::SIZE, PromiseReaction::SIZE, 3U);
1115                 JSHandle<PromiseReaction> promiseReact = factory->NewPromiseReaction();
1116                 DUMP_FOR_HANDLE(promiseReact);
1117                 break;
1118             }
1119             case JSType::PROMISE_ITERATOR_RECORD: {
1120                 CHECK_DUMP_FIELDS(Record::SIZE, PromiseIteratorRecord::SIZE, 2U);
1121                 JSHandle<JSTaggedValue> emptyObj(thread, NewJSObject(thread, factory, globalEnv).GetTaggedValue());
1122                 JSHandle<PromiseIteratorRecord> promiseIter = factory->NewPromiseIteratorRecord(emptyObj, false);
1123                 DUMP_FOR_HANDLE(promiseIter);
1124                 break;
1125             }
1126             case JSType::MICRO_JOB_QUEUE: {
1127                 CHECK_DUMP_FIELDS(Record::SIZE, ecmascript::job::MicroJobQueue::SIZE, 2U);
1128                 JSHandle<ecmascript::job::MicroJobQueue> microJob = factory->NewMicroJobQueue();
1129                 DUMP_FOR_HANDLE(microJob);
1130                 break;
1131             }
1132             case JSType::PENDING_JOB: {
1133 #if defined(ENABLE_HITRACE)
1134                 CHECK_DUMP_FIELDS(Record::SIZE, ecmascript::job::PendingJob::SIZE, 7U);
1135 #else
1136                 CHECK_DUMP_FIELDS(Record::SIZE, ecmascript::job::PendingJob::SIZE, 2U);
1137 #endif
1138                 JSHandle<JSHClass> pendingClass(thread,
1139                     JSHClass::Cast(globalConst->GetPendingJobClass().GetTaggedObject()));
1140                 JSHandle<TaggedObject> pendingJob(thread, factory->NewObject(pendingClass));
1141                 ecmascript::job::PendingJob::Cast(*pendingJob)->SetJob(thread, JSTaggedValue::Undefined());
1142                 ecmascript::job::PendingJob::Cast(*pendingJob)->SetArguments(thread, JSTaggedValue::Undefined());
1143                 DUMP_FOR_HANDLE(pendingJob);
1144                 break;
1145             }
1146             case JSType::COMPLETION_RECORD: {
1147                 CHECK_DUMP_FIELDS(Record::SIZE, CompletionRecord::SIZE, 2U);
1148                 JSHandle<CompletionRecord> comRecord =
1149                     factory->NewCompletionRecord(CompletionRecordType::NORMAL, globalConst->GetHandledEmptyArray());
1150                 DUMP_FOR_HANDLE(comRecord);
1151                 break;
1152             }
1153             case JSType::MACHINE_CODE_OBJECT: {
1154                 CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), MachineCode::SIZE, 6U);
1155                 GTEST_LOG_(INFO) << "MACHINE_CODE_OBJECT not support new in MachineCodeSpace";
1156                 break;
1157             }
1158             case JSType::CLASS_INFO_EXTRACTOR: {
1159                 CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), ClassInfoExtractor::SIZE, 8U);
1160                 JSHandle<ClassInfoExtractor> classInfoExtractor = factory->NewClassInfoExtractor(
1161                     JSHandle<JSTaggedValue>(thread, JSTaggedValue::Undefined()));
1162                 DUMP_FOR_HANDLE(classInfoExtractor);
1163                 break;
1164             }
1165             case JSType::JS_API_ARRAY_LIST: {
1166                 // 1 : 1 dump fileds number
1167                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIArrayList::SIZE, 1U);
1168                 JSHandle<JSAPIArrayList> jsArrayList = NewJSAPIArrayList(thread, factory, proto);
1169                 DUMP_FOR_HANDLE(jsArrayList);
1170                 break;
1171             }
1172             case JSType::JS_API_ARRAYLIST_ITERATOR: {
1173                 // 2 : 2 dump fileds number
1174                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIArrayListIterator::SIZE, 2U);
1175                 JSHandle<JSAPIArrayList> jsArrayList = NewJSAPIArrayList(thread, factory, proto);
1176                 JSHandle<JSAPIArrayListIterator> jsArrayListIter = factory->NewJSAPIArrayListIterator(jsArrayList);
1177                 DUMP_FOR_HANDLE(jsArrayListIter);
1178                 break;
1179             }
1180             case JSType::JS_API_BITVECTOR: {
1181                 break;
1182             }
1183             case JSType::JS_API_BITVECTOR_ITERATOR: {
1184                 break;
1185             }
1186             case JSType::LINKED_NODE: {
1187                 CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), LinkedNode::SIZE, 4U);
1188                 break;
1189             }
1190             case JSType::RB_TREENODE: {
1191                 CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), RBTreeNode::SIZE, 7U);
1192                 break;
1193             }
1194             case JSType::JS_API_HASH_MAP: {
1195                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIHashMap::SIZE, 2U);
1196                 JSHandle<JSAPIHashMap> jsHashMap = NewJSAPIHashMap(thread, factory);
1197                 DUMP_FOR_HANDLE(jsHashMap);
1198                 break;
1199             }
1200             case JSType::JS_API_HASH_SET: {
1201                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIHashSet::SIZE, 2U);
1202                 JSHandle<JSAPIHashSet> jsHashSet = NewJSAPIHashSet(thread, factory);
1203                 DUMP_FOR_HANDLE(jsHashSet);
1204                 break;
1205             }
1206             case JSType::JS_API_HASHMAP_ITERATOR: {
1207                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIHashMapIterator::SIZE, 4U);
1208                 JSHandle<JSAPIHashMap> jsHashMap = NewJSAPIHashMap(thread, factory);
1209                 JSHandle<JSAPIHashMapIterator> jsHashMapIter =
1210                     factory->NewJSAPIHashMapIterator(jsHashMap, IterationKind::KEY);
1211                 DUMP_FOR_HANDLE(jsHashMapIter);
1212                 break;
1213             }
1214             case JSType::JS_API_HASHSET_ITERATOR: {
1215                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIHashSetIterator::SIZE, 5U);
1216                 JSHandle<JSAPIHashSet> jsHashSet = NewJSAPIHashSet(thread, factory);
1217                 JSHandle<JSAPIHashSetIterator> jsHashSetIter =
1218                     factory->NewJSAPIHashSetIterator(jsHashSet, IterationKind::KEY);
1219                 DUMP_FOR_HANDLE(jsHashSetIter);
1220                 break;
1221             }
1222             case JSType::JS_API_LIGHT_WEIGHT_MAP: {
1223                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPILightWeightMap::SIZE, 4U);
1224                 JSHandle<JSAPILightWeightMap> jSAPILightWeightMap = NewJSAPILightWeightMap(thread, factory);
1225                 DUMP_FOR_HANDLE(jSAPILightWeightMap);
1226                 break;
1227             }
1228             case JSType::JS_API_LIGHT_WEIGHT_MAP_ITERATOR: {
1229                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPILightWeightMapIterator::SIZE, 2U);
1230                 JSHandle<JSAPILightWeightMap> jSAPILightWeightMap = NewJSAPILightWeightMap(thread, factory);
1231                 JSHandle<JSAPILightWeightMapIterator> jSAPILightWeightMapIterator =
1232                     factory->NewJSAPILightWeightMapIterator(jSAPILightWeightMap, IterationKind::KEY);
1233                 DUMP_FOR_HANDLE(jSAPILightWeightMapIterator);
1234                 break;
1235             }
1236             case JSType::JS_API_LIGHT_WEIGHT_SET: {
1237                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPILightWeightSet::SIZE, 3U);
1238                 JSHandle<JSAPILightWeightSet> jSAPILightWeightSet = NewJSAPILightWeightSet(thread, factory);
1239                 DUMP_FOR_HANDLE(jSAPILightWeightSet);
1240                 break;
1241             }
1242             case JSType::JS_API_LIGHT_WEIGHT_SET_ITERATOR: {
1243                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPILightWeightSetIterator::SIZE, 2U);
1244                 JSHandle<JSAPILightWeightSetIterator> jSAPILightWeightSetIter =
1245                     factory->NewJSAPILightWeightSetIterator(NewJSAPILightWeightSet(thread, factory),
1246                                                             IterationKind::KEY);
1247                 DUMP_FOR_HANDLE(jSAPILightWeightSetIter);
1248                 break;
1249             }
1250             case JSType::JS_API_QUEUE: {
1251                 // 2 : 2 dump fileds number
1252                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIQueue::SIZE, 2U);
1253                 JSHandle<JSAPIQueue> jsQueue = NewJSAPIQueue(thread, factory, proto);
1254                 DUMP_FOR_HANDLE(jsQueue);
1255                 break;
1256             }
1257             case JSType::JS_API_QUEUE_ITERATOR: {
1258                 // 2 : 2 dump fileds number
1259                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIQueueIterator::SIZE, 2U);
1260                 JSHandle<JSAPIQueue> jsQueue = NewJSAPIQueue(thread, factory, proto);
1261                 JSHandle<JSAPIQueueIterator> jsQueueIter =
1262                     factory->NewJSAPIQueueIterator(jsQueue);
1263                 DUMP_FOR_HANDLE(jsQueueIter);
1264                 break;
1265             }
1266             case JSType::JS_API_PLAIN_ARRAY: {
1267                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIPlainArray::SIZE, 3U);
1268                 JSHandle<JSAPIPlainArray> jSAPIPlainArray = NewJSAPIPlainArray(thread, factory);
1269                 DUMP_FOR_HANDLE(jSAPIPlainArray);
1270                 break;
1271             }
1272             case JSType::JS_API_PLAIN_ARRAY_ITERATOR: {
1273                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIPlainArrayIterator::SIZE, 2U);
1274                 JSHandle<JSAPIPlainArray> jSAPIPlainArray = NewJSAPIPlainArray(thread, factory);
1275                 JSHandle<JSAPIPlainArrayIterator> jSAPIPlainArrayIter =
1276                     factory->NewJSAPIPlainArrayIterator(jSAPIPlainArray, IterationKind::KEY);
1277                 DUMP_FOR_HANDLE(jSAPIPlainArrayIter);
1278                 break;
1279             }
1280             case JSType::JS_API_TREE_MAP: {
1281                 // 1 : 1 dump fileds number
1282                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPITreeMap::SIZE, 1U);
1283                 JSHandle<JSAPITreeMap> jsTreeMap = NewJSAPITreeMap(thread, factory);
1284                 DUMP_FOR_HANDLE(jsTreeMap);
1285                 break;
1286             }
1287             case JSType::JS_API_TREE_SET: {
1288                 // 1 : 1 dump fileds number
1289                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPITreeSet::SIZE, 1U);
1290                 JSHandle<JSAPITreeSet> jsTreeSet = NewJSAPITreeSet(thread, factory);
1291                 DUMP_FOR_HANDLE(jsTreeSet);
1292                 break;
1293             }
1294             case JSType::JS_API_TREEMAP_ITERATOR: {
1295                 // 3 : 3 dump fileds number
1296                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPITreeMapIterator::SIZE, 3U);
1297                 JSHandle<JSAPITreeMap> jsTreeMap = NewJSAPITreeMap(thread, factory);
1298                 JSHandle<JSAPITreeMapIterator> jsTreeMapIter =
1299                     factory->NewJSAPITreeMapIterator(jsTreeMap, IterationKind::KEY);
1300                 DUMP_FOR_HANDLE(jsTreeMapIter);
1301                 break;
1302             }
1303             case JSType::JS_API_TREESET_ITERATOR: {
1304                 // 3 : 3 dump fileds number
1305                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPITreeSetIterator::SIZE, 3U);
1306                 JSHandle<JSAPITreeSet> jsTreeSet = NewJSAPITreeSet(thread, factory);
1307                 JSHandle<JSAPITreeSetIterator> jsTreeSetIter =
1308                     factory->NewJSAPITreeSetIterator(jsTreeSet, IterationKind::KEY);
1309                 DUMP_FOR_HANDLE(jsTreeSetIter);
1310                 break;
1311             }
1312             case JSType::JS_API_DEQUE: {
1313                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIDeque::SIZE, 1U);
1314                 JSHandle<JSAPIDeque> jsDeque = NewJSAPIDeque(thread, factory, proto);
1315                 DUMP_FOR_HANDLE(jsDeque);
1316                 break;
1317             }
1318             case JSType::JS_API_DEQUE_ITERATOR: {
1319                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIDequeIterator::SIZE, 2U);
1320                 JSHandle<JSAPIDequeIterator> jsDequeIter =
1321                     factory->NewJSAPIDequeIterator(NewJSAPIDeque(thread, factory, proto));
1322                 DUMP_FOR_HANDLE(jsDequeIter);
1323                 break;
1324             }
1325             case JSType::JS_API_STACK: {
1326                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIStack::SIZE, 1U);
1327                 JSHandle<JSAPIStack> jsStack = NewJSAPIStack(factory, proto);
1328                 DUMP_FOR_HANDLE(jsStack);
1329                 break;
1330             }
1331             case JSType::JS_API_STACK_ITERATOR: {
1332                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIStackIterator::SIZE, 2U);
1333                 JSHandle<JSAPIStackIterator> jsStackIter =
1334                     factory->NewJSAPIStackIterator(NewJSAPIStack(factory, proto));
1335                 DUMP_FOR_HANDLE(jsStackIter);
1336                 break;
1337             }
1338             case JSType::JS_API_VECTOR: {
1339                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIVector::SIZE, 1U);
1340                 JSHandle<JSAPIVector> jsVector = NewJSAPIVector(factory, proto);
1341                 DUMP_FOR_HANDLE(jsVector);
1342                 break;
1343             }
1344             case JSType::JS_API_VECTOR_ITERATOR: {
1345                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIVectorIterator::SIZE, 2U);
1346                 JSHandle<JSAPIVectorIterator> jsVectorIter =
1347                     factory->NewJSAPIVectorIterator(NewJSAPIVector(factory, proto));
1348                 DUMP_FOR_HANDLE(jsVectorIter);
1349                 break;
1350             }
1351             case JSType::JS_API_LIST: {
1352                 // 1 : 1 dump fileds number
1353                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIList::SIZE, 2U);
1354                 JSHandle<JSAPIList> jsAPIList = NewJSAPIList(thread, factory);
1355                 DUMP_FOR_HANDLE(jsAPIList);
1356                 break;
1357             }
1358             case JSType::JS_API_LINKED_LIST: {
1359                 // 1 : 1 dump fileds number
1360                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPILinkedList::SIZE, 1U);
1361                 JSHandle<JSAPILinkedList> jsAPILinkedList = NewJSAPILinkedList(thread, factory);
1362                 DUMP_FOR_HANDLE(jsAPILinkedList);
1363                 break;
1364             }
1365             case JSType::JS_API_LIST_ITERATOR: {
1366                 // 2 : 2 dump fileds number
1367                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIListIterator::SIZE, 2U);
1368                 JSHandle<JSAPIList> jsAPIList = NewJSAPIList(thread, factory);
1369                 JSHandle<JSAPIListIterator> jsAPIListIter = factory->NewJSAPIListIterator(jsAPIList);
1370                 DUMP_FOR_HANDLE(jsAPIListIter);
1371                 break;
1372             }
1373             case JSType::JS_API_LINKED_LIST_ITERATOR: {
1374                 // 2 : 2 dump fileds number
1375                 CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPILinkedListIterator::SIZE, 2U);
1376                 JSHandle<JSAPILinkedList> jsAPILinkedList = NewJSAPILinkedList(thread, factory);
1377                 JSHandle<JSAPILinkedListIterator> jsAPILinkedListIter =
1378                     factory->NewJSAPILinkedListIterator(jsAPILinkedList);
1379                 DUMP_FOR_HANDLE(jsAPILinkedListIter);
1380                 break;
1381             }
1382             case JSType::MODULE_RECORD: {
1383                 CHECK_DUMP_FIELDS(Record::SIZE, ModuleRecord::SIZE, 0U);
1384                 break;
1385             }
1386             case JSType::SOURCE_TEXT_MODULE_RECORD: {
1387                 CHECK_DUMP_FIELDS(ModuleRecord::SIZE, SourceTextModule::SIZE, 18U);
1388                 JSHandle<SourceTextModule> moduleSourceRecord = factory->NewSourceTextModule();
1389                 DUMP_FOR_HANDLE(moduleSourceRecord);
1390                 break;
1391             }
1392             case JSType::IMPORTENTRY_RECORD: {
1393                 CHECK_DUMP_FIELDS(Record::SIZE, ImportEntry::SIZE, 3U);
1394                 JSHandle<ImportEntry> importEntry = factory->NewImportEntry();
1395                 DUMP_FOR_HANDLE(importEntry);
1396                 break;
1397             }
1398             case JSType::LOCAL_EXPORTENTRY_RECORD: {
1399                 CHECK_DUMP_FIELDS(Record::SIZE, LocalExportEntry::SIZE, 3U);
1400                 JSHandle<LocalExportEntry> localExportEntry = factory->NewLocalExportEntry();
1401                 DUMP_FOR_HANDLE(localExportEntry);
1402                 break;
1403             }
1404             case JSType::INDIRECT_EXPORTENTRY_RECORD: {
1405                 CHECK_DUMP_FIELDS(Record::SIZE, IndirectExportEntry::SIZE, 3U);
1406                 JSHandle<IndirectExportEntry> indirectExportEntry = factory->NewIndirectExportEntry();
1407                 DUMP_FOR_HANDLE(indirectExportEntry);
1408                 break;
1409             }
1410             case JSType::STAR_EXPORTENTRY_RECORD: {
1411                 CHECK_DUMP_FIELDS(Record::SIZE, StarExportEntry::SIZE, 1U);
1412                 JSHandle<StarExportEntry> starExportEntry = factory->NewStarExportEntry();
1413                 DUMP_FOR_HANDLE(starExportEntry);
1414                 break;
1415             }
1416             case JSType::RESOLVEDBINDING_RECORD: {
1417                 CHECK_DUMP_FIELDS(Record::SIZE, ResolvedBinding::SIZE, 2U);
1418                 JSHandle<ResolvedBinding> resolvedBinding = factory->NewResolvedBindingRecord();
1419                 DUMP_FOR_HANDLE(resolvedBinding);
1420                 break;
1421             }
1422             case JSType::RESOLVEDINDEXBINDING_RECORD: {
1423                 CHECK_DUMP_FIELDS(Record::SIZE, ResolvedIndexBinding::SIZE, 2U);
1424                 JSHandle<ResolvedIndexBinding> resolvedBinding = factory->NewResolvedIndexBindingRecord();
1425                 DUMP_FOR_HANDLE(resolvedBinding);
1426                 break;
1427             }
1428             case JSType::RESOLVEDRECORDINDEXBINDING_RECORD: {
1429                 CHECK_DUMP_FIELDS(Record::SIZE, ResolvedRecordIndexBinding::SIZE, 3U);
1430                 JSHandle<ResolvedRecordIndexBinding> recordBinding = factory->NewSResolvedRecordIndexBindingRecord();
1431                 DUMP_FOR_HANDLE(recordBinding);
1432                 break;
1433             }
1434             case JSType::RESOLVEDRECORDBINDING_RECORD: {
1435                 CHECK_DUMP_FIELDS(Record::SIZE, ResolvedRecordBinding::SIZE, 2U);
1436                 JSHandle<ResolvedRecordBinding> recordBinding = factory->NewSResolvedRecordBindingRecord();
1437                 DUMP_FOR_HANDLE(recordBinding);
1438                 break;
1439             }
1440             case JSType::JS_MODULE_NAMESPACE: {
1441                 CHECK_DUMP_FIELDS(JSObject::SIZE, ModuleNamespace::SIZE, 3U);
1442                 JSHandle<ModuleNamespace> moduleNamespace = factory->NewModuleNamespace();
1443                 DUMP_FOR_HANDLE(moduleNamespace);
1444                 break;
1445             }
1446             case JSType::NATIVE_MODULE_FAILURE_INFO: {
1447                 CHECK_DUMP_FIELDS(JSObject::SIZE, NativeModuleFailureInfo::SIZE, 1U);
1448                 JSHandle<NativeModuleFailureInfo> nativeFailureInfo = factory->NewNativeModuleFailureInfo();
1449                 DUMP_FOR_HANDLE(nativeFailureInfo);
1450                 break;
1451             }
1452             case JSType::JS_CJS_EXPORTS: {
1453                 CHECK_DUMP_FIELDS(JSObject::SIZE, CjsExports::SIZE, 1U);
1454                 JSHandle<CjsExports> cjsExports = factory->NewCjsExports();
1455                 DUMP_FOR_HANDLE(cjsExports);
1456                 break;
1457             }
1458             case JSType::JS_CJS_MODULE: {
1459                 CHECK_DUMP_FIELDS(JSObject::SIZE, CjsModule::SIZE, 5U);
1460                 JSHandle<CjsModule> cjsModule = factory->NewCjsModule();
1461                 DUMP_FOR_HANDLE(cjsModule);
1462                 break;
1463             }
1464             case JSType::JS_CJS_REQUIRE: {
1465                 CHECK_DUMP_FIELDS(JSObject::SIZE, CjsRequire::SIZE, 2U);
1466                 JSHandle<CjsRequire> cjsRequire = factory->NewCjsRequire();
1467                 DUMP_FOR_HANDLE(cjsRequire);
1468                 break;
1469             }
1470             case JSType::JS_ITERATOR:
1471             case JSType::JS_ASYNCITERATOR:
1472             case JSType::FREE_OBJECT_WITH_ONE_FIELD:
1473             case JSType::FREE_OBJECT_WITH_NONE_FIELD:
1474             case JSType::FREE_OBJECT_WITH_TWO_FIELD:
1475             case JSType::JS_NATIVE_POINTER: {
1476                 break;
1477             }
1478             case JSType::JS_ASYNC_GENERATOR_RESUME_NEXT_RETURN_PROCESSOR_RST_FTN: {
1479                 CHECK_DUMP_FIELDS(JSFunction::SIZE, JSAsyncGeneratorResNextRetProRstFtn::SIZE, 1U);
1480                 break;
1481             }
1482             case JSType::CLASS_LITERAL: {
1483                 CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), ClassLiteral::SIZE, 2U);
1484                 JSHandle<ClassLiteral> classLiteral = factory->NewClassLiteral();
1485                 DUMP_FOR_HANDLE(classLiteral);
1486                 break;
1487             }
1488             default:
1489                 LOG_ECMA_MEM(FATAL) << "JSType " << static_cast<int>(type) << " cannot be dumped.";
1490                 UNREACHABLE();
1491                 break;
1492         }
1493     }
1494 #undef NEW_OBJECT_AND_DUMP
1495 #undef DUMP_FOR_HANDLE
1496 }
1497 }  // namespace panda::test
1498