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