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