• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 
17 #include "ecmascript/base/config.h"
18 #include "ecmascript/js_object.h"
19 #include "ecmascript/stubs/runtime_optimized_stubs-inl.h"
20 #include "ecmascript/stubs/runtime_stubs-inl.h"
21 #include "ecmascript/base/gc_helper.h"
22 #include "ecmascript/base/json_stringifier.h"
23 #include "ecmascript/base/typed_array_helper-inl.h"
24 #include "ecmascript/builtins/builtins_array.h"
25 #include "ecmascript/js_stable_array.h"
26 #include "ecmascript/builtins/builtins_bigint.h"
27 #include "ecmascript/builtins/builtins_function.h"
28 #include "ecmascript/builtins/builtins_iterator.h"
29 #include "ecmascript/builtins/builtins_reflect.h"
30 #include "ecmascript/builtins/builtins_string_iterator.h"
31 #include "ecmascript/compiler/builtins/containers_stub_builder.h"
32 #include "ecmascript/builtins/builtins_array.h"
33 #include "ecmascript/dfx/cpu_profiler/cpu_profiler.h"
34 #include "ecmascript/dfx/stackinfo/js_stackinfo.h"
35 #include "ecmascript/dfx/vmstat/function_call_timer.h"
36 #include "ecmascript/dfx/vmstat/opt_code_profiler.h"
37 #include "ecmascript/ic/ic_runtime_stub-inl.h"
38 #include "ecmascript/interpreter/interpreter_assembly.h"
39 #include "ecmascript/interpreter/slow_runtime_stub.h"
40 #include "ecmascript/jit/jit.h"
41 #include "ecmascript/js_map_iterator.h"
42 #include "ecmascript/js_set_iterator.h"
43 #include "ecmascript/js_string_iterator.h"
44 #include "ecmascript/js_stable_array.h"
45 #include "ecmascript/jspandafile/js_pandafile_executor.h"
46 #include "ecmascript/stubs/runtime_stubs.h"
47 #include "ecmascript/linked_hash_table.h"
48 #include "ecmascript/builtins/builtins_object.h"
49 #include "ecmascript/module/module_value_accessor.h"
50 #include "ecmascript/module/module_path_helper.h"
51 #include "common_components/heap/allocator/region_desc.h"
52 #include "common_components/mutator/mutator.h"
53 #ifdef ARK_SUPPORT_INTL
54 #include "ecmascript/js_collator.h"
55 #include "ecmascript/js_locale.h"
56 #else
57 #ifndef ARK_NOT_SUPPORT_INTL_GLOBAL
58 #include "ecmascript/intl/global_intl_helper.h"
59 #endif
60 #endif
61 
62 namespace panda::ecmascript {
63 #if defined(__clang__)
64 #pragma clang diagnostic push
65 #pragma clang diagnostic ignored "-Wunused-parameter"
66 #elif defined(__GNUC__)
67 #pragma GCC diagnostic push
68 #pragma GCC diagnostic ignored "-Wunused-parameter"
69 #endif
70 
71 #define DEF_RUNTIME_STUBS(name) \
72     JSTaggedType RuntimeStubs::name(uintptr_t argGlue, uint32_t argc, uintptr_t argv)
73 
74 #define RUNTIME_STUBS_HEADER(name)                        \
75     auto thread = JSThread::GlueToJSThread(argGlue);      \
76     RUNTIME_TRACE(thread, name);                          \
77     [[maybe_unused]] EcmaHandleScope handleScope(thread)  \
78 
79 #define GET_ASM_FRAME(CurrentSp) \
80     (reinterpret_cast<AsmInterpretedFrame *>(CurrentSp) - 1) // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
81 
DEF_RUNTIME_STUBS(InitializeGeneratorFunction)82 DEF_RUNTIME_STUBS(InitializeGeneratorFunction)
83 {
84     RUNTIME_STUBS_HEADER(InitializeGeneratorFunction);
85     FunctionKind kind = static_cast<FunctionKind>(GetTArg(argv, argc, 0)); // 1: means the first parameter
86     JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
87     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
88     JSHandle<JSFunction> objFun(env->GetObjectFunction());
89     JSHandle<JSObject> initialGeneratorFuncPrototype = factory->NewJSObjectByConstructor(objFun);
90     if (kind == FunctionKind::ASYNC_GENERATOR_FUNCTION) {
91         JSObject::SetPrototype(thread, initialGeneratorFuncPrototype, env->GetAsyncGeneratorPrototype());
92     } else if (kind == FunctionKind::GENERATOR_FUNCTION) {
93         JSObject::SetPrototype(thread, initialGeneratorFuncPrototype, env->GetGeneratorPrototype());
94     }
95     return initialGeneratorFuncPrototype.GetTaggedType();
96 }
97 
DEF_RUNTIME_STUBS(FunctionDefineOwnProperty)98 DEF_RUNTIME_STUBS(FunctionDefineOwnProperty)
99 {
100     RUNTIME_STUBS_HEADER(FunctionDefineOwnProperty);
101     JSHandle<JSFunction> func(GetHArg<JSTaggedValue>(argv, argc, 0));
102     JSHandle<JSTaggedValue> accessor = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
103     FunctionKind kind = static_cast<FunctionKind>(GetTArg(argv, argc, 2)); // 2: means the second parameter
104     PropertyDescriptor desc(thread, accessor, kind != FunctionKind::BUILTIN_CONSTRUCTOR, false, false);
105     JSObject::DefineOwnProperty(thread, JSHandle<JSObject>(func),
106                                 thread->GlobalConstants()->GetHandledPrototypeString(), desc);
107     return JSTaggedValue::Hole().GetRawData();
108 }
109 
DEF_RUNTIME_STUBS(HeapAlloc)110 DEF_RUNTIME_STUBS(HeapAlloc)
111 {
112     RUNTIME_STUBS_HEADER(HeapAlloc);
113     JSTaggedValue allocateSize = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
114     auto size = static_cast<size_t>(allocateSize.GetLargeUInt());
115     JSHandle<JSHClass> hclassHandle = GetHArg<JSHClass>(argv, argc, 1);  // 1: means the first parameter
116     auto type = static_cast<RegionSpaceFlag>(GetArg(argv, argc, 2).GetInt());
117     MemSpaceType mtype;
118     switch (type) {
119         case RegionSpaceFlag::IN_YOUNG_SPACE:
120             mtype = MemSpaceType::SEMI_SPACE;
121             break;
122         case RegionSpaceFlag::IN_OLD_SPACE:
123             mtype = MemSpaceType::OLD_SPACE;
124             break;
125         case RegionSpaceFlag::IN_NON_MOVABLE_SPACE:
126             mtype = MemSpaceType::NON_MOVABLE;
127             break;
128         case RegionSpaceFlag::IN_SHARED_OLD_SPACE:
129             mtype = MemSpaceType::SHARED_OLD_SPACE;
130             break;
131         case RegionSpaceFlag::IN_SHARED_NON_MOVABLE:
132             mtype = MemSpaceType::SHARED_NON_MOVABLE;
133             break;
134         default:
135             LOG_ECMA(FATAL) << "this branch is unreachable";
136             UNREACHABLE();
137     }
138     auto hclass = JSHClass::Cast(hclassHandle.GetTaggedValue().GetTaggedObject());
139     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
140     auto result = factory->AllocObjectWithSpaceType(size, hclass, mtype);
141     return JSTaggedValue(result).GetRawData();
142 }
143 
DEF_RUNTIME_STUBS(AllocateInYoung)144 DEF_RUNTIME_STUBS(AllocateInYoung)
145 {
146     RUNTIME_STUBS_HEADER(AllocateInYoung);
147     JSTaggedValue allocateSize = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
148     auto size = static_cast<size_t>(allocateSize.GetLargeUInt());
149     auto heap = const_cast<Heap*>(thread->GetEcmaVM()->GetHeap());
150     auto result = heap->AllocateYoungOrHugeObject(size);
151     ASSERT(result != nullptr);
152     if (argc > 1) { // 1: means the first parameter
153         JSHandle<JSHClass> hclassHandle = GetHArg<JSHClass>(argv, argc, 1);  // 1: means the first parameter
154         auto hclass = JSHClass::Cast(hclassHandle.GetTaggedValue().GetTaggedObject());
155         heap->SetHClassAndDoAllocateEvent(thread, result, hclass, size);
156     }
157     return JSTaggedValue(result).GetRawData();
158 }
159 
DEF_RUNTIME_STUBS(AllocateInOld)160 DEF_RUNTIME_STUBS(AllocateInOld)
161 {
162     RUNTIME_STUBS_HEADER(AllocateInOld);
163     JSTaggedValue allocateSize = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
164     auto size = static_cast<size_t>(allocateSize.GetLargeUInt());
165     auto heap = const_cast<Heap*>(thread->GetEcmaVM()->GetHeap());
166     auto result = heap->AllocateOldOrHugeObject(size);
167     ASSERT(result != nullptr);
168     if (argc > 1) { // 1: means the first parameter
169         JSHandle<JSHClass> hclassHandle = GetHArg<JSHClass>(argv, argc, 1);  // 1: means the first parameter
170         auto hclass = JSHClass::Cast(hclassHandle.GetTaggedValue().GetTaggedObject());
171         heap->SetHClassAndDoAllocateEvent(thread, result, hclass, size);
172     }
173     return JSTaggedValue(result).GetRawData();
174 }
175 
176 #define ALLOCATE_IN_SHARED_HEAP(SPACE)                                                     \
177     DEF_RUNTIME_STUBS(AllocateInS##SPACE)                                                  \
178     {                                                                                      \
179         RUNTIME_STUBS_HEADER(AllocateInS##SPACE);                                          \
180         JSTaggedValue allocateSize = GetArg(argv, argc, 0);                                \
181         auto size = static_cast<size_t>(allocateSize.GetInt());                            \
182         auto sharedHeap = const_cast<SharedHeap*>(SharedHeap::GetInstance());              \
183         ASSERT(size <= g_maxRegularHeapObjectSize);                                      \
184         auto result = sharedHeap->Allocate##SPACE##OrHugeObject(thread, size);             \
185         ASSERT(result != nullptr);                                                         \
186         if (argc > 1) {                                                                    \
187             JSHandle<JSHClass> hclassHandle = GetHArg<JSHClass>(argv, argc, 1);            \
188             auto hclass = JSHClass::Cast(hclassHandle.GetTaggedValue().GetTaggedObject()); \
189             sharedHeap->SetHClassAndDoAllocateEvent(thread, result, hclass, size);         \
190         }                                                                                  \
191         return JSTaggedValue(result).GetRawData();                                         \
192     }
193 
194 #undef ALLOCATE_IN_SHARED_HEAP
195 
DEF_RUNTIME_STUBS(AllocateInSNonMovable)196 DEF_RUNTIME_STUBS(AllocateInSNonMovable)
197 {
198     RUNTIME_STUBS_HEADER(AllocateInSNonMovable);
199     JSTaggedValue allocateSize = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
200     auto size = static_cast<size_t>(allocateSize.GetInt());
201     auto heap = const_cast<Heap*>(thread->GetEcmaVM()->GetHeap());
202     auto result = heap->AllocateSharedNonMovableSpaceFromTlab(thread, size);
203     if (result != nullptr) {
204         return JSTaggedValue(result).GetRawData();
205     }
206     auto sharedHeap = const_cast<SharedHeap*>(SharedHeap::GetInstance());
207     result = sharedHeap->AllocateNonMovableOrHugeObject(thread, size);
208     ASSERT(result != nullptr);
209     if (argc > 1) { // 1: means the first parameter
210         JSHandle<JSHClass> hclassHandle = GetHArg<JSHClass>(argv, argc, 1);  // 1: means the first parameter
211         auto hclass = JSHClass::Cast(hclassHandle.GetTaggedValue().GetTaggedObject());
212         sharedHeap->SetHClassAndDoAllocateEvent(thread, result, hclass, size);
213     }
214     return JSTaggedValue(result).GetRawData();
215 }
216 
DEF_RUNTIME_STUBS(DefineOwnProperty)217 DEF_RUNTIME_STUBS(DefineOwnProperty)
218 {
219     RUNTIME_STUBS_HEADER(DefineOwnProperty);
220     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);
221     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
222     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
223     PropertyDescriptor desc(thread, value, true, true, true);
224     bool res = JSTaggedValue::DefineOwnProperty(thread, obj, key, desc);
225     return JSTaggedValue(res).GetRawData();
226 }
227 
DEF_RUNTIME_STUBS(AllocateInSOld)228 DEF_RUNTIME_STUBS(AllocateInSOld)
229 {
230     RUNTIME_STUBS_HEADER(AllocateInSOld);
231     JSTaggedValue allocateSize = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
232     auto size = static_cast<size_t>(allocateSize.GetInt());
233     auto heap = const_cast<Heap*>(thread->GetEcmaVM()->GetHeap());
234     auto result = heap->AllocateSharedOldSpaceFromTlab(thread, size);
235     if (result != nullptr) {
236         return JSTaggedValue(result).GetRawData();
237     }
238     auto sharedHeap = const_cast<SharedHeap*>(SharedHeap::GetInstance());
239     result = sharedHeap->AllocateOldOrHugeObject(thread, size);
240     ASSERT(result != nullptr);
241     if (argc > 1) { // 1: means the first parameter
242         JSHandle<JSHClass> hclassHandle = GetHArg<JSHClass>(argv, argc, 1);  // 1: means the first parameter
243         auto hclass = JSHClass::Cast(hclassHandle.GetTaggedValue().GetTaggedObject());
244         sharedHeap->SetHClassAndDoAllocateEvent(thread, result, hclass, size);
245     }
246     return JSTaggedValue(result).GetRawData();
247 }
248 
DEF_RUNTIME_STUBS(TypedArraySpeciesCreate)249 DEF_RUNTIME_STUBS(TypedArraySpeciesCreate)
250 {
251     RUNTIME_STUBS_HEADER(TypedArraySpeciesCreate);
252     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);    // 0: means the zeroth parameter
253     JSHandle<JSTypedArray> thisObj(obj);
254     JSTaggedValue indexValue = GetArg(argv, argc, 1);   // 1: means the first parameter
255     uint32_t index = static_cast<uint32_t>(indexValue.GetInt());
256     JSTaggedValue arrayLen = GetArg(argv, argc, 2); // 2: means the second parameter
257     uint32_t length = static_cast<uint32_t>(arrayLen.GetInt());
258     JSTaggedType args[1] = {JSTaggedValue(length).GetRawData()};
259     JSHandle<JSObject> newArr = base::TypedArrayHelper::TypedArraySpeciesCreate(thread, thisObj, index, args);
260     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
261     return newArr.GetTaggedValue().GetRawData();
262 }
263 
DEF_RUNTIME_STUBS(TypedArrayCreateSameType)264 DEF_RUNTIME_STUBS(TypedArrayCreateSameType)
265 {
266     RUNTIME_STUBS_HEADER(TypedArrayCreateSameType);
267     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);    // 0: means the zeroth parameter
268     JSHandle<JSTypedArray> thisObj(obj);
269     JSTaggedValue indexValue = GetArg(argv, argc, 1);   // 1: means the first parameter
270     uint32_t index = static_cast<uint32_t>(indexValue.GetInt());
271     JSTaggedValue arrayLen = GetArg(argv, argc, 2); // 2: means the second parameter
272     uint32_t length = static_cast<uint32_t>(arrayLen.GetInt());
273     JSTaggedType args[1] = {JSTaggedValue(length).GetRawData()};
274     JSHandle<JSObject> newArr = base::TypedArrayHelper::TypedArrayCreateSameType(thread, thisObj, index, args);
275     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
276     return newArr.GetTaggedValue().GetRawData();
277 }
278 
CopyTypedArrayBuffer(uintptr_t argGlue,JSTypedArray * srcArray,JSTypedArray * targetArray,int32_t srcStartPos,int32_t tarStartPos,int32_t count)279 void RuntimeStubs::CopyTypedArrayBuffer(uintptr_t argGlue, JSTypedArray *srcArray, JSTypedArray *targetArray,
280                                         int32_t srcStartPos, int32_t tarStartPos, int32_t count)
281 {
282     DISALLOW_GARBAGE_COLLECTION;
283     if (count <= 0) {
284         return;
285     }
286 
287     JSType srcType = srcArray->GetClass()->GetObjectType();
288     JSType tarType = targetArray->GetClass()->GetObjectType();
289     uint32_t srcElementSize = base::TypedArrayHelper::GetElementSize(srcType);
290     uint32_t uSrcStartPos = static_cast<uint32_t>(srcStartPos);
291     uint32_t uTarStartPos = static_cast<uint32_t>(tarStartPos);
292     uint32_t uCount = static_cast<uint32_t>(count);
293     if (LIKELY(srcType == tarType)) {
294         auto thread = JSThread::GlueToJSThread(argGlue);
295         JSTaggedValue srcBuffer = srcArray->GetViewedArrayBufferOrByteArray(thread);
296         JSTaggedValue targetBuffer = targetArray->GetViewedArrayBufferOrByteArray(thread);
297         uint32_t srcByteIndex = uSrcStartPos * srcElementSize + srcArray->GetByteOffset();
298         uint32_t targetByteIndex = uTarStartPos * srcElementSize + targetArray->GetByteOffset();
299         uint8_t *srcBuf =
300             (uint8_t *)builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, srcBuffer, srcByteIndex);
301         uint8_t *targetBuf =
302             (uint8_t *)builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, targetBuffer, targetByteIndex);
303         if (memmove_s(targetBuf, srcElementSize * uCount, srcBuf, srcElementSize * uCount) != EOK) {
304             LOG_FULL(FATAL) << "memmove_s failed";
305             UNREACHABLE();
306         }
307     } else {
308         auto thread = JSThread::GlueToJSThread(argGlue);
309         for (uint32_t i = 0; i < uCount; ++i) {
310             JSTaggedValue curElement = JSTypedArray::FastGetPropertyByIndex(thread, JSTaggedValue::Cast(srcArray),
311                                                                             uSrcStartPos + i, srcType);
312             JSTypedArray::FastSetPropertyByIndex(thread, JSTaggedValue::Cast(targetArray), uTarStartPos + i,
313                                                  curElement, tarType);
314         }
315     }
316 }
317 
DEF_RUNTIME_STUBS(CallInternalGetter)318 DEF_RUNTIME_STUBS(CallInternalGetter)
319 {
320     RUNTIME_STUBS_HEADER(CallInternalGetter);
321     JSTaggedType argAccessor = GetTArg(argv, argc, 0);  // 0: means the zeroth parameter
322     JSHandle<JSObject> argReceiver = GetHArg<JSObject>(argv, argc, 1);  // 1: means the first parameter
323 
324     auto accessor = AccessorData::Cast(reinterpret_cast<TaggedObject *>(argAccessor));
325     return accessor->CallInternalGet(thread, argReceiver).GetRawData();
326 }
327 
DEF_RUNTIME_STUBS(CallInternalSetter)328 DEF_RUNTIME_STUBS(CallInternalSetter)
329 {
330     RUNTIME_STUBS_HEADER(CallInternalSetter);
331     JSHandle<JSObject> receiver = GetHArg<JSObject>(argv, argc, 0);  // 0: means the zeroth parameter
332     JSTaggedType argSetter = GetTArg(argv, argc, 1);  // 1: means the first parameter
333     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
334     auto setter = AccessorData::Cast((reinterpret_cast<TaggedObject *>(argSetter)));
335     auto result = setter->CallInternalSet(thread, receiver, value, true);
336     if (!result) {
337         return JSTaggedValue::Exception().GetRawData();
338     }
339     return JSTaggedValue::Undefined().GetRawData();
340 }
341 
DEF_RUNTIME_STUBS(CallInternalSetterNoThrow)342 DEF_RUNTIME_STUBS(CallInternalSetterNoThrow)
343 {
344     RUNTIME_STUBS_HEADER(CallInternalSetterNoThrow);
345     JSHandle<JSObject> receiver = GetHArg<JSObject>(argv, argc, 0); // 0: means the zeroth parameter
346     JSTaggedType argSetter = GetTArg(argv, argc, 1); // 1: means the first parameter
347     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
348     auto setter = AccessorData::Cast((reinterpret_cast<TaggedObject*>(argSetter)));
349     bool result = setter->CallInternalSet(thread, receiver, value, false);
350     return result ? JSTaggedValue::Undefined().GetRawData() : JSTaggedValue::False().GetRawData();
351 }
352 
DEF_RUNTIME_STUBS(GetHash32)353 DEF_RUNTIME_STUBS(GetHash32)
354 {
355     JSTaggedValue argKey = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
356     JSTaggedValue len = GetArg(argv, argc, 1);  // 1: means the first parameter
357     int key = argKey.GetInt();
358     auto pkey = reinterpret_cast<uint8_t *>(&key);
359     uint32_t result = panda::GetHash32(pkey, len.GetInt());
360     return JSTaggedValue(static_cast<uint64_t>(result)).GetRawData();
361 }
362 
DEF_RUNTIME_STUBS(NewInternalString)363 DEF_RUNTIME_STUBS(NewInternalString)
364 {
365     RUNTIME_STUBS_HEADER(NewInternalString);
366     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
367     return JSTaggedValue(thread->GetEcmaVM()->GetFactory()->InternString(keyHandle)).GetRawData();
368 }
369 
DEF_RUNTIME_STUBS(NewTaggedArray)370 DEF_RUNTIME_STUBS(NewTaggedArray)
371 {
372     RUNTIME_STUBS_HEADER(NewTaggedArray);
373     JSTaggedValue length = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
374 
375     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
376     return factory->NewTaggedArray(length.GetInt()).GetTaggedValue().GetRawData();
377 }
378 
DEF_RUNTIME_STUBS(CopyArray)379 DEF_RUNTIME_STUBS(CopyArray)
380 {
381     RUNTIME_STUBS_HEADER(CopyArray);
382     JSHandle<TaggedArray> array = GetHArg<TaggedArray>(argv, argc, 0);  // 0: means the zeroth parameter
383     JSTaggedValue length = GetArg(argv, argc, 1);  // 1: means the first parameter
384     JSTaggedValue capacity = GetArg(argv, argc, 2);  // 2: means the second parameter
385 
386     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
387     return factory->CopyArray(array, length.GetInt(), capacity.GetInt()).GetTaggedValue().GetRawData();
388 }
389 
DEF_RUNTIME_STUBS(RTSubstitution)390 DEF_RUNTIME_STUBS(RTSubstitution)
391 {
392     RUNTIME_STUBS_HEADER(RTSubstitution);
393     JSHandle<EcmaString> matched = GetHArg<EcmaString>(argv, argc, 0);     // 0: means the zeroth parameter
394     JSHandle<EcmaString> srcString = GetHArg<EcmaString>(argv, argc, 1);   // 1: means the first parameter
395     int position = GetArg(argv, argc, 2).GetInt();                         // 2: means the second parameter
396     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
397     JSHandle<TaggedArray> captureList = factory->EmptyArray();
398     JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
399     JSHandle<EcmaString> replacement = GetHArg<EcmaString>(argv, argc, 3); // 3: means the third parameter
400     JSTaggedValue result = builtins::BuiltinsString::GetSubstitution(thread, matched, srcString, position,
401         captureList, undefined, replacement);
402     return result.GetRawData();
403 }
404 
DEF_RUNTIME_STUBS(NameDictPutIfAbsent)405 DEF_RUNTIME_STUBS(NameDictPutIfAbsent)
406 {
407     RUNTIME_STUBS_HEADER(NameDictPutIfAbsent);
408     JSTaggedType receiver = GetTArg(argv, argc, 0);  // 0: means the zeroth parameter
409     JSTaggedType array = GetTArg(argv, argc, 1);  // 1: means the first parameter
410     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
411     JSHandle<JSTaggedValue> valueHandle = GetHArg<JSTaggedValue>(argv, argc, 3);  // 3: means the third parameter
412     JSTaggedValue attr = GetArg(argv, argc, 4);   // 4: means the fourth parameter
413     JSTaggedValue needTransToDict = GetArg(argv, argc, 5);  // 5: means the fifth parameter
414 
415     PropertyAttributes propAttr(attr);
416     if (needTransToDict.IsTrue()) {
417         JSHandle<JSObject> objHandle(thread, JSTaggedValue(reinterpret_cast<TaggedObject *>(receiver)));
418         JSHandle<NameDictionary> dictHandle(JSObject::TransitionToDictionary(thread, objHandle));
419         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
420         return NameDictionary::
421             PutIfAbsent(thread, dictHandle, keyHandle, valueHandle, propAttr).GetTaggedValue().GetRawData();
422     } else {
423         JSHandle<NameDictionary> dictHandle(thread, JSTaggedValue(reinterpret_cast<TaggedObject *>(array)));
424         return NameDictionary::
425             PutIfAbsent(thread, dictHandle, keyHandle, valueHandle, propAttr).GetTaggedValue().GetRawData();
426     }
427 }
428 
DEF_RUNTIME_STUBS(NumberDictionaryPut)429 DEF_RUNTIME_STUBS(NumberDictionaryPut)
430 {
431     RUNTIME_STUBS_HEADER(NumberDictionaryPut);
432     JSTaggedType receiver = GetTArg(argv, argc, 0);  // 0: means the zeroth parameter
433     JSTaggedType array = GetTArg(argv, argc, 1);  // 1: means the first parameter
434     JSTaggedValue key = GetArg(argv, argc, 2);  // 2: means the second parameter
435     JSHandle<JSTaggedValue> valueHandle = GetHArg<JSTaggedValue>(argv, argc, 3);  // 3: means the third parameter
436     JSTaggedValue attr = GetArg(argv, argc, 4);   // 4: means the fourth parameter
437     JSTaggedValue needTransToDict = GetArg(argv, argc, 5);  // 5: means the fifth parameter
438 
439     JSHandle<JSTaggedValue> keyHandle(thread, key);
440     PropertyAttributes propAttr(attr);
441     JSHandle<JSObject> objHandle(thread, JSTaggedValue(reinterpret_cast<TaggedObject *>(receiver)));
442     if (needTransToDict.IsTrue()) {
443         JSObject::ElementsToDictionary(thread, objHandle);
444         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
445         JSHandle<NumberDictionary> dict(thread, objHandle->GetElements(thread));
446         return NumberDictionary::Put(thread, dict, keyHandle, valueHandle, propAttr).GetTaggedValue().GetRawData();
447     } else {
448         JSHandle<NumberDictionary> dict(thread, JSTaggedValue(reinterpret_cast<TaggedObject *>(array)));
449         return NumberDictionary::Put(thread, dict, keyHandle, valueHandle, propAttr).GetTaggedValue().GetRawData();
450     }
451 }
452 
DEF_RUNTIME_STUBS(PropertiesSetValue)453 DEF_RUNTIME_STUBS(PropertiesSetValue)
454 {
455     RUNTIME_STUBS_HEADER(PropertiesSetValue);
456     JSHandle<JSObject> objHandle = GetHArg<JSObject>(argv, argc, 0);  // 0: means the zeroth parameter
457     JSHandle<JSTaggedValue> valueHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
458     JSHandle<TaggedArray> arrayHandle = GetHArg<TaggedArray>(argv, argc, 2);   // 2: means the second parameter
459     JSTaggedValue taggedCapacity = GetArg(argv, argc, 3);
460     JSTaggedValue taggedIndex = GetArg(argv, argc, 4);
461     int capacity = taggedCapacity.GetInt();
462     int index = taggedIndex.GetInt();
463 
464     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
465     JSHandle<TaggedArray> properties;
466     if (capacity == 0) {
467         properties = factory->NewTaggedArray(JSObject::MIN_PROPERTIES_LENGTH);
468     } else {
469         uint32_t maxNonInlinedFastPropsCapacity = objHandle->GetNonInlinedFastPropsCapacity();
470         uint32_t newLen = JSObject::ComputeNonInlinedFastPropsCapacity(thread, capacity,
471                                                                        maxNonInlinedFastPropsCapacity);
472         properties = factory->CopyArray(arrayHandle, capacity, newLen);
473     }
474     properties->Set(thread, index, valueHandle);
475     objHandle->SetProperties(thread, properties);
476     return JSTaggedValue::Hole().GetRawData();
477 }
478 
DEF_RUNTIME_STUBS(CheckAndCopyArray)479 DEF_RUNTIME_STUBS(CheckAndCopyArray)
480 {
481     RUNTIME_STUBS_HEADER(CheckAndCopyArray);
482     JSTaggedType argReceiver = GetTArg(argv, argc, 0);  // 0: means the zeroth parameter
483     JSHandle<JSArray> receiverHandle(thread, reinterpret_cast<JSArray *>(argReceiver));
484     JSArray::CheckAndCopyArray(thread, receiverHandle);
485     return receiverHandle->GetElements(thread).GetRawData();
486 }
487 
DEF_RUNTIME_STUBS(JSArrayReduceUnStable)488 DEF_RUNTIME_STUBS(JSArrayReduceUnStable)
489 {
490     RUNTIME_STUBS_HEADER(JSArrayReduceUnStable);
491     JSHandle<JSTaggedValue> thisHandle = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
492     JSHandle<JSTaggedValue> thisObjVal = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the one parameter
493     JSTaggedType taggedValueK = GetTArg(argv, argc, 2);  // 2: means the two parameter
494     int64_t k = JSTaggedNumber(JSTaggedValue(taggedValueK)).GetNumber();
495     JSTaggedType taggedValueLen = GetTArg(argv, argc, 3);  // 3: means the three parameter
496     int64_t len = JSTaggedNumber(JSTaggedValue(taggedValueLen)).GetNumber();
497     JSMutableHandle<JSTaggedValue> accumulator = JSMutableHandle<JSTaggedValue>(thread,
498         GetHArg<JSTaggedValue>(argv, argc, 4));  // 4: means the four parameter
499     JSHandle<JSTaggedValue> callbackFnHandle = GetHArg<JSTaggedValue>(argv, argc, 5);  // 5: means the five parameter
500 
501     JSTaggedValue ret = builtins::BuiltinsArray::ReduceUnStableJSArray(thread, thisHandle, thisObjVal, k, len,
502         accumulator, callbackFnHandle);
503     return ret.GetRawData();
504 }
505 
DEF_RUNTIME_STUBS(JSObjectGrowElementsCapacity)506 DEF_RUNTIME_STUBS(JSObjectGrowElementsCapacity)
507 {
508     RUNTIME_STUBS_HEADER(JSObjectGrowElementsCapacity);
509     JSHandle<JSObject> elements = GetHArg<JSObject>(argv, argc, 0);  // 0: means the zeroth parameter
510     JSTaggedValue length = GetArg(argv, argc, 1);                    // 1: means the zeroth parameter
511     uint32_t newLength = static_cast<uint32_t>(length.GetInt());
512     JSHandle<TaggedArray> newElements = JSObject::GrowElementsCapacity(thread, elements, newLength, true);
513     return newElements.GetTaggedValue().GetRawData();
514 }
515 
DEF_RUNTIME_STUBS(NewEcmaHClass)516 DEF_RUNTIME_STUBS(NewEcmaHClass)
517 {
518     RUNTIME_STUBS_HEADER(NewEcmaHClass);
519     JSTaggedValue size = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
520     JSTaggedValue type = GetArg(argv, argc, 1);  // 1: means the first parameter
521     JSTaggedValue inlinedProps = GetArg(argv, argc, 2);  // 2: means the second parameter
522     return (thread->GetEcmaVM()->GetFactory()->NewEcmaHClass(
523         size.GetInt(), JSType(type.GetInt()), inlinedProps.GetInt())).GetTaggedValue().GetRawData();
524 }
525 
DEF_RUNTIME_STUBS(JSArrayFilterUnStable)526 DEF_RUNTIME_STUBS(JSArrayFilterUnStable)
527 {
528     RUNTIME_STUBS_HEADER(JSArrayFilterUnStable);
529     JSHandle<JSTaggedValue> thisArgHandle = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
530     JSHandle<JSTaggedValue> thisObjVal = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the one parameter
531     JSTaggedType taggedValueK = GetTArg(argv, argc, 2);  // 2: means the two parameter
532     int64_t k = JSTaggedNumber(JSTaggedValue(taggedValueK)).GetNumber();
533     JSTaggedType taggedValueLen = GetTArg(argv, argc, 3);  // 3: means the three parameter
534     int64_t len = JSTaggedNumber(JSTaggedValue(taggedValueLen)).GetNumber();
535     JSTaggedType toIndexValue = GetTArg(argv, argc, 4);  // 4: means the three parameter
536     int32_t toIndex = JSTaggedNumber(JSTaggedValue(toIndexValue)).GetNumber();
537     JSHandle<JSObject> newArrayHandle = JSMutableHandle<JSObject>(thread,
538         GetHArg<JSObject>(argv, argc, 5));  // 5: means the four parameter
539     JSHandle<JSTaggedValue> callbackFnHandle = GetHArg<JSTaggedValue>(argv, argc, 6);  // 6: means the five parameter
540 
541     JSTaggedValue ret = builtins::BuiltinsArray::FilterUnStableJSArray(thread, thisArgHandle, thisObjVal, k, len,
542         toIndex, newArrayHandle, callbackFnHandle);
543     return ret.GetRawData();
544 }
545 
DEF_RUNTIME_STUBS(JSArrayMapUnStable)546 DEF_RUNTIME_STUBS(JSArrayMapUnStable)
547 {
548     RUNTIME_STUBS_HEADER(JSArrayMapUnStable);
549     JSHandle<JSTaggedValue> thisArgHandle = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
550     JSHandle<JSTaggedValue> thisObjVal = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the one parameter
551     JSTaggedType taggedValueK = GetTArg(argv, argc, 2);  // 2: means the two parameter
552     int64_t k = JSTaggedNumber(JSTaggedValue(taggedValueK)).GetNumber();
553     JSTaggedType taggedValueLen = GetTArg(argv, argc, 3);  // 3: means the three parameter
554     int64_t len = JSTaggedNumber(JSTaggedValue(taggedValueLen)).GetNumber();
555     JSHandle<JSObject> newArrayHandle =
556         JSMutableHandle<JSObject>(thread, GetHArg<JSObject>(argv, argc, 4));  // 4: means the four parameter
557     JSHandle<JSTaggedValue> callbackFnHandle = GetHArg<JSTaggedValue>(argv, argc, 5);  // 5: means the five parameter
558 
559     JSTaggedValue ret = builtins::BuiltinsArray::MapUnStableJSArray(thread, thisArgHandle, thisObjVal, k, len,
560         newArrayHandle, callbackFnHandle);
561     return ret.GetRawData();
562 }
563 
DEF_RUNTIME_STUBS(UpdateLayOutAndAddTransition)564 DEF_RUNTIME_STUBS(UpdateLayOutAndAddTransition)
565 {
566     RUNTIME_STUBS_HEADER(UpdateLayOutAndAddTransition);
567     JSHandle<JSHClass> oldHClassHandle = GetHArg<JSHClass>(argv, argc, 0);  // 0: means the zeroth parameter
568     JSHandle<JSHClass> newHClassHandle = GetHArg<JSHClass>(argv, argc, 1);  // 1: means the first parameter
569     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
570     JSTaggedValue attr = GetArg(argv, argc, 3);  // 3: means the third parameter
571 
572     PropertyAttributes attrValue(attr);
573 
574     JSHClass::AddPropertyToNewHClass(thread, oldHClassHandle, newHClassHandle, keyHandle, attrValue);
575 
576     return JSTaggedValue::Hole().GetRawData();
577 }
578 
DEF_RUNTIME_STUBS(CopyAndUpdateObjLayout)579 DEF_RUNTIME_STUBS(CopyAndUpdateObjLayout)
580 {
581     RUNTIME_STUBS_HEADER(CopyAndUpdateObjLayout);
582     JSHandle<JSHClass> newHClassHandle = GetHArg<JSHClass>(argv, argc, 1);  // 1: means the first parameter
583     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
584     JSTaggedValue attr = GetArg(argv, argc, 3);  // 3: means the third parameter
585 
586     auto factory = thread->GetEcmaVM()->GetFactory();
587     PropertyAttributes attrValue(attr);
588 
589     // 1. Copy
590     JSHandle<LayoutInfo> oldLayout(thread, newHClassHandle->GetLayout(thread));
591     JSHandle<LayoutInfo> newLayout(factory->CopyLayoutInfo(oldLayout));
592     newHClassHandle->SetLayout(thread, newLayout);
593 
594     // 2. Update attr
595     auto hclass = JSHClass::Cast(newHClassHandle.GetTaggedValue().GetTaggedObject());
596     int entry = JSHClass::FindPropertyEntry(thread, hclass, keyHandle.GetTaggedValue());
597     ASSERT(entry != -1);
598     newLayout->SetNormalAttr(thread, entry, attrValue);
599 
600     // 3. Maybe Transition And Maintain subtypeing check
601     return JSTaggedValue::Hole().GetRawData();
602 }
603 
DEF_RUNTIME_STUBS(UpdateHClassForElementsKind)604 DEF_RUNTIME_STUBS(UpdateHClassForElementsKind)
605 {
606     RUNTIME_STUBS_HEADER(UpdateHClassForElementsKind);
607     JSHandle<JSTaggedValue> receiver = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the first parameter
608     ElementsKind elementsKind = static_cast<ElementsKind>(GetTArg(argv, argc, 1));  // 1: means the first parameter
609     // 1: means the first parameter
610     ASSERT(receiver->IsJSArray());
611     auto array = JSHandle<JSArray>(receiver);
612     ASSERT(JSHClass::IsInitialArrayHClassWithElementsKind(thread, receiver->GetTaggedObject()->GetClass(),
613                                                           receiver->GetTaggedObject()->GetClass()->GetElementsKind()));
614     if (!JSHClass::TransitToElementsKindUncheck(thread, JSHandle<JSObject>(array), elementsKind)) {
615         return JSTaggedValue::Hole().GetRawData();
616     }
617 
618     if (thread->IsEnableElementsKind() || thread->IsPGOProfilerEnable()) {
619         // Update TrackInfo
620         JSHandle<JSArray>(receiver)->UpdateTrackInfo(thread);
621     }
622 
623     if (!thread->IsPGOProfilerEnable()) {
624         return JSTaggedValue::Hole().GetRawData();
625     }
626     JSTaggedValue trackInfoVal = JSHandle<JSArray>(receiver)->GetTrackInfo(thread);
627     if (trackInfoVal.IsHeapObject() && trackInfoVal.IsWeak()) {
628         TrackInfo *trackInfo = TrackInfo::Cast(trackInfoVal.GetWeakReferentUnChecked());
629         thread->GetEcmaVM()->GetPGOProfiler()->UpdateTrackInfo(JSTaggedValue(trackInfo));
630     }
631     return JSTaggedValue::Hole().GetRawData();
632 }
633 
DEF_RUNTIME_STUBS(NewMutantTaggedArray)634 DEF_RUNTIME_STUBS(NewMutantTaggedArray)
635 {
636     RUNTIME_STUBS_HEADER(NewMutantTaggedArray);
637     JSTaggedValue length = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
638 
639     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
640     return factory->NewMutantTaggedArray(length.GetInt()).GetTaggedValue().GetRawData();
641 }
642 
DEF_RUNTIME_STUBS(NewCOWMutantTaggedArray)643 DEF_RUNTIME_STUBS(NewCOWMutantTaggedArray)
644 {
645     RUNTIME_STUBS_HEADER(NewCOWMutantTaggedArray);
646     JSTaggedValue length = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
647 
648     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
649     return factory->NewCOWMutantTaggedArray(length.GetInt()).GetTaggedValue().GetRawData();
650 }
651 
DEF_RUNTIME_STUBS(NewCOWTaggedArray)652 DEF_RUNTIME_STUBS(NewCOWTaggedArray)
653 {
654     RUNTIME_STUBS_HEADER(NewCOWTaggedArray);
655     JSTaggedValue length = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
656 
657     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
658     return factory->NewCOWMutantTaggedArray(length.GetInt()).GetTaggedValue().GetRawData();
659 }
660 
DEF_RUNTIME_STUBS(ForceGC)661 DEF_RUNTIME_STUBS(ForceGC)
662 {
663     RUNTIME_STUBS_HEADER(ForceGC);
664     if (!thread->GetEcmaVM()->GetJSOptions().EnableForceGC()) {
665         return JSTaggedValue::Hole().GetRawData();
666     }
667     if (g_isEnableCMCGC) {
668         common::BaseRuntime::RequestGC(common::GC_REASON_USER, true, common::GC_TYPE_FULL);
669     } else {
670         thread->GetEcmaVM()->CollectGarbage(TriggerGCType::FULL_GC);
671     }
672     return JSTaggedValue::Hole().GetRawData();
673 }
674 
DEF_RUNTIME_STUBS(RuntimeDump)675 DEF_RUNTIME_STUBS(RuntimeDump)
676 {
677     RUNTIME_STUBS_HEADER(RuntimeDump);
678     JSHandle<JSTaggedValue> obj = JSHandle<JSTaggedValue>(GetHArg<JSTaggedValue>(argv, argc, 0));
679     {
680         std::ostringstream oss;
681         obj->Dump(thread, oss);
682         LOG_ECMA(ERROR) << "RuntimeDump: " << oss.str();
683     }
684 
685     LOG_ECMA(ERROR) << "---------- before force gc ---------------";
686     {
687         thread->GetEcmaVM()->CollectGarbage(TriggerGCType::FULL_GC);
688     }
689     LOG_ECMA(ERROR) << "---------- end force gc ---------------";
690     return JSTaggedValue::Hole().GetRawData();
691 }
692 
Dump(JSTaggedType rawValue)693 void RuntimeStubs::Dump(JSTaggedType rawValue)
694 {
695     DISALLOW_GARBAGE_COLLECTION;
696     std::ostringstream oss;
697     auto value = JSTaggedValue(rawValue);
698     value.Dump(THREAD_ARG_PLACEHOLDER, oss);
699     LOG_ECMA(INFO) << "dump log for read-only crash " << oss.str();
700 }
701 
DebugDump(JSTaggedType rawValue)702 void RuntimeStubs::DebugDump(JSTaggedType rawValue)
703 {
704     DISALLOW_GARBAGE_COLLECTION;
705     DebugDumpWithHint(reinterpret_cast<uintptr_t>(nullptr), rawValue);
706 }
707 
DumpWithHint(uintptr_t hintStrAddress,JSTaggedType rawValue)708 void RuntimeStubs::DumpWithHint(uintptr_t hintStrAddress, JSTaggedType rawValue)
709 {
710     DISALLOW_GARBAGE_COLLECTION;
711     const char *origHintStr = reinterpret_cast<const char*>(hintStrAddress); // May be nullptr
712     const char *hintStr = (origHintStr == nullptr) ? "" : origHintStr;
713     DumpToStreamWithHint(std::cout, hintStr, JSTaggedValue(rawValue));
714     std::cout << std::endl; // New line
715 }
716 
DebugDumpWithHint(uintptr_t hintStrAddress,JSTaggedType rawValue)717 void RuntimeStubs::DebugDumpWithHint(uintptr_t hintStrAddress, JSTaggedType rawValue)
718 {
719     DISALLOW_GARBAGE_COLLECTION;
720     const char *origHintStr = reinterpret_cast<const char*>(hintStrAddress); // May be nullptr
721     const char *hintStr = (origHintStr == nullptr) ? "" : origHintStr;
722     // The immediate lambda expression call is not evaluated when the logger is unabled.
723     LOG_ECMA(DEBUG) << [](const char *hintStr, JSTaggedType rawValue) {
724         std::ostringstream out;
725         DumpToStreamWithHint(out, hintStr, JSTaggedValue(rawValue));
726         return out.str();
727     }(hintStr, rawValue);
728 }
729 
DumpToStreamWithHint(std::ostream & out,std::string_view hint,JSTaggedValue value)730 void RuntimeStubs::DumpToStreamWithHint(std::ostream &out, std::string_view hint, JSTaggedValue value)
731 {
732     constexpr std::string_view dumpDelimiterLine = "================";
733     // Begin line
734     out << dumpDelimiterLine << " Begin dump: " << hint << ' ' << dumpDelimiterLine << std::endl;
735     // Dumps raw data
736     out << "(Raw value = 0x" << std::setw(base::INT64_HEX_DIGITS) << std::hex
737         << std::setfill('0') << value.GetRawData() << ") ";
738     out << std::dec << std::setfill(' '); // Recovers integer radix & fill character
739     // Dumps tagged value
740     value.Dump(THREAD_ARG_PLACEHOLDER, out);
741     // End line
742     out << dumpDelimiterLine << "   End dump: " << hint << ' ' << dumpDelimiterLine;
743 }
744 
DebugPrint(int fmtMessageId,...)745 void RuntimeStubs::DebugPrint(int fmtMessageId, ...)
746 {
747     std::string format = MessageString::GetMessageString(fmtMessageId);
748     va_list args;
749     va_start(args, fmtMessageId);
750     std::string result = base::StringHelper::Vformat(format.c_str(), args);
751     if (MessageString::IsBuiltinsStubMessageString(fmtMessageId)) {
752         LOG_BUILTINS(DEBUG) << result;
753     } else {
754         LOG_ECMA(DEBUG) << result;
755     }
756     va_end(args);
757 }
758 
DebugPrintCustom(uintptr_t fmt,...)759 void RuntimeStubs::DebugPrintCustom(uintptr_t fmt, ...)
760 {
761     va_list args;
762     va_start(args, fmt);
763     std::string result = base::StringHelper::Vformat(reinterpret_cast<const char*>(fmt), args);
764     LOG_ECMA(DEBUG) << result;
765     va_end(args);
766 }
767 
DebugPrintInstruction(uintptr_t argGlue,const uint8_t * pc)768 void RuntimeStubs::DebugPrintInstruction([[maybe_unused]] uintptr_t argGlue, const uint8_t *pc)
769 {
770     BytecodeInstruction inst(pc);
771     LOG_INTERPRETER(DEBUG) << inst;
772 }
773 
CollectingOpcodes(uintptr_t argGlue,const uint8_t * pc)774 void RuntimeStubs::CollectingOpcodes([[maybe_unused]] uintptr_t argGlue, const uint8_t *pc)
775 {
776 #if ECMASCRIPT_ENABLE_COLLECTING_OPCODES
777     BytecodeInstruction inst(pc);
778     auto thread = JSThread::GlueToJSThread(argGlue);
779     auto vm = thread->GetEcmaVM();
780     auto opcode = inst.GetOpcode();
781     std::stack<std::unordered_map<BytecodeInstruction::Opcode, int>> &bytecodeStatsStack_ =
782             vm->GetBytecodeStatsStack();
783     if (bytecodeStatsStack_.empty()) {
784         return;
785     }
786     std::unordered_map<BytecodeInstruction::Opcode, int> &bytecodeStatsMap_ = bytecodeStatsStack_.top();
787     auto foundInst = bytecodeStatsMap_.find(opcode);
788     if (foundInst != bytecodeStatsMap_.end()) {
789         ++foundInst->second;
790     } else {
791         bytecodeStatsMap_[opcode] = 1;
792     }
793     LOG_INTERPRETER(DEBUG) << inst;
794 #endif
795 }
796 
DebugOsrEntry(uintptr_t argGlue,const uint8_t * codeEntry)797 void RuntimeStubs::DebugOsrEntry([[maybe_unused]] uintptr_t argGlue, const uint8_t *codeEntry)
798 {
799     LOG_JIT(DEBUG) << "[OSR]: Enter OSR Code: " << reinterpret_cast<const void*>(codeEntry);
800 }
801 
Comment(uintptr_t argStr)802 void RuntimeStubs::Comment(uintptr_t argStr)
803 {
804     std::string str(reinterpret_cast<char *>(argStr));
805     LOG_ECMA(DEBUG) << str;
806 }
807 
FatalPrint(int fmtMessageId,...)808 void RuntimeStubs::FatalPrint(int fmtMessageId, ...)
809 {
810     std::string format = MessageString::GetMessageString(fmtMessageId);
811     va_list args;
812     va_start(args, fmtMessageId);
813     std::string result = base::StringHelper::Vformat(format.c_str(), args);
814     LOG_FULL(FATAL) << result;
815     va_end(args);
816     LOG_ECMA(FATAL) << "this branch is unreachable";
817     UNREACHABLE();
818 }
819 
FatalPrintCustom(uintptr_t fmt,...)820 void RuntimeStubs::FatalPrintCustom(uintptr_t fmt, ...)
821 {
822     va_list args;
823     va_start(args, fmt);
824     std::string result = base::StringHelper::Vformat(reinterpret_cast<const char*>(fmt), args);
825     LOG_FULL(FATAL) << result;
826     va_end(args);
827     LOG_ECMA(FATAL) << "this branch is unreachable";
828     UNREACHABLE();
829 }
830 
DEF_RUNTIME_STUBS(NoticeThroughChainAndRefreshUser)831 DEF_RUNTIME_STUBS(NoticeThroughChainAndRefreshUser)
832 {
833     RUNTIME_STUBS_HEADER(NoticeThroughChainAndRefreshUser);
834     JSHandle<JSHClass> oldHClassHandle = GetHArg<JSHClass>(argv, argc, 0);  // 0: means the zeroth parameter
835     JSHandle<JSHClass> newHClassHandle = GetHArg<JSHClass>(argv, argc, 1);  // 1: means the first parameter
836 
837     JSHClass::NotifyHClassNotPrototypeChanged(thread, newHClassHandle);
838     JSHClass::NoticeThroughChain(thread, oldHClassHandle);
839     JSHClass::RefreshUsers(thread, oldHClassHandle, newHClassHandle);
840     return JSTaggedValue::Hole().GetRawData();
841 }
842 
DEF_RUNTIME_STUBS(GetNativePcOfstForBaseline)843 DEF_RUNTIME_STUBS(GetNativePcOfstForBaseline)
844 {
845     RUNTIME_STUBS_HEADER(GetNativePcOfstForBaseline);
846     JSHandle<JSFunction> func = GetHArg<JSFunction>(argv, argc, 0);  // 0: means the zeroth parameter
847     uint64_t bytecodePc = static_cast<uint64_t>(GetTArg(argv, argc, 1));  // 1: means the first parameter
848     return RuntimeGetNativePcOfstForBaseline(thread, func, bytecodePc);
849 }
850 
DEF_RUNTIME_STUBS(Inc)851 DEF_RUNTIME_STUBS(Inc)
852 {
853     RUNTIME_STUBS_HEADER(Inc);
854     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
855     return RuntimeInc(thread, value).GetRawData();
856 }
857 
DEF_RUNTIME_STUBS(Dec)858 DEF_RUNTIME_STUBS(Dec)
859 {
860     RUNTIME_STUBS_HEADER(Dec);
861     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
862     return RuntimeDec(thread, value).GetRawData();
863 }
864 
DEF_RUNTIME_STUBS(CallGetPrototype)865 DEF_RUNTIME_STUBS(CallGetPrototype)
866 {
867     RUNTIME_STUBS_HEADER(CallGetPrototype);
868     JSHandle<JSProxy> proxy = GetHArg<JSProxy>(argv, argc, 0);  // 0: means the zeroth parameter
869     return JSProxy::GetPrototype(thread, proxy).GetRawData();
870 }
871 
DEF_RUNTIME_STUBS(RegularJSObjDeletePrototype)872 DEF_RUNTIME_STUBS(RegularJSObjDeletePrototype)
873 {
874     RUNTIME_STUBS_HEADER(RegularJSObjDeletePrototype);
875     JSHandle<JSObject> tagged = GetHArg<JSObject>(argv, argc, 0);  // 0: means the zeroth parameter
876     JSTaggedValue value = GetArg(argv, argc, 1);
877     uint32_t index = 0;
878     if (value.IsString()) {
879         auto string = JSHandle<EcmaString>(thread, value);
880         if (EcmaStringAccessor(string).ToElementIndex(thread, &index)) {
881             value = JSTaggedValue(index);
882         } else if (!EcmaStringAccessor(string).IsInternString()) {
883             JSTaggedValue key(RuntimeTryGetInternString(argGlue, string));
884             if (key.IsHole()) {
885                 return JSTaggedValue::True().GetRawData();
886             } else {
887                 value = key;
888             }
889         }
890     }
891     auto result = JSObject::DeleteProperty(thread, tagged, JSHandle<JSTaggedValue>(thread, value));
892     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
893     if (!result) {
894         auto factory = thread->GetEcmaVM()->GetFactory();
895         JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR, "Cannot delete property", StackCheck::NO);
896         thread->SetException(error.GetTaggedValue());
897         return JSTaggedValue::Exception().GetRawData();
898     }
899     return JSTaggedValue::True().GetRawData();
900 }
901 
DEF_RUNTIME_STUBS(CallJSObjDeletePrototype)902 DEF_RUNTIME_STUBS(CallJSObjDeletePrototype)
903 {
904     RUNTIME_STUBS_HEADER(CallJSObjDeletePrototype);
905     JSHandle<JSTaggedValue> tagged = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
906     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);
907     auto result = JSTaggedValue::DeleteProperty(thread, tagged, value);
908     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
909     if (!result) {
910         auto factory = thread->GetEcmaVM()->GetFactory();
911         JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR, "Cannot delete property", StackCheck::NO);
912         thread->SetException(error.GetTaggedValue());
913         return JSTaggedValue::Exception().GetRawData();
914     }
915     return JSTaggedValue::True().GetRawData();
916 }
917 
DEF_RUNTIME_STUBS(ToPropertyKey)918 DEF_RUNTIME_STUBS(ToPropertyKey)
919 {
920     RUNTIME_STUBS_HEADER(ToPropertyKey);
921     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
922     JSTaggedValue res = JSTaggedValue::ToPropertyKey(thread, key).GetTaggedValue();
923     return res.GetRawData();
924 }
925 
DEF_RUNTIME_STUBS(Exp)926 DEF_RUNTIME_STUBS(Exp)
927 {
928     RUNTIME_STUBS_HEADER(Exp);
929     JSTaggedValue baseValue = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
930     JSTaggedValue exponentValue = GetArg(argv, argc, 1);  // 1: means the first parameter
931     if (baseValue.IsNumber() && exponentValue.IsNumber()) {
932         // fast path
933         double doubleBase = baseValue.IsInt() ? baseValue.GetInt() : baseValue.GetDouble();
934         double doubleExponent = exponentValue.IsInt() ? exponentValue.GetInt() : exponentValue.GetDouble();
935         if ((std::abs(doubleBase) == 1 && std::isinf(doubleExponent)) || std::isnan(doubleExponent)) {
936             return JSTaggedValue(base::NAN_VALUE).GetRawData();
937         }
938         if ((doubleBase == 0 &&
939             ((base::bit_cast<uint64_t>(doubleBase)) & base::DOUBLE_SIGN_MASK) == base::DOUBLE_SIGN_MASK) &&
940             std::isfinite(doubleExponent) && base::NumberHelper::TruncateDouble(doubleExponent) == doubleExponent &&
941             base::NumberHelper::TruncateDouble(doubleExponent / 2) + base::HALF ==  // 2 : half
942             (doubleExponent / 2)) {  // 2 : half
943             if (doubleExponent > 0) {
944                 return JSTaggedValue(-0.0).GetRawData();
945             }
946             if (doubleExponent < 0) {
947                 return JSTaggedValue(-base::POSITIVE_INFINITY).GetRawData();
948             }
949         }
950         return JSTaggedValue(std::pow(doubleBase, doubleExponent)).GetRawData();
951     }
952     // Slow path
953     JSTaggedValue res = RuntimeExp(thread, baseValue, exponentValue);
954     return res.GetRawData();
955 }
956 
DEF_RUNTIME_STUBS(IsIn)957 DEF_RUNTIME_STUBS(IsIn)
958 {
959     RUNTIME_STUBS_HEADER(IsIn);
960     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
961     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
962     return RuntimeIsIn(thread, prop, obj).GetRawData();
963 }
964 
DEF_RUNTIME_STUBS(InstanceOf)965 DEF_RUNTIME_STUBS(InstanceOf)
966 {
967     RUNTIME_STUBS_HEADER(InstanceOf);
968     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
969     JSHandle<JSTaggedValue> target = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
970     return RuntimeInstanceof(thread, obj, target).GetRawData();
971 }
972 
DEF_RUNTIME_STUBS(DumpObject)973 DEF_RUNTIME_STUBS(DumpObject)
974 {
975     RUNTIME_STUBS_HEADER(DumpObject);
976     JSHandle<JSTaggedValue> target = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
977     JSHandle<JSTaggedValue> targetId = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
978     LOG_ECMA(INFO) << "InstanceOf Stability Testing Num: " << targetId->GetInt();
979     std::ostringstream oss;
980     target->Dump(thread, oss);
981     LOG_ECMA(INFO) << "dump log for instance of target: " << oss.str();
982     return JSTaggedValue::True().GetRawData();
983 }
984 
DEF_RUNTIME_STUBS(DumpHeapObjectAddress)985 DEF_RUNTIME_STUBS(DumpHeapObjectAddress)
986 {
987     RUNTIME_STUBS_HEADER(DumpHeapObjectAddress);
988     JSHandle<JSTaggedValue> target = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
989     std::ostringstream oss;
990     target->DumpHeapObjAddress(thread, oss);
991     LOG_ECMA(INFO) << "dump log for instance of target: " << oss.str();
992     return JSTaggedValue::True().GetRawData();
993 }
994 
DEF_RUNTIME_STUBS(BigIntConstructor)995 DEF_RUNTIME_STUBS(BigIntConstructor)
996 {
997     RUNTIME_STUBS_HEADER(BigIntConstructor);
998     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);
999     return builtins::BuiltinsBigInt::BigIntConstructorInternal(thread, value).GetRawData();
1000 }
1001 
DEF_RUNTIME_STUBS(CreateGeneratorObj)1002 DEF_RUNTIME_STUBS(CreateGeneratorObj)
1003 {
1004     RUNTIME_STUBS_HEADER(CreateGeneratorObj);
1005     JSHandle<JSTaggedValue> genFunc = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1006     return RuntimeCreateGeneratorObj(thread, genFunc).GetRawData();
1007 }
1008 
DEF_RUNTIME_STUBS(CreateAsyncGeneratorObj)1009 DEF_RUNTIME_STUBS(CreateAsyncGeneratorObj)
1010 {
1011     RUNTIME_STUBS_HEADER(CreateAsyncGeneratorObj);
1012     JSHandle<JSTaggedValue> genFunc = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1013     return RuntimeCreateAsyncGeneratorObj(thread, genFunc).GetRawData();
1014 }
1015 
DEF_RUNTIME_STUBS(GetTemplateObject)1016 DEF_RUNTIME_STUBS(GetTemplateObject)
1017 {
1018     RUNTIME_STUBS_HEADER(GetTemplateObject);
1019     JSHandle<JSTaggedValue> literal = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1020     return RuntimeGetTemplateObject(thread, literal).GetRawData();
1021 }
1022 
DEF_RUNTIME_STUBS(CreateStringIterator)1023 DEF_RUNTIME_STUBS(CreateStringIterator)
1024 {
1025     RUNTIME_STUBS_HEADER(CreateStringIterator);
1026     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1027     return JSStringIterator::CreateStringIterator(thread, JSHandle<EcmaString>(obj)).GetTaggedValue().GetRawData();
1028 }
1029 
DEF_RUNTIME_STUBS(NewJSArrayIterator)1030 DEF_RUNTIME_STUBS(NewJSArrayIterator)
1031 {
1032     RUNTIME_STUBS_HEADER(NewJSArrayIterator);
1033     JSHandle<JSObject> obj = GetHArg<JSObject>(argv, argc, 0);  // 0: means the zeroth parameter
1034     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1035     return factory->NewJSArrayIterator(obj, IterationKind::VALUE).GetTaggedValue().GetRawData();
1036 }
1037 
DEF_RUNTIME_STUBS(NewJSTypedArrayIterator)1038 DEF_RUNTIME_STUBS(NewJSTypedArrayIterator)
1039 {
1040     RUNTIME_STUBS_HEADER(NewJSArrayIterator);
1041     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1042     base::TypedArrayHelper::ValidateTypedArray(thread, obj);
1043     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
1044     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1045     JSHandle<JSArrayIterator> iter(factory->NewJSArrayIterator(JSHandle<JSObject>(obj), IterationKind::VALUE));
1046     return iter.GetTaggedValue().GetRawData();
1047 }
1048 
DEF_RUNTIME_STUBS(StringIteratorNext)1049 DEF_RUNTIME_STUBS(StringIteratorNext)
1050 {
1051     RUNTIME_STUBS_HEADER(StringIteratorNext);
1052     JSHandle<JSTaggedValue> thisObj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1053     return builtins::BuiltinsStringIterator::NextInternal(thread, thisObj).GetRawData();
1054 }
1055 
DEF_RUNTIME_STUBS(ArrayIteratorNext)1056 DEF_RUNTIME_STUBS(ArrayIteratorNext)
1057 {
1058     RUNTIME_STUBS_HEADER(ArrayIteratorNext);
1059     JSHandle<JSTaggedValue> thisObj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1060     return JSArrayIterator::NextInternal(thread, thisObj).GetRawData();
1061 }
1062 
DEF_RUNTIME_STUBS(IteratorReturn)1063 DEF_RUNTIME_STUBS(IteratorReturn)
1064 {
1065     RUNTIME_STUBS_HEADER(IteratorReturn);
1066     JSHandle<JSTaggedValue> thisObj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1067     return builtins::BuiltinsIterator::ReturnInternal(thread, thisObj).GetRawData();
1068 }
1069 
DEF_RUNTIME_STUBS(GetNextPropNameSlowpath)1070 DEF_RUNTIME_STUBS(GetNextPropNameSlowpath)
1071 {
1072     RUNTIME_STUBS_HEADER(GetNextPropNameSlowpath);
1073     JSHandle<JSTaggedValue> iter = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1074     ASSERT(iter->IsForinIterator());
1075     JSTaggedValue res = JSForInIterator::NextInternalSlowpath(thread, JSHandle<JSForInIterator>::Cast(iter));
1076     return res.GetRawData();
1077 }
1078 
DEF_RUNTIME_STUBS(CloseIterator)1079 DEF_RUNTIME_STUBS(CloseIterator)
1080 {
1081     RUNTIME_STUBS_HEADER(CloseIterator);
1082     JSHandle<JSTaggedValue> iter = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1083     return RuntimeCloseIterator(thread, iter).GetRawData();
1084 }
1085 
DEF_RUNTIME_STUBS(SuperCallSpread)1086 DEF_RUNTIME_STUBS(SuperCallSpread)
1087 {
1088     RUNTIME_STUBS_HEADER(SuperCallSpread);
1089     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1090     JSHandle<JSTaggedValue> array = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1091     auto sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1092     JSTaggedValue function = InterpreterAssembly::GetNewTarget(thread, sp);
1093     return RuntimeSuperCallSpread(thread, func, JSHandle<JSTaggedValue>(thread, function), array).GetRawData();
1094 }
1095 
DEF_RUNTIME_STUBS(OptSuperCallSpread)1096 DEF_RUNTIME_STUBS(OptSuperCallSpread)
1097 {
1098     RUNTIME_STUBS_HEADER(OptSuperCallSpread);
1099     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1100     JSHandle<JSTaggedValue> newTarget = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1101     JSHandle<JSTaggedValue> taggedArray = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
1102     return RuntimeOptSuperCallSpread(thread, func, newTarget, taggedArray).GetRawData();
1103 }
1104 
DEF_RUNTIME_STUBS(SuperCallForwardAllArgs)1105 DEF_RUNTIME_STUBS(SuperCallForwardAllArgs)
1106 {
1107     RUNTIME_STUBS_HEADER(SuperCallForwardAllArgs);
1108     auto sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1109     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: index of child constructor
1110     JSHandle<JSTaggedValue> superFunc(thread, JSTaggedValue::GetPrototype(thread, func));
1111     auto newTarget = JSHandle<JSTaggedValue>(thread, InterpreterAssembly::GetNewTarget(thread, sp));
1112     uint32_t startIdx = 0;
1113     uint32_t restNumArgs = InterpreterAssembly::GetNumArgs(thread, sp, 0, startIdx);  // 0: rest args start idx
1114     return RuntimeSuperCallForwardAllArgs(thread, sp, superFunc, newTarget, restNumArgs, startIdx).GetRawData();
1115 }
1116 
DEF_RUNTIME_STUBS(OptSuperCallForwardAllArgs)1117 DEF_RUNTIME_STUBS(OptSuperCallForwardAllArgs)
1118 {
1119     RUNTIME_STUBS_HEADER(OptSuperCallForwardAllArgs);
1120     JSTaggedType *sp = reinterpret_cast<JSTaggedType *>(GetActualArgv(thread));
1121     JSHandle<JSTaggedValue> superFunc = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: index of super constructor
1122     JSHandle<JSTaggedValue> newTarget = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: index of newTarget
1123     int actualArgc = GetArg(argv, argc, 2).GetInt();                            // 2: index of actual argc
1124     ASSERT(actualArgc >= 0);
1125     uint32_t convertedActualArgc = static_cast<uint32_t>(actualArgc);
1126     ASSERT(convertedActualArgc >= NUM_MANDATORY_JSFUNC_ARGS);
1127     uint32_t restNumArgs = convertedActualArgc - NUM_MANDATORY_JSFUNC_ARGS;
1128     uint32_t startIdx = NUM_MANDATORY_JSFUNC_ARGS;
1129     return RuntimeSuperCallForwardAllArgs(thread, sp, superFunc, newTarget, restNumArgs, startIdx).GetRawData();
1130 }
1131 
DEF_RUNTIME_STUBS(GetCallSpreadArgs)1132 DEF_RUNTIME_STUBS(GetCallSpreadArgs)
1133 {
1134     RUNTIME_STUBS_HEADER(GetCallSpreadArgs);
1135     JSHandle<JSTaggedValue> jsArray = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1136     return RuntimeGetCallSpreadArgs(thread, jsArray).GetRawData();
1137 }
1138 
DEF_RUNTIME_STUBS(DelObjProp)1139 DEF_RUNTIME_STUBS(DelObjProp)
1140 {
1141     RUNTIME_STUBS_HEADER(DelObjProp);
1142     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1143     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1144     return RuntimeDelObjProp(thread, obj, prop).GetRawData();
1145 }
1146 
DEF_RUNTIME_STUBS(NewObjApply)1147 DEF_RUNTIME_STUBS(NewObjApply)
1148 {
1149     RUNTIME_STUBS_HEADER(NewObjApply);
1150     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1151     JSHandle<JSTaggedValue> array = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1152     return RuntimeNewObjApply(thread, func, array).GetRawData();
1153 }
1154 
DEF_RUNTIME_STUBS(CreateIterResultObj)1155 DEF_RUNTIME_STUBS(CreateIterResultObj)
1156 {
1157     RUNTIME_STUBS_HEADER(CreateIterResultObj);
1158     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1159     JSTaggedValue flag = GetArg(argv, argc, 1);  // 1: means the first parameter
1160     return RuntimeCreateIterResultObj(thread, value, flag).GetRawData();
1161 }
1162 
DEF_RUNTIME_STUBS(AsyncFunctionAwaitUncaught)1163 DEF_RUNTIME_STUBS(AsyncFunctionAwaitUncaught)
1164 {
1165     RUNTIME_STUBS_HEADER(AsyncFunctionAwaitUncaught);
1166     JSHandle<JSTaggedValue> asyncFuncObj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1167     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1168     return RuntimeAsyncFunctionAwaitUncaught(thread, asyncFuncObj, value).GetRawData();
1169 }
1170 
DEF_RUNTIME_STUBS(AsyncFunctionResolveOrReject)1171 DEF_RUNTIME_STUBS(AsyncFunctionResolveOrReject)
1172 {
1173     RUNTIME_STUBS_HEADER(AsyncFunctionResolveOrReject);
1174     JSHandle<JSTaggedValue> asyncFuncObj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1175     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1176     JSTaggedValue isResolve = GetArg(argv, argc, 2);  // 2: means the second parameter
1177     return RuntimeAsyncFunctionResolveOrReject(thread, asyncFuncObj, value, isResolve.IsTrue()).GetRawData();
1178 }
1179 
DEF_RUNTIME_STUBS(AsyncGeneratorResolve)1180 DEF_RUNTIME_STUBS(AsyncGeneratorResolve)
1181 {
1182     RUNTIME_STUBS_HEADER(AsyncGeneratorResolve);
1183     JSHandle<JSTaggedValue> asyncGenerator = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1184     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1185     JSTaggedValue flag = GetArg(argv, argc, 2); // 2: means the second parameter
1186     return RuntimeAsyncGeneratorResolve(thread, asyncGenerator, value, flag).GetRawData();
1187 }
1188 
DEF_RUNTIME_STUBS(AsyncGeneratorReject)1189 DEF_RUNTIME_STUBS(AsyncGeneratorReject)
1190 {
1191     RUNTIME_STUBS_HEADER(AsyncGeneratorReject);
1192     JSHandle<JSTaggedValue> asyncGenerator = GetHArg<JSTaggedValue>(argv, argc, 0);
1193     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);
1194     return RuntimeAsyncGeneratorReject(thread, asyncGenerator, value).GetRawData();
1195 }
1196 
DEF_RUNTIME_STUBS(SetGeneratorState)1197 DEF_RUNTIME_STUBS(SetGeneratorState)
1198 {
1199     RUNTIME_STUBS_HEADER(SetGeneratorState);
1200     JSHandle<JSTaggedValue> asyncGenerator = GetHArg<JSTaggedValue>(argv, argc, 0);
1201     JSTaggedValue index = GetArg(argv, argc, 1);
1202     RuntimeSetGeneratorState(thread, asyncGenerator, index.GetInt());
1203     return JSTaggedValue::Hole().GetRawData();
1204 }
1205 
DEF_RUNTIME_STUBS(CopyDataProperties)1206 DEF_RUNTIME_STUBS(CopyDataProperties)
1207 {
1208     RUNTIME_STUBS_HEADER(CopyDataProperties);
1209     JSHandle<JSTaggedValue> dst = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1210     JSHandle<JSTaggedValue> src = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1211     return RuntimeCopyDataProperties(thread, dst, src).GetRawData();
1212 }
1213 
DEF_RUNTIME_STUBS(StArraySpread)1214 DEF_RUNTIME_STUBS(StArraySpread)
1215 {
1216     RUNTIME_STUBS_HEADER(StArraySpread);
1217     JSHandle<JSTaggedValue> dst = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1218     JSTaggedValue index = GetArg(argv, argc, 1);  // 1: means the first parameter
1219     JSHandle<JSTaggedValue> src = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1220     return RuntimeStArraySpread(thread, dst, index, src).GetRawData();
1221 }
1222 
DEF_RUNTIME_STUBS(GetIteratorNext)1223 DEF_RUNTIME_STUBS(GetIteratorNext)
1224 {
1225     RUNTIME_STUBS_HEADER(GetIteratorNext);
1226     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1227     JSHandle<JSTaggedValue> method = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1228     return RuntimeGetIteratorNext(thread, obj, method).GetRawData();
1229 }
1230 
DEF_RUNTIME_STUBS(SetObjectWithProto)1231 DEF_RUNTIME_STUBS(SetObjectWithProto)
1232 {
1233     RUNTIME_STUBS_HEADER(SetObjectWithProto);
1234     JSHandle<JSTaggedValue> proto = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1235     JSHandle<JSObject> obj = GetHArg<JSObject>(argv, argc, 1);  // 1: means the first parameter
1236     return RuntimeSetObjectWithProto(thread, proto, obj).GetRawData();
1237 }
1238 
DEF_RUNTIME_STUBS(LoadICByValue)1239 DEF_RUNTIME_STUBS(LoadICByValue)
1240 {
1241     RUNTIME_STUBS_HEADER(LoadICByValue);
1242     JSHandle<JSTaggedValue> profileTypeInfo = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1243     JSHandle<JSTaggedValue> receiver = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1244     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1245     JSTaggedValue slotId = GetArg(argv, argc, 3);  // 3: means the third parameter
1246 
1247     JSTaggedValue::RequireObjectCoercible(thread, receiver, "Cannot load property of null or undefined");
1248     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
1249 
1250     if (profileTypeInfo->IsUndefined()) {
1251         return RuntimeLdObjByValue(thread, receiver, key, false, JSTaggedValue::Undefined()).GetRawData();
1252     }
1253     JSHandle<JSTaggedValue> propKey = JSTaggedValue::ToPropertyKey(thread, key);
1254     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
1255     LoadICRuntime icRuntime(thread, JSHandle<ProfileTypeInfo>::Cast(profileTypeInfo), slotId.GetInt(), ICKind::LoadIC);
1256     return icRuntime.LoadValueMiss(receiver, propKey).GetRawData();
1257 }
1258 
DEF_RUNTIME_STUBS(StoreICByValue)1259 DEF_RUNTIME_STUBS(StoreICByValue)
1260 {
1261     RUNTIME_STUBS_HEADER(StoreICByValue);
1262     JSHandle<JSTaggedValue> profileTypeInfo = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1263     JSHandle<JSTaggedValue> receiver = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1264     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1265     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 3);  // 3: means the third parameter
1266     JSTaggedValue slotId = GetArg(argv, argc, 4);   // 4: means the fourth parameter
1267 
1268     if (profileTypeInfo->IsUndefined()) {
1269         return RuntimeStObjByValue(thread, receiver, key, value).GetRawData();
1270     }
1271     JSHandle<JSTaggedValue> propKey = JSTaggedValue::ToPropertyKey(thread, key);
1272     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
1273     StoreICRuntime icRuntime(thread, JSHandle<ProfileTypeInfo>::Cast(profileTypeInfo), slotId.GetInt(),
1274                              ICKind::StoreIC);
1275     return icRuntime.StoreMiss(receiver, propKey, value).GetRawData();
1276 }
1277 
DEF_RUNTIME_STUBS(StoreOwnICByValue)1278 DEF_RUNTIME_STUBS(StoreOwnICByValue)
1279 {
1280     RUNTIME_STUBS_HEADER(StoreOwnICByValue);
1281     JSHandle<JSTaggedValue> profileTypeInfo = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1282     JSHandle<JSTaggedValue> receiver = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1283     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1284     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 3);  // 3: means the third parameter
1285     JSTaggedValue slotId = GetArg(argv, argc, 4);   // 4: means the fourth parameter
1286     if (profileTypeInfo->IsUndefined()) {
1287         return RuntimeStOwnByIndex(thread, receiver, key, value).GetRawData();
1288     }
1289     JSHandle<JSTaggedValue> propKey = JSTaggedValue::ToPropertyKey(thread, key);
1290     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
1291     StoreICRuntime icRuntime(thread, JSHandle<ProfileTypeInfo>::Cast(profileTypeInfo), slotId.GetInt(),
1292                              ICKind::StoreIC);
1293     return icRuntime.StoreMiss(receiver, propKey, value, true).GetRawData();
1294 }
1295 
DEF_RUNTIME_STUBS(StOwnByValue)1296 DEF_RUNTIME_STUBS(StOwnByValue)
1297 {
1298     RUNTIME_STUBS_HEADER(StOwnByValue);
1299     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1300     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1301     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1302 
1303     return RuntimeStOwnByValue(thread, obj, key, value).GetRawData();
1304 }
1305 
DEF_RUNTIME_STUBS(LdSuperByValue)1306 DEF_RUNTIME_STUBS(LdSuperByValue)
1307 {
1308     RUNTIME_STUBS_HEADER(LdSuperByValue);
1309     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1310     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1311     auto sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1312     JSTaggedValue thisFunc = InterpreterAssembly::GetFunction(sp);
1313     return RuntimeLdSuperByValue(thread, obj, key, thisFunc).GetRawData();
1314 }
1315 
DEF_RUNTIME_STUBS(OptLdSuperByValue)1316 DEF_RUNTIME_STUBS(OptLdSuperByValue)
1317 {
1318     RUNTIME_STUBS_HEADER(OptLdSuperByValue);
1319     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1320     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1321     JSTaggedValue thisFunc = GetArg(argv, argc, 2);  // 2: means the second parameter
1322     return RuntimeLdSuperByValue(thread, obj, key, thisFunc).GetRawData();
1323 }
1324 
DEF_RUNTIME_STUBS(StSuperByValue)1325 DEF_RUNTIME_STUBS(StSuperByValue)
1326 {
1327     RUNTIME_STUBS_HEADER(StSuperByValue);
1328     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1329     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1330     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1331     auto sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1332     JSTaggedValue thisFunc = InterpreterAssembly::GetFunction(sp);
1333     return RuntimeStSuperByValue(thread, obj, key, value, thisFunc).GetRawData();
1334 }
1335 
DEF_RUNTIME_STUBS(OptStSuperByValue)1336 DEF_RUNTIME_STUBS(OptStSuperByValue)
1337 {
1338     RUNTIME_STUBS_HEADER(OptStSuperByValue);
1339     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1340     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1341     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1342     JSTaggedValue thisFunc = GetArg(argv, argc, 3);  // 3: means the third parameter
1343     return RuntimeStSuperByValue(thread, obj, key, value, thisFunc).GetRawData();
1344 }
1345 
DEF_RUNTIME_STUBS(GetMethodFromCache)1346 DEF_RUNTIME_STUBS(GetMethodFromCache)
1347 {
1348     RUNTIME_STUBS_HEADER(GetMethodFromCache);
1349     JSHandle<JSTaggedValue> constpool = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1350     JSTaggedValue index = GetArg(argv, argc, 1);  // 1: means the first parameter
1351     return ConstantPool::GetMethodFromCache(
1352         thread, constpool.GetTaggedValue(), index.GetInt()).GetRawData();
1353 }
1354 
DEF_RUNTIME_STUBS(GetStringFromCache)1355 DEF_RUNTIME_STUBS(GetStringFromCache)
1356 {
1357     RUNTIME_STUBS_HEADER(GetStringFromCache);
1358     JSHandle<JSTaggedValue> constpool = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1359     JSTaggedValue index = GetArg(argv, argc, 1);  // 1: means the first parameter
1360     return ConstantPool::GetStringFromCache(
1361         thread, constpool.GetTaggedValue(), index.GetInt()).GetRawData();
1362 }
1363 
DEF_RUNTIME_STUBS(GetObjectLiteralFromCache)1364 DEF_RUNTIME_STUBS(GetObjectLiteralFromCache)
1365 {
1366     RUNTIME_STUBS_HEADER(GetObjectLiteralFromCache);
1367     JSHandle<JSTaggedValue> constpool = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1368     JSTaggedValue index = GetArg(argv, argc, 1);  // 1: means the first parameter
1369     JSHandle<JSTaggedValue> module = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1370     JSTaggedValue cp = thread->GetEcmaVM()->FindOrCreateUnsharedConstpool(constpool.GetTaggedValue());
1371     return ConstantPool::GetLiteralFromCache<ConstPoolType::OBJECT_LITERAL>(
1372         thread, cp, index.GetInt(), module.GetTaggedValue()).GetRawData();
1373 }
1374 
DEF_RUNTIME_STUBS(GetArrayLiteralFromCache)1375 DEF_RUNTIME_STUBS(GetArrayLiteralFromCache)
1376 {
1377     RUNTIME_STUBS_HEADER(GetArrayLiteralFromCache);
1378     JSHandle<JSTaggedValue> constpool = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1379     JSTaggedValue index = GetArg(argv, argc, 1);  // 1: means the first parameter
1380     JSHandle<JSTaggedValue> module = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1381     JSTaggedValue cp = thread->GetEcmaVM()->FindOrCreateUnsharedConstpool(constpool.GetTaggedValue());
1382     return ConstantPool::GetLiteralFromCache<ConstPoolType::ARRAY_LITERAL>(
1383         thread, cp, index.GetInt(), module.GetTaggedValue()).GetRawData();
1384 }
1385 
DEF_RUNTIME_STUBS(StObjByValue)1386 DEF_RUNTIME_STUBS(StObjByValue)
1387 {
1388     RUNTIME_STUBS_HEADER(StObjByValue);
1389     JSHandle<JSTaggedValue> receiver = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1390     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1391     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1392     return RuntimeStObjByValue(thread, receiver, key, value).GetRawData();
1393 }
1394 
DEF_RUNTIME_STUBS(LdObjByIndex)1395 DEF_RUNTIME_STUBS(LdObjByIndex)
1396 {
1397     RUNTIME_STUBS_HEADER(LdObjByIndex);
1398     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1399     JSTaggedValue idx = GetArg(argv, argc, 1);  // 1: means the first parameter
1400     JSTaggedValue callGetter = GetArg(argv, argc, 2);  // 2: means the second parameter
1401     JSTaggedValue receiver = GetArg(argv, argc, 3);  // 3: means the third parameter
1402     return RuntimeLdObjByIndex(thread, obj, idx.GetInt(), callGetter.IsTrue(), receiver).GetRawData();
1403 }
1404 
DEF_RUNTIME_STUBS(StObjByIndex)1405 DEF_RUNTIME_STUBS(StObjByIndex)
1406 {
1407     RUNTIME_STUBS_HEADER(StObjByIndex);
1408     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1409     JSTaggedValue idx = GetArg(argv, argc, 1);  // 1: means the first parameter
1410     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1411     return RuntimeStObjByIndex(thread, obj, idx.GetInt(), value).GetRawData();
1412 }
1413 
DEF_RUNTIME_STUBS(StOwnByIndex)1414 DEF_RUNTIME_STUBS(StOwnByIndex)
1415 {
1416     RUNTIME_STUBS_HEADER(StOwnByIndex);
1417     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1418     JSHandle<JSTaggedValue> idx = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1419     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1420     return RuntimeStOwnByIndex(thread, obj, idx, value).GetRawData();
1421 }
1422 
DEF_RUNTIME_STUBS(StGlobalRecord)1423 DEF_RUNTIME_STUBS(StGlobalRecord)
1424 {
1425     RUNTIME_STUBS_HEADER(StGlobalRecord);
1426     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1427     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1428     JSTaggedValue isConst = GetArg(argv, argc, 2);
1429     return RuntimeStGlobalRecord(thread, prop, value, isConst.IsTrue()).GetRawData();
1430 }
1431 
DEF_RUNTIME_STUBS(Neg)1432 DEF_RUNTIME_STUBS(Neg)
1433 {
1434     RUNTIME_STUBS_HEADER(Neg);
1435     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1436     return RuntimeNeg(thread, value).GetRawData();
1437 }
1438 
DEF_RUNTIME_STUBS(Not)1439 DEF_RUNTIME_STUBS(Not)
1440 {
1441     RUNTIME_STUBS_HEADER(Not);
1442     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1443     return RuntimeNot(thread, value).GetRawData();
1444 }
1445 
DEF_RUNTIME_STUBS(Shl2)1446 DEF_RUNTIME_STUBS(Shl2)
1447 {
1448     RUNTIME_STUBS_HEADER(Shl2);
1449     JSTaggedValue left = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1450     JSTaggedValue right = GetArg(argv, argc, 1);  // 1: means the first parameter
1451 
1452     auto res = SlowRuntimeStub::Shl2(thread, left, right);
1453     return JSTaggedValue(res).GetRawData();
1454 }
1455 
DEF_RUNTIME_STUBS(Shr2)1456 DEF_RUNTIME_STUBS(Shr2)
1457 {
1458     RUNTIME_STUBS_HEADER(Shr2);
1459     JSTaggedValue left = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1460     JSTaggedValue right = GetArg(argv, argc, 1);  // 1: means the first parameter
1461 
1462     auto res = SlowRuntimeStub::Shr2(thread, left, right);
1463     return JSTaggedValue(res).GetRawData();
1464 }
1465 
DEF_RUNTIME_STUBS(Ashr2)1466 DEF_RUNTIME_STUBS(Ashr2)
1467 {
1468     RUNTIME_STUBS_HEADER(Ashr2);
1469     JSTaggedValue left = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1470     JSTaggedValue right = GetArg(argv, argc, 1);  // 1: means the first parameter
1471 
1472     auto res = SlowRuntimeStub::Ashr2(thread, left, right);
1473     return JSTaggedValue(res).GetRawData();
1474 }
1475 
DEF_RUNTIME_STUBS(And2)1476 DEF_RUNTIME_STUBS(And2)
1477 {
1478     RUNTIME_STUBS_HEADER(And2);
1479     JSTaggedValue left = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1480     JSTaggedValue right = GetArg(argv, argc, 1);  // 1: means the first parameter
1481 
1482     auto res = SlowRuntimeStub::And2(thread, left, right);
1483     return JSTaggedValue(res).GetRawData();
1484 }
1485 
DEF_RUNTIME_STUBS(Xor2)1486 DEF_RUNTIME_STUBS(Xor2)
1487 {
1488     RUNTIME_STUBS_HEADER(Xor2);
1489     JSTaggedValue left = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1490     JSTaggedValue right = GetArg(argv, argc, 1);  // 1: means the first parameter
1491 
1492     auto res = SlowRuntimeStub::Xor2(thread, left, right);
1493     return JSTaggedValue(res).GetRawData();
1494 }
1495 
DEF_RUNTIME_STUBS(Or2)1496 DEF_RUNTIME_STUBS(Or2)
1497 {
1498     RUNTIME_STUBS_HEADER(Or2);
1499     JSTaggedValue left = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1500     JSTaggedValue right = GetArg(argv, argc, 1);  // 1: means the first parameter
1501 
1502     auto res = SlowRuntimeStub::Or2(thread, left, right);
1503     return JSTaggedValue(res).GetRawData();
1504 }
1505 
DEF_RUNTIME_STUBS(CreateClassWithBuffer)1506 DEF_RUNTIME_STUBS(CreateClassWithBuffer)
1507 {
1508     RUNTIME_STUBS_HEADER(CreateClassWithBuffer);
1509     JSHandle<JSTaggedValue> base = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1510     JSHandle<JSTaggedValue> lexenv = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1511     JSHandle<JSTaggedValue> constpool = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1512     JSTaggedValue methodId = GetArg(argv, argc, 3);  // 3: means the third parameter
1513     JSTaggedValue literalId = GetArg(argv, argc, 4);  // 4: means the four parameter
1514     JSHandle<JSTaggedValue> module = GetHArg<JSTaggedValue>(argv, argc, 5);  // 5: means the fifth parameter
1515     JSHandle<JSTaggedValue> length = GetHArg<JSTaggedValue>(argv, argc, 6);  // 6: means the sixth parameter
1516 
1517     auto res = RuntimeCreateClassWithBuffer(thread, base, lexenv, constpool,
1518                                             static_cast<uint16_t>(methodId.GetInt()),
1519                                             static_cast<uint16_t>(literalId.GetInt()),
1520                                             module, length);
1521 #if ECMASCRIPT_ENABLE_IC
1522     const uint32_t INDEX_OF_SLOT_ID = 7; // 7: index of slotId in argv
1523     if (argc > INDEX_OF_SLOT_ID) {
1524         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
1525         uint16_t slotId = static_cast<uint16_t>(GetArg(argv, argc, INDEX_OF_SLOT_ID).GetInt());
1526         const uint32_t INDEX_OF_JS_FUNC = 8;  // 8: index of jsFunc in argv
1527         ASSERT(argc > INDEX_OF_JS_FUNC);
1528         JSHandle<JSFunction> jsFuncHandle = GetHArg<JSFunction>(argv, argc, INDEX_OF_JS_FUNC);
1529         JSHandle<JSFunction> resHandle(thread, res);
1530         SetProfileTypeInfoCellToFunction(thread, jsFuncHandle, resHandle, slotId);
1531         res = resHandle.GetTaggedValue();
1532     }
1533 #endif
1534     return res.GetRawData();
1535 }
1536 
DEF_RUNTIME_STUBS(CreateSharedClass)1537 DEF_RUNTIME_STUBS(CreateSharedClass)
1538 {
1539     RUNTIME_STUBS_HEADER(CreateSharedClass);
1540     JSHandle<JSTaggedValue> base = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1541     JSHandle<JSTaggedValue> constpool = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1542     JSTaggedValue methodId = GetArg(argv, argc, 2);  // 2: means the second parameter
1543     JSTaggedValue literalId = GetArg(argv, argc, 3);  // 3: means the third parameter
1544     JSTaggedValue length = GetArg(argv, argc, 4);  // 4: means the fourth parameter
1545     JSHandle<JSTaggedValue> module = GetHArg<JSTaggedValue>(argv, argc, 5);  // 5: means the fifth parameter
1546     return RuntimeCreateSharedClass(thread, base, constpool,
1547                                     static_cast<uint16_t>(methodId.GetInt()),
1548                                     static_cast<uint16_t>(literalId.GetInt()),
1549                                     static_cast<uint16_t>(length.GetInt()), module).GetRawData();
1550 }
1551 
DEF_RUNTIME_STUBS(LdSendableClass)1552 DEF_RUNTIME_STUBS(LdSendableClass)
1553 {
1554     RUNTIME_STUBS_HEADER(LdSendableClass);
1555     JSHandle<JSTaggedValue> env = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1556     uint16_t level = static_cast<uint16_t>(GetArg(argv, argc, 1).GetInt());  // 1: means the first parameter
1557     return RuntimeLdSendableClass(thread, env, level).GetRawData();
1558 }
1559 
DEF_RUNTIME_STUBS(SetClassConstructorLength)1560 DEF_RUNTIME_STUBS(SetClassConstructorLength)
1561 {
1562     RUNTIME_STUBS_HEADER(SetClassConstructorLength);
1563     JSTaggedValue ctor = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1564     JSTaggedValue length = GetArg(argv, argc, 1);  // 1: means the first parameter
1565     return RuntimeSetClassConstructorLength(thread, ctor, length).GetRawData();
1566 }
1567 
DEF_RUNTIME_STUBS(UpdateHotnessCounter)1568 DEF_RUNTIME_STUBS(UpdateHotnessCounter)
1569 {
1570     RUNTIME_STUBS_HEADER(UpdateHotnessCounter);
1571     JSHandle<JSFunction> thisFunc = GetHArg<JSFunction>(argv, argc, 0);  // 0: means the zeroth parameter
1572     thread->CheckSafepoint();
1573     JSHandle<Method> method(thread, thisFunc->GetMethod(thread));
1574     auto profileTypeInfo = thisFunc->GetProfileTypeInfo(thread);
1575     if (profileTypeInfo.IsUndefined()) {
1576         uint32_t slotSize = method->GetSlotSize();
1577         auto res = RuntimeNotifyInlineCache(thread, thisFunc, slotSize);
1578         return res.GetRawData();
1579     }
1580     return profileTypeInfo.GetRawData();
1581 }
1582 
DEF_RUNTIME_STUBS(PGODump)1583 DEF_RUNTIME_STUBS(PGODump)
1584 {
1585     RUNTIME_STUBS_HEADER(PGODump);
1586     JSHandle<JSFunction> thisFunc = GetHArg<JSFunction>(argv, argc, 0);  // 0: means the zeroth parameter
1587     thread->GetEcmaVM()->GetPGOProfiler()->PGODump(thisFunc.GetTaggedType());
1588     return JSTaggedValue::Undefined().GetRawData();
1589 }
1590 
DEF_RUNTIME_STUBS(PGOPreDump)1591 DEF_RUNTIME_STUBS(PGOPreDump)
1592 {
1593     RUNTIME_STUBS_HEADER(PGOPreDump);
1594     JSHandle<JSFunction> thisFunc = GetHArg<JSFunction>(argv, argc, 0);  // 0: means the zeroth parameter
1595     thread->GetEcmaVM()->GetPGOProfiler()->PGOPreDump(thisFunc.GetTaggedType());
1596     return JSTaggedValue::Undefined().GetRawData();
1597 }
1598 
DEF_RUNTIME_STUBS(UpdateHotnessCounterWithProf)1599 DEF_RUNTIME_STUBS(UpdateHotnessCounterWithProf)
1600 {
1601     RUNTIME_STUBS_HEADER(UpdateHotnessCounterWithProf);
1602     JSHandle<JSFunction> thisFunc = GetHArg<JSFunction>(argv, argc, 0);  // 0: means the zeroth parameter
1603     thread->CheckSafepoint();
1604     auto profileTypeInfo = thisFunc->GetProfileTypeInfo(thread);
1605     if (profileTypeInfo.IsUndefined()) {
1606         uint32_t slotSize = thisFunc->GetCallTarget(thread)->GetSlotSize();
1607         auto res = RuntimeNotifyInlineCache(thread, thisFunc, slotSize);
1608         return res.GetRawData();
1609     }
1610     return profileTypeInfo.GetRawData();
1611 }
1612 
DEF_RUNTIME_STUBS(JitCompile)1613 DEF_RUNTIME_STUBS(JitCompile)
1614 {
1615     RUNTIME_STUBS_HEADER(JitCompile);
1616     JSHandle<JSFunction> thisFunc = GetHArg<JSFunction>(argv, argc, 0);  // 0: means the zeroth parameter
1617     JSTaggedValue offset = GetArg(argv, argc, 1);  // 1: means the first parameter
1618     Jit::Compile(thread->GetEcmaVM(), thisFunc, CompilerTier::Tier::FAST, offset.GetInt(), JitCompileMode::Mode::ASYNC);
1619     return JSTaggedValue::Undefined().GetRawData();
1620 }
1621 
DEF_RUNTIME_STUBS(BaselineJitCompile)1622 DEF_RUNTIME_STUBS(BaselineJitCompile)
1623 {
1624     RUNTIME_STUBS_HEADER(BaselineJitCompile);
1625     JSHandle<JSFunction> thisFunc = GetHArg<JSFunction>(argv, argc, 0);  // 0: means the zeroth parameter
1626     Jit::Compile(thread->GetEcmaVM(), thisFunc, CompilerTier::Tier::BASELINE,
1627                  MachineCode::INVALID_OSR_OFFSET, JitCompileMode::Mode::ASYNC);
1628     return JSTaggedValue::Undefined().GetRawData();
1629 }
1630 
DEF_RUNTIME_STUBS(CountInterpExecFuncs)1631 DEF_RUNTIME_STUBS(CountInterpExecFuncs)
1632 {
1633     RUNTIME_STUBS_HEADER(CountInterpExecFuncs);
1634     JSHandle thisFunc = GetHArg<JSFunction>(argv, argc, 0); // 0: means the zeroth parameter
1635     Jit::CountInterpExecFuncs(thread, thisFunc);
1636     return JSTaggedValue::Undefined().GetRawData();
1637 }
1638 
DEF_RUNTIME_STUBS(CheckSafePoint)1639 DEF_RUNTIME_STUBS(CheckSafePoint)
1640 {
1641     auto thread = JSThread::GlueToJSThread(argGlue);
1642     thread->CheckSafepoint();
1643     return JSTaggedValue::Undefined().GetRawData();
1644 }
1645 
DEF_RUNTIME_STUBS(LoadICByName)1646 DEF_RUNTIME_STUBS(LoadICByName)
1647 {
1648     RUNTIME_STUBS_HEADER(LoadICByName);
1649     JSHandle<JSTaggedValue> profileHandle = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1650     JSHandle<JSTaggedValue> receiverHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1651     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1652     JSTaggedValue slotId = GetArg(argv, argc, 3);  // 3: means the third parameter
1653 
1654     if (profileHandle->IsUndefined()) {
1655         auto res = JSTaggedValue::GetProperty(thread, receiverHandle, keyHandle).GetValue().GetTaggedValue();
1656         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
1657         return res.GetRawData();
1658     }
1659     LoadICRuntime icRuntime(
1660         thread, JSHandle<ProfileTypeInfo>::Cast(profileHandle), slotId.GetInt(), ICKind::NamedLoadIC);
1661     return icRuntime.LoadMiss(receiverHandle, keyHandle).GetRawData();
1662 }
1663 
DEF_RUNTIME_STUBS(TryLdGlobalICByName)1664 DEF_RUNTIME_STUBS(TryLdGlobalICByName)
1665 {
1666     RUNTIME_STUBS_HEADER(TryLdGlobalICByName);
1667     JSHandle<JSTaggedValue> profileHandle = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1668     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1669     JSTaggedValue slotId = GetArg(argv, argc, 2);  // 2: means the third parameter
1670 
1671     EcmaVM *ecmaVm = thread->GetEcmaVM();
1672     JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
1673     JSHandle<JSTaggedValue> globalObj(thread, globalEnv->GetGlobalObject());
1674     if (profileHandle->IsUndefined()) {
1675         auto res = RuntimeTryLdGlobalByName(thread, globalObj, keyHandle);
1676         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
1677         return res.GetRawData();
1678     }
1679     LoadICRuntime icRuntime(
1680         thread, JSHandle<ProfileTypeInfo>::Cast(profileHandle), slotId.GetInt(), ICKind::NamedGlobalTryLoadIC);
1681     return icRuntime.LoadMiss(globalObj, keyHandle).GetRawData();
1682 }
1683 
DEF_RUNTIME_STUBS(StoreICByName)1684 DEF_RUNTIME_STUBS(StoreICByName)
1685 {
1686     RUNTIME_STUBS_HEADER(StoreICByName);
1687     JSHandle<JSTaggedValue> profileHandle = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1688     JSHandle<JSTaggedValue> receiverHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1689     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1690     JSHandle<JSTaggedValue> valueHandle = GetHArg<JSTaggedValue>(argv, argc, 3);  // 3: means the third parameter
1691     JSTaggedValue slotId = GetArg(argv, argc, 4);   // 4: means the fourth parameter
1692 
1693     if (profileHandle->IsUndefined()) {
1694         JSTaggedValue::SetProperty(thread, receiverHandle, keyHandle, valueHandle, true);
1695         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
1696         return JSTaggedValue::True().GetRawData();
1697     }
1698     StoreICRuntime icRuntime(
1699         thread, JSHandle<ProfileTypeInfo>::Cast(profileHandle), slotId.GetInt(), ICKind::NamedStoreIC);
1700     return icRuntime.StoreMiss(receiverHandle, keyHandle, valueHandle).GetRawData();
1701 }
1702 
DEF_RUNTIME_STUBS(StoreOwnICByName)1703 DEF_RUNTIME_STUBS(StoreOwnICByName)
1704 {
1705     RUNTIME_STUBS_HEADER(StoreOwnICByName);
1706     JSHandle<JSTaggedValue> profileHandle = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1707     JSHandle<JSTaggedValue> receiverHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1708     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1709     JSHandle<JSTaggedValue> valueHandle = GetHArg<JSTaggedValue>(argv, argc, 3);  // 3: means the third parameter
1710     JSTaggedValue slotId = GetArg(argv, argc, 4);   // 4: means the fourth parameter
1711 
1712     if (profileHandle->IsUndefined()) {
1713         JSTaggedValue::SetProperty(thread, receiverHandle, keyHandle, valueHandle, true);
1714         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
1715         return JSTaggedValue::True().GetRawData();
1716     }
1717     StoreICRuntime icRuntime(
1718         thread, JSHandle<ProfileTypeInfo>::Cast(profileHandle), slotId.GetInt(), ICKind::NamedStoreIC);
1719     return icRuntime.StoreMiss(receiverHandle, keyHandle, valueHandle, true, true).GetRawData();
1720 }
1721 
DEF_RUNTIME_STUBS(SetFunctionNameNoPrefix)1722 DEF_RUNTIME_STUBS(SetFunctionNameNoPrefix)
1723 {
1724     RUNTIME_STUBS_HEADER(SetFunctionNameNoPrefix);
1725     JSTaggedType argFunc = GetTArg(argv, argc, 0);  // 0: means the zeroth parameter
1726     JSTaggedValue argName = GetArg(argv, argc, 1);  // 1: means the first parameter
1727     JSFunction::SetFunctionNameNoPrefix(thread, reinterpret_cast<JSFunction *>(argFunc), argName);
1728     return JSTaggedValue::Hole().GetRawData();
1729 }
1730 
DEF_RUNTIME_STUBS(StOwnByValueWithNameSet)1731 DEF_RUNTIME_STUBS(StOwnByValueWithNameSet)
1732 {
1733     RUNTIME_STUBS_HEADER(StOwnByValueWithNameSet);
1734     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1735     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1736     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1737     return RuntimeStOwnByValueWithNameSet(thread, obj, prop, value).GetRawData();
1738 }
1739 
DEF_RUNTIME_STUBS(StOwnByName)1740 DEF_RUNTIME_STUBS(StOwnByName)
1741 {
1742     RUNTIME_STUBS_HEADER(StOwnByName);
1743     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1744     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1745     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1746     return RuntimeStOwnByName(thread, obj, prop, value).GetRawData();
1747 }
1748 
DEF_RUNTIME_STUBS(StOwnByNameWithNameSet)1749 DEF_RUNTIME_STUBS(StOwnByNameWithNameSet)
1750 {
1751     RUNTIME_STUBS_HEADER(StOwnByNameWithNameSet);
1752     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1753     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1754     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1755     return RuntimeStOwnByValueWithNameSet(thread, obj, prop, value).GetRawData();
1756 }
1757 
DEF_RUNTIME_STUBS(SuspendGenerator)1758 DEF_RUNTIME_STUBS(SuspendGenerator)
1759 {
1760     RUNTIME_STUBS_HEADER(SuspendGenerator);
1761     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1762     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1763     return RuntimeSuspendGenerator(thread, obj, value).GetRawData();
1764 }
1765 
DEF_RUNTIME_STUBS(OptSuspendGenerator)1766 DEF_RUNTIME_STUBS(OptSuspendGenerator)
1767 {
1768     RUNTIME_STUBS_HEADER(OptSuspendGenerator);
1769     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1770     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1771     return RuntimeOptSuspendGenerator(thread, obj, value).GetRawData();
1772 }
1773 
DEF_RUNTIME_STUBS(OptAsyncGeneratorResolve)1774 DEF_RUNTIME_STUBS(OptAsyncGeneratorResolve)
1775 {
1776     RUNTIME_STUBS_HEADER(OptAsyncGeneratorResolve);
1777     JSHandle<JSTaggedValue> asyncGenerator = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1778     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1779     JSTaggedValue flag = GetArg(argv, argc, 2); // 2: means the second parameter
1780     return RuntimeOptAsyncGeneratorResolve(thread, asyncGenerator, value, flag).GetRawData();
1781 }
1782 
DEF_RUNTIME_STUBS(OptCreateObjectWithExcludedKeys)1783 DEF_RUNTIME_STUBS(OptCreateObjectWithExcludedKeys)
1784 {
1785     RUNTIME_STUBS_HEADER(OptCreateObjectWithExcludedKeys);
1786     return RuntimeOptCreateObjectWithExcludedKeys(thread, argv, argc).GetRawData();
1787 }
1788 
DEF_RUNTIME_STUBS(UpFrame)1789 DEF_RUNTIME_STUBS(UpFrame)
1790 {
1791     RUNTIME_STUBS_HEADER(UpFrame);
1792     FrameHandler frameHandler(thread);
1793     uint32_t pcOffset = panda_file::INVALID_OFFSET;
1794     for (; frameHandler.HasFrame(); frameHandler.PrevJSFrame()) {
1795         if (frameHandler.IsEntryFrame() || frameHandler.IsBuiltinFrame()) {
1796             thread->SetCurrentFrame(frameHandler.GetSp());
1797             thread->SetLastFp(frameHandler.GetFp());
1798             return JSTaggedValue(static_cast<uint64_t>(0)).GetRawData();
1799         }
1800         auto method = frameHandler.GetMethod();
1801         uint32_t curBytecodePcOfst = INVALID_INDEX;
1802         if (reinterpret_cast<uintptr_t>(frameHandler.GetPc()) == std::numeric_limits<uintptr_t>::max()) {
1803             // For baselineJit
1804             uintptr_t curNativePc = frameHandler.GetBaselineNativePc();
1805             ASSERT(curNativePc != 0);
1806             LOG_BASELINEJIT(DEBUG) << "current native pc in UpFrame: " << std::hex <<
1807                 reinterpret_cast<void*>(curNativePc);
1808             JSHandle<JSTaggedValue> funcVal = JSHandle<JSTaggedValue>(thread, frameHandler.GetFunction());
1809             JSHandle<JSFunction> func = JSHandle<JSFunction>::Cast(funcVal);
1810             curBytecodePcOfst = RuntimeGetBytecodePcOfstForBaseline(thread, func, curNativePc);
1811         } else {
1812             curBytecodePcOfst = frameHandler.GetBytecodeOffset();
1813         }
1814         pcOffset = method->FindCatchBlock(thread, curBytecodePcOfst);
1815         if (pcOffset != INVALID_INDEX) {
1816             thread->SetCurrentFrame(frameHandler.GetSp());
1817             thread->SetLastFp(frameHandler.GetFp());
1818             uintptr_t pc = reinterpret_cast<uintptr_t>(method->GetBytecodeArray() + pcOffset);
1819             return JSTaggedValue(static_cast<uint64_t>(pc)).GetRawData();
1820         }
1821         if (!method->IsNativeWithCallField()) {
1822             auto *debuggerMgr = thread->GetEcmaVM()->GetJsDebuggerManager();
1823             debuggerMgr->GetNotificationManager()->MethodExitEvent(thread, method);
1824         }
1825     }
1826     LOG_FULL(FATAL) << "EXCEPTION: EntryFrame Not Found";
1827     UNREACHABLE();
1828 }
1829 
DEF_RUNTIME_STUBS(GetModuleNamespaceByIndex)1830 DEF_RUNTIME_STUBS(GetModuleNamespaceByIndex)
1831 {
1832     RUNTIME_STUBS_HEADER(GetModuleNamespaceByIndex);
1833     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1834     return RuntimeGetModuleNamespace(thread, index.GetInt()).GetRawData();
1835 }
1836 
DEF_RUNTIME_STUBS(GetModuleNamespaceByIndexOnJSFunc)1837 DEF_RUNTIME_STUBS(GetModuleNamespaceByIndexOnJSFunc)
1838 {
1839     RUNTIME_STUBS_HEADER(GetModuleNamespaceByIndexOnJSFunc);
1840     JSTaggedValue index = GetArg(argv, argc, 0);
1841     JSTaggedValue jsFunc = GetArg(argv, argc, 1);
1842     return RuntimeGetModuleNamespace(thread, index.GetInt(), jsFunc).GetRawData();
1843 }
1844 
DEF_RUNTIME_STUBS(GetModuleNamespace)1845 DEF_RUNTIME_STUBS(GetModuleNamespace)
1846 {
1847     RUNTIME_STUBS_HEADER(GetModuleNamespace);
1848     JSTaggedValue localName = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1849     return RuntimeGetModuleNamespace(thread, localName).GetRawData();
1850 }
1851 
DEF_RUNTIME_STUBS(StModuleVarByIndex)1852 DEF_RUNTIME_STUBS(StModuleVarByIndex)
1853 {
1854     RUNTIME_STUBS_HEADER(StModuleVar);
1855     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1856     JSTaggedValue value = GetArg(argv, argc, 1);  // 1: means the first parameter
1857     RuntimeStModuleVar(thread, index.GetInt(), value);
1858     return JSTaggedValue::Hole().GetRawData();
1859 }
1860 
DEF_RUNTIME_STUBS(StModuleVarByIndexOnJSFunc)1861 DEF_RUNTIME_STUBS(StModuleVarByIndexOnJSFunc)
1862 {
1863     RUNTIME_STUBS_HEADER(StModuleVarByIndexOnJSFunc);
1864     JSTaggedValue index = GetArg(argv, argc, 0);
1865     JSTaggedValue value = GetArg(argv, argc, 1);
1866     JSTaggedValue jsFunc = GetArg(argv, argc, 2);
1867     RuntimeStModuleVar(thread, index.GetInt(), value, jsFunc);
1868     return JSTaggedValue::Hole().GetRawData();
1869 }
1870 
DEF_RUNTIME_STUBS(StModuleVar)1871 DEF_RUNTIME_STUBS(StModuleVar)
1872 {
1873     RUNTIME_STUBS_HEADER(StModuleVar);
1874     JSTaggedValue key = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1875     JSTaggedValue value = GetArg(argv, argc, 1);  // 1: means the first parameter
1876     RuntimeStModuleVar(thread, key, value);
1877     return JSTaggedValue::Hole().GetRawData();
1878 }
1879 
DEF_RUNTIME_STUBS(LdLocalModuleVarByIndex)1880 DEF_RUNTIME_STUBS(LdLocalModuleVarByIndex)
1881 {
1882     RUNTIME_STUBS_HEADER(LdLocalModuleVarByIndex);
1883     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1884     return RuntimeLdLocalModuleVar(thread, index.GetInt()).GetRawData();
1885 }
1886 
DEF_RUNTIME_STUBS(LdLocalModuleVarByIndexWithModule)1887 DEF_RUNTIME_STUBS(LdLocalModuleVarByIndexWithModule)
1888 {
1889     RUNTIME_STUBS_HEADER(LdLocalModuleVarByIndexWithModule);
1890     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1891     JSHandle<JSTaggedValue> module = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1892     return RuntimeLdLocalModuleVarWithModule(thread, index.GetInt(), module).GetRawData();
1893 }
1894 
DEF_RUNTIME_STUBS(LdExternalModuleVarByIndex)1895 DEF_RUNTIME_STUBS(LdExternalModuleVarByIndex)
1896 {
1897     RUNTIME_STUBS_HEADER(LdExternalModuleVarByIndex);
1898     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1899     return RuntimeLdExternalModuleVar(thread, index.GetInt()).GetRawData();
1900 }
1901 
DEF_RUNTIME_STUBS(LdExternalModuleVarByIndexWithModule)1902 DEF_RUNTIME_STUBS(LdExternalModuleVarByIndexWithModule)
1903 {
1904     RUNTIME_STUBS_HEADER(LdExternalModuleVarByIndexWithModule);
1905     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1906     JSHandle<JSTaggedValue> module = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1907     return RuntimeLdExternalModuleVarWithModule(thread, index.GetInt(), module).GetRawData();
1908 }
1909 
DEF_RUNTIME_STUBS(LdSendableExternalModuleVarByIndex)1910 DEF_RUNTIME_STUBS(LdSendableExternalModuleVarByIndex)
1911 {
1912     RUNTIME_STUBS_HEADER(LdSendableExternalModuleVarByIndex);
1913     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1914     JSTaggedValue jsFunc = GetArg(argv, argc, 1); // 1: means the first parameter
1915     return RuntimeLdSendableExternalModuleVar(thread, index.GetInt(), jsFunc).GetRawData();
1916 }
1917 
DEF_RUNTIME_STUBS(LdSendableLocalModuleVarByIndex)1918 DEF_RUNTIME_STUBS(LdSendableLocalModuleVarByIndex)
1919 {
1920     RUNTIME_STUBS_HEADER(LdSendableLocalModuleVarByIndex);
1921     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1922     JSTaggedValue jsFunc = GetArg(argv, argc, 1); // 1: means the first parameter
1923     return RuntimeLdSendableLocalModuleVar(thread, index.GetInt(), jsFunc).GetRawData();
1924 }
1925 
DEF_RUNTIME_STUBS(LdLazyExternalModuleVarByIndex)1926 DEF_RUNTIME_STUBS(LdLazyExternalModuleVarByIndex)
1927 {
1928     RUNTIME_STUBS_HEADER(LdLazyExternalModuleVarByIndex);
1929     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1930     JSTaggedValue jsFunc = GetArg(argv, argc, 1); // 1: means the first parameter
1931     return RuntimeLdLazyExternalModuleVar(thread, index.GetInt(), jsFunc).GetRawData();
1932 }
1933 
DEF_RUNTIME_STUBS(LdLazySendableExternalModuleVarByIndex)1934 DEF_RUNTIME_STUBS(LdLazySendableExternalModuleVarByIndex)
1935 {
1936     RUNTIME_STUBS_HEADER(LdLazySendableExternalModuleVarByIndex);
1937     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1938     JSTaggedValue jsFunc = GetArg(argv, argc, 1); // 1: means the first parameter
1939     return RuntimeLdLazySendableExternalModuleVar(thread, index.GetInt(), jsFunc).GetRawData();
1940 }
1941 
DEF_RUNTIME_STUBS(LdLocalModuleVarByIndexOnJSFunc)1942 DEF_RUNTIME_STUBS(LdLocalModuleVarByIndexOnJSFunc)
1943 {
1944     RUNTIME_STUBS_HEADER(LdLocalModuleVarByIndexOnJSFunc);
1945     JSTaggedValue index = GetArg(argv, argc, 0);
1946     JSTaggedValue jsFunc = GetArg(argv, argc, 1);
1947     return RuntimeLdLocalModuleVar(thread, index.GetInt(), jsFunc).GetRawData();
1948 }
1949 
DEF_RUNTIME_STUBS(LdExternalModuleVarByIndexOnJSFunc)1950 DEF_RUNTIME_STUBS(LdExternalModuleVarByIndexOnJSFunc)
1951 {
1952     RUNTIME_STUBS_HEADER(LdExternalModuleVarByIndexOnJSFunc);
1953     JSTaggedValue index = GetArg(argv, argc, 0);
1954     JSTaggedValue jsFunc = GetArg(argv, argc, 1);
1955     return RuntimeLdExternalModuleVar(thread, index.GetInt(), jsFunc).GetRawData();
1956 }
1957 
DEF_RUNTIME_STUBS(LdModuleVar)1958 DEF_RUNTIME_STUBS(LdModuleVar)
1959 {
1960     RUNTIME_STUBS_HEADER(LdModuleVar);
1961     JSTaggedValue key = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1962     JSTaggedValue taggedFlag = GetArg(argv, argc, 1);  // 1: means the first parameter
1963     bool innerFlag = taggedFlag.GetInt() != 0;
1964     return RuntimeLdModuleVar(thread, key, innerFlag).GetRawData();
1965 }
1966 
DEF_RUNTIME_STUBS(GetModuleValueOuterInternal)1967 DEF_RUNTIME_STUBS(GetModuleValueOuterInternal)
1968 {
1969     RUNTIME_STUBS_HEADER(GetModuleValueOuterInternal);
1970     JSTaggedValue curModule = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1971     int32_t index =
1972         JSTaggedValue::ToInt32(thread, GetHArg<JSTaggedValue>(argv, argc, 1));  // 2: means the second parameter
1973     return ModuleValueAccessor::GetModuleValueOuterInternal<false>(thread, index, curModule).GetRawData();
1974 }
1975 
DEF_RUNTIME_STUBS(GetModuleName)1976 DEF_RUNTIME_STUBS(GetModuleName)
1977 {
1978     RUNTIME_STUBS_HEADER(GetModuleName);
1979     JSTaggedValue curModule = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1980     CString cjsModuleName = SourceTextModule::GetModuleName(curModule);
1981     JSHandle<JSTaggedValue> moduleNameHandle(thread->GetEcmaVM()->GetFactory()->NewFromUtf8(cjsModuleName));
1982     return moduleNameHandle.GetTaggedValue().GetRawData();
1983 }
1984 
DEF_RUNTIME_STUBS(ThrowExportsIsHole)1985 DEF_RUNTIME_STUBS(ThrowExportsIsHole)
1986 {
1987     RUNTIME_STUBS_HEADER(ThrowExportsIsHole);
1988     JSTaggedValue curModule = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1989     CString errorMsg = "Loading cjs module:" + SourceTextModule::GetModuleName(curModule) + ", failed";
1990     THROW_NEW_ERROR_WITH_MSG_AND_RETURN_VALUE(thread, ErrorType::SYNTAX_ERROR, errorMsg.c_str(),
1991                                               JSTaggedValue::Exception().GetRawData());
1992 }
1993 
DEF_RUNTIME_STUBS(NewResolvedIndexBindingRecord)1994 DEF_RUNTIME_STUBS(NewResolvedIndexBindingRecord)
1995 {
1996     RUNTIME_STUBS_HEADER(NewResolvedIndexBindingRecord);
1997     JSHandle<SourceTextModule> module = GetHArg<SourceTextModule>(argv, argc, 0); // 0: means the zeroth parameter
1998     int32_t index =
1999         JSTaggedValue::ToInt32(thread, GetHArg<JSTaggedValue>(argv, argc, 1)); // 1: means the first parameter
2000     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
2001     return JSHandle<JSTaggedValue>::Cast(factory->NewResolvedIndexBindingRecord(module, index))->GetRawData();
2002 }
2003 
DEF_RUNTIME_STUBS(HandleResolutionIsNullOrString)2004 DEF_RUNTIME_STUBS(HandleResolutionIsNullOrString)
2005 {
2006     RUNTIME_STUBS_HEADER(HandleResolutionIsNullOrString);
2007     JSHandle<SourceTextModule> module = GetHArg<SourceTextModule>(argv, argc, 0); // 0: means the zeroth parameter
2008     JSHandle<SourceTextModule> requiredModule =
2009         GetHArg<SourceTextModule>(argv, argc, 1); // 1: means the first parameter
2010     JSTaggedValue bindingName = GetArg(argv, argc, 2); // 2: means the second parameter
2011     JSHandle<JSTaggedValue> resolution = GetHArg<JSTaggedValue>(argv, argc, 3); // 3: means the third parameter
2012     CString requestMod =
2013         ModulePathHelper::ReformatPath(SourceTextModule::GetModuleName(requiredModule.GetTaggedValue()));
2014     CString recordStr = ModulePathHelper::ReformatPath(SourceTextModule::GetModuleName(module.GetTaggedValue()));
2015     CString msg = "the requested module '" + requestMod + SourceTextModule::GetResolveErrorReason(resolution) +
2016                   ModulePathHelper::Utf8ConvertToString(thread, bindingName) + "' which imported by '" + recordStr +
2017                   "'";
2018     THROW_NEW_ERROR_WITH_MSG_AND_RETURN_VALUE(
2019         thread, ErrorType::SYNTAX_ERROR, msg.c_str(), JSTaggedValue::Exception().GetRawData());
2020 }
2021 
DEF_RUNTIME_STUBS(CheckAndThrowModuleError)2022 DEF_RUNTIME_STUBS(CheckAndThrowModuleError)
2023 {
2024     RUNTIME_STUBS_HEADER(CheckAndThrowModuleError);
2025     JSHandle<SourceTextModule> module = GetHArg<SourceTextModule>(argv, argc, 0); // 0: means the zeroth parameter
2026     bool isThrow = GetArg(argv, argc, 1).ToBoolean(); // 1: means the first parameter
2027     module->CheckAndThrowModuleError(thread);
2028     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
2029     if (isThrow) {
2030         CString errorMsg = module->GetEcmaModuleRecordNameString();
2031         errorMsg = errorMsg.empty() ? module->GetEcmaModuleFilenameString() :
2032                                       errorMsg;
2033         errorMsg.append(" environment is undefined");
2034         THROW_REFERENCE_ERROR_AND_RETURN(thread, errorMsg.c_str(), JSTaggedValue::Exception().GetRawData());
2035     }
2036     return JSTaggedValue::Hole().GetRawData();
2037 }
2038 
DEF_RUNTIME_STUBS(GetResolvedRecordIndexBindingModule)2039 DEF_RUNTIME_STUBS(GetResolvedRecordIndexBindingModule)
2040 {
2041     RUNTIME_STUBS_HEADER(GetResolvedRecordIndexBindingModule);
2042     JSHandle<SourceTextModule> module = GetHArg<SourceTextModule>(argv, argc, 0); // 0: means the zeroth parameter
2043     JSHandle<ResolvedRecordIndexBinding> binding =
2044         GetHArg<ResolvedRecordIndexBinding>(argv, argc, 1); // 1: means the first parameter
2045     JSTaggedType argModuleManager = GetTArg(argv, argc, 2);  // 2: means the second parameter
2046     ModuleManager *moduleManager = reinterpret_cast<ModuleManager *>(argModuleManager);
2047     JSTaggedValue recordName = GetArg(argv, argc, 3); // 3: means the third parameter
2048     CString recordNameStr = ModulePathHelper::Utf8ConvertToString(thread, recordName);
2049     if (!moduleManager->IsEvaluatedModule(recordNameStr)) {
2050         auto isMergedAbc = !module->GetEcmaModuleRecordNameString().empty();
2051         CString fileName = ModulePathHelper::Utf8ConvertToString(thread, (binding->GetAbcFileName(thread)));
2052         if (!JSPandaFileExecutor::LazyExecuteModule(thread,
2053             recordNameStr, fileName, isMergedAbc)) { // LCOV_EXCL_BR_LINE
2054             LOG_ECMA(FATAL) << "LazyExecuteModule failed";
2055         }
2056     }
2057     return moduleManager->HostGetImportedModule(recordNameStr).GetTaggedValue().GetRawData();
2058 }
2059 
DEF_RUNTIME_STUBS(GetResolvedRecordBindingModule)2060 DEF_RUNTIME_STUBS(GetResolvedRecordBindingModule)
2061 {
2062     RUNTIME_STUBS_HEADER(GetResolvedRecordBindingModule);
2063     JSHandle<SourceTextModule> module = GetHArg<SourceTextModule>(argv, argc, 0); // 0: means the zeroth parameter
2064     JSTaggedType argModuleManager = GetTArg(argv, argc, 1);  // 1: means the first parameter
2065     ModuleManager *moduleManager = reinterpret_cast<ModuleManager *>(argModuleManager);
2066     JSTaggedValue recordName = GetArg(argv, argc, 2); // 2: means the second parameter
2067     CString recordNameStr = ModulePathHelper::Utf8ConvertToString(thread, recordName);
2068     if (!moduleManager->IsEvaluatedModule(recordNameStr)) {
2069         auto isMergedAbc = !module->GetEcmaModuleRecordNameString().empty();
2070         CString fileName = module->GetEcmaModuleFilenameString();
2071         if (!JSPandaFileExecutor::LazyExecuteModule(thread,
2072             recordNameStr, fileName, isMergedAbc)) { // LCOV_EXCL_BR_LINE
2073             LOG_ECMA(FATAL) << "LazyExecuteModule failed";
2074         }
2075     }
2076     return moduleManager->HostGetImportedModule(recordNameStr).GetTaggedValue().GetRawData();
2077 }
2078 
DEF_RUNTIME_STUBS(GetPropIteratorSlowpath)2079 DEF_RUNTIME_STUBS(GetPropIteratorSlowpath)
2080 {
2081     RUNTIME_STUBS_HEADER(GetPropIteratorSlowpath);
2082     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2083     return JSObject::LoadEnumerateProperties(thread, value).GetTaggedValue().GetRawData();
2084 }
2085 
DEF_RUNTIME_STUBS(PrimitiveStringCreate)2086 DEF_RUNTIME_STUBS(PrimitiveStringCreate)
2087 {
2088     RUNTIME_STUBS_HEADER(PrimitiveStringCreate);
2089     JSHandle<JSTaggedValue> str = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2090     JSHandle<JSTaggedValue> newTarget = thread->GlobalConstants()->GetHandledUndefined();
2091     return JSPrimitiveRef::StringCreate(thread, str, newTarget).GetTaggedValue().GetRawData();
2092 }
2093 
DEF_RUNTIME_STUBS(AsyncFunctionEnter)2094 DEF_RUNTIME_STUBS(AsyncFunctionEnter)
2095 {
2096     RUNTIME_STUBS_HEADER(AsyncFunctionEnter);
2097     return RuntimeAsyncFunctionEnter(thread).GetRawData();
2098 }
2099 
DEF_RUNTIME_STUBS(GetAsyncIterator)2100 DEF_RUNTIME_STUBS(GetAsyncIterator)
2101 {
2102     RUNTIME_STUBS_HEADER(GetAsyncIterator);
2103     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2104     return RuntimeGetAsyncIterator(thread, obj).GetRawData();
2105 }
2106 
DEF_RUNTIME_STUBS(LdPrivateProperty)2107 DEF_RUNTIME_STUBS(LdPrivateProperty)
2108 {
2109     RUNTIME_STUBS_HEADER(LdPrivateProperty);
2110     JSTaggedValue lexicalEnv = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2111     uint32_t levelIndex = static_cast<uint32_t>(GetArg(argv, argc, 1).GetInt());  // 1: means the first parameter
2112     uint32_t slotIndex = static_cast<uint32_t>(GetArg(argv, argc, 2).GetInt());  // 2: means the second parameter
2113     JSTaggedValue obj = GetArg(argv, argc, 3);  // 3: means the third parameter
2114     return RuntimeLdPrivateProperty(thread, lexicalEnv, levelIndex, slotIndex, obj).GetRawData();
2115 }
2116 
DEF_RUNTIME_STUBS(StPrivateProperty)2117 DEF_RUNTIME_STUBS(StPrivateProperty)
2118 {
2119     RUNTIME_STUBS_HEADER(StPrivateProperty);
2120     JSTaggedValue lexicalEnv = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2121     uint32_t levelIndex = static_cast<uint32_t>(GetArg(argv, argc, 1).GetInt());  // 1: means the first parameter
2122     uint32_t slotIndex = static_cast<uint32_t>(GetArg(argv, argc, 2).GetInt());  // 2: means the second parameter
2123     JSTaggedValue obj = GetArg(argv, argc, 3);  // 3: means the third parameter
2124     JSTaggedValue value = GetArg(argv, argc, 4);  // 4: means the fourth parameter
2125     return RuntimeStPrivateProperty(thread, lexicalEnv, levelIndex, slotIndex, obj, value).GetRawData();
2126 }
2127 
DEF_RUNTIME_STUBS(TestIn)2128 DEF_RUNTIME_STUBS(TestIn)
2129 {
2130     RUNTIME_STUBS_HEADER(TestIn);
2131     JSTaggedValue lexicalEnv = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2132     uint32_t levelIndex = static_cast<uint32_t>(GetArg(argv, argc, 1).GetInt());  // 1: means the first parameter
2133     uint32_t slotIndex = static_cast<uint32_t>(GetArg(argv, argc, 2).GetInt());  // 2: means the second parameter
2134     JSTaggedValue obj = GetArg(argv, argc, 3);  // 3: means the third parameter
2135     return RuntimeTestIn(thread, lexicalEnv, levelIndex, slotIndex, obj).GetRawData();
2136 }
2137 
DEF_RUNTIME_STUBS(Throw)2138 DEF_RUNTIME_STUBS(Throw)
2139 {
2140     RUNTIME_STUBS_HEADER(Throw);
2141     JSTaggedValue value = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2142     RuntimeThrow(thread, value);
2143     return JSTaggedValue::Hole().GetRawData();
2144 }
2145 
DEF_RUNTIME_STUBS(ThrowThrowNotExists)2146 DEF_RUNTIME_STUBS(ThrowThrowNotExists)
2147 {
2148     RUNTIME_STUBS_HEADER(ThrowThrowNotExists);
2149     RuntimeThrowThrowNotExists(thread);
2150     return JSTaggedValue::Hole().GetRawData();
2151 }
2152 
DEF_RUNTIME_STUBS(ThrowPatternNonCoercible)2153 DEF_RUNTIME_STUBS(ThrowPatternNonCoercible)
2154 {
2155     RUNTIME_STUBS_HEADER(ThrowPatternNonCoercible);
2156     RuntimeThrowPatternNonCoercible(thread);
2157     return JSTaggedValue::Hole().GetRawData();
2158 }
2159 
DEF_RUNTIME_STUBS(ThrowDeleteSuperProperty)2160 DEF_RUNTIME_STUBS(ThrowDeleteSuperProperty)
2161 {
2162     RUNTIME_STUBS_HEADER(ThrowDeleteSuperProperty);
2163     RuntimeThrowDeleteSuperProperty(thread);
2164     return JSTaggedValue::Hole().GetRawData();
2165 }
2166 
DEF_RUNTIME_STUBS(ThrowUndefinedIfHole)2167 DEF_RUNTIME_STUBS(ThrowUndefinedIfHole)
2168 {
2169     RUNTIME_STUBS_HEADER(ThrowUndefinedIfHole);
2170     JSHandle<EcmaString> obj = GetHArg<EcmaString>(argv, argc, 0);  // 0: means the zeroth parameter
2171     RuntimeThrowUndefinedIfHole(thread, obj);
2172     return JSTaggedValue::Hole().GetRawData();
2173 }
2174 
DEF_RUNTIME_STUBS(ThrowIfNotObject)2175 DEF_RUNTIME_STUBS(ThrowIfNotObject)
2176 {
2177     RUNTIME_STUBS_HEADER(ThrowIfNotObject);
2178     RuntimeThrowIfNotObject(thread);
2179     return JSTaggedValue::Hole().GetRawData();
2180 }
2181 
DEF_RUNTIME_STUBS(ThrowConstAssignment)2182 DEF_RUNTIME_STUBS(ThrowConstAssignment)
2183 {
2184     RUNTIME_STUBS_HEADER(ThrowConstAssignment);
2185     JSHandle<EcmaString> value = GetHArg<EcmaString>(argv, argc, 0);  // 0: means the zeroth parameter
2186     RuntimeThrowConstAssignment(thread, value);
2187     return JSTaggedValue::Hole().GetRawData();
2188 }
2189 
DEF_RUNTIME_STUBS(ThrowTypeError)2190 DEF_RUNTIME_STUBS(ThrowTypeError)
2191 {
2192     RUNTIME_STUBS_HEADER(ThrowTypeError);
2193     JSTaggedValue argMessageStringId = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2194     std::string message = MessageString::GetMessageString(argMessageStringId.GetInt());
2195     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
2196     JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR, message.c_str(), StackCheck::NO);
2197     THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error.GetTaggedValue(), JSTaggedValue::Hole().GetRawData());
2198 }
2199 
DEF_RUNTIME_STUBS(MismatchError)2200 DEF_RUNTIME_STUBS(MismatchError)
2201 {
2202     RUNTIME_STUBS_HEADER(MismatchError);
2203     JSTaggedValue shareFieldType = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2204     JSTaggedValue value = GetArg(argv, argc, 1);  // 1: means the first parameter
2205     std::stringstream oss;
2206     value.DumpTaggedValueType(oss);
2207     LOG_ECMA(ERROR) << "Sendable obj Match field type fail. expected type: " <<
2208         ClassHelper::StaticFieldTypeToString(shareFieldType.GetInt()) << ", actual type: " << oss.str();
2209     return JSTaggedValue::Undefined().GetRawData();
2210 }
2211 
DEF_RUNTIME_STUBS(ThrowRangeError)2212 DEF_RUNTIME_STUBS(ThrowRangeError)
2213 {
2214     RUNTIME_STUBS_HEADER(ThrowRangeError);
2215     JSTaggedValue argMessageStringId = GetArg(argv, argc, 0);
2216     std::string message = MessageString::GetMessageString(argMessageStringId.GetInt());
2217     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
2218     JSHandle<JSObject> error = factory->GetJSError(ErrorType::RANGE_ERROR, message.c_str(), StackCheck::NO);
2219     THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error.GetTaggedValue(), JSTaggedValue::Hole().GetRawData());
2220 }
2221 
DEF_RUNTIME_STUBS(LoadMiss)2222 DEF_RUNTIME_STUBS(LoadMiss)
2223 {
2224     RUNTIME_STUBS_HEADER(LoadMiss);
2225     JSTaggedType profileTypeInfo = GetTArg(argv, argc, 0);  // 0: means the zeroth parameter
2226     JSTaggedValue receiver = GetArg(argv, argc, 1);  // 1: means the first parameter
2227     JSTaggedValue key = GetArg(argv, argc, 2);  // 2: means the second parameter
2228     JSTaggedValue slotId = GetArg(argv, argc, 3);  // 3: means the third parameter
2229     JSTaggedValue kind = GetArg(argv, argc, 4);   // 4: means the fourth parameter
2230     return ICRuntimeStub::LoadMiss(thread, reinterpret_cast<ProfileTypeInfo *>(profileTypeInfo), receiver, key,
2231         slotId.GetInt(), static_cast<ICKind>(kind.GetInt())).GetRawData();
2232 }
2233 
DEF_RUNTIME_STUBS(StoreMiss)2234 DEF_RUNTIME_STUBS(StoreMiss)
2235 {
2236     RUNTIME_STUBS_HEADER(StoreMiss);
2237     JSTaggedType profileTypeInfo = GetTArg(argv, argc, 0);  // 0: means the zeroth parameter
2238     JSTaggedValue receiver = GetArg(argv, argc, 1);  // 1: means the first parameter
2239     JSTaggedValue key = GetArg(argv, argc, 2);  // 2: means the second parameter
2240     JSTaggedValue value = GetArg(argv, argc, 3);  // 3: means the third parameter
2241     JSTaggedValue slotId = GetArg(argv, argc, 4);  // 4: means the fourth parameter
2242     JSTaggedValue kind = GetArg(argv, argc, 5);  // 5: means the fifth parameter
2243     return ICRuntimeStub::StoreMiss(thread, reinterpret_cast<ProfileTypeInfo *>(profileTypeInfo), receiver, key, value,
2244         slotId.GetInt(), static_cast<ICKind>(kind.GetInt())).GetRawData();
2245 }
2246 
DEF_RUNTIME_STUBS(TryUpdateGlobalRecord)2247 DEF_RUNTIME_STUBS(TryUpdateGlobalRecord)
2248 {
2249     RUNTIME_STUBS_HEADER(TryUpdateGlobalRecord);
2250     JSTaggedValue prop = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2251     JSTaggedValue value = GetArg(argv, argc, 1);  // 1: means the first parameter
2252     return RuntimeTryUpdateGlobalRecord(thread, prop, value).GetRawData();
2253 }
2254 
DEF_RUNTIME_STUBS(ThrowReferenceError)2255 DEF_RUNTIME_STUBS(ThrowReferenceError)
2256 {
2257     RUNTIME_STUBS_HEADER(ThrowReferenceError);
2258     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2259     return RuntimeThrowReferenceError(thread, prop, " is not defined").GetRawData();
2260 }
2261 
DEF_RUNTIME_STUBS(LdGlobalICVar)2262 DEF_RUNTIME_STUBS(LdGlobalICVar)
2263 {
2264     RUNTIME_STUBS_HEADER(LdGlobalICVar);
2265     JSHandle<JSTaggedValue> global = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2266     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2267     JSHandle<JSTaggedValue> profileHandle = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
2268     JSTaggedValue slotId = GetArg(argv, argc, 3);  // 3: means the third parameter
2269 
2270     if (profileHandle->IsUndefined()) {
2271         return RuntimeLdGlobalVarFromProto(thread, global, prop).GetRawData();
2272     }
2273     LoadICRuntime icRuntime(
2274         thread, JSHandle<ProfileTypeInfo>::Cast(profileHandle), slotId.GetInt(), ICKind::NamedGlobalLoadIC);
2275     return icRuntime.LoadMiss(global, prop).GetRawData();
2276 }
2277 
DEF_RUNTIME_STUBS(StGlobalVar)2278 DEF_RUNTIME_STUBS(StGlobalVar)
2279 {
2280     RUNTIME_STUBS_HEADER(StGlobalVar);
2281     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2282     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2283     return RuntimeStGlobalVar(thread, prop, value).GetRawData();
2284 }
2285 
DEF_RUNTIME_STUBS(ToIndex)2286 DEF_RUNTIME_STUBS(ToIndex)
2287 {
2288     RUNTIME_STUBS_HEADER(ToIndex);
2289     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2290     return JSTaggedValue::ToIndex(thread, value).GetRawData();
2291 }
2292 
DEF_RUNTIME_STUBS(NewJSObjectByConstructor)2293 DEF_RUNTIME_STUBS(NewJSObjectByConstructor)
2294 {
2295     RUNTIME_STUBS_HEADER(NewJSObjectByConstructor);
2296     JSHandle<JSFunction> constructor = GetHArg<JSFunction>(argv, argc, 0);      // 0: means the zeroth parameter
2297     JSHandle<JSTaggedValue> newTarget = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2298     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
2299     JSHandle<JSObject> obj = factory->NewJSObjectByConstructor(constructor, newTarget);
2300     return obj.GetTaggedValue().GetRawData();
2301 }
2302 
DEF_RUNTIME_STUBS(CloneHclass)2303 DEF_RUNTIME_STUBS(CloneHclass)
2304 {
2305     RUNTIME_STUBS_HEADER(CloneHclass);
2306     JSHandle<JSHClass> objHclass = GetHArg<JSHClass>(argv, argc, 0);      // 0: means the zeroth parameter
2307     return JSHClass::Clone(thread, objHclass).GetTaggedValue().GetRawData();
2308 }
2309 
DEF_RUNTIME_STUBS(AllocateTypedArrayBuffer)2310 DEF_RUNTIME_STUBS(AllocateTypedArrayBuffer)
2311 {
2312     RUNTIME_STUBS_HEADER(AllocateTypedArrayBuffer);
2313     JSHandle<JSObject> obj = GetHArg<JSObject>(argv, argc, 0);    // 0: means the zeroth parameter
2314     JSTaggedValue length = GetArg(argv, argc, 1);  // 1: means the first parameter
2315     return base::TypedArrayHelper::AllocateTypedArrayBuffer(thread, obj, length.GetNumber(),
2316         base::TypedArrayHelper::GetType(JSHandle<JSTypedArray>(obj))).GetTaggedValue().GetRawData();
2317 }
2318 
DEF_RUNTIME_STUBS(ToNumber)2319 DEF_RUNTIME_STUBS(ToNumber)
2320 {
2321     RUNTIME_STUBS_HEADER(ToNumber);
2322     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2323     return RuntimeToNumber(thread, value).GetRawData();
2324 }
2325 
DEF_RUNTIME_STUBS(ToBoolean)2326 DEF_RUNTIME_STUBS(ToBoolean)
2327 {
2328     RUNTIME_STUBS_HEADER(ToBoolean);
2329     JSTaggedValue value = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2330     bool result = value.ToBoolean();
2331     return JSTaggedValue(result).GetRawData();
2332 }
2333 
DEF_RUNTIME_STUBS(Eq)2334 DEF_RUNTIME_STUBS(Eq)
2335 {
2336     RUNTIME_STUBS_HEADER(Eq);
2337     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2338     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2339     return RuntimeEq(thread, left, right).GetRawData();
2340 }
2341 
DEF_RUNTIME_STUBS(NotEq)2342 DEF_RUNTIME_STUBS(NotEq)
2343 {
2344     RUNTIME_STUBS_HEADER(NotEq);
2345     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2346     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2347     return RuntimeNotEq(thread, left, right).GetRawData();
2348 }
2349 
DEF_RUNTIME_STUBS(Less)2350 DEF_RUNTIME_STUBS(Less)
2351 {
2352     RUNTIME_STUBS_HEADER(Less);
2353     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2354     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2355     return RuntimeLess(thread, left, right).GetRawData();
2356 }
2357 
DEF_RUNTIME_STUBS(LessEq)2358 DEF_RUNTIME_STUBS(LessEq)
2359 {
2360     RUNTIME_STUBS_HEADER(LessEq);
2361     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2362     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2363     return RuntimeLessEq(thread, left, right).GetRawData();
2364 }
2365 
DEF_RUNTIME_STUBS(Greater)2366 DEF_RUNTIME_STUBS(Greater)
2367 {
2368     RUNTIME_STUBS_HEADER(Greater);
2369     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2370     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2371     return RuntimeGreater(thread, left, right).GetRawData();
2372 }
2373 
DEF_RUNTIME_STUBS(GreaterEq)2374 DEF_RUNTIME_STUBS(GreaterEq)
2375 {
2376     RUNTIME_STUBS_HEADER(GreaterEq);
2377     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2378     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2379     return RuntimeGreaterEq(thread, left, right).GetRawData();
2380 }
2381 
DEF_RUNTIME_STUBS(Add2)2382 DEF_RUNTIME_STUBS(Add2)
2383 {
2384     RUNTIME_STUBS_HEADER(Add2);
2385     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2386     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2387     JSTaggedValue res = RuntimeAdd2(thread, left, right);
2388     return res.GetRawData();
2389 }
2390 
DEF_RUNTIME_STUBS(Sub2)2391 DEF_RUNTIME_STUBS(Sub2)
2392 {
2393     RUNTIME_STUBS_HEADER(Sub2);
2394     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2395     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2396     return RuntimeSub2(thread, left, right).GetRawData();
2397 }
2398 
DEF_RUNTIME_STUBS(Mul2)2399 DEF_RUNTIME_STUBS(Mul2)
2400 {
2401     RUNTIME_STUBS_HEADER(Mul2);
2402     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2403     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2404     return RuntimeMul2(thread, left, right).GetRawData();
2405 }
2406 
DEF_RUNTIME_STUBS(Div2)2407 DEF_RUNTIME_STUBS(Div2)
2408 {
2409     RUNTIME_STUBS_HEADER(Div2);
2410     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2411     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2412     return RuntimeDiv2(thread, left, right).GetRawData();
2413 }
2414 
DEF_RUNTIME_STUBS(Mod2)2415 DEF_RUNTIME_STUBS(Mod2)
2416 {
2417     RUNTIME_STUBS_HEADER(Mod2);
2418     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2419     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2420     return RuntimeMod2(thread, left, right).GetRawData();
2421 }
2422 
DEF_RUNTIME_STUBS(JumpToCInterpreter)2423 DEF_RUNTIME_STUBS(JumpToCInterpreter)
2424 {
2425 #ifndef EXCLUDE_C_INTERPRETER
2426     RUNTIME_STUBS_HEADER(JumpToCInterpreter);
2427     JSTaggedValue constpool = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2428     JSTaggedValue profileTypeInfo = GetArg(argv, argc, 1);  // 1: means the first parameter
2429     JSTaggedValue acc = GetArg(argv, argc, 2);  // 2: means the second parameter
2430     JSTaggedValue hotnessCounter = GetArg(argv, argc, 3);  // 3: means the third parameter
2431 
2432     auto sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
2433     const uint8_t *currentPc = reinterpret_cast<const uint8_t*>(GET_ASM_FRAME(sp)->pc);
2434 
2435     uint8_t opcode = currentPc[0];
2436     asmDispatchTable[opcode](thread, currentPc, sp, constpool, profileTypeInfo, acc, hotnessCounter.GetInt());
2437     sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
2438     return JSTaggedValue(reinterpret_cast<uint64_t>(sp)).GetRawData();
2439 #else
2440     return JSTaggedValue::Hole().GetRawData();
2441 #endif
2442 }
2443 
DEF_RUNTIME_STUBS(NotifyBytecodePcChanged)2444 DEF_RUNTIME_STUBS(NotifyBytecodePcChanged)
2445 {
2446     RUNTIME_STUBS_HEADER(NotifyBytecodePcChanged);
2447     FrameHandler frameHandler(thread);
2448     for (; frameHandler.HasFrame(); frameHandler.PrevJSFrame()) {
2449         if (frameHandler.IsEntryFrame() || frameHandler.IsBuiltinFrame()) {
2450             continue;
2451         }
2452         Method *method = frameHandler.GetMethod();
2453         // Skip builtins method
2454         if (method->IsNativeWithCallField()) {
2455             continue;
2456         }
2457         auto bcOffset = frameHandler.GetBytecodeOffset();
2458         auto *debuggerMgr = thread->GetEcmaVM()->GetJsDebuggerManager();
2459         debuggerMgr->GetNotificationManager()->BytecodePcChangedEvent(thread, method, bcOffset);
2460         return JSTaggedValue::Hole().GetRawData();
2461     }
2462     return JSTaggedValue::Hole().GetRawData();
2463 }
2464 
DEF_RUNTIME_STUBS(NotifyDebuggerStatement)2465 DEF_RUNTIME_STUBS(NotifyDebuggerStatement)
2466 {
2467     RUNTIME_STUBS_HEADER(NotifyDebuggerStatement);
2468     return RuntimeNotifyDebuggerStatement(thread).GetRawData();
2469 }
2470 
DEF_RUNTIME_STUBS(MethodEntry)2471 DEF_RUNTIME_STUBS(MethodEntry)
2472 {
2473     RUNTIME_STUBS_HEADER(MethodEntry);
2474     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2475     if (func.GetTaggedValue().IsECMAObject()) {
2476         Method *method = ECMAObject::Cast(func.GetTaggedValue().GetTaggedObject())->GetCallTarget(thread);
2477         if (method->IsNativeWithCallField()) {
2478             return JSTaggedValue::Hole().GetRawData();
2479         }
2480         JSHandle<JSFunction> funcObj = JSHandle<JSFunction>::Cast(func);
2481         FrameHandler frameHandler(thread);
2482         for (; frameHandler.HasFrame(); frameHandler.PrevJSFrame()) {
2483             if (frameHandler.IsEntryFrame() || frameHandler.IsBuiltinFrame()) {
2484                 continue;
2485             }
2486             auto *debuggerMgr = thread->GetEcmaVM()->GetJsDebuggerManager();
2487             debuggerMgr->GetNotificationManager()->MethodEntryEvent(thread, method, funcObj->GetLexicalEnv(thread));
2488             return JSTaggedValue::Hole().GetRawData();
2489         }
2490     }
2491     return JSTaggedValue::Hole().GetRawData();
2492 }
2493 
DEF_RUNTIME_STUBS(MethodExit)2494 DEF_RUNTIME_STUBS(MethodExit)
2495 {
2496     RUNTIME_STUBS_HEADER(MethodExit);
2497     FrameHandler frameHandler(thread);
2498     for (; frameHandler.HasFrame(); frameHandler.PrevJSFrame()) {
2499         if (frameHandler.IsEntryFrame() || frameHandler.IsBuiltinFrame()) {
2500             continue;
2501         }
2502         Method *method = frameHandler.GetMethod();
2503         // Skip builtins method
2504         if (method->IsNativeWithCallField()) {
2505             continue;
2506         }
2507         auto *debuggerMgr = thread->GetEcmaVM()->GetJsDebuggerManager();
2508         debuggerMgr->GetNotificationManager()->MethodExitEvent(thread, method);
2509         return JSTaggedValue::Hole().GetRawData();
2510     }
2511     return JSTaggedValue::Hole().GetRawData();
2512 }
2513 
DEF_RUNTIME_STUBS(CreateEmptyObject)2514 DEF_RUNTIME_STUBS(CreateEmptyObject)
2515 {
2516     RUNTIME_STUBS_HEADER(CreateEmptyObject);
2517     EcmaVM *ecmaVm = thread->GetEcmaVM();
2518     ObjectFactory *factory = ecmaVm->GetFactory();
2519     JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
2520     return RuntimeCreateEmptyObject(thread, factory, globalEnv).GetRawData();
2521 }
2522 
DEF_RUNTIME_STUBS(GetUnmapedArgs)2523 DEF_RUNTIME_STUBS(GetUnmapedArgs)
2524 {
2525     RUNTIME_STUBS_HEADER(GetUnmapedArgs);
2526     auto sp = const_cast<JSTaggedType*>(thread->GetCurrentInterpretedFrame());
2527     uint32_t startIdx = 0;
2528     // 0: means restIdx
2529     uint32_t actualNumArgs = InterpreterAssembly::GetNumArgs(thread, sp, 0, startIdx);
2530     return RuntimeGetUnmapedArgs(thread, sp, actualNumArgs, startIdx).GetRawData();
2531 }
2532 
DEF_RUNTIME_STUBS(CopyRestArgs)2533 DEF_RUNTIME_STUBS(CopyRestArgs)
2534 {
2535     RUNTIME_STUBS_HEADER(CopyRestArgs);
2536     JSTaggedValue restIdx = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2537     auto sp = const_cast<JSTaggedType*>(thread->GetCurrentInterpretedFrame());
2538     uint32_t startIdx = 0;
2539     uint32_t restNumArgs = InterpreterAssembly::GetNumArgs(thread, sp, restIdx.GetInt(), startIdx);
2540     return RuntimeCopyRestArgs(thread, sp, restNumArgs, startIdx).GetRawData();
2541 }
2542 
DEF_RUNTIME_STUBS(CreateArrayWithBuffer)2543 DEF_RUNTIME_STUBS(CreateArrayWithBuffer)
2544 {
2545     RUNTIME_STUBS_HEADER(CreateArrayWithBuffer);
2546     JSHandle<JSTaggedValue> argArray = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2547     EcmaVM *ecmaVm = thread->GetEcmaVM();
2548     ObjectFactory *factory = ecmaVm->GetFactory();
2549     return RuntimeCreateArrayWithBuffer(thread, factory, argArray).GetRawData();
2550 }
2551 
DEF_RUNTIME_STUBS(CreateObjectWithBuffer)2552 DEF_RUNTIME_STUBS(CreateObjectWithBuffer)
2553 {
2554     RUNTIME_STUBS_HEADER(CreateObjectWithBuffer);
2555     JSHandle<JSObject> argObj = GetHArg<JSObject>(argv, argc, 0);  // 0: means the zeroth parameter
2556     EcmaVM *ecmaVm = thread->GetEcmaVM();
2557     ObjectFactory *factory = ecmaVm->GetFactory();
2558     return RuntimeCreateObjectWithBuffer(thread, factory, argObj).GetRawData();
2559 }
2560 
DEF_RUNTIME_STUBS(NewThisObject)2561 DEF_RUNTIME_STUBS(NewThisObject)
2562 {
2563     RUNTIME_STUBS_HEADER(NewThisObject);
2564     JSHandle<JSFunction> ctor(GetHArg<JSTaggedValue>(argv, argc, 0));  // 0: means the zeroth parameter
2565     JSHandle<JSTaggedValue> newTarget(GetHArg<JSTaggedValue>(argv, argc, 1));  // 1: means the first parameter
2566 
2567     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
2568     JSHandle<JSObject> obj;
2569     if (newTarget->IsUndefined()) {
2570         obj = factory->NewJSObjectByConstructor(ctor);
2571     } else {
2572         obj = factory->NewJSObjectByConstructor(ctor, newTarget);
2573     }
2574     if (obj.GetTaggedValue().IsJSShared()) {
2575         obj->GetJSHClass()->SetExtensible(false);
2576     }
2577     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
2578     return obj.GetTaggedType();  // state is not set here
2579 }
2580 
DEF_RUNTIME_STUBS(NewObjRange)2581 DEF_RUNTIME_STUBS(NewObjRange)
2582 {
2583     RUNTIME_STUBS_HEADER(NewObjRange);
2584     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2585     JSHandle<JSTaggedValue> newTarget = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2586     JSTaggedValue firstArgIdx = GetArg(argv, argc, 2);  // 2: means the second parameter
2587     JSTaggedValue length = GetArg(argv, argc, 3);  // 3: means the third parameter
2588     return RuntimeNewObjRange(thread, func, newTarget, static_cast<uint16_t>(firstArgIdx.GetInt()),
2589         static_cast<uint16_t>(length.GetInt())).GetRawData();
2590 }
2591 
DEF_RUNTIME_STUBS(DefineFunc)2592 DEF_RUNTIME_STUBS(DefineFunc)
2593 {
2594     RUNTIME_STUBS_HEADER(DefineFunc);
2595     JSHandle<JSTaggedValue> constpool = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2596     JSTaggedValue methodId = GetArg(argv, argc, 1);  // 1: means the first parameter
2597     JSHandle<JSTaggedValue> module = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
2598     uint16_t length = static_cast<uint16_t>(GetArg(argv, argc, 3).GetInt()); // 3: means the third parameter
2599     JSHandle<JSTaggedValue> env = GetHArg<JSTaggedValue>(argv, argc, 4); // 4: means the fourth parameter
2600     JSHandle<JSTaggedValue> homeObject = GetHArg<JSTaggedValue>(argv, argc, 5); // 5: means the fifth parameter
2601     return RuntimeDefinefunc(thread, constpool, static_cast<uint16_t>(methodId.GetInt()), module,
2602         length, env, homeObject).GetRawData();
2603 }
2604 
DEF_RUNTIME_STUBS(CreateRegExpWithLiteral)2605 DEF_RUNTIME_STUBS(CreateRegExpWithLiteral)
2606 {
2607     RUNTIME_STUBS_HEADER(CreateRegExpWithLiteral);
2608     JSHandle<JSTaggedValue> pattern = GetHArg<JSTaggedValue>(argv, argc, 0);
2609     JSTaggedValue flags = GetArg(argv, argc, 1);
2610     return RuntimeCreateRegExpWithLiteral(thread, pattern, static_cast<uint8_t>(flags.GetInt())).GetRawData();
2611 }
2612 
DEF_RUNTIME_STUBS(ThrowIfSuperNotCorrectCall)2613 DEF_RUNTIME_STUBS(ThrowIfSuperNotCorrectCall)
2614 {
2615     RUNTIME_STUBS_HEADER(ThrowIfSuperNotCorrectCall);
2616     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2617     JSTaggedValue thisValue = GetArg(argv, argc, 1);  // 1: means the first parameter
2618     return RuntimeThrowIfSuperNotCorrectCall(thread, static_cast<uint16_t>(index.GetInt()), thisValue).GetRawData();
2619 }
2620 
DEF_RUNTIME_STUBS(CreateObjectHavingMethod)2621 DEF_RUNTIME_STUBS(CreateObjectHavingMethod)
2622 {
2623     RUNTIME_STUBS_HEADER(CreateObjectHavingMethod);
2624     JSHandle<JSObject> literal = GetHArg<JSObject>(argv, argc, 0);  // 0: means the zeroth parameter
2625     JSHandle<JSTaggedValue> env = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2626     EcmaVM *ecmaVm = thread->GetEcmaVM();
2627     ObjectFactory *factory = ecmaVm->GetFactory();
2628     return RuntimeCreateObjectHavingMethod(thread, factory, literal, env).GetRawData();
2629 }
2630 
DEF_RUNTIME_STUBS(CreateObjectWithExcludedKeys)2631 DEF_RUNTIME_STUBS(CreateObjectWithExcludedKeys)
2632 {
2633     RUNTIME_STUBS_HEADER(CreateObjectWithExcludedKeys);
2634     JSTaggedValue numKeys = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2635     JSHandle<JSTaggedValue> objVal = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2636     JSTaggedValue firstArgRegIdx = GetArg(argv, argc, 2);  // 2: means the second parameter
2637     return RuntimeCreateObjectWithExcludedKeys(thread, static_cast<uint16_t>(numKeys.GetInt()), objVal,
2638         static_cast<uint16_t>(firstArgRegIdx.GetInt())).GetRawData();
2639 }
2640 
DEF_RUNTIME_STUBS(DefineMethod)2641 DEF_RUNTIME_STUBS(DefineMethod)
2642 {
2643     RUNTIME_STUBS_HEADER(DefineMethod);
2644     JSHandle<Method> method = GetHArg<Method>(argv, argc, 0);  // 0: means the zeroth parameter
2645     JSHandle<JSTaggedValue> homeObject = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2646     uint16_t length = static_cast<uint16_t>(GetArg(argv, argc, 2).GetInt()); // 2: means the second parameter
2647     JSHandle<JSTaggedValue> env = GetHArg<JSTaggedValue>(argv, argc, 3); // 3: means the third parameter
2648     JSHandle<JSTaggedValue> module = GetHArg<JSTaggedValue>(argv, argc, 4); // 4: means the fourth parameter
2649     auto res = RuntimeDefineMethod(thread, method, homeObject, length, env, module);
2650 #if ECMASCRIPT_ENABLE_IC
2651     const uint32_t INDEX_OF_SLOT_ID = 5; // 5: index of slotId in argv
2652     if (argc > INDEX_OF_SLOT_ID) {
2653         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
2654         uint16_t slotId = static_cast<uint16_t>(GetArg(argv, argc, INDEX_OF_SLOT_ID).GetInt());
2655         const uint32_t INDEX_OF_JS_FUNC = 6;  // 6: index of jsFunc in argv
2656         ASSERT(argc > INDEX_OF_JS_FUNC);
2657         JSHandle<JSFunction> jsFuncHandle = GetHArg<JSFunction>(argv, argc, INDEX_OF_JS_FUNC);
2658         JSHandle<JSFunction> resHandle(thread, res);
2659         SetProfileTypeInfoCellToFunction(thread, jsFuncHandle, resHandle, slotId);
2660         res = resHandle.GetTaggedValue();
2661     }
2662 #endif
2663     return res.GetRawData();
2664 }
2665 
DEF_RUNTIME_STUBS(SetPatchModule)2666 DEF_RUNTIME_STUBS(SetPatchModule)
2667 {
2668     RUNTIME_STUBS_HEADER(SetPatchModule);
2669     JSHandle<JSFunction> func = GetHArg<JSFunction>(argv, argc, 0);  // 0: means the zeroth parameter
2670     RuntimeSetPatchModule(thread, func);
2671     return JSTaggedValue::Hole().GetRawData();
2672 }
2673 
DEF_RUNTIME_STUBS(CallSpread)2674 DEF_RUNTIME_STUBS(CallSpread)
2675 {
2676     RUNTIME_STUBS_HEADER(CallSpread);
2677     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2678     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2679     JSHandle<JSTaggedValue> array = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
2680     return RuntimeCallSpread(thread, func, obj, array).GetRawData();
2681 }
2682 
DEF_RUNTIME_STUBS(DefineGetterSetterByValue)2683 DEF_RUNTIME_STUBS(DefineGetterSetterByValue)
2684 {
2685     RUNTIME_STUBS_HEADER(DefineGetterSetterByValue);
2686     JSHandle<JSObject> obj = GetHArg<JSObject>(argv, argc, 0);  // 0: means the zeroth parameter
2687     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2688     JSHandle<JSTaggedValue> getter = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
2689     JSHandle<JSTaggedValue> setter = GetHArg<JSTaggedValue>(argv, argc, 3);  // 3: means the third parameter
2690     JSTaggedValue flag = GetArg(argv, argc, 4);  // 4: means the fourth parameter
2691     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 5);  // 5: means the sixth parameter
2692     int32_t pcOffset = GetArg(argv, argc, 6).GetInt();  // 6: means the seventh parameter
2693     bool bFlag = flag.ToBoolean();
2694     return RuntimeDefineGetterSetterByValue(thread, obj, prop, getter, setter, bFlag, func, pcOffset).GetRawData();
2695 }
2696 
DEF_RUNTIME_STUBS(SuperCall)2697 DEF_RUNTIME_STUBS(SuperCall)
2698 {
2699     RUNTIME_STUBS_HEADER(SuperCall);
2700     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2701     JSTaggedValue firstVRegIdx = GetArg(argv, argc, 1);  // 1: means the first parameter
2702     JSTaggedValue length = GetArg(argv, argc, 2);  // 2: means the second parameter
2703     auto sp = const_cast<JSTaggedType*>(thread->GetCurrentInterpretedFrame());
2704     JSTaggedValue newTarget = InterpreterAssembly::GetNewTarget(thread, sp);
2705     return RuntimeSuperCall(thread, func, JSHandle<JSTaggedValue>(thread, newTarget),
2706         static_cast<uint16_t>(firstVRegIdx.GetInt()),
2707         static_cast<uint16_t>(length.GetInt())).GetRawData();
2708 }
2709 
DEF_RUNTIME_STUBS(OptSuperCall)2710 DEF_RUNTIME_STUBS(OptSuperCall)
2711 {
2712     RUNTIME_STUBS_HEADER(OptSuperCall);
2713     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2714     JSHandle<JSTaggedValue> newTarget = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2715     JSHandle<TaggedArray> taggedArray(thread, GetArg(argv, argc, 2));  // 2: means the second parameter
2716     JSTaggedValue length = GetArg(argv, argc, 3);  // 3: means the third parameter
2717     return RuntimeOptSuperCall(thread, func, newTarget, taggedArray,
2718                                static_cast<uint16_t>(length.GetInt())).GetRawData();
2719 }
2720 
DEF_RUNTIME_STUBS(ThrowNotCallableException)2721 DEF_RUNTIME_STUBS(ThrowNotCallableException)
2722 {
2723     RUNTIME_STUBS_HEADER(ThrowNotCallableException);
2724     EcmaVM *ecmaVm = thread->GetEcmaVM();
2725     ObjectFactory *factory = ecmaVm->GetFactory();
2726     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0);
2727     std::string message = JSTaggedValue::ExceptionToString(thread, func);
2728     message.append(" is not callable");
2729     JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR, message.c_str(), StackCheck::NO);
2730     thread->SetException(error.GetTaggedValue());
2731     return JSTaggedValue::Exception().GetRawData();
2732 }
2733 
DEF_RUNTIME_STUBS(ThrowSetterIsUndefinedException)2734 DEF_RUNTIME_STUBS(ThrowSetterIsUndefinedException)
2735 {
2736     RUNTIME_STUBS_HEADER(ThrowSetterIsUndefinedException);
2737     EcmaVM *ecmaVm = thread->GetEcmaVM();
2738     ObjectFactory *factory = ecmaVm->GetFactory();
2739     JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR,
2740         "Cannot set property when setter is undefined", StackCheck::NO);
2741     thread->SetException(error.GetTaggedValue());
2742     return JSTaggedValue::Exception().GetRawData();
2743 }
2744 
DEF_RUNTIME_STUBS(ThrowCallConstructorException)2745 DEF_RUNTIME_STUBS(ThrowCallConstructorException)
2746 {
2747     RUNTIME_STUBS_HEADER(ThrowCallConstructorException);
2748     EcmaVM *ecmaVm = thread->GetEcmaVM();
2749     ObjectFactory *factory = ecmaVm->GetFactory();
2750     JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR,
2751                                                    "class constructor cannot called without 'new'", StackCheck::NO);
2752     thread->SetException(error.GetTaggedValue());
2753     return JSTaggedValue::Exception().GetRawData();
2754 }
2755 
DEF_RUNTIME_STUBS(ThrowNonConstructorException)2756 DEF_RUNTIME_STUBS(ThrowNonConstructorException)
2757 {
2758     RUNTIME_STUBS_HEADER(ThrowNonConstructorException);
2759     EcmaVM *ecmaVm = thread->GetEcmaVM();
2760     ObjectFactory *factory = ecmaVm->GetFactory();
2761     JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR,
2762                                                    "function is non-constructor", StackCheck::NO);
2763     thread->SetException(error.GetTaggedValue());
2764     return JSTaggedValue::Exception().GetRawData();
2765 }
2766 
DEF_RUNTIME_STUBS(ThrowStackOverflowException)2767 DEF_RUNTIME_STUBS(ThrowStackOverflowException)
2768 {
2769     RUNTIME_STUBS_HEADER(ThrowStackOverflowException);
2770     EcmaVM *ecmaVm = thread->GetEcmaVM();
2771     // Multi-thread could cause stack-overflow-check failed too,
2772     // so check thread here to distinguish it with the actual stack overflow.
2773     ecmaVm->CheckThread();
2774     LOG_ECMA(ERROR) << "Stack overflow! current:" << thread->GetCurrentStackPosition()
2775         << " limit:" << thread->GetStackLimit();
2776     ObjectFactory *factory = ecmaVm->GetFactory();
2777     JSHandle<JSObject> error = factory->GetJSError(ErrorType::RANGE_ERROR, "Stack overflow!", StackCheck::NO);
2778     if (LIKELY(!thread->HasPendingException())) {
2779         thread->SetException(error.GetTaggedValue());
2780     }
2781     return JSTaggedValue::Exception().GetRawData();
2782 }
2783 
DEF_RUNTIME_STUBS(ThrowDerivedMustReturnException)2784 DEF_RUNTIME_STUBS(ThrowDerivedMustReturnException)
2785 {
2786     RUNTIME_STUBS_HEADER(ThrowDerivedMustReturnException);
2787     EcmaVM *ecmaVm = thread->GetEcmaVM();
2788     ObjectFactory *factory = ecmaVm->GetFactory();
2789     JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR,
2790         "Derived constructor must return object or undefined", StackCheck::NO);
2791     thread->SetException(error.GetTaggedValue());
2792     return JSTaggedValue::Exception().GetRawData();
2793 }
2794 
DEF_RUNTIME_STUBS(LdBigInt)2795 DEF_RUNTIME_STUBS(LdBigInt)
2796 {
2797     RUNTIME_STUBS_HEADER(LdBigInt);
2798     JSHandle<JSTaggedValue> numberBigInt = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2799     return RuntimeLdBigInt(thread, numberBigInt).GetRawData();
2800 }
2801 
DEF_RUNTIME_STUBS(CallBigIntAsIntN)2802 DEF_RUNTIME_STUBS(CallBigIntAsIntN)
2803 {
2804     RUNTIME_STUBS_HEADER(CallBigIntAsIntN);
2805     JSTaggedValue bits = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2806     JSTaggedValue bigint = GetArg(argv, argc, 1);  // 1: means the first parameter
2807     return RuntimeCallBigIntAsIntN(thread, bits, bigint).GetRawData();
2808 }
2809 
DEF_RUNTIME_STUBS(CallBigIntAsUintN)2810 DEF_RUNTIME_STUBS(CallBigIntAsUintN)
2811 {
2812     RUNTIME_STUBS_HEADER(CallBigIntAsUintN);
2813     JSTaggedValue bits = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2814     JSTaggedValue bigint = GetArg(argv, argc, 1);  // 1: means the first parameter
2815     return RuntimeCallBigIntAsUintN(thread, bits, bigint).GetRawData();
2816 }
2817 
DEF_RUNTIME_STUBS(ToNumeric)2818 DEF_RUNTIME_STUBS(ToNumeric)
2819 {
2820     RUNTIME_STUBS_HEADER(ToNumeric);
2821     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2822     return RuntimeToNumeric(thread, value).GetRawData();
2823 }
2824 
DEF_RUNTIME_STUBS(ToNumericConvertBigInt)2825 DEF_RUNTIME_STUBS(ToNumericConvertBigInt)
2826 {
2827     RUNTIME_STUBS_HEADER(ToNumericConvertBigInt);
2828     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2829     JSHandle<JSTaggedValue> numericVal(thread, RuntimeToNumeric(thread, value));
2830     if (numericVal->IsBigInt()) {
2831         JSHandle<BigInt> bigNumericVal(numericVal);
2832         return BigInt::BigIntToNumber(bigNumericVal).GetRawData();
2833     }
2834     return numericVal->GetRawData();
2835 }
2836 
DEF_RUNTIME_STUBS(DynamicImport)2837 DEF_RUNTIME_STUBS(DynamicImport)
2838 {
2839     RUNTIME_STUBS_HEADER(DynamicImport);
2840     JSHandle<JSTaggedValue> specifier = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2841     JSHandle<JSTaggedValue> currentFunc = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the zeroth parameter
2842     return RuntimeDynamicImport(thread, specifier, currentFunc).GetRawData();
2843 }
2844 
DEF_RUNTIME_STUBS(NewLexicalEnvWithName)2845 DEF_RUNTIME_STUBS(NewLexicalEnvWithName)
2846 {
2847     RUNTIME_STUBS_HEADER(NewLexicalEnvWithName);
2848     JSTaggedValue numVars = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2849     JSTaggedValue scopeId = GetArg(argv, argc, 1);  // 1: means the first parameter
2850     return RuntimeNewLexicalEnvWithName(thread,
2851         static_cast<uint16_t>(numVars.GetInt()),
2852         static_cast<uint16_t>(scopeId.GetInt())).GetRawData();
2853 }
2854 
DEF_RUNTIME_STUBS(NewSendableEnv)2855 DEF_RUNTIME_STUBS(NewSendableEnv)
2856 {
2857     RUNTIME_STUBS_HEADER(NewSendableEnv);
2858     JSTaggedValue numVars = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2859     return RuntimeNewSendableEnv(thread, static_cast<uint16_t>(numVars.GetInt())).GetRawData();
2860 }
2861 
DEF_RUNTIME_STUBS(OptGetUnmapedArgs)2862 DEF_RUNTIME_STUBS(OptGetUnmapedArgs)
2863 {
2864     RUNTIME_STUBS_HEADER(OptGetUnmapedArgs);
2865     JSTaggedValue actualNumArgs = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2866     return RuntimeOptGetUnmapedArgs(thread, actualNumArgs.GetInt()).GetRawData();
2867 }
2868 
DEF_RUNTIME_STUBS(OptNewLexicalEnvWithName)2869 DEF_RUNTIME_STUBS(OptNewLexicalEnvWithName)
2870 {
2871     RUNTIME_STUBS_HEADER(OptNewLexicalEnvWithName);
2872     JSTaggedValue taggedNumVars = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2873     JSTaggedValue taggedScopeId = GetArg(argv, argc, 1);  // 1: means the first parameter
2874     JSHandle<JSTaggedValue> currentEnv = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
2875     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 3);  // 3: means the third parameter
2876     uint16_t numVars = static_cast<uint16_t>(taggedNumVars.GetInt());
2877     uint16_t scopeId = static_cast<uint16_t>(taggedScopeId.GetInt());
2878     return RuntimeOptNewLexicalEnvWithName(thread, numVars, scopeId, currentEnv, func).GetRawData();
2879 }
2880 
DEF_RUNTIME_STUBS(OptCopyRestArgs)2881 DEF_RUNTIME_STUBS(OptCopyRestArgs)
2882 {
2883     RUNTIME_STUBS_HEADER(OptCopyRestArgs);
2884     JSTaggedValue actualArgc = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2885     JSTaggedValue restIndex = GetArg(argv, argc, 1);  // 1: means the first parameter
2886     return RuntimeOptCopyRestArgs(thread, actualArgc.GetInt(), restIndex.GetInt()).GetRawData();
2887 }
2888 
DEF_RUNTIME_STUBS(OptNewObjRange)2889 DEF_RUNTIME_STUBS(OptNewObjRange)
2890 {
2891     RUNTIME_STUBS_HEADER(OptNewObjRange);
2892     return RuntimeOptNewObjRange(thread, argv, argc).GetRawData();
2893 }
2894 
DEF_RUNTIME_STUBS(GetTypeArrayPropertyByIndex)2895 DEF_RUNTIME_STUBS(GetTypeArrayPropertyByIndex)
2896 {
2897     RUNTIME_STUBS_HEADER(GetTypeArrayPropertyByIndex);
2898     JSTaggedValue obj = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2899     JSTaggedValue idx = GetArg(argv, argc, 1);  // 1: means the first parameter
2900     JSTaggedValue jsType = GetArg(argv, argc, 2); // 2: means the second parameter
2901     return JSTypedArray::FastGetPropertyByIndex(thread, obj, idx.GetInt(), JSType(jsType.GetInt())).GetRawData();
2902 }
2903 
DEF_RUNTIME_STUBS(SetTypeArrayPropertyByIndex)2904 DEF_RUNTIME_STUBS(SetTypeArrayPropertyByIndex)
2905 {
2906     RUNTIME_STUBS_HEADER(SetTypeArrayPropertyByIndex);
2907     JSTaggedValue obj = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
2908     JSTaggedValue idx = GetArg(argv, argc, 1);  // 1: means the first parameter
2909     JSTaggedValue value = GetArg(argv, argc, 2);  // 2: means the second parameter
2910     JSTaggedValue jsType = GetArg(argv, argc, 3); // 3: means the third parameter
2911     return JSTypedArray::FastSetPropertyByIndex(thread, obj, idx.GetInt(), value, JSType(jsType.GetInt())).GetRawData();
2912 }
2913 
DEF_RUNTIME_STUBS(FastCopyElementToArray)2914 DEF_RUNTIME_STUBS(FastCopyElementToArray)
2915 {
2916     RUNTIME_STUBS_HEADER(FastCopyElementToArray);
2917     JSHandle<JSTaggedValue> typedArray = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2918     JSHandle<TaggedArray> array = GetHArg<TaggedArray>(argv, argc, 1);  // 1: means the first parameter
2919     return JSTaggedValue(JSTypedArray::FastCopyElementToArray(thread, typedArray, array)).GetRawData();
2920 }
2921 
DEF_RUNTIME_STUBS(GetPropertyByName)2922 DEF_RUNTIME_STUBS(GetPropertyByName)
2923 {
2924     RUNTIME_STUBS_HEADER(GetPropertyByName);
2925     JSHandle<JSTaggedValue> target = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
2926     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
2927     return JSTaggedValue::GetProperty(thread, target, key).GetValue()->GetRawData();
2928 }
2929 
DEF_RUNTIME_STUBS(DebugAOTPrint)2930 DEF_RUNTIME_STUBS(DebugAOTPrint)
2931 {
2932     RUNTIME_STUBS_HEADER(DebugAOTPrint);
2933     int ecmaOpcode = GetArg(argv, argc, 0).GetInt();
2934     int path = GetArg(argv, argc, 1).GetInt();
2935     std::string pathStr = path == 0 ? "slow path  " : "TYPED path ";
2936 
2937     std::string data = JsStackInfo::BuildJsStackTrace(thread, true);
2938     std::string opcode = kungfu::GetEcmaOpcodeStr(static_cast<EcmaOpcode>(ecmaOpcode));
2939     LOG_ECMA(INFO) << "AOT " << pathStr << ": " << opcode << "@ " << data;
2940     return JSTaggedValue::Undefined().GetRawData();
2941 }
2942 
DEF_RUNTIME_STUBS(ProfileOptimizedCode)2943 DEF_RUNTIME_STUBS(ProfileOptimizedCode)
2944 {
2945     RUNTIME_STUBS_HEADER(ProfileOptimizedCode);
2946     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0);
2947     int bcIndex = GetArg(argv, argc, 1).GetInt();
2948     EcmaOpcode ecmaOpcode = static_cast<EcmaOpcode>(GetArg(argv, argc, 2).GetInt());
2949     OptCodeProfiler::Mode mode = static_cast<OptCodeProfiler::Mode>(GetArg(argv, argc, 3).GetInt());
2950     OptCodeProfiler* profiler = thread->GetEcmaVM()->GetOptCodeProfiler();
2951     profiler->Update(thread, func, bcIndex, ecmaOpcode, mode);
2952     return JSTaggedValue::Undefined().GetRawData();
2953 }
2954 
DEF_RUNTIME_STUBS(ProfileTypedOp)2955 DEF_RUNTIME_STUBS(ProfileTypedOp)
2956 {
2957     RUNTIME_STUBS_HEADER(ProfileOptimizedCode);
2958     kungfu::OpCode opcode = static_cast<kungfu::OpCode>(GetArg(argv, argc, 0).GetInt());
2959     TypedOpProfiler* profiler = thread->GetEcmaVM()->GetTypedOpProfiler();
2960     if (profiler != nullptr) {
2961         profiler->Update(opcode);
2962     }
2963     return JSTaggedValue::Undefined().GetRawData();
2964 }
2965 
DEF_RUNTIME_STUBS(VerifyVTableLoading)2966 DEF_RUNTIME_STUBS(VerifyVTableLoading)
2967 {
2968     RUNTIME_STUBS_HEADER(VerifyVTableLoading);
2969     JSHandle<JSTaggedValue> receiver = GetHArg<JSTaggedValue>(argv, argc, 0);        // 0: means the zeroth parameter
2970     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1);             // 1: means the first parameter
2971     JSHandle<JSTaggedValue> typedPathValue = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
2972 
2973     JSHandle<JSTaggedValue> verifiedPathValue = JSTaggedValue::GetProperty(thread, receiver, key).GetValue();
2974     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
2975     if (UNLIKELY(!JSTaggedValue::SameValue(thread, typedPathValue, verifiedPathValue))) {
2976         std::ostringstream oss;
2977         receiver->Dump(thread, oss);
2978         LOG_ECMA(ERROR) << "Verify VTable Load Failed, receiver: " << oss.str();
2979         oss.str("");
2980 
2981         LOG_ECMA(ERROR) << "Verify VTable Load Failed, key: "
2982                         << EcmaStringAccessor(key.GetTaggedValue()).ToStdString(thread);
2983 
2984         typedPathValue->Dump(thread, oss);
2985         LOG_ECMA(ERROR) << "Verify VTable Load Failed, typed path value: " << oss.str();
2986         oss.str("");
2987 
2988         verifiedPathValue->Dump(thread, oss);
2989         LOG_ECMA(ERROR) << "Verify VTable Load Failed, verified path value: " << oss.str();
2990     }
2991     return JSTaggedValue::Undefined().GetRawData();
2992 }
2993 
DEF_RUNTIME_STUBS(VerifyVTableStoring)2994 DEF_RUNTIME_STUBS(VerifyVTableStoring)
2995 {
2996     RUNTIME_STUBS_HEADER(VerifyVTableStoring);
2997     JSHandle<JSTaggedValue> receiver = GetHArg<JSTaggedValue>(argv, argc, 0);    // 0: means the zeroth parameter
2998     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1);         // 1: means the first parameter
2999     JSHandle<JSTaggedValue> storeValue = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
3000 
3001     JSHandle<JSTaggedValue> verifiedValue = JSTaggedValue::GetProperty(thread, receiver, key).GetValue();
3002     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
3003     if (UNLIKELY(!JSTaggedValue::SameValue(thread, storeValue, verifiedValue))) {
3004         std::ostringstream oss;
3005         receiver->Dump(thread, oss);
3006         LOG_ECMA(ERROR) << "Verify VTable Store Failed, receiver: " << oss.str();
3007         oss.str("");
3008 
3009         LOG_ECMA(ERROR) << "Verify VTable Store Failed, key: "
3010                         << EcmaStringAccessor(key.GetTaggedValue()).ToStdString(thread);
3011 
3012         storeValue->Dump(thread, oss);
3013         LOG_ECMA(ERROR) << "Verify VTable Store Failed, typed path store value: " << oss.str();
3014         oss.str("");
3015 
3016         verifiedValue->Dump(thread, oss);
3017         LOG_ECMA(ERROR) << "Verify VTable Store Failed, verified path load value: " << oss.str();
3018     }
3019     return JSTaggedValue::Undefined().GetRawData();
3020 }
3021 
DEF_RUNTIME_STUBS(JSObjectGetMethod)3022 DEF_RUNTIME_STUBS(JSObjectGetMethod)
3023 {
3024     RUNTIME_STUBS_HEADER(JSObjectGetMethod);
3025     JSHandle<JSTaggedValue> obj(thread, GetArg(argv, argc, 0));
3026     JSHandle<JSTaggedValue> key(thread, GetArg(argv, argc, 1));
3027     JSHandle<JSTaggedValue> result = JSObject::GetMethod(thread, obj, key);
3028     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
3029     return result->GetRawData();
3030 }
3031 
DEF_RUNTIME_STUBS(BigIntEqual)3032 DEF_RUNTIME_STUBS(BigIntEqual)
3033 {
3034     RUNTIME_STUBS_HEADER(BigIntEqual);
3035     JSTaggedValue left = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
3036     JSTaggedValue right = GetArg(argv, argc, 1);  // 1: means the first parameter
3037     if (BigInt::Equal(left, right)) {
3038         return JSTaggedValue::VALUE_TRUE;
3039     }
3040     return JSTaggedValue::VALUE_FALSE;
3041 }
3042 
DEF_RUNTIME_STUBS(StringEqual)3043 DEF_RUNTIME_STUBS(StringEqual)
3044 {
3045     RUNTIME_STUBS_HEADER(StringEqual);
3046     JSHandle<EcmaString> left = GetHArg<EcmaString>(argv, argc, 0);
3047     JSHandle<EcmaString> right = GetHArg<EcmaString>(argv, argc, 1);
3048     EcmaVM *vm = thread->GetEcmaVM();
3049     left = JSHandle<EcmaString>(thread, EcmaStringAccessor::Flatten(vm, left));
3050     right = JSHandle<EcmaString>(thread, EcmaStringAccessor::Flatten(vm, right));
3051     if (EcmaStringAccessor::StringsAreEqualDiffUtfEncoding(thread, *left, *right)) {
3052         return JSTaggedValue::VALUE_TRUE;
3053     }
3054     return JSTaggedValue::VALUE_FALSE;
3055 }
3056 
DEF_RUNTIME_STUBS(StringIndexOf)3057 DEF_RUNTIME_STUBS(StringIndexOf)
3058 {
3059     RUNTIME_STUBS_HEADER(StringIndexOf);
3060     JSHandle<JSTaggedValue> receiver = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
3061     JSHandle<JSTaggedValue> searchElement = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
3062     uint32_t from = static_cast<uint32_t>(GetArg(argv, argc, 2).GetInt());  // 2: means the second parameter
3063     uint32_t len = static_cast<uint32_t>(GetArg(argv, argc, 3).GetInt());  // 3: means the third parameter
3064 
3065     return JSStableArray::IndexOf(thread, receiver, searchElement, from, len).GetRawData();
3066 }
3067 
DEF_RUNTIME_STUBS(LdPatchVar)3068 DEF_RUNTIME_STUBS(LdPatchVar)
3069 {
3070     RUNTIME_STUBS_HEADER(LdPatchVar);
3071     JSTaggedValue idx = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
3072     return RuntimeLdPatchVar(thread, idx.GetInt()).GetRawData();
3073 }
3074 
DEF_RUNTIME_STUBS(StPatchVar)3075 DEF_RUNTIME_STUBS(StPatchVar)
3076 {
3077     RUNTIME_STUBS_HEADER(StPatchVar);
3078     JSTaggedValue idx = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
3079     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
3080     return RuntimeStPatchVar(thread, idx.GetInt(), value).GetRawData();
3081 }
3082 
DEF_RUNTIME_STUBS(NotifyConcurrentResult)3083 DEF_RUNTIME_STUBS(NotifyConcurrentResult)
3084 {
3085     RUNTIME_STUBS_HEADER(NotifyConcurrentResult);
3086     JSTaggedValue result = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
3087     JSTaggedValue hint = GetArg(argv, argc, 1);  // 1: means the first parameter
3088     return RuntimeNotifyConcurrentResult(thread, result, hint).GetRawData();
3089 }
3090 
DEF_RUNTIME_STUBS(NotifyArrayPrototypeChanged)3091 DEF_RUNTIME_STUBS(NotifyArrayPrototypeChanged)
3092 {
3093     RUNTIME_STUBS_HEADER(NotifyArrayPrototypeChanged);
3094     thread->GetEcmaVM()->GetGlobalEnv()->NotifyDetectorDeoptimize(
3095         thread, GlobalEnv::ArrayPrototypeChangedGuardiansBits::START_BIT);
3096     return JSTaggedValue::Undefined().GetRawData();
3097 }
3098 
DEF_RUNTIME_STUBS(UpdateAOTHClass)3099 DEF_RUNTIME_STUBS(UpdateAOTHClass)
3100 {
3101     RUNTIME_STUBS_HEADER(UpdateAOTHClass);
3102     JSHandle<JSHClass> oldhclass = GetHArg<JSHClass>(argv, argc, 0);  // 0: means the zeroth parameter
3103     JSHandle<JSHClass> newhclass = GetHArg<JSHClass>(argv, argc, 1);  // 1: means the first parameter
3104     JSTaggedValue key = GetArg(argv, argc, 2);  // 2: means the second parameter
3105     return RuntimeUpdateAOTHClass(thread, oldhclass, newhclass, key).GetRawData();
3106 }
3107 
DEF_RUNTIME_STUBS(DefineField)3108 DEF_RUNTIME_STUBS(DefineField)
3109 {
3110     RUNTIME_STUBS_HEADER(DefineField);
3111     JSTaggedValue obj = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
3112     JSTaggedValue propKey = GetArg(argv, argc, 1);  // 1: means the first parameter
3113     JSTaggedValue value = GetArg(argv, argc, 2);  // 2: means the second parameter
3114     return RuntimeDefineField(thread, obj, propKey, value).GetRawData();
3115 }
3116 
DEF_RUNTIME_STUBS(CreatePrivateProperty)3117 DEF_RUNTIME_STUBS(CreatePrivateProperty)
3118 {
3119     RUNTIME_STUBS_HEADER(CreatePrivateProperty);
3120     JSTaggedValue lexicalEnv = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
3121     uint32_t count = static_cast<uint32_t>(GetArg(argv, argc, 1).GetInt());  // 1: means the first parameter
3122     JSTaggedValue constpool = GetArg(argv, argc, 2);  // 2: means the second parameter
3123     uint32_t literalId = static_cast<uint32_t>(GetArg(argv, argc, 3).GetInt());  // 3: means the third parameter
3124     JSTaggedValue module = GetArg(argv, argc, 4);  // 4: means the fourth parameter
3125     return RuntimeCreatePrivateProperty(thread, lexicalEnv, count, constpool, literalId, module).GetRawData();
3126 }
3127 
DEF_RUNTIME_STUBS(DefinePrivateProperty)3128 DEF_RUNTIME_STUBS(DefinePrivateProperty)
3129 {
3130     RUNTIME_STUBS_HEADER(DefinePrivateProperty);
3131     JSTaggedValue lexicalEnv = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
3132     uint32_t levelIndex = static_cast<uint32_t>(GetArg(argv, argc, 1).GetInt());  // 1: means the first parameter
3133     uint32_t slotIndex = static_cast<uint32_t>(GetArg(argv, argc, 2).GetInt());  // 2: means the second parameter
3134     JSTaggedValue obj = GetArg(argv, argc, 3);  // 3: means the third parameter
3135     JSTaggedValue value = GetArg(argv, argc, 4);  // 4: means the fourth parameter
3136     return RuntimeDefinePrivateProperty(thread, lexicalEnv, levelIndex, slotIndex, obj, value).GetRawData();
3137 }
3138 
DEF_RUNTIME_STUBS(ContainerRBTreeForEach)3139 DEF_RUNTIME_STUBS(ContainerRBTreeForEach)
3140 {
3141     RUNTIME_STUBS_HEADER(ContainerRBTreeForEach);
3142     JSHandle<JSTaggedValue> node = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: param index
3143     JSHandle<JSTaggedValue> callbackFnHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: param index
3144     JSHandle<JSTaggedValue> thisArgHandle = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: param index
3145     JSHandle<JSTaggedValue> thisHandle = GetHArg<JSTaggedValue>(argv, argc, 3);  // 3: param index
3146     JSHandle<JSTaggedValue> type = GetHArg<JSTaggedValue>(argv, argc, 4);  // 4: param index
3147 
3148     ASSERT(node->IsRBTreeNode());
3149     ASSERT(callbackFnHandle->IsCallable());
3150     ASSERT(type->IsInt());
3151     JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
3152     auto containersType = static_cast<kungfu::ContainersType>(type->GetInt());
3153     JSMutableHandle<TaggedQueue> queue(thread, thread->GetEcmaVM()->GetFactory()->NewTaggedQueue(0));
3154     JSMutableHandle<RBTreeNode> treeNode(thread, JSTaggedValue::Undefined());
3155     queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, node)));
3156     while (!queue->Empty(thread)) {
3157         treeNode.Update(queue->Pop(thread));
3158         EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle,
3159                                                                         undefined, 3); // 3: three args
3160         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
3161         info->SetCallArg(containersType == kungfu::ContainersType::HASHSET_FOREACH ? treeNode->GetKey(thread)
3162                                                                                    : treeNode->GetValue(thread),
3163                          treeNode->GetKey(thread), thisHandle.GetTaggedValue());
3164         JSTaggedValue funcResult = JSFunction::Call(info);
3165         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult.GetRawData());
3166         if (!treeNode->GetLeft(thread).IsHole()) {
3167             JSHandle<JSTaggedValue> left(thread, treeNode->GetLeft(thread));
3168             queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, left)));
3169         }
3170         if (!treeNode->GetRight(thread).IsHole()) {
3171             JSHandle<JSTaggedValue> right(thread, treeNode->GetRight(thread));
3172             queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, right)));
3173         }
3174     }
3175     return JSTaggedValue::True().GetRawData();
3176 }
3177 
3178 
DEF_RUNTIME_STUBS(GetOrInternStringFromHashTrieTable)3179 DEF_RUNTIME_STUBS(GetOrInternStringFromHashTrieTable)
3180 {
3181     RUNTIME_STUBS_HEADER(GetOrInternStringFromHashTrieTable);
3182     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
3183     ASSERT(value->IsString());
3184     JSHandle<EcmaString> str = JSTaggedValue::ToString(thread, value);
3185     EcmaStringTable *stringTable = thread->GetEcmaVM()->GetEcmaStringTable();
3186     return JSTaggedValue::Cast(static_cast<void *>(stringTable->GetOrInternString(thread->GetEcmaVM(), *str)));
3187 }
3188 
DEF_RUNTIME_STUBS(InsertStringToTable)3189 DEF_RUNTIME_STUBS(InsertStringToTable)
3190 {
3191 #if !ENABLE_NEXT_OPTIMIZATION
3192     RUNTIME_STUBS_HEADER(InsertStringToTable);
3193     JSHandle<EcmaString> str = GetHArg<EcmaString>(argv, argc, 0);  // 0: means the zeroth parameter
3194     return JSTaggedValue::Cast(
3195         static_cast<void *>(thread->GetEcmaVM()->GetEcmaStringTable()->InsertStringToTable(thread->GetEcmaVM(), str)));
3196 #else
3197     return JSTaggedType();
3198 #endif
3199 }
3200 
DEF_RUNTIME_STUBS(SlowFlattenString)3201 DEF_RUNTIME_STUBS(SlowFlattenString)
3202 {
3203     RUNTIME_STUBS_HEADER(SlowFlattenString);
3204     JSHandle<EcmaString> str = GetHArg<EcmaString>(argv, argc, 0);  // 0: means the zeroth parameter
3205     return JSTaggedValue(EcmaStringAccessor::SlowFlatten(thread->GetEcmaVM(), str)).GetRawData();
3206 }
3207 
DEF_RUNTIME_STUBS(TryGetInternString)3208 DEF_RUNTIME_STUBS(TryGetInternString)
3209 {
3210     RUNTIME_STUBS_HEADER(TryGetInternString);
3211     JSHandle<EcmaString> string = GetHArg<EcmaString>(argv, argc, 0);  // 0: means the zeroth parameter
3212     return RuntimeTryGetInternString(argGlue, string);
3213 }
3214 
DEF_RUNTIME_STUBS(FastCopyFromArrayToTypedArray)3215 DEF_RUNTIME_STUBS(FastCopyFromArrayToTypedArray)
3216 {
3217     RUNTIME_STUBS_HEADER(FastCopyFromArrayToTypedArray);
3218     JSHandle<JSTypedArray> targetArray = GetHArg<JSTypedArray>(argv, argc, 0);  // 0: means the zeroth parameter
3219     JSTaggedValue len = GetArg(argv, argc, 1);  // 1: param index
3220     JSHandle<JSObject> obj = GetHArg<JSObject>(argv, argc, 2);  // 2: param index
3221     return JSStableArray::FastCopyFromArrayToTypedArray(thread, targetArray,
3222         base::TypedArrayHelper::GetType(targetArray), 0, len.GetInt(), obj).GetRawData();
3223 }
3224 
DEF_RUNTIME_STUBS(DecodeURIComponent)3225 DEF_RUNTIME_STUBS(DecodeURIComponent)
3226 {
3227     RUNTIME_STUBS_HEADER(DecodeURIComponent);
3228     JSHandle<JSTaggedValue> arg = GetHArg<JSTaggedValue>(argv, argc, 0);
3229     JSHandle<EcmaString> string = JSTaggedValue::ToString(thread, arg);
3230     if (thread->HasPendingException()) {
3231         return JSTaggedValue::VALUE_EXCEPTION;
3232     }
3233     if (EcmaStringAccessor(string).IsTreeString()) {
3234         string = JSHandle<EcmaString>(thread, EcmaStringAccessor::Flatten(thread->GetEcmaVM(), string));
3235     }
3236     auto stringAcc = EcmaStringAccessor(string);
3237     JSTaggedValue result;
3238     if (stringAcc.IsLineString()) {
3239         // line string or flatten tree string
3240         if (!stringAcc.IsUtf16()) {
3241             result = RuntimeDecodeURIComponent<uint8_t>(thread, string, stringAcc.GetDataUtf8());
3242         } else {
3243             result = RuntimeDecodeURIComponent<uint16_t>(thread, string, stringAcc.GetDataUtf16());
3244         }
3245     } else {
3246         ASSERT(stringAcc.IsSlicedString());
3247         auto parent = SlicedEcmaString::Cast(string.GetTaggedValue())->GetParent(thread);
3248         auto parentStrAcc = EcmaStringAccessor(parent);
3249         auto startIndex = SlicedEcmaString::Cast(string.GetTaggedValue())->GetStartIndex();
3250 #if !ENABLE_NEXT_OPTIMIZATION
3251         if (parentStrAcc.IsLineString()) {
3252             if (parentStrAcc.IsUtf8()) {
3253                 result = RuntimeDecodeURIComponent<uint8_t>(thread, string,
3254                                                             parentStrAcc.GetDataUtf8() + startIndex);
3255             } else {
3256                 result = RuntimeDecodeURIComponent<uint16_t>(thread, string,
3257                                                              parentStrAcc.GetDataUtf16() + startIndex);
3258             }
3259 #else // ENABLE_NEXT_OPTIMIZATION
3260         if (parentStrAcc.IsLineString() && !parentStrAcc.IsUtf8()) {
3261             result = RuntimeDecodeURIComponent<uint16_t>(thread, string, parentStrAcc.GetDataUtf16() + startIndex);
3262 #endif // ENABLE_NEXT_OPTIMIZATION
3263         } else {
3264             result = RuntimeDecodeURIComponent<uint8_t>(thread, string, parentStrAcc.GetDataUtf8() + startIndex);
3265         }
3266     }
3267     return result.GetRawData();
3268 }
3269 
3270 void RuntimeStubs::UpdateFieldType(uintptr_t argGlue, JSTaggedType hclass, uint64_t value)
3271 {
3272     auto cls = reinterpret_cast<JSHClass *>(hclass);
3273     PropertyAttributes attrValue(value);
3274     JSHClass::UpdateFieldType(JSThread::GlueToJSThread(argGlue), cls, attrValue);
3275 }
3276 
3277 JSTaggedType RuntimeStubs::GetActualArgvNoGC(uintptr_t argGlue)
3278 {
3279     DISALLOW_GARBAGE_COLLECTION;
3280     auto thread = JSThread::GlueToJSThread(argGlue);
3281     JSTaggedType *current = const_cast<JSTaggedType *>(thread->GetLastLeaveFrame());
3282     FrameIterator it(current, thread);
3283     ASSERT(it.IsOptimizedFrame());
3284     it.Advance<GCVisitedFlag::VISITED>();
3285     ASSERT(it.IsAotOrJitFunctionFrame());
3286     if (it.IsFastJitFunctionFrame()) {
3287         auto fastJitFunctionFrame = it.GetFrame<FASTJITFunctionFrame>();
3288         return reinterpret_cast<uintptr_t>(fastJitFunctionFrame->GetArgv(it));
3289     } else {
3290         auto optimizedJSFunctionFrame = it.GetFrame<OptimizedJSFunctionFrame>();
3291         return reinterpret_cast<uintptr_t>(optimizedJSFunctionFrame->GetArgv(it));
3292     }
3293 }
3294 
3295 double RuntimeStubs::FloatMod(double x, double y)
3296 {
3297     return std::fmod(x, y);
3298 }
3299 
3300 double RuntimeStubs::FloatAcos(double x)
3301 {
3302     return std::acos(x);
3303 }
3304 
3305 double RuntimeStubs::FloatAcosh(double x)
3306 {
3307     return std::acosh(x);
3308 }
3309 
3310 double RuntimeStubs::FloatAsin(double x)
3311 {
3312     return std::asin(x);
3313 }
3314 
3315 double RuntimeStubs::FloatAsinh(double x)
3316 {
3317     return std::asinh(x);
3318 }
3319 
3320 double RuntimeStubs::FloatAtan(double x)
3321 {
3322     return std::atan(x);
3323 }
3324 
3325 double RuntimeStubs::FloatAtan2(double y, double x)
3326 {
3327     return std::atan2(y, x);
3328 }
3329 
3330 double RuntimeStubs::FloatAtanh(double x)
3331 {
3332     return std::atanh(x);
3333 }
3334 
3335 double RuntimeStubs::FloatCos(double x)
3336 {
3337     return std::cos(x);
3338 }
3339 
3340 double RuntimeStubs::FloatCosh(double x)
3341 {
3342     return std::cosh(x);
3343 }
3344 
3345 double RuntimeStubs::FloatSin(double x)
3346 {
3347     return std::sin(x);
3348 }
3349 
3350 double RuntimeStubs::FloatSinh(double x)
3351 {
3352     return std::sinh(x);
3353 }
3354 
3355 double RuntimeStubs::FloatTan(double x)
3356 {
3357     return std::tan(x);
3358 }
3359 
3360 double RuntimeStubs::FloatTanh(double x)
3361 {
3362     return std::tanh(x);
3363 }
3364 
3365 double RuntimeStubs::FloatCbrt(double x)
3366 {
3367     return std::cbrt(x);
3368 }
3369 
3370 double RuntimeStubs::FloatTrunc(double x)
3371 {
3372     return std::trunc(x);
3373 }
3374 
3375 double RuntimeStubs::FloatCeil(double x)
3376 {
3377     return std::ceil(x);
3378 }
3379 
3380 double RuntimeStubs::FloatFloor(double x)
3381 {
3382     return std::floor(x);
3383 }
3384 
3385 double RuntimeStubs::FloatLog(double x)
3386 {
3387     return std::log(x);
3388 }
3389 
3390 double RuntimeStubs::FloatLog2(double x)
3391 {
3392     return std::log2(x);
3393 }
3394 
3395 double RuntimeStubs::FloatLog10(double x)
3396 {
3397     return std::log10(x);
3398 }
3399 
3400 double RuntimeStubs::FloatLog1p(double x)
3401 {
3402     return std::log1p(x);
3403 }
3404 
3405 double RuntimeStubs::FloatExp(double x)
3406 {
3407     return std::exp(x);
3408 }
3409 
3410 double RuntimeStubs::FloatExpm1(double x)
3411 {
3412     return std::expm1(x);
3413 }
3414 
3415 double RuntimeStubs::FloatPow(double base, double exp)
3416 {
3417     return std::pow(base, exp);
3418 }
3419 
3420 double RuntimeStubs::CallDateNow()
3421 {
3422     // time from now is in ms.
3423     int64_t ans;
3424     struct timeval tv {
3425     };
3426     gettimeofday(&tv, nullptr);
3427     ans = static_cast<int64_t>(tv.tv_sec) * MS_PER_SECOND + (tv.tv_usec / MS_PER_SECOND);
3428     return static_cast<double>(ans);
3429 }
3430 
3431 int32_t RuntimeStubs::DoubleToInt(double x, size_t bits)
3432 {
3433     return base::NumberHelper::DoubleToInt(x, bits);
3434 }
3435 
3436 int32_t RuntimeStubs::SaturateTruncDoubleToInt32(double x)
3437 {
3438     return base::NumberHelper::SaturateTruncDoubleToInt32(x);
3439 }
3440 
3441 uint8_t RuntimeStubs::LrInt(double x)
3442 {
3443     DISALLOW_GARBAGE_COLLECTION;
3444     return static_cast<uint8_t>(std::lrint(x));
3445 }
3446 
3447 void RuntimeStubs::InsertOldToNewRSet([[maybe_unused]] uintptr_t argGlue,
3448     uintptr_t object, size_t offset)
3449 {
3450     Region *region = Region::ObjectAddressToRange(object);
3451     uintptr_t slotAddr = object + offset;
3452     return region->InsertOldToNewRSet(slotAddr);
3453 }
3454 
3455 void RuntimeStubs::InsertLocalToShareRSet([[maybe_unused]] uintptr_t argGlue,
3456     uintptr_t object, size_t offset)
3457 {
3458     Region *region = Region::ObjectAddressToRange(object);
3459     uintptr_t slotAddr = object + offset;
3460     region->InsertLocalToShareRSet(slotAddr);
3461 }
3462 
3463 void RuntimeStubs::SetBitAtomic(GCBitset::GCBitsetWord *word, GCBitset::GCBitsetWord mask,
3464                                 GCBitset::GCBitsetWord oldValue)
3465 {
3466     volatile auto atomicWord = reinterpret_cast<volatile std::atomic<GCBitset::GCBitsetWord> *>(word);
3467     GCBitset::GCBitsetWord oldValueBeforeCAS = oldValue;
3468     std::atomic_compare_exchange_strong_explicit(atomicWord, &oldValue, oldValue | mask,
3469         std::memory_order_release, std::memory_order_relaxed);
3470     while (oldValue != oldValueBeforeCAS) {
3471         if (oldValue & mask) {
3472             return;
3473         }
3474         oldValueBeforeCAS = oldValue;
3475         std::atomic_compare_exchange_strong_explicit(atomicWord, &oldValue, oldValue | mask,
3476             std::memory_order_release, std::memory_order_relaxed);
3477     }
3478 }
3479 
3480 void RuntimeStubs::MarkingBarrier([[maybe_unused]] uintptr_t argGlue,
3481     uintptr_t object, size_t offset, TaggedObject *value)
3482 {
3483     uintptr_t slotAddr = object + offset;
3484     Region *objectRegion = Region::ObjectAddressToRange(object);
3485     Region *valueRegion = Region::ObjectAddressToRange(value);
3486     ASSERT(!valueRegion->InSharedHeap());
3487     auto thread = JSThread::GlueToJSThread(argGlue);
3488 #if ECMASCRIPT_ENABLE_BARRIER_CHECK
3489     if (!thread->GetEcmaVM()->GetHeap()->IsAlive(JSTaggedValue(value).GetHeapObject())) {
3490         LOG_FULL(FATAL) << "RuntimeStubs::MarkingBarrier checked value:" << value << " is invalid!";
3491     }
3492 #endif
3493     ASSERT(thread->IsConcurrentMarkingOrFinished());
3494     if (!g_isEnableCMCGC) {
3495         Barriers::Update(thread, slotAddr, objectRegion, value, valueRegion);
3496     }
3497 }
3498 
3499 void RuntimeStubs::SharedGCMarkingBarrier(uintptr_t argGlue, uintptr_t object, size_t offset, TaggedObject *value)
3500 {
3501     uintptr_t slotAddr = object + offset;
3502     Region *objectRegion = Region::ObjectAddressToRange(object);
3503     Region *valueRegion = Region::ObjectAddressToRange(value);
3504     ASSERT(valueRegion->InSharedSweepableSpace());
3505     auto thread = JSThread::GlueToJSThread(argGlue);
3506 #if ECMASCRIPT_ENABLE_BARRIER_CHECK
3507     if (!thread->GetEcmaVM()->GetHeap()->IsAlive(JSTaggedValue(value).GetHeapObject())) {
3508         LOG_FULL(FATAL) << "RuntimeStubs::SharedGCMarkingBarrier checked value:" << value << " is invalid!";
3509     }
3510 #endif
3511     ASSERT(thread->IsSharedConcurrentMarkingOrFinished());
3512     if (!g_isEnableCMCGC) {
3513         Barriers::UpdateShared(thread, slotAddr, objectRegion, value, valueRegion);
3514     }
3515 }
3516 
3517 void RuntimeStubs::CMCGCMarkingBarrier([[maybe_unused]] uintptr_t argGlue,
3518                                        [[maybe_unused]] uintptr_t object,
3519                                        [[maybe_unused]] size_t offset,
3520                                        [[maybe_unused]] TaggedObject *value)
3521 {
3522     auto thread = JSThread::GlueToJSThread(argGlue);
3523     ASSERT(g_isEnableCMCGC);
3524     Barriers::CMCWriteBarrier(thread, (TaggedObject*)object, offset, JSTaggedType(value));
3525 }
3526 
3527 JSTaggedType RuntimeStubs::ReadBarrier(uintptr_t argGlue, uintptr_t addr)
3528 {
3529     auto thread = JSThread::GlueToJSThread(argGlue);
3530     return Barriers::ReadBarrierForObject(thread, addr);
3531 }
3532 
3533 void RuntimeStubs::CopyCallTarget(uintptr_t argGlue, uintptr_t callTarget)
3534 {
3535     auto thread = JSThread::GlueToJSThread(argGlue);
3536     base::GCHelper::CopyCallTarget(thread, reinterpret_cast<void *>(callTarget));
3537 }
3538 
3539 void RuntimeStubs::CopyArgvArray(uintptr_t argGlue, uintptr_t argv, uint64_t argc)
3540 {
3541     auto thread = JSThread::GlueToJSThread(argGlue);
3542     base::GCHelper::CopyArgvArray(thread, reinterpret_cast<void *>(argv), argc);  // argv should be ToSpace Reference
3543 }
3544 
3545 bool RuntimeStubs::BigIntEquals(JSTaggedType left, JSTaggedType right)
3546 {
3547     DISALLOW_GARBAGE_COLLECTION;
3548     return BigInt::Equal(JSTaggedValue(left), JSTaggedValue(right));
3549 }
3550 
3551 bool RuntimeStubs::BigIntSameValueZero(JSTaggedType left, JSTaggedType right)
3552 {
3553     DISALLOW_GARBAGE_COLLECTION;
3554     return BigInt::SameValueZero(JSTaggedValue(left), JSTaggedValue(right));
3555 }
3556 
3557 JSTaggedValue RuntimeStubs::JSHClassFindProtoTransitions(uintptr_t argGlue, JSHClass *cls, JSTaggedValue key,
3558                                                          JSTaggedValue proto)
3559 {
3560     DISALLOW_GARBAGE_COLLECTION;
3561     return JSTaggedValue(cls->FindProtoTransitions(JSThread::GlueToJSThread(argGlue), key, proto));
3562 }
3563 
3564 JSTaggedValue RuntimeStubs::NumberHelperStringToDouble(uintptr_t argGlue, EcmaString *numberString)
3565 {
3566     DISALLOW_GARBAGE_COLLECTION;
3567     CVector<uint8_t> buf;
3568     JSThread *thread = JSThread::GlueToJSThread(argGlue);
3569     Span<const uint8_t> str = EcmaStringAccessor(numberString).ToUtf8Span(thread, buf);
3570     if (base::NumberHelper::IsEmptyString(str.begin(), str.end())) {
3571         return base::BuiltinsBase::GetTaggedDouble(base::NAN_VALUE);
3572     }
3573     double result = base::NumberHelper::StringToDouble(str.begin(), str.end(), 0, base::IGNORE_TRAILING);
3574     return base::BuiltinsBase::GetTaggedDouble(result);
3575 }
3576 
3577 double RuntimeStubs::TimeClip(double time)
3578 {
3579     DISALLOW_GARBAGE_COLLECTION;
3580     return JSDate::TimeClip(time);
3581 }
3582 
3583 double RuntimeStubs::SetDateValues(double year, double month, double day)
3584 {
3585     DISALLOW_GARBAGE_COLLECTION;
3586     if (std::isnan(year) || !std::isfinite(year) || std::isnan(month) || !std::isfinite(month) || std::isnan(day) ||
3587         !std::isfinite(day)) {
3588         return base::NAN_VALUE;
3589     }
3590 
3591     return JSDate::SetDateValues(static_cast<int64_t>(year), static_cast<int64_t>(month), static_cast<int64_t>(day));
3592 }
3593 
3594 JSTaggedValue RuntimeStubs::NewObject(EcmaRuntimeCallInfo *info)
3595 {
3596     ASSERT(info);
3597     JSThread *thread = info->GetThread();
3598     JSHandle<JSTaggedValue> func(info->GetFunction());
3599     if (!func->IsHeapObject()) {
3600         RETURN_STACK_BEFORE_THROW_IF_ASM(thread);
3601         THROW_TYPE_ERROR_AND_RETURN(thread, "function is nullptr", JSTaggedValue::Exception());
3602     }
3603 
3604     if (!func->IsJSFunction()) {
3605         if (func->IsBoundFunction()) {
3606             JSTaggedValue result = JSBoundFunction::ConstructInternal(info);
3607             RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
3608             return result;
3609         }
3610 
3611         if (func->IsJSProxy()) {
3612             JSTaggedValue jsObj = JSProxy::ConstructInternal(info);
3613             RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
3614             return jsObj;
3615         }
3616         THROW_TYPE_ERROR_AND_RETURN(thread, "Constructed NonConstructable", JSTaggedValue::Exception());
3617     }
3618 
3619     JSTaggedValue result = JSFunction::ConstructInternal(info);
3620     RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
3621     return result;
3622 }
3623 
3624 void RuntimeStubs::SaveFrameToContext(JSThread *thread, JSHandle<GeneratorContext> context)
3625 {
3626     FrameHandler frameHandler(thread);
3627     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
3628     uint32_t nregs = frameHandler.GetNumberArgs();
3629     JSHandle<TaggedArray> regsArray = factory->NewTaggedArray(nregs);
3630     for (uint32_t i = 0; i < nregs; i++) {
3631         JSTaggedValue value = frameHandler.GetVRegValue(i);
3632         regsArray->Set(thread, i, value);
3633     }
3634     context->SetRegsArray(thread, regsArray.GetTaggedValue());
3635     JSTaggedValue function = frameHandler.GetFunction();
3636     JSFunction *func = JSFunction::Cast(function.GetTaggedObject());
3637     Method *method = func->GetCallTarget(thread);
3638     if (func->IsCompiledCode()) {
3639         bool isFastCall = func->IsCompiledFastCall();  // get this flag before clear it
3640         uintptr_t entry = isFastCall ? thread->GetRTInterface(kungfu::RuntimeStubCSigns::ID_FastCallToAsmInterBridge)
3641                                      : thread->GetRTInterface(kungfu::RuntimeStubCSigns::ID_AOTCallToAsmInterBridge);
3642         func->SetCodeEntry(entry);
3643         method->ClearAOTStatusWhenDeopt(entry);
3644         func->ClearCompiledCodeFlags();
3645     }
3646     context->SetMethod(thread, function);
3647     context->SetThis(thread, frameHandler.GetThis());
3648 
3649     uint32_t offset = 0;
3650     // pc in baseline is not real bytecode offset, so skip to get the offset
3651     if (reinterpret_cast<uint64_t>(frameHandler.GetPc()) != std::numeric_limits<uint64_t>::max()) {
3652         BytecodeInstruction ins(frameHandler.GetPc());
3653         offset = ins.GetSize();
3654     }
3655 
3656     context->SetAcc(thread, frameHandler.GetAcc());
3657     context->SetLexicalEnv(thread, thread->GetCurrentLexenv());
3658     context->SetNRegs(nregs);
3659     context->SetBCOffset(frameHandler.GetBytecodeOffset() + offset);
3660 }
3661 
3662 JSTaggedValue RuntimeStubs::CallBoundFunction(EcmaRuntimeCallInfo *info)
3663 {
3664     JSThread *thread = info->GetThread();
3665     JSHandle<JSBoundFunction> boundFunc(info->GetFunction());
3666     if (boundFunc->GetBoundTarget(thread).IsJSFunction()) {
3667         JSHandle<JSFunction> targetFunc(thread, boundFunc->GetBoundTarget(thread));
3668         if (targetFunc->IsClassConstructor()) {
3669             THROW_TYPE_ERROR_AND_RETURN(thread, "class constructor cannot called without 'new'",
3670                                         JSTaggedValue::Exception());
3671         }
3672     }
3673     JSHandle<TaggedArray> boundArgs(thread, boundFunc->GetBoundArguments(thread));
3674     const uint32_t boundLength = boundArgs->GetLength();
3675     const uint32_t argsLength = info->GetArgsNumber() + boundLength;
3676     JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
3677     EcmaRuntimeCallInfo *runtimeInfo =
3678         EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle<JSTaggedValue>(thread, boundFunc->GetBoundTarget(thread)),
3679                                             info->GetThis(), undefined, argsLength);
3680     RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
3681     if (boundLength == 0) {
3682         runtimeInfo->SetCallArg(argsLength, 0, info, 0);
3683     } else {
3684         // 0 ~ boundLength is boundArgs; boundLength ~ argsLength is args of EcmaRuntimeCallInfo.
3685         runtimeInfo->SetCallArg(boundLength, boundArgs);
3686         runtimeInfo->SetCallArg(argsLength, boundLength, info, 0);
3687     }
3688     return EcmaInterpreter::Execute(runtimeInfo);
3689 }
3690 
3691 DEF_RUNTIME_STUBS(DeoptHandler)
3692 {
3693     RUNTIME_STUBS_HEADER(DeoptHandler);
3694     kungfu::DeoptType type = static_cast<kungfu::DeoptType>(GetTArg(argv, argc, 0));
3695     JSHandle<JSTaggedValue> maybeAcc = GetHArg<JSTaggedValue>(argv, argc, 1);
3696     size_t depth = Deoptimizier::GetInlineDepth(thread);
3697     Deoptimizier deopt(thread, depth, type);
3698     std::vector<kungfu::ARKDeopt> deoptBundle;
3699     deopt.CollectDeoptBundleVec(deoptBundle);
3700     ASSERT(!deoptBundle.empty());
3701     size_t shift = Deoptimizier::ComputeShift(depth);
3702     deopt.CollectVregs(deoptBundle, shift);
3703     deopt.UpdateAndDumpDeoptInfo(type);
3704     return deopt.ConstructAsmInterpretFrame(maybeAcc);
3705 }
3706 
3707 DEF_RUNTIME_STUBS(AotInlineTrace)
3708 {
3709     RUNTIME_STUBS_HEADER(AotInlineTrace);
3710     JSTaggedValue callerFunc = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
3711     JSTaggedValue inlineFunc = GetArg(argv, argc, 1);  // 1: means the first parameter
3712     JSFunction *callerJSFunc = JSFunction::Cast(callerFunc);
3713     JSFunction *inlineJSFunc = JSFunction::Cast(inlineFunc);
3714     Method *callerMethod = Method::Cast(JSFunction::Cast(callerJSFunc)->GetMethod(thread));
3715     Method *inlineMethod = Method::Cast(JSFunction::Cast(inlineJSFunc)->GetMethod(thread));
3716     auto callerRecordName = callerMethod->GetRecordNameStr(thread);
3717     auto inlineRecordNanme = inlineMethod->GetRecordNameStr(thread);
3718     const std::string callerFuncName(callerMethod->GetMethodName(thread));
3719     const std::string inlineFuncNanme(inlineMethod->GetMethodName(thread));
3720     std::string callerFullName = callerFuncName + "@" + std::string(callerRecordName);
3721     std::string inlineFullName = inlineFuncNanme + "@" + std::string(inlineRecordNanme);
3722 
3723     LOG_TRACE(INFO) << "aot inline function name: " << inlineFullName << " caller function name: " << callerFullName;
3724     return JSTaggedValue::Undefined().GetRawData();
3725 }
3726 
3727 DEF_RUNTIME_STUBS(AotInlineBuiltinTrace)
3728 {
3729     RUNTIME_STUBS_HEADER(AotInlineBuiltinTrace);
3730     JSTaggedValue callerFunc = GetArg(argv, argc, 0);
3731     JSFunction *callerJSFunc = JSFunction::Cast(callerFunc);
3732     Method *callerMethod = Method::Cast(callerJSFunc->GetMethod(thread));
3733     auto callerRecordName = callerMethod->GetRecordNameStr(thread);
3734     const std::string callerFuncName(callerMethod->GetMethodName(thread));
3735     std::string callerFullName = callerFuncName + "@" + std::string(callerRecordName);
3736 
3737     auto builtinId = static_cast<kungfu::BuiltinsStubCSigns::ID>(GetArg(argv, argc, 1).GetInt());
3738     LOG_TRACE(INFO) << "aot inline builtin: " << kungfu::BuiltinsStubCSigns::GetBuiltinName(builtinId)
3739                     << ", caller function name:" << callerFullName;
3740     return JSTaggedValue::Undefined().GetRawData();
3741 }
3742 
3743 DEF_RUNTIME_STUBS(AotCallBuiltinTrace)
3744 {
3745     RUNTIME_STUBS_HEADER(AotCallBuiltinTrace);
3746     JSTaggedValue callerFunc = GetArg(argv, argc, 0);
3747     JSFunction *callerJSFunc = JSFunction::Cast(callerFunc);
3748     Method *callerMethod = Method::Cast(callerJSFunc->GetMethod(thread));
3749     auto callerRecordName = callerMethod->GetRecordNameStr(thread);
3750     const std::string callerFuncName(callerMethod->GetMethodName(thread));
3751     std::string callerFullName = callerFuncName + "@" + std::string(callerRecordName);
3752 
3753     auto builtinId = static_cast<kungfu::BuiltinsStubCSigns::ID>(GetArg(argv, argc, 1).GetInt());
3754     LOG_TRACE(INFO) << "aot call builtin: " << kungfu::BuiltinsStubCSigns::GetBuiltinName(builtinId)
3755                     << ", caller function name:" << callerFullName;
3756     return JSTaggedValue::Undefined().GetRawData();
3757 }
3758 
3759 DEF_RUNTIME_STUBS(LocaleCompare)
3760 {
3761     RUNTIME_STUBS_HEADER(LocaleCompare);
3762 
3763     JSHandle<JSTaggedValue> thisTag = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
3764     JSHandle<JSTaggedValue> thatTag = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
3765     JSHandle<JSTaggedValue> locales = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
3766     JSHandle<JSTaggedValue> options = GetHArg<JSTaggedValue>(argv, argc, 3);  // 3: means the third parameter
3767 
3768     JSHandle<JSTaggedValue> thisObj(JSTaggedValue::RequireObjectCoercible(thread, thisTag));
3769     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
3770     [[maybe_unused]] JSHandle<EcmaString> thisHandle = JSTaggedValue::ToString(thread, thisObj);
3771     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
3772     [[maybe_unused]] JSHandle<EcmaString> thatHandle = JSTaggedValue::ToString(thread, thatTag);
3773     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
3774 
3775     return builtins::BuiltinsString::DoLocaleCompare(thread, thisHandle, thatHandle, locales, options).GetRawData();
3776 }
3777 
3778 DEF_RUNTIME_STUBS(ArraySort)
3779 {
3780     RUNTIME_STUBS_HEADER(ArraySort);
3781 
3782     JSHandle<JSTaggedValue> thisHandle = GetHArg<JSTaggedValue>(argv, argc, 0);
3783     return RuntimeArraySort(thread, thisHandle).GetRawData();
3784 }
3785 
3786 JSTaggedValue RuntimeStubs::RuntimeArraySort(JSThread *thread, JSHandle<JSTaggedValue> thisHandle)
3787 {
3788     // 1. Let obj be ToObject(this value).
3789     JSHandle<JSObject> thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle);
3790     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception());
3791 
3792     // 2. Let len be ToLength(Get(obj, "length")).
3793     int64_t len = ArrayHelper::GetArrayLength(thread, JSHandle<JSTaggedValue>(thisObjHandle));
3794     // 3. ReturnIfAbrupt(len).
3795     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception());
3796     JSHandle<JSHClass> hclass(thread, thisObjHandle->GetClass());
3797     if (!hclass->IsDictionaryElement()) {
3798         JSHandle<TaggedArray> elements(thread, thisObjHandle->GetElements(thread));
3799         // remove elements number check with pgo later and add int fast path at the same time
3800         if (len <= elements->GetLength() && CheckElementsNumber(thread, elements, len)) {
3801             return ArrayNumberSort(thread, thisObjHandle, len);
3802         }
3803     }
3804 
3805     JSHandle<JSTaggedValue> callbackFnHandle(thread, JSTaggedValue::Undefined());
3806     JSArray::Sort(thread, JSHandle<JSTaggedValue>::Cast(thisObjHandle), callbackFnHandle);
3807     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception());
3808     return thisObjHandle.GetTaggedValue();
3809 }
3810 
3811 DEF_RUNTIME_STUBS(HClassCloneWithAddProto)
3812 {
3813     RUNTIME_STUBS_HEADER(HClassCloneWithAddProto);
3814     JSHandle<JSHClass> jshclass = GetHArg<JSHClass>(argv, argc, 0);            // 0: means the zeroth parameter
3815     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1);       // 1: means the first parameter
3816     JSHandle<JSTaggedValue> proto = GetHArg<JSTaggedValue>(argv, argc, 2);     // 2: means the second parameter
3817     return JSHClass::CloneWithAddProto(thread, jshclass, key, proto).GetTaggedValue().GetRawData();
3818 }
3819 
3820 void RuntimeStubs::StartCallTimer(uintptr_t argGlue, JSTaggedType func, bool isAot)
3821 {
3822     DISALLOW_GARBAGE_COLLECTION;
3823     auto thread =  JSThread::GlueToJSThread(argGlue);
3824     JSTaggedValue callTarget(func);
3825     Method *method = Method::Cast(JSFunction::Cast(callTarget)->GetMethod(thread));
3826     if (method->IsNativeWithCallField()) {
3827         return;
3828     }
3829     size_t methodId = method->GetMethodId().GetOffset();
3830     auto callTimer = thread->GetEcmaVM()->GetCallTimer();
3831     callTimer->InitialStatAndTimer(thread, method, methodId, isAot);
3832     callTimer->StartCount(methodId, isAot);
3833 }
3834 
3835 void RuntimeStubs::EndCallTimer(uintptr_t argGlue, JSTaggedType func)
3836 {
3837     DISALLOW_GARBAGE_COLLECTION;
3838     auto thread =  JSThread::GlueToJSThread(argGlue);
3839     JSTaggedValue callTarget(func);
3840     Method *method = Method::Cast(JSFunction::Cast(callTarget)->GetMethod(thread));
3841     if (method->IsNativeWithCallField()) {
3842         return;
3843     }
3844     auto callTimer = thread->GetEcmaVM()->GetCallTimer();
3845     callTimer->StopCount(thread, method);
3846 }
3847 
3848 int32_t RuntimeStubs::StringGetStart(bool isUtf8, EcmaString *srcString, int32_t length, int32_t startIndex)
3849 {
3850     DISALLOW_GARBAGE_COLLECTION;
3851     if (isUtf8) {
3852         Span<const uint8_t> data(EcmaStringAccessor(srcString).GetDataUtf8() + startIndex, length);
3853         return static_cast<int32_t>(base::StringHelper::GetStart(data, length));
3854     } else {
3855         Span<const uint16_t> data(EcmaStringAccessor(srcString).GetDataUtf16() + startIndex, length);
3856         return static_cast<int32_t>(base::StringHelper::GetStart(data, length));
3857     }
3858 }
3859 
3860 int32_t RuntimeStubs::StringGetEnd(bool isUtf8, EcmaString *srcString,
3861     int32_t start, int32_t length, int32_t startIndex)
3862 {
3863     DISALLOW_GARBAGE_COLLECTION;
3864     if (isUtf8) {
3865         Span<const uint8_t> data(EcmaStringAccessor(srcString).GetDataUtf8() + startIndex, length);
3866         return base::StringHelper::GetEnd(data, start, length);
3867     } else {
3868         Span<const uint16_t> data(EcmaStringAccessor(srcString).GetDataUtf16() + startIndex, length);
3869         return base::StringHelper::GetEnd(data, start, length);
3870     }
3871 }
3872 
3873 DEF_RUNTIME_STUBS(FastStringify)
3874 {
3875     RUNTIME_STUBS_HEADER(FastStringify);
3876     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);
3877     JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
3878     base::JsonStringifier jsonStringifier(thread);
3879     JSHandle<JSTaggedValue> result = jsonStringifier.Stringify(value, undefined, undefined);
3880     return result.GetTaggedValue().GetRawData();
3881 }
3882 
3883 DEF_RUNTIME_STUBS(GetLinkedHash)
3884 {
3885     RUNTIME_STUBS_HEADER(GetLinkedHash);
3886     JSTaggedValue key = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
3887     return JSTaggedValue(LinkedHash::Hash(thread, key)).GetRawData();
3888 }
3889 
3890 DEF_RUNTIME_STUBS(LinkedHashMapComputeCapacity)
3891 {
3892     RUNTIME_STUBS_HEADER(LinkedHashMapComputeCapacity);
3893     JSTaggedValue value = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
3894     return JSTaggedValue(LinkedHashMap::ComputeCapacity(value.GetInt())).GetRawData();
3895 }
3896 
3897 DEF_RUNTIME_STUBS(LinkedHashSetComputeCapacity)
3898 {
3899     RUNTIME_STUBS_HEADER(LinkedHashSetComputeCapacity);
3900     JSTaggedValue value = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
3901     return JSTaggedValue(LinkedHashSet::ComputeCapacity(value.GetInt())).GetRawData();
3902 }
3903 
3904 DEF_RUNTIME_STUBS(ObjectSlowAssign)
3905 {
3906     RUNTIME_STUBS_HEADER(ObjectSlowAssign);
3907     JSHandle<JSObject> toAssign = GetHArg<JSObject>(argv, argc, 0);            // 0: means the zeroth parameter
3908     JSHandle<JSTaggedValue> source = GetHArg<JSTaggedValue>(argv, argc, 1);    // 1: means the first parameter
3909     return builtins::BuiltinsObject::AssignTaggedValue(thread, source, toAssign).GetRawData();
3910 }
3911 
3912 DEF_RUNTIME_STUBS(NameDictionaryGetAllEnumKeys)
3913 {
3914     RUNTIME_STUBS_HEADER(NameDictionaryGetAllEnumKeys);
3915     JSHandle<JSObject> object = GetHArg<JSObject>(argv, argc, 0);            // 0: means the zeroth parameter
3916     JSTaggedValue argKeys = GetArg(argv, argc, 1);    // 1: means the first parameter
3917     int numOfKeys = argKeys.GetInt();
3918     uint32_t keys = 0;
3919     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
3920     JSHandle<TaggedArray> keyArray = factory->NewTaggedArray(numOfKeys);
3921     NameDictionary *dict = NameDictionary::Cast(object->GetProperties(thread).GetTaggedObject());
3922     dict->GetAllEnumKeys(thread, 0, keyArray, &keys);
3923     if (keys < keyArray->GetLength()) {
3924         keyArray->Trim(thread, keys);
3925     }
3926     return keyArray.GetTaggedValue().GetRawData();
3927 }
3928 
3929 DEF_RUNTIME_STUBS(NumberDictionaryGetAllEnumKeys)
3930 {
3931     RUNTIME_STUBS_HEADER(NumberDictionaryGetAllEnumKeys);
3932     JSHandle<TaggedArray> array = GetHArg<TaggedArray>(argv, argc, 0);  // 0: means the zeroth parameter
3933     JSHandle<TaggedArray> elementArray = GetHArg<TaggedArray>(argv, argc, 1);  // 1: means the first parameter
3934     JSTaggedValue argKeys = GetArg(argv, argc, 2);  // 2: means the second parameter
3935     int elementIndex = argKeys.GetInt();
3936     uint32_t keys = elementIndex;
3937     NumberDictionary::GetAllEnumKeys(
3938         thread, JSHandle<NumberDictionary>(array), elementIndex, elementArray, &keys);
3939     if (keys < elementArray->GetLength()) {
3940         elementArray->Trim(thread, keys);
3941     }
3942     return JSTaggedValue::Undefined().GetRawData();
3943 }
3944 
3945 DEF_RUNTIME_STUBS(NumberToString)
3946 {
3947     RUNTIME_STUBS_HEADER(NumberToString);
3948     JSTaggedValue argKeys = GetArg(argv, argc, 0);
3949     return JSHandle<JSTaggedValue>::Cast(base::NumberHelper::NumberToString(thread,
3950         argKeys)).GetTaggedValue().GetRawData();
3951 }
3952 
3953 DEF_RUNTIME_STUBS(NumberBigIntNativePointerToString)
3954 {
3955     RUNTIME_STUBS_HEADER(NumberBigIntNativePointerToString);
3956     JSTaggedValue argKeys = GetArg(argv, argc, 0);
3957     if (argKeys.IsNumber()) {
3958         return JSHandle<JSTaggedValue>::Cast(base::NumberHelper::NumberToString(thread,
3959             argKeys)).GetTaggedValue().GetRawData();
3960     }
3961     JSHandle<JSTaggedValue> tagged(thread, argKeys);
3962     if (tagged->IsBigInt()) {
3963         JSHandle<BigInt> taggedValue(tagged);
3964         return BigInt::ToString(thread, taggedValue).GetTaggedValue().GetRawData();
3965     }
3966     if (tagged->IsNativePointer()) {
3967         JSHandle<JSNativePointer> taggedValue(tagged);
3968         return taggedValue->ToString(thread).GetTaggedValue().GetRawData();
3969     }
3970     return JSTaggedValue::Undefined().GetRawData();
3971 }
3972 
3973 DEF_RUNTIME_STUBS(IntToString)
3974 {
3975     RUNTIME_STUBS_HEADER(IntToString);
3976     JSTaggedValue argKeys = GetArg(argv, argc, 0);
3977     return JSHandle<JSTaggedValue>::Cast(base::NumberHelper::IntToEcmaString(thread,
3978         argKeys.GetInt())).GetTaggedValue().GetRawData();
3979 }
3980 
3981 DEF_RUNTIME_STUBS(LocaleCompareWithGc)
3982 {
3983     RUNTIME_STUBS_HEADER(LocaleCompareWithGc);
3984     JSHandle<JSTaggedValue> locales = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
3985     JSHandle<EcmaString> thisHandle = GetHArg<EcmaString>(argv, argc, 1);    // 1: means the first parameter
3986     JSHandle<EcmaString> thatHandle = GetHArg<EcmaString>(argv, argc, 2);    // 2: means the second parameter
3987     JSHandle<JSTaggedValue> options = GetHArg<JSTaggedValue>(argv, argc, 3); // 3: means the third parameter
3988     bool cacheable = options->IsUndefined() && (locales->IsUndefined() || locales->IsString());
3989     const CompareStringsOption csOption = JSCollator::CompareStringsOptionFor(thread, locales, options);
3990     return builtins::BuiltinsString::LocaleCompareGC(thread, thisHandle, thatHandle, locales,
3991         options, csOption, cacheable).GetRawData();
3992 }
3993 
3994 DEF_RUNTIME_STUBS(ParseInt)
3995 {
3996     RUNTIME_STUBS_HEADER(ParseInt);
3997     JSHandle<JSTaggedValue> msg = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
3998     JSHandle<JSTaggedValue> arg2 = GetHArg<JSTaggedValue>(argv, argc, 1);    // 1: means the first parameter
3999 
4000     int32_t radix = 0;
4001     // 1. Let inputString be ToString(string).
4002     JSHandle<EcmaString> numberString = JSTaggedValue::ToString(thread, msg);
4003     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
4004     if (!arg2->IsUndefined()) {
4005         // 7. Let R = ToInt32(radix).
4006         radix = JSTaggedValue::ToInt32(thread, arg2);
4007         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
4008     }
4009 
4010     return base::NumberHelper::StringToNumber(thread, *numberString, radix).GetRawData();
4011 }
4012 
4013 int RuntimeStubs::IntLexicographicCompare(JSTaggedType x, JSTaggedType y)
4014 {
4015     DISALLOW_GARBAGE_COLLECTION;
4016     return JSTaggedValue::IntLexicographicCompare(JSTaggedValue(x), JSTaggedValue(y));
4017 }
4018 
4019 int RuntimeStubs::DoubleLexicographicCompare(JSTaggedType x, JSTaggedType y)
4020 {
4021     DISALLOW_GARBAGE_COLLECTION;
4022     return JSTaggedValue::DoubleLexicographicCompare(JSTaggedValue(x), JSTaggedValue(y));
4023 }
4024 
4025 int RuntimeStubs::FastArraySortString(uintptr_t argGlue, JSTaggedValue x, JSTaggedValue y)
4026 {
4027     DISALLOW_GARBAGE_COLLECTION;
4028     auto thread = JSThread::GlueToJSThread(argGlue);
4029     JSHandle<EcmaString> valueX(thread, x);
4030     JSHandle<EcmaString> valueY(thread, y);
4031     return static_cast<int>(EcmaStringAccessor::Compare(thread->GetEcmaVM(), valueX, valueY));
4032 }
4033 
4034 DEF_RUNTIME_STUBS(LocaleCompareCacheable)
4035 {
4036     RUNTIME_STUBS_HEADER(LocaleCompareCacheable);
4037     JSHandle<JSTaggedValue> locales = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
4038     JSHandle<EcmaString> thisHandle = GetHArg<EcmaString>(argv, argc, 1);    // 1: means the first parameter
4039     JSHandle<EcmaString> thatHandle = GetHArg<EcmaString>(argv, argc, 2);    // 2: means the second parameter
4040 #if ENABLE_NEXT_OPTIMIZATION
4041     const CompareStringsOption csOption = JSCollator::CompareStringsOptionFor(thread, locales);
4042     JSTaggedValue result = JSCollator::FastCachedCompareStrings(thread, locales, thisHandle, thatHandle, csOption);
4043 #else
4044     auto collator = JSCollator::GetCachedIcuCollator(thread, locales);
4045     JSTaggedValue result = JSTaggedValue::Undefined();
4046     if (collator != nullptr) {
4047         [[maybe_unused]]const CompareStringsOption csOption = JSCollator::CompareStringsOptionFor(
4048             thread, locales);
4049         result = JSCollator::CompareStrings(thread, collator, thisHandle, thatHandle, csOption);
4050     }
4051 #endif
4052     return result.GetRawData();
4053 }
4054 
4055 JSTaggedValue RuntimeStubs::StringToNumber(uintptr_t argGlue, JSTaggedType numberString, int32_t radix)
4056 {
4057     DISALLOW_GARBAGE_COLLECTION;
4058     auto input = EcmaString::Cast(JSTaggedValue(numberString));
4059     return base::NumberHelper::StringToNumber(JSThread::GlueToJSThread(argGlue), input, radix);
4060 }
4061 
4062 void RuntimeStubs::ArrayTrim(uintptr_t argGlue, TaggedArray *array, int64_t newLength)
4063 {
4064     DISALLOW_GARBAGE_COLLECTION;
4065     uint32_t length = static_cast<uint32_t>(newLength);
4066     auto thread = JSThread::GlueToJSThread(argGlue);
4067     array->Trim(thread, length);
4068 }
4069 
4070 bool RuntimeStubs::IsFastRegExp(uintptr_t argGlue, JSTaggedValue thisValue)
4071 {
4072     auto thread = JSThread::GlueToJSThread(argGlue);
4073     return builtins::BuiltinsRegExp::IsFastRegExp(thread, thisValue);
4074 }
4075 
4076 RememberedSet* RuntimeStubs::CreateLocalToShare(Region* region)
4077 {
4078     return region->CreateLocalToShareRememberedSet();
4079 }
4080 
4081 RememberedSet* RuntimeStubs::CreateOldToNew(Region* region)
4082 {
4083     return region->CreateOldToNewRememberedSet();
4084 }
4085 
4086 template <typename T>
4087 static bool CompareFloat(T x, T y)
4088 {
4089     if (x < y) {
4090         return true;
4091     }
4092     if (x > y) {
4093         return false;
4094     }
4095     if constexpr (!std::is_integral<T>::value) {
4096         double doubleX = x;
4097         double doubleY = y;
4098         if (x == 0 && x == y) {
4099             /* -0.0 is less than +0.0 */
4100             return std::signbit(doubleX) && !std::signbit(doubleY);
4101         }
4102         if (!std::isnan(doubleX) && std::isnan(doubleY)) {
4103             /* number is less than NaN */
4104             return true;
4105         }
4106     }
4107     return false;
4108 }
4109 
4110 void RuntimeStubs::SortTypedArray(uintptr_t argGlue, JSTypedArray *typedArray)
4111 {
4112     DISALLOW_GARBAGE_COLLECTION;
4113     JSHClass *hclass = typedArray->GetClass();
4114     const JSType jsType = hclass->GetObjectType();
4115     JSThread *thread = JSThread::GlueToJSThread(argGlue);
4116     JSTaggedValue buffer = typedArray->GetViewedArrayBufferOrByteArray(thread);
4117     const uint32_t len = typedArray->GetArrayLength();
4118     if (len == 0) {
4119         return;
4120     }
4121     void *pointer = builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, buffer);
4122     switch (jsType) {
4123         case JSType::JS_INT8_ARRAY:
4124             std::sort(static_cast<int8_t*>(pointer), static_cast<int8_t*>(pointer) + len);
4125             break;
4126         case JSType::JS_UINT8_ARRAY:
4127         case JSType::JS_UINT8_CLAMPED_ARRAY:
4128             std::sort(static_cast<uint8_t*>(pointer), static_cast<uint8_t*>(pointer) + len);
4129             break;
4130         case JSType::JS_INT16_ARRAY:
4131             std::sort(static_cast<int16_t*>(pointer), static_cast<int16_t*>(pointer) + len);
4132             break;
4133         case JSType::JS_UINT16_ARRAY:
4134             std::sort(static_cast<uint16_t*>(pointer), static_cast<uint16_t*>(pointer) + len);
4135             break;
4136         case JSType::JS_INT32_ARRAY:
4137             std::sort(static_cast<int32_t*>(pointer), static_cast<int32_t*>(pointer) + len);
4138             break;
4139         case JSType::JS_UINT32_ARRAY:
4140             std::sort(static_cast<uint32_t*>(pointer), static_cast<uint32_t*>(pointer) + len);
4141             break;
4142         case JSType::JS_FLOAT32_ARRAY:
4143             std::sort(static_cast<float*>(pointer), static_cast<float*>(pointer) + len, CompareFloat<float>);
4144             break;
4145         case JSType::JS_FLOAT64_ARRAY:
4146             std::sort(static_cast<double*>(pointer), static_cast<double*>(pointer) + len, CompareFloat<double>);
4147             break;
4148         default:
4149             UNREACHABLE();
4150     }
4151 }
4152 
4153 void RuntimeStubs::ReverseTypedArray(uintptr_t argGlue, JSTypedArray *typedArray)
4154 {
4155     DISALLOW_GARBAGE_COLLECTION;
4156     JSHClass *hclass = typedArray->GetClass();
4157     const JSType jsType = hclass->GetObjectType();
4158     JSThread *thread = JSThread::GlueToJSThread(argGlue);
4159     JSTaggedValue buffer = typedArray->GetViewedArrayBufferOrByteArray(thread);
4160     const uint32_t len = typedArray->GetArrayLength();
4161     void *pointer = builtins::BuiltinsArrayBuffer::GetDataPointFromBuffer(thread, buffer);
4162     switch (jsType) {
4163         case JSType::JS_INT8_ARRAY:
4164             std::reverse(static_cast<int8_t*>(pointer), static_cast<int8_t*>(pointer) + len);
4165             break;
4166         case JSType::JS_UINT8_ARRAY:
4167         case JSType::JS_UINT8_CLAMPED_ARRAY:
4168             std::reverse(static_cast<uint8_t*>(pointer), static_cast<uint8_t*>(pointer) + len);
4169             break;
4170         case JSType::JS_INT16_ARRAY:
4171             std::reverse(static_cast<int16_t*>(pointer), static_cast<int16_t*>(pointer) + len);
4172             break;
4173         case JSType::JS_UINT16_ARRAY:
4174             std::reverse(static_cast<uint16_t*>(pointer), static_cast<uint16_t*>(pointer) + len);
4175             break;
4176         case JSType::JS_INT32_ARRAY:
4177             std::reverse(static_cast<int32_t*>(pointer), static_cast<int32_t*>(pointer) + len);
4178             break;
4179         case JSType::JS_UINT32_ARRAY:
4180             std::reverse(static_cast<uint32_t*>(pointer), static_cast<uint32_t*>(pointer) + len);
4181             break;
4182         case JSType::JS_FLOAT32_ARRAY:
4183             std::reverse(static_cast<float*>(pointer), static_cast<float*>(pointer) + len);
4184             break;
4185         case JSType::JS_FLOAT64_ARRAY:
4186             std::reverse(static_cast<double*>(pointer), static_cast<double*>(pointer) + len);
4187             break;
4188         default:
4189             UNREACHABLE();
4190     }
4191 }
4192 
4193 void RuntimeStubs::FinishObjSizeTracking(uintptr_t argGlue, JSHClass *cls)
4194 {
4195     JSThread *thread = JSThread::GlueToJSThread(argGlue);
4196     uint32_t finalInObjPropsNum = JSHClass::VisitTransitionAndFindMaxNumOfProps(thread, cls);
4197     if (finalInObjPropsNum < cls->GetInlinedProperties()) {
4198         // UpdateObjSize with finalInObjPropsNum
4199         JSHClass::VisitTransitionAndUpdateObjSize(thread, cls, finalInObjPropsNum);
4200     }
4201 }
4202 
4203 void RuntimeStubs::FillObject(JSTaggedType *dst, JSTaggedType value, uint32_t count)
4204 {
4205     DISALLOW_GARBAGE_COLLECTION;
4206     std::fill_n(dst, count, value);
4207 }
4208 
4209 bool RuntimeStubs::IsTargetBundleName(uintptr_t argGlue)
4210 {
4211     auto thread = JSThread::GlueToJSThread(argGlue);
4212     return thread->GetEcmaVM()->GetJSOptions().FindTraceBundleName(
4213         thread->GetEcmaVM()->GetBundleName());
4214 }
4215 
4216 DEF_RUNTIME_STUBS(TraceLoadSlowPath)
4217 {
4218 #if ECMASCRIPT_ENABLE_TRACE_LOAD
4219     if (!IsTargetBundleName(argGlue)) {
4220         return JSTaggedValue::Undefined().GetRawData();
4221     }
4222 
4223     ECMA_BYTRACE_START_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, "[dfx]TraceLoadSlowPath");
4224 #endif
4225     return JSTaggedValue::Undefined().GetRawData();
4226 }
4227 
4228 DEF_RUNTIME_STUBS(TraceLoadGetter)
4229 {
4230 #if ECMASCRIPT_ENABLE_TRACE_LOAD
4231     if (!IsTargetBundleName(argGlue)) {
4232         return JSTaggedValue::Undefined().GetRawData();
4233     }
4234 
4235     ECMA_BYTRACE_START_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, "[DFX]TraceLoadGetter");
4236 #endif
4237     return JSTaggedValue::Undefined().GetRawData();
4238 }
4239 
4240 DEF_RUNTIME_STUBS(TraceLoadDetail)
4241 {
4242 #if ECMASCRIPT_ENABLE_TRACE_LOAD
4243     if (!IsTargetBundleName(argGlue)) {
4244         return JSTaggedValue::Undefined().GetRawData();
4245     }
4246 
4247     JSHandle<JSTaggedValue> receiver = GetHArg<JSTaggedValue>(argv, argc, 0);
4248     JSHandle<JSTaggedValue> profile = GetHArg<JSTaggedValue>(argv, argc, 1);
4249     JSTaggedValue slotId = GetArg(argv, argc, 2);
4250     CString msg = "[DFX]Trace Load Detail: ";
4251     if (profile->IsUndefined()) {
4252         msg += "ProfileTypeInfo Undefine";
4253     } else {
4254         auto prof = JSHandle<ProfileTypeInfo>::Cast(profile);
4255         auto slot = slotId.GetInt();
4256         auto first = prof->GetIcSlot(thread, slot);
4257         auto second = prof->GetIcSlot(thread, slot + 1);
4258         if (first.IsHole()) {
4259             if (second.IsHole()) {
4260                 msg += "other-mega, ";
4261             // 1: Call SetAsMegaDFX and set it to 1 (for placeholder purposes)..
4262             } else if (second == JSTaggedValue(ProfileTypeAccessor::MegaState::NOTFOUND_MEGA)) {
4263                 msg += "not_found-mage, ";
4264             // 2: Call SetAsMegaDFX and set it to 2 (for placeholder purposes).
4265             } else if (second == JSTaggedValue(ProfileTypeAccessor::MegaState::DICT_MEGA)) {
4266                 msg += "dictionary-mega, ";
4267             } else if (second.IsString()) {
4268                 msg += "ic-mega, ";
4269             } else {
4270                 msg += "unkown-mega, ";
4271             }
4272         } else if (first.IsUndefined()) {
4273             msg += "undedfine slot, ";
4274         } else if (first.IsWeak()) {
4275             if (second.IsPrototypeHandler()) {
4276                 auto prototypeHandler = PrototypeHandler::Cast(second.GetTaggedObject());
4277                 JSTaggedValue handlerInfoVal = prototypeHandler->GetHandlerInfo();
4278                 if (!handlerInfoVal.IsInt()) {
4279                     msg += "mono prototype, ";
4280                 } else {
4281                     auto handlerInfo = static_cast<uint32_t>(handlerInfoVal.GetInt());
4282                     if (HandlerBase::IsNumber(handlerInfo)) {
4283                         msg += "mono primitive type number prototype, ";
4284                     } else if (HandlerBase::IsBoolean(handlerInfo)) {
4285                         msg += "mono primitive type boolean prototype, ";
4286                     } else {
4287                         msg += "mono prototype, ";
4288                     }
4289                 }
4290             } else {
4291                 msg += "mono, ";
4292             }
4293         } else {
4294             msg += "poly, ";
4295         }
4296 #if ECMASCRIPT_ENABLE_TRACE_LOAD_MORE
4297         auto thread = JSThread::GlueToJSThread(argGlue);
4298         DumpInfoForMoreLdInfo(thread, receiver, msg);
4299 #endif
4300     }
4301     if (!receiver->IsHeapObject()) {
4302         if (receiver->IsNumber()) {
4303             msg += "prim_number";
4304         } else if (receiver->IsBoolean()) {
4305             msg += "prim_boolean";
4306         } else if (receiver->IsSymbol()) {
4307             msg += "prim_symbol";
4308         } else if (receiver->IsBigInt()) {
4309             msg += "prim_bigint";
4310         } else if (receiver->IsString()) {
4311             msg += "prim_string";
4312         } else {
4313             msg += "prim_obj";
4314         }
4315     } else {
4316         msg += "heap_obj";
4317     }
4318     ECMA_BYTRACE_START_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, msg.c_str());
4319 #endif
4320     return JSTaggedValue::Undefined().GetRawData();
4321 }
4322 
4323 DEF_RUNTIME_STUBS(TraceLoadEnd)
4324 {
4325 #if ECMASCRIPT_ENABLE_TRACE_LOAD
4326     if (!IsTargetBundleName(argGlue)) {
4327         return JSTaggedValue::Undefined().GetRawData();
4328     }
4329 
4330     ECMA_BYTRACE_FINISH_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK);
4331 #endif
4332     return JSTaggedValue::Undefined().GetRawData();
4333 }
4334 
4335 DEF_RUNTIME_STUBS(TraceLoadValueSlowPath)
4336 {
4337 #if ECMASCRIPT_ENABLE_TRACE_LOAD_VALUE
4338     if (!IsTargetBundleName(argGlue)) {
4339         return JSTaggedValue::Undefined().GetRawData();
4340     }
4341 
4342     ECMA_BYTRACE_START_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, "[dfx]TraceLoadValueSlowPath");
4343 #endif
4344     return JSTaggedValue::Undefined().GetRawData();
4345 }
4346 
4347 DEF_RUNTIME_STUBS(TraceLoadValueDetail)
4348 {
4349 #if ECMASCRIPT_ENABLE_TRACE_LOAD_VALUE
4350     if (!IsTargetBundleName(argGlue)) {
4351         return JSTaggedValue::Undefined().GetRawData();
4352     }
4353     JSHandle<JSTaggedValue> receiver = GetHArg<JSTaggedValue>(argv, argc, 0);
4354     JSHandle<JSTaggedValue> profile = GetHArg<JSTaggedValue>(argv, argc, 1);
4355     JSTaggedValue slotId = GetArg(argv, argc, 2);
4356     JSTaggedValue key = GetArg(argv, argc, 3);
4357     CString msg = "";
4358     DumpInfoForLdObjByValue(profile, slotId, key, msg);
4359 #if ECMASCRIPT_ENABLE_TRACE_LOAD_MORE
4360     msg += " | ";
4361     auto thread = JSThread::GlueToJSThread(argGlue);
4362     DumpInfoForMoreLdInfo(thread, receiver, msg);
4363 #endif
4364     ECMA_BYTRACE_START_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, msg.c_str());
4365 #endif
4366     return JSTaggedValue::Undefined().GetRawData();
4367 }
4368 
4369 DEF_RUNTIME_STUBS(TraceLoadValueEnd)
4370 {
4371 #if ECMASCRIPT_ENABLE_TRACE_LOAD_VALUE
4372     if (!IsTargetBundleName(argGlue)) {
4373         return JSTaggedValue::Undefined().GetRawData();
4374     }
4375 
4376     ECMA_BYTRACE_FINISH_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK);
4377 #endif
4378     return JSTaggedValue::Undefined().GetRawData();
4379 }
4380 
4381 DEF_RUNTIME_STUBS(TraceCallDetail)
4382 {
4383 #if ECMASCRIPT_ENABLE_TRACE_CALL
4384     if (!IsTargetBundleName(argGlue)) {
4385         return JSTaggedValue::Undefined().GetRawData();
4386     }
4387     JSHandle<JSTaggedValue> profile = GetHArg<JSTaggedValue>(argv, argc, 0);
4388     JSTaggedValue slotId = GetArg(argv, argc, 1);
4389     std::string msg = "[DFX]Trace Call Detail: ";
4390     if (profile->IsUndefined()) {
4391         msg += "ProfileTypeInfo Undefine";
4392     } else {
4393         auto prof = JSHandle<ProfileTypeInfo>::Cast(profile);
4394         auto slot = slotId.GetInt();
4395         auto slotValue = prof->GetIcSlot(slot);
4396         if (slotValue.IsJSFunction()) {
4397             JSFunction *callee = JSFunction::Cast(slotValue);
4398             Method *calleeMethod = Method::Cast(callee->GetMethod());
4399             auto methodName = calleeMethod->GetMethodName();
4400             auto calleeMethodId = static_cast<int>(calleeMethod->GetMethodId().GetOffset());
4401             auto calleeAbcId = PGOProfiler::GetMethodAbcId(callee);
4402             msg += std::string("[js function] id: ") + std::to_string(calleeMethodId) +
4403                    " abc id: " + std::to_string(calleeAbcId) + " method name: " + methodName;
4404         } else {
4405             msg += "[unkown]";
4406         }
4407     }
4408     ECMA_BYTRACE_START_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, msg.c_str());
4409 #endif
4410     return JSTaggedValue::Undefined().GetRawData();
4411 }
4412 
4413 DEF_RUNTIME_STUBS(TraceCallEnd)
4414 {
4415 #if ECMASCRIPT_ENABLE_TRACE_CALL
4416     if (!IsTargetBundleName(argGlue)) {
4417         return JSTaggedValue::Undefined().GetRawData();
4418     }
4419 
4420     ECMA_BYTRACE_FINISH_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK);
4421 #endif
4422     return JSTaggedValue::Undefined().GetRawData();
4423 }
4424 
4425 DEF_RUNTIME_STUBS(TraceStoreFastPath)
4426 {
4427 #if ECMASCRIPT_ENABLE_TRACE_STORE
4428     if (!IsTargetBundleName(argGlue)) {
4429         return JSTaggedValue::Undefined().GetRawData();
4430     }
4431 
4432     ECMA_BYTRACE_START_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, "[DFX]TraceStoreFastPath");
4433 #endif
4434     return JSTaggedValue::Undefined().GetRawData();
4435 }
4436 
4437 DEF_RUNTIME_STUBS(TraceStoreSlowPath)
4438 {
4439 #if ECMASCRIPT_ENABLE_TRACE_STORE
4440     if (!IsTargetBundleName(argGlue)) {
4441         return JSTaggedValue::Undefined().GetRawData();
4442     }
4443 
4444     ECMA_BYTRACE_START_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, "[DFX]TraceStoreSlowPath");
4445 #endif
4446     return JSTaggedValue::Undefined().GetRawData();
4447 }
4448 
4449 DEF_RUNTIME_STUBS(TraceStoreEnd)
4450 {
4451 #if ECMASCRIPT_ENABLE_TRACE_STORE
4452     if (!IsTargetBundleName(argGlue)) {
4453         return JSTaggedValue::Undefined().GetRawData();
4454     }
4455 
4456     ECMA_BYTRACE_FINISH_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK);
4457 #endif
4458     return JSTaggedValue::Undefined().GetRawData();
4459 }
4460 
4461 DEF_RUNTIME_STUBS(TraceStoreDetail)
4462 {
4463 #if ECMASCRIPT_ENABLE_TRACE_STORE
4464     if (!IsTargetBundleName(argGlue)) {
4465         return JSTaggedValue::Undefined().GetRawData();
4466     }
4467 
4468     JSHandle<JSTaggedValue> receiver = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the first parameter
4469     JSHandle<JSTaggedValue> profile = GetHArg<JSTaggedValue>(argv, argc, 1);   // 1: means the second parameter
4470     JSTaggedValue slotId = GetArg(argv, argc, 2);  // 2: means the third parameter
4471     CString msg = "[DFX]Trace Store Detail: ";
4472     if (profile->IsUndefined()) {
4473         msg += "ProfileTypeInfo Undefine";
4474     } else {
4475         auto prof = JSHandle<ProfileTypeInfo>::Cast(profile);
4476         auto slot = slotId.GetInt();
4477         auto first = prof->GetIcSlot(slot);
4478         auto second = prof->GetIcSlot(slot + 1);
4479         if (first.IsHole()) {
4480             if (second.IsHole()) {
4481                 msg += "mega, ";
4482             }
4483         } else if (first.IsUndefined()) {
4484             msg += "undedfine slot, ";
4485         } else if (first.IsWeak()) {
4486             if (second.IsPrototypeHandler()) {
4487                 msg += "mono prototype, ";
4488             } else if (second.IsTransitionHandler()) {
4489                 msg += "mono transition, ";
4490             } else if (second.IsTransWithProtoHandler()) {
4491                 msg += "mono transition with proto, ";
4492             } else {
4493                 msg += "mono, ";
4494             }
4495         } else {
4496             msg += "poly, ";
4497         }
4498     }
4499     if (!receiver->IsHeapObject()) {
4500         msg += "prim_obj";
4501     } else {
4502         msg += "heap_obj";
4503     }
4504     ECMA_BYTRACE_START_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, msg.c_str());
4505 #endif
4506     return JSTaggedValue::Undefined().GetRawData();
4507 }
4508 
4509 DEF_RUNTIME_STUBS(TraceNum)
4510 {
4511 #if ECMASCRIPT_ENABLE_LAZY_DEOPT_TRACE
4512     if (!IsTargetBundleName(argGlue)) {
4513         return JSTaggedValue::Undefined().GetRawData();
4514     }
4515     uint32_t type = static_cast<uint32_t>(GetTArg(argv, argc, 0));
4516     static uint32_t traceNum[128] = {};
4517     traceNum[type] ++;
4518     if (traceNum[type] % TRACE_NUMBER == 0) {
4519         std::string s = "Trace type " + std::to_string(type);
4520         ECMA_BYTRACE_START_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, s.c_str());
4521         ECMA_BYTRACE_FINISH_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK);
4522     }
4523 #endif
4524     return JSTaggedValue::Undefined().GetRawData();
4525 }
4526 
4527 DEF_RUNTIME_STUBS(TraceLazyDeoptNum)
4528 {
4529 #if ECMASCRIPT_ENABLE_LAZY_DEOPT_TRACE
4530     if (!IsTargetBundleName(argGlue)) {
4531         return JSTaggedValue::Undefined().GetRawData();
4532     }
4533     static uint32_t traceLazyDeoptNum = 0;
4534     traceLazyDeoptNum ++;
4535     if (traceLazyDeoptNum % TRACE_NUMBER == 0) {
4536         std::string s = "Lazy Deoptimize Code.";
4537         ECMA_BYTRACE_START_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, s.c_str());
4538         ECMA_BYTRACE_FINISH_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK);
4539     }
4540 #endif
4541     return JSTaggedValue::Undefined().GetRawData();
4542 }
4543 
4544 DEF_RUNTIME_STUBS(TraceLazyDeoptFailNum)
4545 {
4546 #if ECMASCRIPT_ENABLE_LAZY_DEOPT_TRACE
4547     if (!IsTargetBundleName(argGlue)) {
4548         return JSTaggedValue::Undefined().GetRawData();
4549     }
4550     static uint32_t traceLazyDeoptFailNum = 0;
4551     traceLazyDeoptFailNum ++;
4552     if (traceLazyDeoptFailNum % TRACE_NUMBER == 0) {
4553         std::string s = "Lazy Deoptimize Code Fail."
4554         ECMA_BYTRACE_START_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, s.c_str());
4555         ECMA_BYTRACE_FINISH_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK);
4556     }
4557 #endif
4558     return JSTaggedValue::Undefined().GetRawData();
4559 }
4560 
4561 // static
4562 void RuntimeStubs::TraceLazyDeoptCommitSuccess(uintptr_t argGlue, JSHandle<JSTaggedValue> func)
4563 {
4564 #if ECMASCRIPT_ENABLE_LAZY_DEOPT_TRACE
4565     if (!IsTargetBundleName(argGlue)) {
4566         return;
4567     }
4568 
4569     auto thread = JSThread::GlueToJSThread(argGlue);
4570     JSTaggedValue funcNameValue =
4571         JSFunction::NameGetter(thread, JSHandle<JSObject>::Cast(func));
4572     std::string funcName = EcmaStringAccessor(funcNameValue).ToStdString();
4573     funcName += " Lazy Deoptimize Commit Success.";
4574     ECMA_BYTRACE_START_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, funcName.c_str());
4575     ECMA_BYTRACE_FINISH_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK);
4576 #endif
4577 }
4578 
4579 DEF_RUNTIME_STUBS(TraceDefineFunc)
4580 {
4581 #if ECMASCRIPT_ENABLE_TRACE_DEFINEFUNC
4582     RUNTIME_STUBS_HEADER(TraceDefineFunc);
4583     if (!IsTargetBundleName(argGlue)) {
4584         return JSTaggedValue::Undefined().GetRawData();
4585     }
4586     int methodId = GetArg(argv, argc, 0).GetInt();
4587     JSHandle<JSTaggedValue> profileTypeInfo = GetHArg<JSTaggedValue>(argv, argc, 1);
4588     int slotId = GetArg(argv, argc, 2).GetInt();
4589     CStringStream msg;
4590     msg << "[DFX]Trace Define Func: ";
4591     msg << "method id " << methodId << " ";
4592     if (profileTypeInfo->IsUndefined()) {
4593         msg << "profileTypeInfo undefined";
4594     } else {
4595         ProfileTypeInfo *profile = ProfileTypeInfo::Cast(profileTypeInfo->GetTaggedObject());
4596         JSTaggedValue slotValue = profile->Get(slotId);
4597         if (slotValue.IsUndefined()) {
4598             msg << "slot value undefined";
4599         }
4600         if (slotValue.IsHole()) {
4601             msg << "slot value hole";
4602         }
4603         if (slotValue.IsProfileTypeInfoCell()) {
4604             JSTaggedValue code = ProfileTypeInfoCell::Cast(slotValue)->GetMachineCode();
4605             msg << "slot has machine code: " << code.IsHeapObject() && code.IsWeak();
4606         }
4607     }
4608 
4609     ECMA_BYTRACE_START_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, msg.str().c_str());
4610 #endif
4611     return JSTaggedValue::Undefined().GetRawData();
4612 }
4613 
4614 DEF_RUNTIME_STUBS(TraceDefineFuncEnd)
4615 {
4616 #if ECMASCRIPT_ENABLE_TRACE_DEFINEFUNC
4617     ECMA_BYTRACE_FINISH_TRACE(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK);
4618 #endif
4619     return JSTaggedValue::Undefined().GetRawData();
4620 }
4621 
4622 DEF_RUNTIME_STUBS(ArrayForEachContinue)
4623 {
4624     RUNTIME_STUBS_HEADER(ArrayForEachContinue);
4625     JSHandle<JSTaggedValue> thisArgHandle = GetHArg<JSTaggedValue>(argv, argc, 0);      // 0: means the zeroth parameter
4626     JSMutableHandle<JSTaggedValue> key(thread, GetHArg<JSTaggedValue>(argv, argc, 1));  // 1: means the first parameter
4627     JSHandle<JSTaggedValue> thisObjVal = GetHArg<JSTaggedValue>(argv, argc, 2);         // 2: means the second parameter
4628     JSHandle<JSTaggedValue> callbackFnHandle = GetHArg<JSTaggedValue>(argv, argc, 3);   // 3: means the third parameter
4629     JSHandle<JSTaggedValue> lengthHandle = GetHArg<JSTaggedValue>(argv, argc, 4);       // 4: means the fourth parameter
4630     const uint32_t argsLength = 3; // 3: «kValue, k, O»
4631     uint32_t i = static_cast<uint32_t>(key->GetInt());
4632     uint32_t len = static_cast<uint32_t>(lengthHandle->GetInt());
4633     JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
4634     while (i < len) {
4635         bool exists = JSTaggedValue::HasProperty(thread, thisObjVal, i);
4636         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
4637         if (exists) {
4638             JSHandle<JSTaggedValue> kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, i);
4639             key.Update(JSTaggedValue(i));
4640             RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
4641             EcmaRuntimeCallInfo *info =
4642                 EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength);
4643             RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
4644             info->SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue());
4645             JSTaggedValue funcResult = JSFunction::Call(info);
4646             RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult.GetRawData());
4647         }
4648         i++;
4649     }
4650 
4651     return JSTaggedValue::Undefined().GetRawData();
4652 }
4653 
4654 DEF_RUNTIME_STUBS(AOTEnableProtoChangeMarker)
4655 {
4656     RUNTIME_STUBS_HEADER(AOTEnableProtoChangeMarker);
4657     JSHandle<JSFunction> result(GetHArg<JSTaggedValue>(argv, argc, 0)); // 0: means the zeroth parameter
4658     JSHandle<JSTaggedValue> ihc = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
4659     JSHandle<AOTLiteralInfo> aotLiteralInfo(GetHArg<JSTaggedValue>(argv, argc, 2)); // 2: means the second parameter
4660     DefineFuncTryUseAOTHClass(thread, result, ihc, aotLiteralInfo);
4661     return JSTaggedValue::Hole().GetRawData();
4662 }
4663 
4664 DEF_RUNTIME_STUBS(GetSharedModule)
4665 {
4666     RUNTIME_STUBS_HEADER(GetSharedModule);
4667     JSHandle<JSTaggedValue> module = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
4668     ModuleManager *moduleManager = thread->GetModuleManager();
4669     return moduleManager->GenerateSendableFuncModule(module).GetTaggedValue().GetRawData();
4670 }
4671 
4672 DEF_RUNTIME_STUBS(SetPrototypeTransition)
4673 {
4674     RUNTIME_STUBS_HEADER(SetPrototypeTransition);
4675     JSHandle<JSObject> obj = GetHArg<JSObject>(argv, argc, 0); // 0: means the zeroth parameter
4676     JSHandle<JSTaggedValue> proto = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the third parameter
4677     ElementsKind oldKind = obj->GetJSHClass()->GetElementsKind();
4678     JSHClass::SetPrototypeTransition(thread, obj, proto);
4679     JSObject::TryMigrateToGenericKindForJSObject(thread, obj, oldKind);
4680     return JSTaggedValue::Hole().GetRawData();
4681 }
4682 
4683 DEF_RUNTIME_STUBS(JSProxyGetProperty)
4684 {
4685     RUNTIME_STUBS_HEADER(JSProxyGetProperty);
4686     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
4687     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
4688     JSHandle<JSTaggedValue> receiver = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
4689     return JSProxy::GetProperty(thread, JSHandle<JSProxy>(obj), keyHandle, receiver).GetValue()->GetRawData();
4690 }
4691 
4692 DEF_RUNTIME_STUBS(JSProxySetProperty)
4693 {
4694     RUNTIME_STUBS_HEADER(JSProxySetProperty);
4695     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
4696     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
4697     JSHandle<JSTaggedValue> valueHandle = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
4698     JSHandle<JSTaggedValue> receiver = GetHArg<JSTaggedValue>(argv, argc, 3); // 3: means the third parameter
4699     bool mayThrow = GetArg(argv, argc, 4).ToBoolean();  // 4: means mayThrow exception during JSProxy::SetProperty
4700     auto result = JSProxy::SetProperty(thread, JSHandle<JSProxy>(obj), keyHandle, valueHandle, receiver, mayThrow);
4701     return JSTaggedValue(result).GetRawData();
4702 }
4703 
4704 DEF_RUNTIME_STUBS(CheckGetTrapResult)
4705 {
4706     RUNTIME_STUBS_HEADER(CheckGetTrapResult);
4707     JSHandle<JSTaggedValue> targetHandle = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
4708     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
4709     JSHandle<JSTaggedValue> resutlHandle = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
4710     return JSProxy::CheckGetTrapResult(thread, targetHandle, keyHandle, resutlHandle).GetValue()->GetRawData();
4711 }
4712 
4713 DEF_RUNTIME_STUBS(CheckSetTrapResult)
4714 {
4715     RUNTIME_STUBS_HEADER(CheckSetTrapResult);
4716     JSHandle<JSTaggedValue> targetHandle = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
4717     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
4718     JSHandle<JSTaggedValue> valueHandle = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
4719     return JSTaggedValue(JSProxy::CheckSetTrapResult(thread, targetHandle, keyHandle, valueHandle)).GetRawData();
4720 }
4721 
4722 DEF_RUNTIME_STUBS(JSProxyHasProperty)
4723 {
4724     RUNTIME_STUBS_HEADER(JSProxyHasProperty);
4725     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);        // 0: means the zeroth parameter
4726     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
4727     bool res = false;
4728     res = JSProxy::HasProperty(thread, JSHandle<JSProxy>(obj), keyHandle);
4729     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
4730     return JSTaggedValue(res).GetRawData();
4731 }
4732 
4733 DEF_RUNTIME_STUBS(JSTypedArrayHasProperty)
4734 {
4735     RUNTIME_STUBS_HEADER(JSTypedArrayHasProperty);
4736     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);        // 0: means the zeroth parameter
4737     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
4738     bool res = false;
4739     res = JSTypedArray::HasProperty(thread, obj, keyHandle);
4740     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
4741     return JSTaggedValue(res).GetRawData();
4742 }
4743 
4744 DEF_RUNTIME_STUBS(ModuleNamespaceHasProperty)
4745 {
4746     RUNTIME_STUBS_HEADER(ModuleNamespaceHasProperty);
4747     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);        // 0: means the zeroth parameter
4748     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
4749     bool res = false;
4750     res = ModuleNamespace::HasProperty(thread, obj, keyHandle);
4751     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
4752     return JSTaggedValue(res).GetRawData();
4753 }
4754 
4755 DEF_RUNTIME_STUBS(JSObjectHasProperty)
4756 {
4757     RUNTIME_STUBS_HEADER(JSObjectHasProperty);
4758     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);        // 0: means the zeroth parameter
4759     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
4760     bool res = false;
4761     if (keyHandle->IsInt()) {
4762         uint32_t keyToIndex = static_cast<uint32_t>(keyHandle->GetInt());
4763         res = JSObject::HasProperty(thread, JSHandle<JSObject>(obj), keyToIndex);
4764     } else {
4765         res = JSObject::HasProperty(thread, JSHandle<JSObject>(obj), keyHandle);
4766     }
4767     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
4768     return JSTaggedValue(res).GetRawData();
4769 }
4770 
4771 DEF_RUNTIME_STUBS(HasProperty)
4772 {
4773     RUNTIME_STUBS_HEADER(HasProperty);
4774     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
4775     JSTaggedValue key = GetArg(argv, argc, 1);  // 1: means the first parameter
4776     bool res = false;
4777     if (key.IsInt()) {
4778         uint32_t keyToIndex = static_cast<uint32_t>(key.GetInt());
4779         res = JSTaggedValue::HasProperty(thread, obj, keyToIndex);
4780     } else {
4781         JSHandle<JSTaggedValue> keyHandle(thread, key);
4782         res = JSTaggedValue::HasProperty(thread, obj, keyHandle);
4783     }
4784     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
4785     return JSTaggedValue(res).GetRawData();
4786 }
4787 
4788 DEF_RUNTIME_STUBS(ObjectPrototypeHasOwnProperty)
4789 {
4790     RUNTIME_STUBS_HEADER(ObjectPrototypeHasOwnProperty);
4791     JSHandle<JSTaggedValue> thisValue = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
4792     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
4793     JSTaggedValue result = builtins::BuiltinsObject::HasOwnPropertyInternal(thread, thisValue, key);
4794     return result.GetRawData();
4795 }
4796 
4797 DEF_RUNTIME_STUBS(ReflectHas)
4798 {
4799     RUNTIME_STUBS_HEADER(ReflectHas);
4800     JSHandle<JSTaggedValue> target = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
4801     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
4802     JSTaggedValue result = builtins::BuiltinsReflect::ReflectHasInternal(thread, target, key);
4803     return result.GetRawData();
4804 }
4805 
4806 DEF_RUNTIME_STUBS(ReflectConstruct)
4807 {
4808     // newTarget = target, args = []
4809     RUNTIME_STUBS_HEADER(ReflectConstruct);
4810     JSHandle<JSTaggedValue> target = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
4811     JSHandle<TaggedArray> args = thread->GetEcmaVM()->GetFactory()->EmptyArray();
4812     JSTaggedValue result = builtins::BuiltinsReflect::ReflectConstructInternal(thread, target, args, target);
4813     return result.GetRawData();
4814 }
4815 
4816 DEF_RUNTIME_STUBS(ReflectApply)
4817 {
4818     RUNTIME_STUBS_HEADER(ReflectApply);
4819     JSHandle<JSTaggedValue> target = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
4820     JSHandle<JSTaggedValue> thisValue = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
4821     JSHandle<JSTaggedValue> argumentsList = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
4822     JSTaggedValue result = builtins::BuiltinsReflect::ReflectApplyInternal(thread, target, thisValue, argumentsList);
4823     return result.GetRawData();
4824 }
4825 
4826 DEF_RUNTIME_STUBS(FunctionPrototypeApply)
4827 {
4828     RUNTIME_STUBS_HEADER(FunctionPrototypeApply);
4829     JSHandle<JSTaggedValue> thisFunc = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
4830     JSHandle<JSTaggedValue> thisArg = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
4831     JSHandle<JSTaggedValue> argArray = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
4832     JSTaggedValue result = builtins::BuiltinsFunction::FunctionPrototypeApplyInternal(thread, thisFunc,
4833                                                                                       thisArg, argArray);
4834     return result.GetRawData();
4835 }
4836 
4837 DEF_RUNTIME_STUBS(FunctionPrototypeBind)
4838 {
4839     RUNTIME_STUBS_HEADER(FunctionPrototypeBind);
4840     JSHandle<JSTaggedValue> target = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
4841     JSHandle<JSTaggedValue> thisArg = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
4842     JSHandle<TaggedArray> argsArray = thread->GetEcmaVM()->GetFactory()->EmptyArray();
4843     JSTaggedValue result = builtins::BuiltinsFunction::FunctionPrototypeBindInternal(thread, target,
4844                                                                                      thisArg, argsArray);
4845     return result.GetRawData();
4846 }
4847 
4848 DEF_RUNTIME_STUBS(FunctionPrototypeCall)
4849 {
4850     RUNTIME_STUBS_HEADER(FunctionPrototypeCall);
4851     JSHandle<JSTaggedValue> thisFunc = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
4852     JSHandle<JSTaggedValue> thisArg = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
4853     if (!thisFunc->IsCallable()) {
4854         THROW_TYPE_ERROR_AND_RETURN(thread, "call target is not callable", JSTaggedValue::VALUE_EXCEPTION);
4855     }
4856     JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
4857     uint32_t argsLength = argc - 2;  // 2: thisFunc and thisArg
4858     EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, thisFunc, thisArg, undefined, argsLength);
4859     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::VALUE_EXCEPTION);
4860     uint32_t index = 0;
4861     for (uint32_t i = 2; i < argc; ++i) {  // 2: thisFunc and thisArg
4862         JSTaggedValue arg = GetArg(argv, argc, i);
4863         info->SetCallArg(index++, arg);
4864     }
4865     return JSFunction::Call(info).GetRawData();
4866 }
4867 
4868 DEF_RUNTIME_STUBS(GetCollationValueFromIcuCollator)
4869 {
4870     RUNTIME_STUBS_HEADER(GetCollationValueFromIcuCollator);
4871     JSHandle<JSCollator> collator = GetHArg<JSCollator>(argv, argc, 0);  // 0: means the zeroth parameter
4872 
4873     UErrorCode status = U_ZERO_ERROR;
4874     icu::Collator *icuCollator = collator->GetIcuCollator(thread);
4875     icu::Locale icu_locale(icuCollator->getLocale(ULOC_VALID_LOCALE, status));
4876     std::string collation_value =
4877         icu_locale.getUnicodeKeywordValue<std::string>("co", status);
4878     if (collation_value != "search" && collation_value != "") {
4879         return thread->GetEcmaVM()->GetFactory()->NewFromStdString(collation_value).GetTaggedValue().GetRawData();
4880     }
4881     return thread->GlobalConstants()->GetDefaultString().GetRawData();
4882 }
4883 
4884 DEF_RUNTIME_STUBS(GetAllFlagsInternal)
4885 {
4886     RUNTIME_STUBS_HEADER(GetAllFlagsInternal);
4887     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
4888 
4889     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
4890     uint64_t bigFlagsStr = static_cast<uint64_t>(value->GetInt());
4891     std::string strFlags = "";
4892     strFlags.reserve(RegExpParser::FLAG_NUM);
4893     if (bigFlagsStr & RegExpParser::FLAG_HASINDICES) {
4894         strFlags += "d";
4895     }
4896     if (bigFlagsStr & RegExpParser::FLAG_GLOBAL) {
4897         strFlags += "g";
4898     }
4899     if (bigFlagsStr & RegExpParser::FLAG_IGNORECASE) {
4900         strFlags += "i";
4901     }
4902     if (bigFlagsStr & RegExpParser::FLAG_MULTILINE) {
4903         strFlags += "m";
4904     }
4905     if (bigFlagsStr & RegExpParser::FLAG_DOTALL) {
4906         strFlags += "s";
4907     }
4908     if (bigFlagsStr & RegExpParser::FLAG_UTF16) {
4909         strFlags += "u";
4910     }
4911     if (bigFlagsStr & RegExpParser::FLAG_STICKY) {
4912         strFlags += "y";
4913     }
4914     JSHandle<EcmaString> flagsString = factory->NewFromUtf8(std::string_view(strFlags));
4915     return flagsString.GetTaggedValue().GetRawData();
4916 }
4917 
4918 DEF_RUNTIME_STUBS(SlowSharedObjectStoreBarrier)
4919 {
4920     RUNTIME_STUBS_HEADER(SlowSharedObjectStoreBarrier);
4921     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
4922     ASSERT(value->IsTreeString());
4923     JSHandle<JSTaggedValue> publishValue = JSTaggedValue::PublishSharedValueSlow(thread, value);
4924     return publishValue.GetTaggedValue().GetRawData();
4925 }
4926 
4927 void RuntimeStubs::CopyObjectPrimitive(uintptr_t argGlue, JSTaggedType *dstObj,
4928                                        JSTaggedType *dst, JSTaggedType *src, uint32_t count)
4929 {
4930     DISALLOW_GARBAGE_COLLECTION;
4931     auto thread = JSThread::GlueToJSThread(argGlue);
4932     // check CMC-GC phase inside
4933     if (thread->NeedReadBarrier()) {
4934         Barriers::CopyObjectPrimitive<true, true>(thread,
4935             reinterpret_cast<JSTaggedValue *>(dst), reinterpret_cast<JSTaggedValue *>(src), count);
4936     } else {
4937         Barriers::CopyObjectPrimitive<false, true>(thread,
4938             reinterpret_cast<JSTaggedValue *>(dst), reinterpret_cast<JSTaggedValue *>(src), count);
4939     }
4940 }
4941 
4942 void RuntimeStubs::ObjectCopy(uintptr_t argGlue, JSTaggedType *dstObj,
4943                               JSTaggedType *dst, JSTaggedType *src, uint32_t count)
4944 {
4945     DISALLOW_GARBAGE_COLLECTION;
4946     if (g_isEnableCMCGC) {
4947         auto thread = JSThread::GlueToJSThread(argGlue);
4948         // check CMC-GC phase inside
4949         Barriers::CopyObject<true, true>(thread, reinterpret_cast<TaggedObject *>(dstObj),
4950             reinterpret_cast<JSTaggedValue *>(dst), reinterpret_cast<JSTaggedValue *>(src), count);
4951     } else {
4952         (void)argGlue;
4953         std::copy_n(src, count, dst);
4954     }
4955 }
4956 
4957 void RuntimeStubs::ReverseArray(uintptr_t argGlue, JSTaggedType *dst, uint32_t length)
4958 {
4959     DISALLOW_GARBAGE_COLLECTION;
4960     if (g_isEnableCMCGC) {
4961         auto thread = JSThread::GlueToJSThread(argGlue);
4962         if (thread->NeedReadBarrier()) {
4963             for (uint32_t i = 0; i < length; i++) {
4964                 Barriers::UpdateSlot(thread, dst, i * sizeof(JSTaggedType));
4965             }
4966         }
4967     }
4968     std::reverse(dst, dst + length);
4969 }
4970 
4971 JSTaggedValue RuntimeStubs::FindPatchModule(uintptr_t argGlue, JSTaggedValue resolvedModule)
4972 {
4973     DISALLOW_GARBAGE_COLLECTION;
4974     auto thread = JSThread::GlueToJSThread(argGlue);
4975     JSHandle<SourceTextModule> module(thread, resolvedModule);
4976     return (thread->GetEcmaVM()->FindPatchModule(module->GetEcmaModuleRecordNameString())).GetTaggedValue();
4977 }
4978 
4979 JSTaggedValue RuntimeStubs::UpdateSharedModule(uintptr_t argGlue, JSTaggedValue resolvedModule)
4980 {
4981     DISALLOW_GARBAGE_COLLECTION;
4982     auto thread = JSThread::GlueToJSThread(argGlue);
4983     JSHandle<SourceTextModule> module(thread, resolvedModule);
4984     JSHandle<SourceTextModule> sharedModule =
4985         SharedModuleManager::GetInstance()->GetSModule(thread, module->GetEcmaModuleRecordNameString());
4986     if (sharedModule.GetTaggedValue().IsSourceTextModule()) {
4987         return sharedModule.GetTaggedValue();
4988     }
4989     return module.GetTaggedValue();
4990 }
4991 
4992 void RuntimeStubs::FatalPrintMisstakenResolvedBinding(int32_t index, JSTaggedValue curModule)
4993 {
4994     DISALLOW_GARBAGE_COLLECTION;
4995     JSThread *thread = JSThread::GetCurrent();
4996     std::ostringstream oss;
4997     curModule.Dump(thread, oss);
4998     LOG_ECMA(FATAL) << "Get module value failed, mistaken ResolvedBinding"
4999         << ", index: " << index << ", currentModule: " << oss.str();
5000     UNREACHABLE();
5001 }
5002 
5003 void RuntimeStubs::LoadNativeModuleFailed(JSTaggedValue curModule)
5004 {
5005     DISALLOW_GARBAGE_COLLECTION;
5006     LOG_FULL(WARN) << "Load native module failed, so is " << SourceTextModule::GetModuleName(curModule);
5007 }
5008 
5009 JSTaggedValue RuntimeStubs::GetExternalModuleVar(uintptr_t argGlue, JSFunction *jsFunc, int32_t index)
5010 {
5011     auto thread = JSThread::GlueToJSThread(argGlue);
5012     return ModuleManager::GetExternalModuleVarFastPathForJIT(thread, index, jsFunc);
5013 }
5014 
5015 bool RuntimeStubs::MarkRSetCardTable(BaseObject* obj)
5016 {
5017     common::RegionDesc* region = common::RegionDesc::GetAliveRegionDescAt(reinterpret_cast<common::MAddress>(obj));
5018     return region->MarkRSetCardTable(obj);
5019 }
5020 
5021 void RuntimeStubs::MarkInBuffer(BaseObject* ref)
5022 {
5023     ref = reinterpret_cast<BaseObject*>(reinterpret_cast<uintptr_t>(ref) & ~(common::Barrier::TAG_WEAK));
5024     common::Mutator* mutator = common::Mutator::GetMutator();
5025     mutator->RememberObjectInSatbBuffer(ref);
5026 }
5027 
5028 void RuntimeStubs::BatchMarkInBuffer(void* src, size_t count)
5029 {
5030     uintptr *srcPtr = reinterpret_cast<uintptr_t *>(src);
5031     common::Mutator* mutator = common::Mutator::GetMutator();
5032     for (size_t i = 0; i < count; i++) {
5033         BaseObject* ref = reinterpret_cast<BaseObject*>(srcPtr[i]);
5034         if (!common::Heap::IsTaggedObject(reinterpret_cast<common::HeapAddress>(ref))) {
5035             continue;
5036         }
5037         ref = reinterpret_cast<BaseObject*>(reinterpret_cast<uintptr_t>(ref) & ~(common::Barrier::TAG_WEAK));
5038         mutator->RememberObjectInSatbBuffer(ref);
5039     }
5040 }
5041 
5042 DEF_RUNTIME_STUBS(ComputeHashcode)
5043 {
5044     RUNTIME_STUBS_HEADER(ComputeHashcode);
5045     JSTaggedValue ecmaString = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
5046     auto string = EcmaString::Cast(ecmaString);
5047     uint32_t result = EcmaStringAccessor(string).ComputeHashcode(thread);
5048     return JSTaggedValue(static_cast<uint64_t>(result)).GetRawData();
5049 }
5050 
5051 void RuntimeStubs::Initialize(JSThread *thread)
5052 {
5053 #define DEF_RUNTIME_STUB(name) kungfu::RuntimeStubCSigns::ID_##name
5054 #define INITIAL_RUNTIME_FUNCTIONS(name) \
5055     thread->RegisterRTInterface(DEF_RUNTIME_STUB(name), reinterpret_cast<uintptr_t>(name));
5056     RUNTIME_STUB_WITHOUT_GC_LIST(INITIAL_RUNTIME_FUNCTIONS)
5057     RUNTIME_STUB_WITH_GC_LIST(INITIAL_RUNTIME_FUNCTIONS)
5058     RUNTIME_STUB_WITH_DFX(INITIAL_RUNTIME_FUNCTIONS)
5059     TEST_RUNTIME_STUB_GC_LIST(INITIAL_RUNTIME_FUNCTIONS)
5060 #undef INITIAL_RUNTIME_FUNCTIONS
5061 #undef DEF_RUNTIME_STUB
5062 }
5063 
5064 #if defined(__clang__)
5065 #pragma clang diagnostic pop
5066 #elif defined(__GNUC__)
5067 #pragma GCC diagnostic pop
5068 #endif
5069 }  // namespace panda::ecmascript
5070