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