• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/class_info_extractor.h"
18 #include "ecmascript/jspandafile/program_object-inl.h"
19 #include "ecmascript/ecma_module.h"
20 #include "ecmascript/ecma_vm.h"
21 #include "ecmascript/global_dictionary-inl.h"
22 #include "ecmascript/global_env.h"
23 #include "ecmascript/hprof/heap_profiler.h"
24 #include "ecmascript/hprof/heap_profiler_interface.h"
25 #include "ecmascript/hprof/heap_snapshot.h"
26 #include "ecmascript/hprof/heap_snapshot_json_serializer.h"
27 #include "ecmascript/hprof/string_hashmap.h"
28 #include "ecmascript/ic/ic_handler.h"
29 #include "ecmascript/ic/property_box.h"
30 #include "ecmascript/ic/proto_change_details.h"
31 #include "ecmascript/jobs/micro_job_queue.h"
32 #include "ecmascript/jobs/pending_job.h"
33 #include "ecmascript/js_api_tree_map.h"
34 #include "ecmascript/js_api_tree_map_iterator.h"
35 #include "ecmascript/js_api_tree_set.h"
36 #include "ecmascript/js_api_tree_set_iterator.h"
37 #include "ecmascript/js_arguments.h"
38 #include "ecmascript/js_array.h"
39 #include "ecmascript/js_api_arraylist.h"
40 #include "ecmascript/js_api_arraylist_iterator.h"
41 #include "ecmascript/js_array_iterator.h"
42 #include "ecmascript/js_arraybuffer.h"
43 #include "ecmascript/js_async_function.h"
44 #include "ecmascript/js_bigint.h"
45 #include "ecmascript/js_collator.h"
46 #include "ecmascript/js_dataview.h"
47 #include "ecmascript/js_date.h"
48 #include "ecmascript/js_date_time_format.h"
49 #include "ecmascript/js_for_in_iterator.h"
50 #include "ecmascript/js_function.h"
51 #include "ecmascript/js_generator_object.h"
52 #include "ecmascript/js_global_object.h"
53 #include "ecmascript/js_handle.h"
54 #include "ecmascript/js_intl.h"
55 #include "ecmascript/js_locale.h"
56 #include "ecmascript/js_map.h"
57 #include "ecmascript/js_map_iterator.h"
58 #include "ecmascript/js_number_format.h"
59 #include "ecmascript/js_object-inl.h"
60 #include "ecmascript/js_plural_rules.h"
61 #include "ecmascript/js_primitive_ref.h"
62 #include "ecmascript/js_promise.h"
63 #include "ecmascript/js_realm.h"
64 #include "ecmascript/js_regexp.h"
65 #include "ecmascript/js_relative_time_format.h"
66 #include "ecmascript/js_set.h"
67 #include "ecmascript/js_set_iterator.h"
68 #include "ecmascript/js_string_iterator.h"
69 #include "ecmascript/js_tagged_number.h"
70 #include "ecmascript/js_tagged_value-inl.h"
71 #include "ecmascript/js_thread.h"
72 #include "ecmascript/js_typed_array.h"
73 #include "ecmascript/js_weak_container.h"
74 #include "ecmascript/layout_info-inl.h"
75 #include "ecmascript/lexical_env.h"
76 #include "ecmascript/linked_hash_table-inl.h"
77 #include "ecmascript/mem/assert_scope-inl.h"
78 #include "ecmascript/mem/c_containers.h"
79 #include "ecmascript/mem/machine_code.h"
80 #include "ecmascript/object_factory.h"
81 #include "ecmascript/tagged_array.h"
82 #include "ecmascript/tagged_dictionary.h"
83 #include "ecmascript/tagged_tree-inl.h"
84 #include "ecmascript/template_map.h"
85 #include "ecmascript/tests/test_helper.h"
86 #include "ecmascript/transitions_dictionary.h"
87 #include "ecmascript/ts_types/ts_type.h"
88 
89 using namespace panda::ecmascript;
90 using namespace panda::ecmascript::base;
91 
92 namespace panda::test {
93 class EcmaDumpTest : public testing::Test {
94 public:
SetUpTestCase()95     static void SetUpTestCase()
96     {
97         GTEST_LOG_(INFO) << "SetUpTestCase";
98     }
99 
TearDownTestCase()100     static void TearDownTestCase()
101     {
102         GTEST_LOG_(INFO) << "TearDownCase";
103     }
104 
SetUp()105     void SetUp() override
106     {
107         TestHelper::CreateEcmaVMWithScope(instance, thread, scope);
108     }
109 
TearDown()110     void TearDown() override
111     {
112         TestHelper::DestroyEcmaVMWithScope(instance, scope);
113     }
114 
115     PandaVM *instance {nullptr};
116     ecmascript::EcmaHandleScope *scope {nullptr};
117     JSThread *thread {nullptr};
118 };
119 
120 #ifndef NDEBUG
HWTEST_F_L0(EcmaDumpTest,Dump)121 HWTEST_F_L0(EcmaDumpTest, Dump)
122 {
123     JSTaggedValue value1(100);
124     value1.D();
125 
126     JSTaggedValue value2(100.0);
127     JSTaggedValue::DV(value2.GetRawData());
128 
129     JSTaggedValue::Undefined().D();
130     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
131     env.Dump();
132 
133     JSHandle<JSFunction> objFunc(env->GetObjectFunction());
134     objFunc.Dump();
135 }
136 #endif  // #ifndef NDEBUG
137 
NewJSMap(JSThread * thread,ObjectFactory * factory,JSHandle<JSTaggedValue> proto)138 static JSHandle<JSMap> NewJSMap(JSThread *thread, ObjectFactory *factory, JSHandle<JSTaggedValue> proto)
139 {
140     JSHandle<JSHClass> mapClass = factory->NewEcmaDynClass(JSMap::SIZE, JSType::JS_MAP, proto);
141     JSHandle<JSMap> jsMap = JSHandle<JSMap>::Cast(factory->NewJSObject(mapClass));
142     JSHandle<LinkedHashMap> linkedMap(LinkedHashMap::Create(thread));
143     jsMap->SetLinkedMap(thread, linkedMap);
144     return jsMap;
145 }
146 
NewJSSet(JSThread * thread,ObjectFactory * factory,JSHandle<JSTaggedValue> proto)147 static JSHandle<JSSet> NewJSSet(JSThread *thread, ObjectFactory *factory, JSHandle<JSTaggedValue> proto)
148 {
149     JSHandle<JSHClass> setClass = factory->NewEcmaDynClass(JSSet::SIZE, JSType::JS_SET, proto);
150     JSHandle<JSSet> jsSet = JSHandle<JSSet>::Cast(factory->NewJSObject(setClass));
151     JSHandle<LinkedHashSet> linkedSet(LinkedHashSet::Create(thread));
152     jsSet->SetLinkedSet(thread, linkedSet);
153     return jsSet;
154 }
155 
NewJSAPITreeMap(JSThread * thread,ObjectFactory * factory)156 static JSHandle<JSAPITreeMap> NewJSAPITreeMap(JSThread *thread, ObjectFactory *factory)
157 {
158     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
159     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
160     JSHandle<JSHClass> mapClass = factory->NewEcmaDynClass(JSAPITreeMap::SIZE, JSType::JS_API_TREE_MAP, proto);
161     JSHandle<JSAPITreeMap> jsTreeMap = JSHandle<JSAPITreeMap>::Cast(factory->NewJSObject(mapClass));
162     JSHandle<TaggedTreeMap> treeMap(thread, TaggedTreeMap::Create(thread));
163     jsTreeMap->SetTreeMap(thread, treeMap);
164     return jsTreeMap;
165 }
166 
NewJSAPITreeSet(JSThread * thread,ObjectFactory * factory)167 static JSHandle<JSAPITreeSet> NewJSAPITreeSet(JSThread *thread, ObjectFactory *factory)
168 {
169     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
170     JSHandle<JSTaggedValue> proto = globalEnv->GetObjectFunctionPrototype();
171     JSHandle<JSHClass> setClass = factory->NewEcmaDynClass(JSAPITreeSet::SIZE, JSType::JS_API_TREE_SET, proto);
172     JSHandle<JSAPITreeSet> jsTreeSet = JSHandle<JSAPITreeSet>::Cast(factory->NewJSObject(setClass));
173     JSHandle<TaggedTreeSet> treeSet(thread, TaggedTreeSet::Create(thread));
174     jsTreeSet->SetTreeSet(thread, treeSet);
175     return jsTreeSet;
176 }
177 
NewJSObject(JSThread * thread,ObjectFactory * factory,JSHandle<GlobalEnv> globalEnv)178 static JSHandle<JSObject> NewJSObject(JSThread *thread, ObjectFactory *factory, JSHandle<GlobalEnv> globalEnv)
179 {
180     JSFunction *jsFunc = globalEnv->GetObjectFunction().GetObject<JSFunction>();
181     JSHandle<JSTaggedValue> jsFunc1(thread, jsFunc);
182     JSHandle<JSObject> jsObj = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(jsFunc1), jsFunc1);
183     return jsObj;
184 }
185 
NewJSAPIArrayList(JSThread * thread,ObjectFactory * factory,JSHandle<JSTaggedValue> proto)186 static JSHandle<JSAPIArrayList> NewJSAPIArrayList(JSThread *thread, ObjectFactory *factory,
187                                                   JSHandle<JSTaggedValue> proto)
188 {
189     JSHandle<JSHClass> arrayListClass =
190         factory->NewEcmaDynClass(JSAPIArrayList::SIZE, JSType::JS_API_ARRAY_LIST, proto);
191     JSHandle<JSAPIArrayList> jsArrayList = JSHandle<JSAPIArrayList>::Cast(factory->NewJSObject(arrayListClass));
192     jsArrayList->SetLength(thread, JSTaggedValue(0));
193     return jsArrayList;
194 }
195 
HWTEST_F_L0(EcmaDumpTest,HeapProfileDump)196 HWTEST_F_L0(EcmaDumpTest, HeapProfileDump)
197 {
198     [[maybe_unused]] ecmascript::EcmaHandleScope scope(thread);
199     auto factory = thread->GetEcmaVM()->GetFactory();
200     auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
201     auto globalConst = const_cast<GlobalEnvConstants *>(thread->GlobalConstants());
202     JSHandle<JSTaggedValue> proto = globalEnv->GetFunctionPrototype();
203     std::vector<std::pair<CString, JSTaggedValue>> snapshotVector;
204 
205 #define DUMP_FOR_HANDLE(dumpHandle)                                        \
206     dumpHandle.GetTaggedValue().D();                                       \
207     dumpHandle.GetTaggedValue().DumpForSnapshot(thread, snapshotVector);
208 
209 #define NEW_OBJECT_AND_DUMP(ClassName, TypeName)                                       \
210     JSHandle<JSHClass> class##ClassName =                                              \
211         factory->NewEcmaDynClass(ClassName::SIZE, JSType::TypeName, proto);            \
212         JSHandle<JSObject> object##ClassName = factory->NewJSObject(class##ClassName); \
213         object##ClassName.GetTaggedValue().D();                                        \
214         object##ClassName.GetTaggedValue().DumpForSnapshot(thread, snapshotVector);
215 
216     for (JSType type = JSType::JS_OBJECT; type <= JSType::TYPE_LAST; type = JSType(static_cast<int>(type) + 1)) {
217         switch (type) {
218             case JSType::JS_ERROR:
219             case JSType::JS_EVAL_ERROR:
220             case JSType::JS_RANGE_ERROR:
221             case JSType::JS_TYPE_ERROR:
222             case JSType::JS_REFERENCE_ERROR:
223             case JSType::JS_URI_ERROR:
224             case JSType::JS_SYNTAX_ERROR:
225             case JSType::JS_OBJECT: {
226                 CHECK_DUMP_FILEDS(ECMAObject::SIZE, JSObject::SIZE, 2)
227                 JSHandle<JSObject> jsObj = NewJSObject(thread, factory, globalEnv);
228                 DUMP_FOR_HANDLE(jsObj)
229                 break;
230             }
231             case JSType::JS_REALM: {
232                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSRealm::SIZE, 2)
233                 JSHandle<JSRealm> jsRealm = factory->NewJSRealm();
234                 DUMP_FOR_HANDLE(jsRealm)
235                 break;
236             }
237             case JSType::JS_FUNCTION_BASE: {
238                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSFunctionBase::SIZE, 1)
239                 break;
240             }
241             case JSType::JS_FUNCTION: {
242                 CHECK_DUMP_FILEDS(JSFunctionBase::SIZE, JSFunction::SIZE, 7)
243                 JSHandle<JSTaggedValue> jsFunc = globalEnv->GetFunctionFunction();
244                 DUMP_FOR_HANDLE(jsFunc)
245                 break;
246             }
247             case JSType::JS_PROXY_REVOC_FUNCTION: {
248                 CHECK_DUMP_FILEDS(JSFunction::SIZE, JSProxyRevocFunction::SIZE, 1)
249                 JSHandle<JSHClass> proxyRevocClass =
250                     JSHandle<JSHClass>::Cast(globalEnv->GetProxyRevocFunctionClass());
251                 JSHandle<JSObject> proxyRevocFunc = factory->NewJSObject(proxyRevocClass);
252                 DUMP_FOR_HANDLE(proxyRevocFunc)
253                 break;
254             }
255             case JSType::JS_PROMISE_REACTIONS_FUNCTION: {
256                 CHECK_DUMP_FILEDS(JSFunction::SIZE, JSPromiseReactionsFunction::SIZE, 2)
257                 JSHandle<JSHClass> promiseReactClass =
258                     JSHandle<JSHClass>::Cast(globalEnv->GetPromiseReactionFunctionClass());
259                 JSHandle<JSObject> promiseReactFunc = factory->NewJSObject(promiseReactClass);
260                 DUMP_FOR_HANDLE(promiseReactFunc)
261                 break;
262             }
263             case JSType::JS_PROMISE_EXECUTOR_FUNCTION: {
264                 CHECK_DUMP_FILEDS(JSFunction::SIZE, JSPromiseExecutorFunction::SIZE, 1)
265                 JSHandle<JSHClass> promiseExeClass =
266                     JSHandle<JSHClass>::Cast(globalEnv->GetPromiseExecutorFunctionClass());
267                 JSHandle<JSObject> promiseExeFunc = factory->NewJSObject(promiseExeClass);
268                 DUMP_FOR_HANDLE(promiseExeFunc)
269                 break;
270             }
271             case JSType::JS_PROMISE_ALL_RESOLVE_ELEMENT_FUNCTION: {
272                 CHECK_DUMP_FILEDS(JSFunction::SIZE, JSPromiseAllResolveElementFunction::SIZE, 5)
273                 JSHandle<JSHClass> promiseAllClass =
274                     JSHandle<JSHClass>::Cast(globalEnv->GetPromiseAllResolveElementFunctionClass());
275                 JSHandle<JSObject> promiseAllFunc = factory->NewJSObject(promiseAllClass);
276                 DUMP_FOR_HANDLE(promiseAllFunc)
277                 break;
278             }
279             case JSType::JS_GENERATOR_FUNCTION: {
280                 CHECK_DUMP_FILEDS(JSFunction::SIZE, JSGeneratorFunction::SIZE, 0)
281                 break;
282             }
283             case JSType::JS_ASYNC_FUNCTION: {
284                 CHECK_DUMP_FILEDS(JSFunction::SIZE, JSAsyncFunction::SIZE, 0)
285                 break;
286             }
287             case JSType::JS_INTL_BOUND_FUNCTION: {
288                 CHECK_DUMP_FILEDS(JSFunction::SIZE, JSIntlBoundFunction::SIZE, 3)
289                 JSHandle<JSIntlBoundFunction> intlBoundFunc = factory->NewJSIntlBoundFunction();
290                 DUMP_FOR_HANDLE(intlBoundFunc)
291                 break;
292             }
293             case JSType::JS_ASYNC_AWAIT_STATUS_FUNCTION: {
294                 CHECK_DUMP_FILEDS(JSFunction::SIZE, JSAsyncAwaitStatusFunction::SIZE, 1)
295                 JSHandle<JSAsyncAwaitStatusFunction> asyncAwaitFunc = factory->NewJSAsyncAwaitStatusFunction();
296                 DUMP_FOR_HANDLE(asyncAwaitFunc)
297                 break;
298             }
299             case JSType::JS_BOUND_FUNCTION: {
300                 CHECK_DUMP_FILEDS(JSFunctionBase::SIZE, JSBoundFunction::SIZE, 3)
301                 NEW_OBJECT_AND_DUMP(JSBoundFunction, JS_BOUND_FUNCTION)
302                 break;
303             }
304             case JSType::JS_REG_EXP: {
305                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSRegExp::SIZE, 4)
306                 NEW_OBJECT_AND_DUMP(JSRegExp, JS_REG_EXP)
307                 break;
308             }
309             case JSType::JS_SET: {
310                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSSet::SIZE, 1)
311                 JSHandle<JSSet> jsSet = NewJSSet(thread, factory, proto);
312                 DUMP_FOR_HANDLE(jsSet)
313                 break;
314             }
315             case JSType::JS_MAP: {
316                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSMap::SIZE, 1)
317                 JSHandle<JSMap> jsMap = NewJSMap(thread, factory, proto);
318                 DUMP_FOR_HANDLE(jsMap)
319                 break;
320             }
321             case JSType::JS_WEAK_MAP: {
322                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSWeakMap::SIZE, 1)
323                 JSHandle<JSHClass> weakMapClass = factory->NewEcmaDynClass(JSWeakMap::SIZE, JSType::JS_WEAK_MAP, proto);
324                 JSHandle<JSWeakMap> jsWeakMap = JSHandle<JSWeakMap>::Cast(factory->NewJSObject(weakMapClass));
325                 JSHandle<LinkedHashMap> weakLinkedMap(LinkedHashMap::Create(thread));
326                 jsWeakMap->SetLinkedMap(thread, weakLinkedMap);
327                 DUMP_FOR_HANDLE(jsWeakMap)
328                 break;
329             }
330             case JSType::JS_WEAK_SET: {
331                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSWeakSet::SIZE, 1)
332                 JSHandle<JSHClass> weakSetClass = factory->NewEcmaDynClass(JSWeakSet::SIZE, JSType::JS_WEAK_SET, proto);
333                 JSHandle<JSWeakSet> jsWeakSet = JSHandle<JSWeakSet>::Cast(factory->NewJSObject(weakSetClass));
334                 JSHandle<LinkedHashSet> weakLinkedSet(LinkedHashSet::Create(thread));
335                 jsWeakSet->SetLinkedSet(thread, weakLinkedSet);
336                 DUMP_FOR_HANDLE(jsWeakSet)
337                 break;
338             }
339             case JSType::JS_DATE: {
340                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSDate::SIZE, 2)
341                 JSHandle<JSHClass> dateClass = factory->NewEcmaDynClass(JSDate::SIZE, JSType::JS_DATE, proto);
342                 JSHandle<JSDate> date = JSHandle<JSDate>::Cast(factory->NewJSObject(dateClass));
343                 date->SetTimeValue(thread, JSTaggedValue(0.0));
344                 date->SetLocalOffset(thread, JSTaggedValue(0.0));
345                 DUMP_FOR_HANDLE(date)
346                 break;
347             }
348             case JSType::JS_ITERATOR:
349                 // JS Iterate is a tool class, so we don't need to check it.
350                 break;
351             case JSType::JS_FORIN_ITERATOR: {
352                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSForInIterator::SIZE, 4)
353                 JSHandle<JSTaggedValue> array(thread, factory->NewJSArray().GetTaggedValue());
354                 JSHandle<JSForInIterator> forInIter = factory->NewJSForinIterator(array);
355                 DUMP_FOR_HANDLE(forInIter)
356                 break;
357             }
358             case JSType::JS_MAP_ITERATOR: {
359                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSMapIterator::SIZE, 2)
360                 JSHandle<JSMapIterator> jsMapIter =
361                     factory->NewJSMapIterator(NewJSMap(thread, factory, proto), IterationKind::KEY);
362                 DUMP_FOR_HANDLE(jsMapIter)
363                 break;
364             }
365             case JSType::JS_SET_ITERATOR: {
366                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSSetIterator::SIZE, 2)
367                 JSHandle<JSSetIterator> jsSetIter =
368                     factory->NewJSSetIterator(NewJSSet(thread, factory, proto), IterationKind::KEY);
369                 DUMP_FOR_HANDLE(jsSetIter)
370                 break;
371             }
372             case JSType::JS_ARRAY_ITERATOR: {
373                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSArrayIterator::SIZE, 2)
374                 JSHandle<JSArrayIterator> arrayIter =
375                     factory->NewJSArrayIterator(JSHandle<JSObject>::Cast(factory->NewJSArray()), IterationKind::KEY);
376                 DUMP_FOR_HANDLE(arrayIter)
377                 break;
378             }
379             case JSType::JS_STRING_ITERATOR: {
380                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSStringIterator::SIZE, 2)
381                 JSHandle<JSTaggedValue> stringIter = globalEnv->GetStringIterator();
382                 DUMP_FOR_HANDLE(stringIter)
383                 break;
384             }
385             case JSType::JS_INTL: {
386                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSIntl::SIZE, 1)
387                 NEW_OBJECT_AND_DUMP(JSIntl, JS_INTL)
388                 break;
389             }
390             case JSType::JS_LOCALE: {
391                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSLocale::SIZE, 1)
392                 NEW_OBJECT_AND_DUMP(JSLocale, JS_LOCALE)
393                 break;
394             }
395             case JSType::JS_DATE_TIME_FORMAT: {
396                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSDateTimeFormat::SIZE, 9)
397                 NEW_OBJECT_AND_DUMP(JSDateTimeFormat, JS_DATE_TIME_FORMAT)
398                 break;
399             }
400             case JSType::JS_RELATIVE_TIME_FORMAT: {
401                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSRelativeTimeFormat::SIZE, 6)
402                 NEW_OBJECT_AND_DUMP(JSRelativeTimeFormat, JS_RELATIVE_TIME_FORMAT)
403                 break;
404             }
405             case JSType::JS_NUMBER_FORMAT: {
406                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSNumberFormat::SIZE, 13)
407                 NEW_OBJECT_AND_DUMP(JSNumberFormat, JS_NUMBER_FORMAT)
408                 break;
409             }
410             case JSType::JS_COLLATOR: {
411                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSCollator::SIZE, 5)
412                 NEW_OBJECT_AND_DUMP(JSCollator, JS_COLLATOR)
413                 break;
414             }
415             case JSType::JS_PLURAL_RULES: {
416                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSPluralRules::SIZE, 10)
417                 NEW_OBJECT_AND_DUMP(JSPluralRules, JS_PLURAL_RULES)
418                 break;
419             }
420             case JSType::JS_ARRAY_BUFFER: {
421                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSArrayBuffer::SIZE, 2)
422                 NEW_OBJECT_AND_DUMP(JSArrayBuffer, JS_ARRAY_BUFFER)
423                 break;
424             }
425             case JSType::JS_PROMISE: {
426                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSPromise::SIZE, 4)
427                 NEW_OBJECT_AND_DUMP(JSPromise, JS_PROMISE)
428                 break;
429             }
430             case JSType::JS_DATA_VIEW: {
431                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSDataView::SIZE, 3)
432                 NEW_OBJECT_AND_DUMP(JSDataView, JS_DATA_VIEW)
433                 break;
434             }
435             case JSType::JS_ARGUMENTS: {
436                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSArguments::SIZE, 1)
437                 NEW_OBJECT_AND_DUMP(JSArguments, JS_ARGUMENTS)
438                 break;
439             }
440             case JSType::JS_GENERATOR_OBJECT: {
441                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSGeneratorObject::SIZE, 3)
442                 NEW_OBJECT_AND_DUMP(JSGeneratorObject, JS_GENERATOR_OBJECT)
443                 break;
444             }
445             case JSType::JS_ASYNC_FUNC_OBJECT: {
446                 CHECK_DUMP_FILEDS(JSGeneratorObject::SIZE, JSAsyncFuncObject::SIZE, 1)
447                 JSHandle<JSAsyncFuncObject> asyncFuncObject = factory->NewJSAsyncFuncObject();
448                 DUMP_FOR_HANDLE(asyncFuncObject)
449                 break;
450             }
451             case JSType::JS_ARRAY: {
452                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSArray::SIZE, 1)
453                 JSHandle<JSArray> jsArray = factory->NewJSArray();
454                 DUMP_FOR_HANDLE(jsArray)
455                 break;
456             }
457             case JSType::JS_TYPED_ARRAY:
458             case JSType::JS_INT8_ARRAY:
459             case JSType::JS_UINT8_ARRAY:
460             case JSType::JS_UINT8_CLAMPED_ARRAY:
461             case JSType::JS_INT16_ARRAY:
462             case JSType::JS_UINT16_ARRAY:
463             case JSType::JS_INT32_ARRAY:
464             case JSType::JS_UINT32_ARRAY:
465             case JSType::JS_FLOAT32_ARRAY:
466             case JSType::JS_FLOAT64_ARRAY: {
467                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSTypedArray::SIZE, 5)
468                 NEW_OBJECT_AND_DUMP(JSTypedArray, JS_TYPED_ARRAY)
469                 break;
470             }
471             case JSType::JS_PRIMITIVE_REF: {
472                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSPrimitiveRef::SIZE, 1)
473                 NEW_OBJECT_AND_DUMP(JSPrimitiveRef, JS_PRIMITIVE_REF)
474                 break;
475             }
476             case JSType::JS_GLOBAL_OBJECT: {
477                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSGlobalObject::SIZE, 0)
478                 JSHandle<JSTaggedValue> globalObject = globalEnv->GetJSGlobalObject();
479                 DUMP_FOR_HANDLE(globalObject)
480                 break;
481             }
482             case JSType::JS_PROXY: {
483                 CHECK_DUMP_FILEDS(ECMAObject::SIZE, JSProxy::SIZE, 3)
484                 JSHandle<JSTaggedValue> emptyObj(thread, NewJSObject(thread, factory, globalEnv).GetTaggedValue());
485                 JSHandle<JSProxy> proxy = factory->NewJSProxy(emptyObj, emptyObj);
486                 DUMP_FOR_HANDLE(proxy)
487                 break;
488             }
489             case JSType::HCLASS: {
490                 CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), JSHClass::SIZE, 7)
491                 JSHandle<JSHClass> hclass = factory->NewEcmaDynClass(JSHClass::SIZE, JSType::HCLASS, proto);
492                 DUMP_FOR_HANDLE(hclass)
493                 break;
494             }
495             case JSType::STRING: {
496                 DUMP_FOR_HANDLE(globalEnv->GetObjectFunction())
497                 break;
498             }
499             case JSType::BIGINT: {
500                 DUMP_FOR_HANDLE(globalEnv->GetBigIntFunction())
501                 break;
502             }
503             case JSType::TAGGED_ARRAY: {
504                 JSHandle<TaggedArray> taggedArray = factory->NewTaggedArray(4);
505                 DUMP_FOR_HANDLE(taggedArray)
506                 break;
507             }
508             case JSType::TAGGED_DICTIONARY: {
509                 JSHandle<TaggedArray> dict = factory->NewDictionaryArray(4);
510                 DUMP_FOR_HANDLE(dict)
511                 break;
512             }
513             case JSType::FREE_OBJECT_WITH_ONE_FIELD:
514             case JSType::FREE_OBJECT_WITH_NONE_FIELD:
515             case JSType::FREE_OBJECT_WITH_TWO_FIELD:
516             {
517                 break;
518             }
519             case JSType::JS_NATIVE_POINTER: {
520                 break;
521             }
522             case JSType::GLOBAL_ENV: {
523                 DUMP_FOR_HANDLE(globalEnv)
524                 break;
525             }
526             case JSType::ACCESSOR_DATA:
527             case JSType::INTERNAL_ACCESSOR: {
528                 CHECK_DUMP_FILEDS(Record::SIZE, AccessorData::SIZE, 2)
529                 JSHandle<AccessorData> accessor = factory->NewAccessorData();
530                 DUMP_FOR_HANDLE(accessor)
531                 break;
532             }
533             case JSType::SYMBOL: {
534                 CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), JSSymbol::SIZE, 2)
535                 JSHandle<JSSymbol> symbol = factory->NewJSSymbol();
536                 DUMP_FOR_HANDLE(symbol)
537                 break;
538             }
539             case JSType::JS_GENERATOR_CONTEXT: {
540                 CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), GeneratorContext::SIZE, 6)
541                 JSHandle<GeneratorContext> genContext = factory->NewGeneratorContext();
542                 DUMP_FOR_HANDLE(genContext)
543                 break;
544             }
545             case JSType::PROTOTYPE_HANDLER: {
546                 CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), PrototypeHandler::SIZE, 3)
547                 JSHandle<PrototypeHandler> protoHandler = factory->NewPrototypeHandler();
548                 DUMP_FOR_HANDLE(protoHandler)
549                 break;
550             }
551             case JSType::TRANSITION_HANDLER: {
552                 CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), TransitionHandler::SIZE, 2)
553                 JSHandle<TransitionHandler> transitionHandler = factory->NewTransitionHandler();
554                 DUMP_FOR_HANDLE(transitionHandler)
555                 break;
556             }
557             case JSType::PROPERTY_BOX: {
558                 CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), PropertyBox::SIZE, 1)
559                 JSHandle<PropertyBox> PropertyBox = factory->NewPropertyBox(globalEnv->GetEmptyArray());
560                 DUMP_FOR_HANDLE(PropertyBox)
561                 break;
562             }
563             case JSType::PROTO_CHANGE_MARKER: {
564                 CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), ProtoChangeMarker::SIZE, 1)
565                 JSHandle<ProtoChangeMarker> protoMaker = factory->NewProtoChangeMarker();
566                 DUMP_FOR_HANDLE(protoMaker)
567                 break;
568             }
569             case JSType::PROTOTYPE_INFO: {
570                 CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), ProtoChangeDetails::SIZE, 2)
571                 JSHandle<ProtoChangeDetails> protoDetails = factory->NewProtoChangeDetails();
572                 DUMP_FOR_HANDLE(protoDetails)
573                 break;
574             }
575             case JSType::TEMPLATE_MAP: {
576                 JSHandle<JSTaggedValue> templateMap = globalEnv->GetTemplateMap();
577                 DUMP_FOR_HANDLE(templateMap)
578                 break;
579             }
580             case JSType::PROGRAM: {
581                 CHECK_DUMP_FILEDS(ECMAObject::SIZE, Program::SIZE, 1)
582                 JSHandle<Program> program = factory->NewProgram();
583                 DUMP_FOR_HANDLE(program)
584                 break;
585             }
586             case JSType::PROMISE_CAPABILITY: {
587                 CHECK_DUMP_FILEDS(Record::SIZE, PromiseCapability::SIZE, 3)
588                 JSHandle<PromiseCapability> promiseCapa = factory->NewPromiseCapability();
589                 DUMP_FOR_HANDLE(promiseCapa)
590                 break;
591             }
592             case JSType::PROMISE_RECORD: {
593                 CHECK_DUMP_FILEDS(Record::SIZE, PromiseRecord::SIZE, 1)
594                 JSHandle<PromiseRecord> promiseRecord = factory->NewPromiseRecord();
595                 DUMP_FOR_HANDLE(promiseRecord)
596                 break;
597             }
598             case JSType::RESOLVING_FUNCTIONS_RECORD: {
599                 CHECK_DUMP_FILEDS(Record::SIZE, ResolvingFunctionsRecord::SIZE, 2)
600                 JSHandle<ResolvingFunctionsRecord> ResolvingFunc = factory->NewResolvingFunctionsRecord();
601                 DUMP_FOR_HANDLE(ResolvingFunc)
602                 break;
603             }
604             case JSType::PROMISE_REACTIONS: {
605                 CHECK_DUMP_FILEDS(Record::SIZE, PromiseReaction::SIZE, 3)
606                 JSHandle<PromiseReaction> promiseReact = factory->NewPromiseReaction();
607                 DUMP_FOR_HANDLE(promiseReact)
608                 break;
609             }
610             case JSType::PROMISE_ITERATOR_RECORD: {
611                 CHECK_DUMP_FILEDS(Record::SIZE, PromiseIteratorRecord::SIZE, 2)
612                 JSHandle<JSTaggedValue> emptyObj(thread, NewJSObject(thread, factory, globalEnv).GetTaggedValue());
613                 JSHandle<PromiseIteratorRecord> promiseIter = factory->NewPromiseIteratorRecord(emptyObj, false);
614                 DUMP_FOR_HANDLE(promiseIter)
615                 break;
616             }
617             case JSType::MICRO_JOB_QUEUE: {
618                 CHECK_DUMP_FILEDS(Record::SIZE, ecmascript::job::MicroJobQueue::SIZE, 2)
619                 JSHandle<ecmascript::job::MicroJobQueue> microJob = factory->NewMicroJobQueue();
620                 DUMP_FOR_HANDLE(microJob)
621                 break;
622             }
623             case JSType::PENDING_JOB: {
624                 CHECK_DUMP_FILEDS(Record::SIZE, ecmascript::job::PendingJob::SIZE, 6)
625                 JSHandle<JSHClass> pendingClass(thread,
626                     JSHClass::Cast(globalConst->GetPendingJobClass().GetTaggedObject()));
627                 JSHandle<TaggedObject> pendingJob(thread, factory->NewDynObject(pendingClass));
628                 DUMP_FOR_HANDLE(pendingJob)
629                 break;
630             }
631             case JSType::COMPLETION_RECORD: {
632                 CHECK_DUMP_FILEDS(Record::SIZE, CompletionRecord::SIZE, 2)
633                 JSHandle<CompletionRecord> comRecord =
634                     factory->NewCompletionRecord(CompletionRecordType::NORMAL, globalEnv->GetEmptyArray());
635                 DUMP_FOR_HANDLE(comRecord)
636                 break;
637             }
638             case JSType::MACHINE_CODE_OBJECT: {
639                 CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), MachineCode::DATA_OFFSET, 1)
640                 JSHandle<MachineCode>  machineCode = factory->NewMachineCodeObject(16, nullptr);
641                 DUMP_FOR_HANDLE(machineCode)
642                 break;
643             }
644             case JSType::ECMA_MODULE: {
645                 CHECK_DUMP_FILEDS(ECMAObject::SIZE, EcmaModule::SIZE, 1)
646                 JSHandle<EcmaModule> ecmaModule = factory->NewEmptyEcmaModule();
647                 DUMP_FOR_HANDLE(ecmaModule)
648                 break;
649             }
650             case JSType::CLASS_INFO_EXTRACTOR: {
651 #ifdef PANDA_TARGET_64
652                 CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), ClassInfoExtractor::SIZE, 10)
653 #else
654                 CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), ClassInfoExtractor::SIZE, 9)
655 #endif
656                 JSHandle<ClassInfoExtractor> classInfoExtractor = factory->NewClassInfoExtractor(nullptr);
657                 DUMP_FOR_HANDLE(classInfoExtractor)
658                 break;
659             }
660             case JSType::JS_QUEUE:
661             case JSType::JS_API_VECTOR:
662             case JSType::JS_API_ARRAY_LIST: {
663                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSAPIArrayList::SIZE, 1)
664                 JSHandle<JSAPIArrayList> jsArrayList = NewJSAPIArrayList(thread, factory, proto);
665                 DUMP_FOR_HANDLE(jsArrayList)
666                 break;
667             }
668             case JSType::JS_API_ARRAYLIST_ITERATOR: {
669                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSAPIArrayListIterator::SIZE, 2)
670                 JSHandle<JSAPIArrayListIterator> jsArrayListIter =
671                     factory->NewJSAPIArrayListIterator(NewJSAPIArrayList(thread, factory, proto));
672                 DUMP_FOR_HANDLE(jsArrayListIter)
673                 break;
674             }
675             case JSType::TS_OBJECT_TYPE: {
676                 CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), TSObjectType::SIZE, 3)
677                 JSHandle<TSObjectType> objectType = factory->NewTSObjectType(0);
678                 DUMP_FOR_HANDLE(objectType)
679                 break;
680             }
681             case JSType::TS_CLASS_TYPE: {
682                 CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), TSClassType::SIZE, 5)
683                 JSHandle<TSClassType> classType = factory->NewTSClassType();
684                 DUMP_FOR_HANDLE(classType)
685                 break;
686             }
687             case JSType::TS_INTERFACE_TYPE: {
688                 CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), TSInterfaceType::SIZE, 3)
689                 JSHandle<TSInterfaceType> interfaceType = factory->NewTSInterfaceType();
690                 DUMP_FOR_HANDLE(interfaceType)
691                 break;
692             }
693             case JSType::TS_IMPORT_TYPE: {
694                 CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), TSImportType::SIZE, 3)
695                 JSHandle<TSImportType> importType = factory->NewTSImportType();
696                 DUMP_FOR_HANDLE(importType)
697                 break;
698             }
699             case JSType::TS_CLASS_INSTANCE_TYPE: {
700                 CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), TSClassInstanceType::SIZE, 2)
701                 JSHandle<TSClassInstanceType> classInstanceType = factory->NewTSClassInstanceType();
702                 DUMP_FOR_HANDLE(classInstanceType)
703                 break;
704             }
705             case JSType::TS_UNION_TYPE: {
706                 CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), TSUnionType::SIZE, 2)
707                 JSHandle<TSUnionType> unionType = factory->NewTSUnionType(1);
708                 DUMP_FOR_HANDLE(unionType)
709                 break;
710             }
711             case JSType::JS_API_TREE_MAP: {
712                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSAPITreeMap::SIZE, 1)
713                 JSHandle<JSAPITreeMap> jsTreeMap = NewJSAPITreeMap(thread, factory);
714                 DUMP_FOR_HANDLE(jsTreeMap)
715                 break;
716             }
717             case JSType::JS_API_TREE_SET: {
718                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSAPITreeSet::SIZE, 1)
719                 JSHandle<JSAPITreeSet> jsTreeSet = NewJSAPITreeSet(thread, factory);
720                 DUMP_FOR_HANDLE(jsTreeSet)
721                 break;
722             }
723             case JSType::JS_API_TREEMAP_ITERATOR: {
724                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSAPITreeMapIterator::SIZE, 4)
725                 JSHandle<JSAPITreeMapIterator> jsTreeMapIter =
726                     factory->NewJSAPITreeMapIterator(NewJSAPITreeMap(thread, factory), IterationKind::KEY);
727                 DUMP_FOR_HANDLE(jsTreeMapIter)
728                 break;
729             }
730             case JSType::JS_API_TREESET_ITERATOR: {
731                 CHECK_DUMP_FILEDS(JSObject::SIZE, JSAPITreeSetIterator::SIZE, 4)
732                 JSHandle<JSAPITreeSetIterator> jsTreeSetIter =
733                     factory->NewJSAPITreeSetIterator(NewJSAPITreeSet(thread, factory), IterationKind::KEY);
734                 DUMP_FOR_HANDLE(jsTreeSetIter)
735                 break;
736             }
737             default:
738                 LOG_ECMA_MEM(ERROR) << "JSType " << static_cast<int>(type) << " cannot be dumped.";
739                 UNREACHABLE();
740                 break;
741         }
742     }
743 #undef NEW_OBJECT_AND_DUMP
744 #undef DUMP_FOR_HANDLE
745 }
746 }  // namespace panda::test
747