• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ecmascript/log_wrapper.h"
17 #include "ecmascript/stubs/runtime_stubs-inl.h"
18 #include "ecmascript/accessor_data.h"
19 #include "ecmascript/base/number_helper.h"
20 #include "ecmascript/base/string_helper.h"
21 #include "ecmascript/compiler/builtins/containers_stub_builder.h"
22 #include "ecmascript/compiler/call_signature.h"
23 #include "ecmascript/compiler/ecma_opcode_des.h"
24 #include "ecmascript/compiler/rt_call_signature.h"
25 #include "ecmascript/deoptimizer/deoptimizer.h"
26 #include "ecmascript/dfx/vmstat/opt_code_profiler.h"
27 #include "ecmascript/ecma_macros.h"
28 #include "ecmascript/ecma_vm.h"
29 #include "ecmascript/frames.h"
30 #include "ecmascript/global_env.h"
31 #include "ecmascript/ic/ic_runtime.h"
32 #include "ecmascript/ic/profile_type_info.h"
33 #include "ecmascript/ic/properties_cache.h"
34 #include "ecmascript/interpreter/interpreter-inl.h"
35 #include "ecmascript/interpreter/interpreter_assembly.h"
36 #include "ecmascript/js_api/js_api_arraylist.h"
37 #include "ecmascript/js_date.h"
38 #include "ecmascript/js_function.h"
39 #include "ecmascript/js_object.h"
40 #include "ecmascript/js_proxy.h"
41 #include "ecmascript/js_thread.h"
42 #include "ecmascript/js_typed_array.h"
43 #include "ecmascript/jspandafile/program_object.h"
44 #include "ecmascript/layout_info.h"
45 #include "ecmascript/mem/space-inl.h"
46 #include "ecmascript/message_string.h"
47 #include "ecmascript/object_factory.h"
48 #include "ecmascript/pgo_profiler/pgo_profiler.h"
49 #include "ecmascript/tagged_dictionary.h"
50 #include "ecmascript/tagged_node.h"
51 #include "ecmascript/ts_types/ts_manager.h"
52 #include "libpandafile/bytecode_instruction-inl.h"
53 
54 namespace panda::ecmascript {
55 #if defined(__clang__)
56 #pragma clang diagnostic push
57 #pragma clang diagnostic ignored "-Wunused-parameter"
58 #elif defined(__GNUC__)
59 #pragma GCC diagnostic push
60 #pragma GCC diagnostic ignored "-Wunused-parameter"
61 #endif
62 
63 #define DEF_RUNTIME_STUBS(name) \
64     JSTaggedType RuntimeStubs::name(uintptr_t argGlue, uint32_t argc, uintptr_t argv)
65 
66 #define RUNTIME_STUBS_HEADER(name)                        \
67     auto thread = JSThread::GlueToJSThread(argGlue);      \
68     RUNTIME_TRACE(thread, name);                          \
69     [[maybe_unused]] EcmaHandleScope handleScope(thread)  \
70 
71 #define GET_ASM_FRAME(CurrentSp) \
72     (reinterpret_cast<AsmInterpretedFrame *>(CurrentSp) - 1) // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
73 
DEF_RUNTIME_STUBS(AddElementInternal)74 DEF_RUNTIME_STUBS(AddElementInternal)
75 {
76     RUNTIME_STUBS_HEADER(AddElementInternal);
77     JSHandle<JSObject> receiver = GetHArg<JSObject>(argv, argc, 0);  // 0: means the zeroth parameter
78     JSTaggedValue argIndex = GetArg(argv, argc, 1);  // 1: means the first parameter
79     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
80     JSTaggedValue argAttr = GetArg(argv, argc, 3);  // 3: means the third parameter
81     auto attr = static_cast<PropertyAttributes>(argAttr.GetInt());
82     auto result = JSObject::AddElementInternal(thread, receiver, argIndex.GetInt(), value, attr);
83     return JSTaggedValue(result).GetRawData();
84 }
85 
DEF_RUNTIME_STUBS(AllocateInYoung)86 DEF_RUNTIME_STUBS(AllocateInYoung)
87 {
88     RUNTIME_STUBS_HEADER(AllocateInYoung);
89     JSTaggedValue allocateSize = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
90     auto size = static_cast<size_t>(allocateSize.GetInt());
91     auto heap = const_cast<Heap*>(thread->GetEcmaVM()->GetHeap());
92     auto space = heap->GetNewSpace();
93     ASSERT(size <= MAX_REGULAR_HEAP_OBJECT_SIZE);
94     auto result = reinterpret_cast<TaggedObject *>(space->Allocate(size));
95     if (result == nullptr) {
96         result = heap->AllocateYoungOrHugeObject(size);
97         ASSERT(result != nullptr);
98     }
99     return JSTaggedValue(result).GetRawData();
100 }
101 
DEF_RUNTIME_STUBS(CallInternalGetter)102 DEF_RUNTIME_STUBS(CallInternalGetter)
103 {
104     RUNTIME_STUBS_HEADER(CallInternalGetter);
105     JSTaggedType argAccessor = GetTArg(argv, argc, 0);  // 0: means the zeroth parameter
106     JSHandle<JSObject> argReceiver = GetHArg<JSObject>(argv, argc, 1);  // 1: means the first parameter
107 
108     auto accessor = AccessorData::Cast(reinterpret_cast<TaggedObject *>(argAccessor));
109     return accessor->CallInternalGet(thread, argReceiver).GetRawData();
110 }
111 
DEF_RUNTIME_STUBS(CallInternalSetter)112 DEF_RUNTIME_STUBS(CallInternalSetter)
113 {
114     RUNTIME_STUBS_HEADER(CallInternalSetter);
115     JSHandle<JSObject> receiver = GetHArg<JSObject>(argv, argc, 0);  // 0: means the zeroth parameter
116     JSTaggedType argSetter = GetTArg(argv, argc, 1);  // 1: means the first parameter
117     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);
118     auto setter = AccessorData::Cast((reinterpret_cast<TaggedObject *>(argSetter)));
119     auto result = setter->CallInternalSet(thread, receiver, value, true);
120     if (!result) {
121         return JSTaggedValue::Exception().GetRawData();
122     }
123     return JSTaggedValue::Undefined().GetRawData();
124 }
125 
DEF_RUNTIME_STUBS(Dump)126 DEF_RUNTIME_STUBS(Dump)
127 {
128     RUNTIME_STUBS_HEADER(Dump);
129     JSTaggedValue value = GetArg(argv, argc, 0);
130     value.D();
131     std::cout << "======================================================" << std::endl;
132     return JSTaggedValue::Undefined().GetRawData();
133 }
134 
DEF_RUNTIME_STUBS(GetHash32)135 DEF_RUNTIME_STUBS(GetHash32)
136 {
137     JSTaggedValue argKey = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
138     JSTaggedValue len = GetArg(argv, argc, 1);  // 1: means the first parameter
139     int key = argKey.GetInt();
140     auto pkey = reinterpret_cast<uint8_t *>(&key);
141     uint32_t result = panda::GetHash32(pkey, len.GetInt());
142     return JSTaggedValue(static_cast<uint64_t>(result)).GetRawData();
143 }
144 
DEF_RUNTIME_STUBS(ComputeHashcode)145 DEF_RUNTIME_STUBS(ComputeHashcode)
146 {
147     JSTaggedType ecmaString = GetTArg(argv, argc, 0);  // 0: means the zeroth parameter
148     auto string = reinterpret_cast<EcmaString *>(ecmaString);
149     uint32_t result = EcmaStringAccessor(string).ComputeHashcode(0);
150     return JSTaggedValue(static_cast<uint64_t>(result)).GetRawData();
151 }
152 
PrintHeapReginInfo(uintptr_t argGlue)153 void RuntimeStubs::PrintHeapReginInfo(uintptr_t argGlue)
154 {
155     auto thread = JSThread::GlueToJSThread(argGlue);
156     thread->GetEcmaVM()->GetHeap()->GetNewSpace()->EnumerateRegions([](Region *current) {
157         LOG_ECMA(INFO) << "semispace region: " << current << std::endl;
158     });
159     thread->GetEcmaVM()->GetHeap()->GetOldSpace()->EnumerateRegions([](Region *current) {
160         LOG_ECMA(INFO) << "GetOldSpace region: " << current << std::endl;
161     });
162     thread->GetEcmaVM()->GetHeap()->GetNonMovableSpace()->EnumerateRegions([](Region *current) {
163         LOG_ECMA(INFO) << "GetNonMovableSpace region: " << current << std::endl;
164     });
165     thread->GetEcmaVM()->GetHeap()->GetMachineCodeSpace()->EnumerateRegions([](Region *current) {
166         LOG_ECMA(INFO) << "GetMachineCodeSpace region: " << current << std::endl;
167     });
168 }
169 
DEF_RUNTIME_STUBS(GetTaggedArrayPtrTest)170 DEF_RUNTIME_STUBS(GetTaggedArrayPtrTest)
171 {
172     RUNTIME_STUBS_HEADER(GetTaggedArrayPtrTest);
173     // this case static static JSHandle<TaggedArray> arr don't free in first call
174     // second call trigger gc.
175     // don't call EcmaHandleScope handleScope(thread);
176     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
177     JSTaggedType array = GetTArg(argv, argc, 0);  // 0: means the zeroth parameter
178     bool allocated = false;
179     if (array == JSTaggedValue::VALUE_UNDEFINED) {
180         // 2 : means construct 2 elements size taggedArray
181         JSHandle<TaggedArray> arr = factory->NewTaggedArray(2);
182         arr->Set(thread, 0, JSTaggedValue(3.5)); // 3.5: first element
183         arr->Set(thread, 1, JSTaggedValue(4.5)); // 4.5: second element
184         array = arr.GetTaggedValue().GetRawData();
185         allocated = true;
186     }
187     JSHandle<TaggedArray> arr1(thread, JSTaggedValue(array));
188 #ifndef NDEBUG
189     PrintHeapReginInfo(argGlue);
190 #endif
191     if (!allocated) {
192         thread->GetEcmaVM()->CollectGarbage(TriggerGCType::FULL_GC);
193     }
194     LOG_ECMA(INFO) << " arr->GetData() " << std::hex << "  " << arr1->GetData();
195     return arr1.GetTaggedValue().GetRawData();
196 }
197 
DEF_RUNTIME_STUBS(NewInternalString)198 DEF_RUNTIME_STUBS(NewInternalString)
199 {
200     RUNTIME_STUBS_HEADER(NewInternalString);
201     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
202     return JSTaggedValue(thread->GetEcmaVM()->GetFactory()->InternString(keyHandle)).GetRawData();
203 }
204 
DEF_RUNTIME_STUBS(NewTaggedArray)205 DEF_RUNTIME_STUBS(NewTaggedArray)
206 {
207     RUNTIME_STUBS_HEADER(NewTaggedArray);
208     JSTaggedValue length = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
209 
210     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
211     return factory->NewTaggedArray(length.GetInt()).GetTaggedValue().GetRawData();
212 }
213 
DEF_RUNTIME_STUBS(CopyArray)214 DEF_RUNTIME_STUBS(CopyArray)
215 {
216     RUNTIME_STUBS_HEADER(CopyArray);
217     JSHandle<TaggedArray> array = GetHArg<TaggedArray>(argv, argc, 0);  // 0: means the zeroth parameter
218     JSTaggedValue length = GetArg(argv, argc, 1);  // 1: means the first parameter
219     JSTaggedValue capacity = GetArg(argv, argc, 2);  // 2: means the second parameter
220 
221     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
222     return factory->CopyArray(array, length.GetInt(), capacity.GetInt()).GetTaggedValue().GetRawData();
223 }
224 
DEF_RUNTIME_STUBS(NameDictPutIfAbsent)225 DEF_RUNTIME_STUBS(NameDictPutIfAbsent)
226 {
227     RUNTIME_STUBS_HEADER(NameDictPutIfAbsent);
228     JSTaggedType receiver = GetTArg(argv, argc, 0);  // 0: means the zeroth parameter
229     JSTaggedType array = GetTArg(argv, argc, 1);  // 1: means the first parameter
230     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
231     JSHandle<JSTaggedValue> valueHandle = GetHArg<JSTaggedValue>(argv, argc, 3);  // 3: means the third parameter
232     JSTaggedValue attr = GetArg(argv, argc, 4);   // 4: means the fourth parameter
233     JSTaggedValue needTransToDict = GetArg(argv, argc, 5);  // 5: means the fifth parameter
234 
235     PropertyAttributes propAttr(attr.GetInt());
236     if (needTransToDict.IsTrue()) {
237         JSHandle<JSObject> objHandle(thread, JSTaggedValue(reinterpret_cast<TaggedObject *>(receiver)));
238         JSHandle<NameDictionary> dictHandle(JSObject::TransitionToDictionary(thread, objHandle));
239         return NameDictionary::
240             PutIfAbsent(thread, dictHandle, keyHandle, valueHandle, propAttr).GetTaggedValue().GetRawData();
241     } else {
242         JSHandle<NameDictionary> dictHandle(thread, JSTaggedValue(reinterpret_cast<TaggedObject *>(array)));
243         return NameDictionary::
244             PutIfAbsent(thread, dictHandle, keyHandle, valueHandle, propAttr).GetTaggedValue().GetRawData();
245     }
246 }
247 
DEF_RUNTIME_STUBS(PropertiesSetValue)248 DEF_RUNTIME_STUBS(PropertiesSetValue)
249 {
250     RUNTIME_STUBS_HEADER(PropertiesSetValue);
251     JSHandle<JSObject> objHandle = GetHArg<JSObject>(argv, argc, 0);  // 0: means the zeroth parameter
252     JSHandle<JSTaggedValue> valueHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
253     JSHandle<TaggedArray> arrayHandle = GetHArg<TaggedArray>(argv, argc, 2);   // 2: means the second parameter
254     JSTaggedValue taggedCapacity = GetArg(argv, argc, 3);
255     JSTaggedValue taggedIndex = GetArg(argv, argc, 4);
256     int capacity = taggedCapacity.GetInt();
257     int index = taggedIndex.GetInt();
258 
259     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
260     JSHandle<TaggedArray> properties;
261     if (capacity == 0) {
262         properties = factory->NewTaggedArray(JSObject::MIN_PROPERTIES_LENGTH);
263     } else {
264         properties = factory->CopyArray(arrayHandle, capacity, JSObject::ComputePropertyCapacity(capacity));
265     }
266     properties->Set(thread, index, valueHandle);
267     objHandle->SetProperties(thread, properties);
268     return JSTaggedValue::Hole().GetRawData();
269 }
270 
DEF_RUNTIME_STUBS(TaggedArraySetValue)271 DEF_RUNTIME_STUBS(TaggedArraySetValue)
272 {
273     RUNTIME_STUBS_HEADER(TaggedArraySetValue);
274     JSTaggedType argReceiver = GetTArg(argv, argc, 0);  // 0: means the zeroth parameter
275     JSTaggedValue value = GetArg(argv, argc, 1);  // 1: means the first parameter
276     JSTaggedType argElement = GetTArg(argv, argc, 2);  // 2: means the second parameter
277     JSTaggedValue taggedElementIndex = GetArg(argv, argc, 3);  // 3: means the third parameter
278     JSTaggedValue taggedCapacity = GetArg(argv, argc, 4);  // 4: means the fourth parameter
279 
280     int elementIndex = taggedElementIndex.GetInt();
281     int capacity = taggedCapacity.GetInt();
282     auto elements = reinterpret_cast<TaggedArray *>(argElement);
283     if (elementIndex >= capacity) {
284         if (JSObject::ShouldTransToDict(capacity, elementIndex)) {
285             return JSTaggedValue::Hole().GetRawData();
286         }
287         JSHandle<JSObject> receiverHandle(thread, reinterpret_cast<JSObject *>(argReceiver));
288         JSHandle<JSTaggedValue> valueHandle(thread, value);
289         elements = *JSObject::GrowElementsCapacity(thread, receiverHandle,
290                                                    JSObject::ComputeElementCapacity(elementIndex + 1));
291         receiverHandle->SetElements(thread, JSTaggedValue(elements));
292         elements->Set(thread, elementIndex, valueHandle);
293         return JSTaggedValue::Undefined().GetRawData();
294     }
295     elements->Set(thread, elementIndex, value);
296     return JSTaggedValue::Undefined().GetRawData();
297 }
298 
DEF_RUNTIME_STUBS(CheckAndCopyArray)299 DEF_RUNTIME_STUBS(CheckAndCopyArray)
300 {
301     RUNTIME_STUBS_HEADER(CheckAndCopyArray);
302     JSTaggedType argReceiver = GetTArg(argv, argc, 0);  // 0: means the zeroth parameter
303     JSHandle<JSArray> receiverHandle(thread, reinterpret_cast<JSArray *>(argReceiver));
304     JSArray::CheckAndCopyArray(thread, receiverHandle);
305     return JSTaggedValue::Hole().GetRawData();
306 }
307 
DEF_RUNTIME_STUBS(NewEcmaHClass)308 DEF_RUNTIME_STUBS(NewEcmaHClass)
309 {
310     RUNTIME_STUBS_HEADER(NewEcmaHClass);
311     JSTaggedValue size = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
312     JSTaggedValue type = GetArg(argv, argc, 1);  // 1: means the first parameter
313     JSTaggedValue inlinedProps = GetArg(argv, argc, 2);  // 2: means the second parameter
314     return (thread->GetEcmaVM()->GetFactory()->NewEcmaHClass(
315         size.GetInt(), JSType(type.GetInt()), inlinedProps.GetInt())).GetTaggedValue().GetRawData();
316 }
317 
DEF_RUNTIME_STUBS(UpdateLayOutAndAddTransition)318 DEF_RUNTIME_STUBS(UpdateLayOutAndAddTransition)
319 {
320     RUNTIME_STUBS_HEADER(UpdateLayOutAndAddTransition);
321     JSHandle<JSHClass> oldHClassHandle = GetHArg<JSHClass>(argv, argc, 0);  // 0: means the zeroth parameter
322     JSHandle<JSHClass> newHClassHandle = GetHArg<JSHClass>(argv, argc, 1);  // 1: means the first parameter
323     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
324     JSTaggedValue attr = GetArg(argv, argc, 3);  // 3: means the third parameter
325 
326     auto factory = thread->GetEcmaVM()->GetFactory();
327     PropertyAttributes attrValue(attr.GetInt());
328     uint32_t offset = attrValue.GetOffset();
329     newHClassHandle->IncNumberOfProps();
330 
331     {
332         JSMutableHandle<LayoutInfo> layoutInfoHandle(thread, newHClassHandle->GetLayout());
333 
334         if (layoutInfoHandle->NumberOfElements() != static_cast<int>(offset)) {
335             layoutInfoHandle.Update(factory->CopyAndReSort(layoutInfoHandle, offset, offset + 1));
336             newHClassHandle->SetLayout(thread, layoutInfoHandle);
337         } else if (layoutInfoHandle->GetPropertiesCapacity() <= static_cast<int>(offset)) {  // need to Grow
338             layoutInfoHandle.Update(
339                 factory->ExtendLayoutInfo(layoutInfoHandle, offset));
340             newHClassHandle->SetLayout(thread, layoutInfoHandle);
341         }
342         layoutInfoHandle->AddKey(thread, offset, keyHandle.GetTaggedValue(), attrValue);
343     }
344 
345     // 5. Add newClass to old hclass's transitions.
346     JSHClass::AddTransitions(thread, oldHClassHandle, newHClassHandle, keyHandle, attrValue);
347     return JSTaggedValue::Hole().GetRawData();
348 }
349 
DebugPrint(int fmtMessageId,...)350 void RuntimeStubs::DebugPrint(int fmtMessageId, ...)
351 {
352     std::string format = MessageString::GetMessageString(fmtMessageId);
353     va_list args;
354     va_start(args, fmtMessageId);
355     std::string result = base::StringHelper::Vformat(format.c_str(), args);
356     if (MessageString::IsBuiltinsStubMessageString(fmtMessageId)) {
357         LOG_BUILTINS(DEBUG) << result;
358     } else {
359         LOG_ECMA(DEBUG) << result;
360     }
361     va_end(args);
362 }
363 
DebugPrintInstruction(uintptr_t argGlue,const uint8_t * pc)364 void RuntimeStubs::DebugPrintInstruction([[maybe_unused]]uintptr_t argGlue, const uint8_t *pc)
365 {
366     BytecodeInstruction inst(pc);
367     LOG_INTERPRETER(DEBUG) << inst;
368 }
369 
PGOProfiler(uintptr_t argGlue,uintptr_t func)370 void RuntimeStubs::PGOProfiler(uintptr_t argGlue, uintptr_t func)
371 {
372     auto thread = JSThread::GlueToJSThread(argGlue);
373     thread->GetEcmaVM()->GetPGOProfiler()->Sample(func);
374 }
375 
FatalPrint(int fmtMessageId,...)376 void RuntimeStubs::FatalPrint(int fmtMessageId, ...)
377 {
378     std::string format = MessageString::GetMessageString(fmtMessageId);
379     va_list args;
380     va_start(args, fmtMessageId);
381     std::string result = base::StringHelper::Vformat(format.c_str(), args);
382     LOG_FULL(FATAL) << result;
383     va_end(args);
384     UNREACHABLE();
385 }
386 
DEF_RUNTIME_STUBS(NoticeThroughChainAndRefreshUser)387 DEF_RUNTIME_STUBS(NoticeThroughChainAndRefreshUser)
388 {
389     RUNTIME_STUBS_HEADER(NoticeThroughChainAndRefreshUser);
390     JSHandle<JSHClass> oldHClassHandle = GetHArg<JSHClass>(argv, argc, 0);  // 0: means the zeroth parameter
391     JSHandle<JSHClass> newHClassHandle = GetHArg<JSHClass>(argv, argc, 1);  // 1: means the first parameter
392 
393     JSHClass::NoticeThroughChain(thread, oldHClassHandle);
394     JSHClass::RefreshUsers(thread, oldHClassHandle, newHClassHandle);
395     return JSTaggedValue::Hole().GetRawData();
396 }
397 
DEF_RUNTIME_STUBS(Inc)398 DEF_RUNTIME_STUBS(Inc)
399 {
400     RUNTIME_STUBS_HEADER(Inc);
401     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
402     return RuntimeInc(thread, value).GetRawData();
403 }
404 
DEF_RUNTIME_STUBS(Dec)405 DEF_RUNTIME_STUBS(Dec)
406 {
407     RUNTIME_STUBS_HEADER(Dec);
408     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
409     return RuntimeDec(thread, value).GetRawData();
410 }
411 
DEF_RUNTIME_STUBS(CallGetPrototype)412 DEF_RUNTIME_STUBS(CallGetPrototype)
413 {
414     RUNTIME_STUBS_HEADER(CallGetPrototype);
415     JSHandle<JSProxy> proxy = GetHArg<JSProxy>(argv, argc, 0);  // 0: means the zeroth parameter
416 
417     return JSProxy::GetPrototype(thread, proxy).GetRawData();
418 }
419 
DEF_RUNTIME_STUBS(Exp)420 DEF_RUNTIME_STUBS(Exp)
421 {
422     RUNTIME_STUBS_HEADER(Exp);
423     JSTaggedValue baseValue = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
424     JSTaggedValue exponentValue = GetArg(argv, argc, 1);  // 1: means the first parameter
425 
426     if (baseValue.IsNumber() && exponentValue.IsNumber()) {
427         // fast path
428         double doubleBase = baseValue.IsInt() ? baseValue.GetInt() : baseValue.GetDouble();
429         double doubleExponent = exponentValue.IsInt() ? exponentValue.GetInt() : exponentValue.GetDouble();
430         if (std::abs(doubleBase) == 1 && std::isinf(doubleExponent)) {
431             return JSTaggedValue(base::NAN_VALUE).GetRawData();
432         }
433         if ((doubleBase == 0 &&
434             ((bit_cast<uint64_t>(doubleBase)) & base::DOUBLE_SIGN_MASK) == base::DOUBLE_SIGN_MASK) &&
435             std::isfinite(doubleExponent) && base::NumberHelper::TruncateDouble(doubleExponent) == doubleExponent &&
436             base::NumberHelper::TruncateDouble(doubleExponent / 2) + base::HALF ==  // 2 : half
437             (doubleExponent / 2)) {  // 2 : half
438             if (doubleExponent > 0) {
439                 return JSTaggedValue(-0.0).GetRawData();
440             }
441             if (doubleExponent < 0) {
442                 return JSTaggedValue(-base::POSITIVE_INFINITY).GetRawData();
443             }
444         }
445         return JSTaggedValue(std::pow(doubleBase, doubleExponent)).GetRawData();
446     }
447     // Slow path
448     JSTaggedValue res = RuntimeExp(thread, baseValue, exponentValue);
449     return res.GetRawData();
450 }
451 
DEF_RUNTIME_STUBS(IsIn)452 DEF_RUNTIME_STUBS(IsIn)
453 {
454     RUNTIME_STUBS_HEADER(IsIn);
455     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
456     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
457     return RuntimeIsIn(thread, prop, obj).GetRawData();
458 }
459 
DEF_RUNTIME_STUBS(InstanceOf)460 DEF_RUNTIME_STUBS(InstanceOf)
461 {
462     RUNTIME_STUBS_HEADER(InstanceOf);
463     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
464     JSHandle<JSTaggedValue> target = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
465     return RuntimeInstanceof(thread, obj, target).GetRawData();
466 }
467 
DEF_RUNTIME_STUBS(CreateGeneratorObj)468 DEF_RUNTIME_STUBS(CreateGeneratorObj)
469 {
470     RUNTIME_STUBS_HEADER(CreateGeneratorObj);
471     JSHandle<JSTaggedValue> genFunc = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
472     return RuntimeCreateGeneratorObj(thread, genFunc).GetRawData();
473 }
474 
DEF_RUNTIME_STUBS(CreateAsyncGeneratorObj)475 DEF_RUNTIME_STUBS(CreateAsyncGeneratorObj)
476 {
477     RUNTIME_STUBS_HEADER(CreateAsyncGeneratorObj);
478     JSHandle<JSTaggedValue> genFunc = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
479     return RuntimeCreateAsyncGeneratorObj(thread, genFunc).GetRawData();
480 }
481 
DEF_RUNTIME_STUBS(GetTemplateObject)482 DEF_RUNTIME_STUBS(GetTemplateObject)
483 {
484     RUNTIME_STUBS_HEADER(GetTemplateObject);
485     JSHandle<JSTaggedValue> literal = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
486     return RuntimeGetTemplateObject(thread, literal).GetRawData();
487 }
488 
DEF_RUNTIME_STUBS(GetNextPropName)489 DEF_RUNTIME_STUBS(GetNextPropName)
490 {
491     RUNTIME_STUBS_HEADER(GetNextPropName);
492     JSHandle<JSTaggedValue> iter = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
493     return RuntimeGetNextPropName(thread, iter).GetRawData();
494 }
495 
DEF_RUNTIME_STUBS(IterNext)496 DEF_RUNTIME_STUBS(IterNext)
497 {
498     RUNTIME_STUBS_HEADER(IterNext);
499     JSHandle<JSTaggedValue> iter = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
500     return RuntimeIterNext(thread, iter).GetRawData();
501 }
502 
DEF_RUNTIME_STUBS(CloseIterator)503 DEF_RUNTIME_STUBS(CloseIterator)
504 {
505     RUNTIME_STUBS_HEADER(CloseIterator);
506     JSHandle<JSTaggedValue> iter = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
507     return RuntimeCloseIterator(thread, iter).GetRawData();
508 }
509 
DEF_RUNTIME_STUBS(SuperCallSpread)510 DEF_RUNTIME_STUBS(SuperCallSpread)
511 {
512     RUNTIME_STUBS_HEADER(SuperCallSpread);
513     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
514     JSHandle<JSTaggedValue> array = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
515     auto sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
516     JSTaggedValue function = InterpreterAssembly::GetNewTarget(sp);
517     return RuntimeSuperCallSpread(thread, func, JSHandle<JSTaggedValue>(thread, function), array).GetRawData();
518 }
519 
DEF_RUNTIME_STUBS(OptSuperCallSpread)520 DEF_RUNTIME_STUBS(OptSuperCallSpread)
521 {
522     RUNTIME_STUBS_HEADER(OptSuperCallSpread);
523     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0);
524     JSHandle<JSTaggedValue> newTarget = GetHArg<JSTaggedValue>(argv, argc, 1);
525     JSHandle<JSTaggedValue> array = GetHArg<JSTaggedValue>(argv, argc, 2);
526     return RuntimeSuperCallSpread(thread, func, newTarget, array).GetRawData();
527 }
528 
DEF_RUNTIME_STUBS(DelObjProp)529 DEF_RUNTIME_STUBS(DelObjProp)
530 {
531     RUNTIME_STUBS_HEADER(DelObjProp);
532     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
533     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
534     return RuntimeDelObjProp(thread, obj, prop).GetRawData();
535 }
536 
DEF_RUNTIME_STUBS(NewObjApply)537 DEF_RUNTIME_STUBS(NewObjApply)
538 {
539     RUNTIME_STUBS_HEADER(NewObjApply);
540     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
541     JSHandle<JSTaggedValue> array = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
542     return RuntimeNewObjApply(thread, func, array).GetRawData();
543 }
544 
DEF_RUNTIME_STUBS(CreateIterResultObj)545 DEF_RUNTIME_STUBS(CreateIterResultObj)
546 {
547     RUNTIME_STUBS_HEADER(CreateIterResultObj);
548     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
549     JSTaggedValue flag = GetArg(argv, argc, 1);  // 1: means the first parameter
550     return RuntimeCreateIterResultObj(thread, value, flag).GetRawData();
551 }
552 
DEF_RUNTIME_STUBS(AsyncFunctionAwaitUncaught)553 DEF_RUNTIME_STUBS(AsyncFunctionAwaitUncaught)
554 {
555     RUNTIME_STUBS_HEADER(AsyncFunctionAwaitUncaught);
556     JSHandle<JSTaggedValue> asyncFuncObj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
557     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
558     return RuntimeAsyncFunctionAwaitUncaught(thread, asyncFuncObj, value).GetRawData();
559 }
560 
DEF_RUNTIME_STUBS(AsyncFunctionResolveOrReject)561 DEF_RUNTIME_STUBS(AsyncFunctionResolveOrReject)
562 {
563     RUNTIME_STUBS_HEADER(AsyncFunctionResolveOrReject);
564     JSHandle<JSTaggedValue> asyncFuncObj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
565     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
566     JSTaggedValue is_resolve = GetArg(argv, argc, 2);  // 2: means the second parameter
567     return RuntimeAsyncFunctionResolveOrReject(thread, asyncFuncObj, value, is_resolve.IsTrue()).GetRawData();
568 }
569 
DEF_RUNTIME_STUBS(AsyncGeneratorResolve)570 DEF_RUNTIME_STUBS(AsyncGeneratorResolve)
571 {
572     RUNTIME_STUBS_HEADER(AsyncGeneratorResolve);
573     JSHandle<JSTaggedValue> asyncGenerator = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
574     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
575     JSTaggedValue flag = GetArg(argv, argc, 2); // 2: means the second parameter
576     return RuntimeAsyncGeneratorResolve(thread, asyncGenerator, value, flag).GetRawData();
577 }
578 
DEF_RUNTIME_STUBS(AsyncGeneratorReject)579 DEF_RUNTIME_STUBS(AsyncGeneratorReject)
580 {
581     RUNTIME_STUBS_HEADER(AsyncGeneratorReject);
582     JSHandle<JSTaggedValue> asyncGenerator = GetHArg<JSTaggedValue>(argv, argc, 0);
583     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);
584     return RuntimeAsyncGeneratorReject(thread, asyncGenerator, value).GetRawData();
585 }
586 
DEF_RUNTIME_STUBS(SetGeneratorState)587 DEF_RUNTIME_STUBS(SetGeneratorState)
588 {
589     RUNTIME_STUBS_HEADER(SetGeneratorState);
590     JSHandle<JSTaggedValue> asyncGenerator = GetHArg<JSTaggedValue>(argv, argc, 0);
591     JSTaggedValue index = GetArg(argv, argc, 1);
592     RuntimeSetGeneratorState(thread, asyncGenerator, index.GetInt());
593     return JSTaggedValue::Hole().GetRawData();
594 }
595 
DEF_RUNTIME_STUBS(CopyDataProperties)596 DEF_RUNTIME_STUBS(CopyDataProperties)
597 {
598     RUNTIME_STUBS_HEADER(CopyDataProperties);
599     JSHandle<JSTaggedValue> dst = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
600     JSHandle<JSTaggedValue> src = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
601     return RuntimeCopyDataProperties(thread, dst, src).GetRawData();
602 }
603 
DEF_RUNTIME_STUBS(StArraySpread)604 DEF_RUNTIME_STUBS(StArraySpread)
605 {
606     RUNTIME_STUBS_HEADER(StArraySpread);
607     JSHandle<JSTaggedValue> dst = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
608     JSTaggedValue index = GetArg(argv, argc, 1);  // 1: means the first parameter
609     JSHandle<JSTaggedValue> src = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
610     return RuntimeStArraySpread(thread, dst, index, src).GetRawData();
611 }
612 
DEF_RUNTIME_STUBS(GetIteratorNext)613 DEF_RUNTIME_STUBS(GetIteratorNext)
614 {
615     RUNTIME_STUBS_HEADER(GetIteratorNext);
616     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
617     JSHandle<JSTaggedValue> method = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
618     return RuntimeGetIteratorNext(thread, obj, method).GetRawData();
619 }
620 
DEF_RUNTIME_STUBS(SetObjectWithProto)621 DEF_RUNTIME_STUBS(SetObjectWithProto)
622 {
623     RUNTIME_STUBS_HEADER(SetObjectWithProto);
624     JSHandle<JSTaggedValue> proto = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
625     JSHandle<JSObject> obj = GetHArg<JSObject>(argv, argc, 1);  // 1: means the first parameter
626     return RuntimeSetObjectWithProto(thread, proto, obj).GetRawData();
627 }
628 
DEF_RUNTIME_STUBS(LoadICByValue)629 DEF_RUNTIME_STUBS(LoadICByValue)
630 {
631     RUNTIME_STUBS_HEADER(LoadICByValue);
632     JSHandle<JSTaggedValue> profileTypeInfo = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
633     JSHandle<JSTaggedValue> receiver = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
634     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
635     JSTaggedValue slotId = GetArg(argv, argc, 3);  // 3: means the third parameter
636 
637     if (profileTypeInfo->IsUndefined()) {
638         return RuntimeLdObjByValue(thread, receiver, key, false, JSTaggedValue::Undefined()).GetRawData();
639     }
640     JSHandle<JSTaggedValue> propKey = JSTaggedValue::ToPropertyKey(thread, key);
641     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
642     LoadICRuntime icRuntime(thread, JSHandle<ProfileTypeInfo>::Cast(profileTypeInfo), slotId.GetInt(), ICKind::LoadIC);
643     return icRuntime.LoadMiss(receiver, propKey).GetRawData();
644 }
645 
DEF_RUNTIME_STUBS(StoreICByValue)646 DEF_RUNTIME_STUBS(StoreICByValue)
647 {
648     RUNTIME_STUBS_HEADER(StoreICByValue);
649     JSHandle<JSTaggedValue> profileTypeInfo = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
650     JSHandle<JSTaggedValue> receiver = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
651     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
652     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 3);  // 3: means the third parameter
653     JSTaggedValue slotId = GetArg(argv, argc, 4);   // 4: means the fourth parameter
654 
655     if (profileTypeInfo->IsUndefined()) {
656         return RuntimeStObjByValue(thread, receiver, key, value).GetRawData();
657     }
658     JSHandle<JSTaggedValue> propKey = JSTaggedValue::ToPropertyKey(thread, key);
659     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
660     StoreICRuntime icRuntime(thread, JSHandle<ProfileTypeInfo>::Cast(profileTypeInfo), slotId.GetInt(),
661                              ICKind::StoreIC);
662     return icRuntime.StoreMiss(receiver, propKey, value).GetRawData();
663 }
664 
DEF_RUNTIME_STUBS(StOwnByValue)665 DEF_RUNTIME_STUBS(StOwnByValue)
666 {
667     RUNTIME_STUBS_HEADER(StOwnByValue);
668     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
669     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
670     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
671 
672     return RuntimeStOwnByValue(thread, obj, key, value).GetRawData();
673 }
674 
DEF_RUNTIME_STUBS(LdSuperByValue)675 DEF_RUNTIME_STUBS(LdSuperByValue)
676 {
677     RUNTIME_STUBS_HEADER(LdSuperByValue);
678     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
679     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
680     auto sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
681     JSTaggedValue thisFunc = InterpreterAssembly::GetFunction(sp);
682     return RuntimeLdSuperByValue(thread, obj, key, thisFunc).GetRawData();
683 }
684 
DEF_RUNTIME_STUBS(OptLdSuperByValue)685 DEF_RUNTIME_STUBS(OptLdSuperByValue)
686 {
687     RUNTIME_STUBS_HEADER(OptLdSuperByValue);
688     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
689     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
690     JSTaggedValue thisFunc = GetArg(argv, argc, 2);  // 2: means the second parameter
691     return RuntimeLdSuperByValue(thread, obj, key, thisFunc).GetRawData();
692 }
693 
DEF_RUNTIME_STUBS(StSuperByValue)694 DEF_RUNTIME_STUBS(StSuperByValue)
695 {
696     RUNTIME_STUBS_HEADER(StSuperByValue);
697     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
698     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
699     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
700     auto sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
701     JSTaggedValue thisFunc = InterpreterAssembly::GetFunction(sp);
702     return RuntimeStSuperByValue(thread, obj, key, value, thisFunc).GetRawData();
703 }
704 
DEF_RUNTIME_STUBS(OptStSuperByValue)705 DEF_RUNTIME_STUBS(OptStSuperByValue)
706 {
707     RUNTIME_STUBS_HEADER(OptStSuperByValue);
708     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
709     JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
710     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
711     JSTaggedValue thisFunc = GetArg(argv, argc, 3);  // 3: means the third parameter
712     return RuntimeStSuperByValue(thread, obj, key, value, thisFunc).GetRawData();
713 }
714 
DEF_RUNTIME_STUBS(GetMethodFromCache)715 DEF_RUNTIME_STUBS(GetMethodFromCache)
716 {
717     RUNTIME_STUBS_HEADER(GetMethodFromCache);
718     JSHandle<JSTaggedValue> constpool = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
719     JSTaggedValue index = GetArg(argv, argc, 1);  // 1: means the first parameter
720     return ConstantPool::GetMethodFromCache(
721         thread, constpool.GetTaggedValue(), index.GetInt()).GetRawData();
722 }
723 
DEF_RUNTIME_STUBS(GetStringFromCache)724 DEF_RUNTIME_STUBS(GetStringFromCache)
725 {
726     RUNTIME_STUBS_HEADER(GetStringFromCache);
727     JSHandle<JSTaggedValue> constpool = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
728     JSTaggedValue index = GetArg(argv, argc, 1);  // 1: means the first parameter
729     return ConstantPool::GetStringFromCache(
730         thread, constpool.GetTaggedValue(), index.GetInt()).GetRawData();
731 }
732 
DEF_RUNTIME_STUBS(GetObjectLiteralFromCache)733 DEF_RUNTIME_STUBS(GetObjectLiteralFromCache)
734 {
735     RUNTIME_STUBS_HEADER(GetObjectLiteralFromCache);
736     JSHandle<JSTaggedValue> constpool = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
737     JSTaggedValue index = GetArg(argv, argc, 1);  // 1: means the first parameter
738     JSHandle<JSTaggedValue> module = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
739     return ConstantPool::GetLiteralFromCache<ConstPoolType::OBJECT_LITERAL>(
740         thread, constpool.GetTaggedValue(), index.GetInt(), module.GetTaggedValue()).GetRawData();
741 }
742 
DEF_RUNTIME_STUBS(GetArrayLiteralFromCache)743 DEF_RUNTIME_STUBS(GetArrayLiteralFromCache)
744 {
745     RUNTIME_STUBS_HEADER(GetArrayLiteralFromCache);
746     JSHandle<JSTaggedValue> constpool = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
747     JSTaggedValue index = GetArg(argv, argc, 1);  // 1: means the first parameter
748     JSHandle<JSTaggedValue> module = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
749     return ConstantPool::GetLiteralFromCache<ConstPoolType::ARRAY_LITERAL>(
750         thread, constpool.GetTaggedValue(), index.GetInt(), module.GetTaggedValue()).GetRawData();
751 }
752 
DEF_RUNTIME_STUBS(LdObjByIndex)753 DEF_RUNTIME_STUBS(LdObjByIndex)
754 {
755     RUNTIME_STUBS_HEADER(LdObjByIndex);
756     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
757     JSTaggedValue idx = GetArg(argv, argc, 1);  // 1: means the first parameter
758     JSTaggedValue callGetter = GetArg(argv, argc, 2);  // 2: means the second parameter
759     JSTaggedValue receiver = GetArg(argv, argc, 3);  // 3: means the third parameter
760     return RuntimeLdObjByIndex(thread, obj, idx.GetInt(), callGetter.IsTrue(), receiver).GetRawData();
761 }
762 
DEF_RUNTIME_STUBS(StObjByIndex)763 DEF_RUNTIME_STUBS(StObjByIndex)
764 {
765     RUNTIME_STUBS_HEADER(StObjByIndex);
766     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
767     JSTaggedValue idx = GetArg(argv, argc, 1);  // 1: means the first parameter
768     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
769     return RuntimeStObjByIndex(thread, obj, idx.GetInt(), value).GetRawData();
770 }
771 
DEF_RUNTIME_STUBS(StOwnByIndex)772 DEF_RUNTIME_STUBS(StOwnByIndex)
773 {
774     RUNTIME_STUBS_HEADER(StOwnByIndex);
775     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
776     JSHandle<JSTaggedValue> idx = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
777     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
778     return RuntimeStOwnByIndex(thread, obj, idx, value).GetRawData();
779 }
780 
DEF_RUNTIME_STUBS(StGlobalRecord)781 DEF_RUNTIME_STUBS(StGlobalRecord)
782 {
783     RUNTIME_STUBS_HEADER(StGlobalRecord);
784     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
785     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
786     JSTaggedValue isConst = GetArg(argv, argc, 2);
787     return RuntimeStGlobalRecord(thread, prop, value, isConst.IsTrue()).GetRawData();
788 }
789 
DEF_RUNTIME_STUBS(Neg)790 DEF_RUNTIME_STUBS(Neg)
791 {
792     RUNTIME_STUBS_HEADER(Neg);
793     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
794     return RuntimeNeg(thread, value).GetRawData();
795 }
796 
DEF_RUNTIME_STUBS(Not)797 DEF_RUNTIME_STUBS(Not)
798 {
799     RUNTIME_STUBS_HEADER(Not);
800     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
801     return RuntimeNot(thread, value).GetRawData();
802 }
803 
DEF_RUNTIME_STUBS(Shl2)804 DEF_RUNTIME_STUBS(Shl2)
805 {
806     RUNTIME_STUBS_HEADER(Shl2);
807     JSTaggedValue left = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
808     JSTaggedValue right = GetArg(argv, argc, 1);  // 1: means the first parameter
809 
810     auto res = SlowRuntimeStub::Shl2(thread, left, right);
811     return JSTaggedValue(res).GetRawData();
812 }
813 
DEF_RUNTIME_STUBS(Shr2)814 DEF_RUNTIME_STUBS(Shr2)
815 {
816     RUNTIME_STUBS_HEADER(Shr2);
817     JSTaggedValue left = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
818     JSTaggedValue right = GetArg(argv, argc, 1);  // 1: means the first parameter
819 
820     auto res = SlowRuntimeStub::Shr2(thread, left, right);
821     return JSTaggedValue(res).GetRawData();
822 }
823 
DEF_RUNTIME_STUBS(Ashr2)824 DEF_RUNTIME_STUBS(Ashr2)
825 {
826     RUNTIME_STUBS_HEADER(Ashr2);
827     JSTaggedValue left = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
828     JSTaggedValue right = GetArg(argv, argc, 1);  // 1: means the first parameter
829 
830     auto res = SlowRuntimeStub::Ashr2(thread, left, right);
831     return JSTaggedValue(res).GetRawData();
832 }
833 
DEF_RUNTIME_STUBS(And2)834 DEF_RUNTIME_STUBS(And2)
835 {
836     RUNTIME_STUBS_HEADER(And2);
837     JSTaggedValue left = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
838     JSTaggedValue right = GetArg(argv, argc, 1);  // 1: means the first parameter
839 
840     auto res = SlowRuntimeStub::And2(thread, left, right);
841     return JSTaggedValue(res).GetRawData();
842 }
843 
DEF_RUNTIME_STUBS(Xor2)844 DEF_RUNTIME_STUBS(Xor2)
845 {
846     RUNTIME_STUBS_HEADER(Xor2);
847     JSTaggedValue left = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
848     JSTaggedValue right = GetArg(argv, argc, 1);  // 1: means the first parameter
849 
850     auto res = SlowRuntimeStub::Xor2(thread, left, right);
851     return JSTaggedValue(res).GetRawData();
852 }
853 
DEF_RUNTIME_STUBS(Or2)854 DEF_RUNTIME_STUBS(Or2)
855 {
856     RUNTIME_STUBS_HEADER(Or2);
857     JSTaggedValue left = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
858     JSTaggedValue right = GetArg(argv, argc, 1);  // 1: means the first parameter
859 
860     auto res = SlowRuntimeStub::Or2(thread, left, right);
861     return JSTaggedValue(res).GetRawData();
862 }
863 
DEF_RUNTIME_STUBS(CreateClassWithBuffer)864 DEF_RUNTIME_STUBS(CreateClassWithBuffer)
865 {
866     RUNTIME_STUBS_HEADER(CreateClassWithBuffer);
867     JSHandle<JSTaggedValue> base = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
868     JSHandle<JSTaggedValue> lexenv = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
869     JSHandle<JSTaggedValue> constpool = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
870     JSTaggedValue methodId = GetArg(argv, argc, 3);  // 3: means the third parameter
871     JSTaggedValue literalId = GetArg(argv, argc, 4);  // 4: means the four parameter
872     JSHandle<JSTaggedValue> module =  GetHArg<JSTaggedValue>(argv, argc, 5);  // 5: means the fifth parameter
873     return RuntimeCreateClassWithBuffer(thread, base, lexenv, constpool,
874                                         static_cast<uint16_t>(methodId.GetInt()),
875                                         static_cast<uint16_t>(literalId.GetInt()), module).GetRawData();
876 }
877 
DEF_RUNTIME_STUBS(CreateClassWithIHClass)878 DEF_RUNTIME_STUBS(CreateClassWithIHClass)
879 {
880     RUNTIME_STUBS_HEADER(CreateClassWithIHClass);
881     JSHandle<JSTaggedValue> base = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
882     JSHandle<JSTaggedValue> lexenv = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
883     JSHandle<JSTaggedValue> constpool = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
884     JSTaggedValue methodId = GetArg(argv, argc, 3);  // 3: means the third parameter
885     JSTaggedValue literalId = GetArg(argv, argc, 4);  // 4: means the four parameter
886     JSHandle<JSHClass> ihclass = GetHArg<JSHClass>(argv, argc, 5);  // 5: means the fifth parameter
887     JSHandle<JSTaggedValue> module = GetHArg<JSTaggedValue>(argv, argc, 6);  // 6: means the sixth parameter
888     return RuntimeCreateClassWithIHClass(thread, base, lexenv, constpool,
889                                          static_cast<uint16_t>(methodId.GetInt()),
890                                          static_cast<uint16_t>(literalId.GetInt()),
891                                          ihclass, module).GetRawData();
892 }
893 
DEF_RUNTIME_STUBS(SetClassConstructorLength)894 DEF_RUNTIME_STUBS(SetClassConstructorLength)
895 {
896     RUNTIME_STUBS_HEADER(SetClassConstructorLength);
897     JSTaggedValue ctor = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
898     JSTaggedValue length = GetArg(argv, argc, 1);  // 1: means the first parameter
899     return RuntimeSetClassConstructorLength(thread, ctor, length).GetRawData();
900 }
901 
902 
DEF_RUNTIME_STUBS(UpdateHotnessCounter)903 DEF_RUNTIME_STUBS(UpdateHotnessCounter)
904 {
905     RUNTIME_STUBS_HEADER(UpdateHotnessCounter);
906     JSHandle<JSFunction> thisFunc = GetHArg<JSFunction>(argv, argc, 0);  // 0: means the zeroth parameter
907     thread->CheckSafepoint();
908     JSHandle<Method> method(thread, thisFunc->GetMethod());
909     auto profileTypeInfo = method->GetProfileTypeInfo();
910     if (profileTypeInfo == JSTaggedValue::Undefined()) {
911         if (thread->IsPGOProfilerEnable()) {
912             thread->GetEcmaVM()->GetPGOProfiler()->Sample(thisFunc.GetTaggedType(), SampleMode::HOTNESS_MODE);
913         }
914         uint32_t slotSize = method->GetSlotSize();
915         auto res = RuntimeNotifyInlineCache(thread, method, slotSize);
916         return res.GetRawData();
917     }
918     return profileTypeInfo.GetRawData();
919 }
920 
DEF_RUNTIME_STUBS(LoadICByName)921 DEF_RUNTIME_STUBS(LoadICByName)
922 {
923     RUNTIME_STUBS_HEADER(LoadICByName);
924     JSHandle<JSTaggedValue> profileHandle = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
925     JSHandle<JSTaggedValue> receiverHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
926     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
927     JSTaggedValue slotId = GetArg(argv, argc, 3);  // 3: means the third parameter
928 
929     if (profileHandle->IsUndefined()) {
930         auto res = JSTaggedValue::GetProperty(thread, receiverHandle, keyHandle).GetValue().GetTaggedValue();
931         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
932         return res.GetRawData();
933     }
934     LoadICRuntime icRuntime(
935         thread, JSHandle<ProfileTypeInfo>::Cast(profileHandle), slotId.GetInt(), ICKind::NamedLoadIC);
936     return icRuntime.LoadMiss(receiverHandle, keyHandle).GetRawData();
937 }
938 
DEF_RUNTIME_STUBS(TryLdGlobalICByName)939 DEF_RUNTIME_STUBS(TryLdGlobalICByName)
940 {
941     RUNTIME_STUBS_HEADER(TryLdGlobalICByName);
942     JSHandle<JSTaggedValue> profileHandle = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
943     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
944     JSTaggedValue slotId = GetArg(argv, argc, 2);  // 2: means the third parameter
945 
946     EcmaVM *ecmaVm = thread->GetEcmaVM();
947     JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
948     JSHandle<JSTaggedValue> globalObj(thread, globalEnv->GetGlobalObject());
949     if (profileHandle->IsUndefined()) {
950         auto res = RuntimeTryLdGlobalByName(thread, globalObj, keyHandle);
951         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
952         return res.GetRawData();
953     }
954     LoadICRuntime icRuntime(
955         thread, JSHandle<ProfileTypeInfo>::Cast(profileHandle), slotId.GetInt(), ICKind::NamedGlobalTryLoadIC);
956     return icRuntime.LoadMiss(globalObj, keyHandle).GetRawData();
957 }
958 
DEF_RUNTIME_STUBS(StoreICByName)959 DEF_RUNTIME_STUBS(StoreICByName)
960 {
961     RUNTIME_STUBS_HEADER(StoreICByName);
962     JSHandle<JSTaggedValue> profileHandle = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
963     JSHandle<JSTaggedValue> receiverHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
964     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
965     JSHandle<JSTaggedValue> valueHandle = GetHArg<JSTaggedValue>(argv, argc, 3);  // 3: means the third parameter
966     JSTaggedValue slotId = GetArg(argv, argc, 4);   // 4: means the fourth parameter
967 
968     if (profileHandle->IsUndefined()) {
969         JSTaggedValue::SetProperty(thread, receiverHandle, keyHandle, valueHandle, true);
970         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
971         return JSTaggedValue::True().GetRawData();
972     }
973     StoreICRuntime icRuntime(
974         thread, JSHandle<ProfileTypeInfo>::Cast(profileHandle), slotId.GetInt(), ICKind::NamedStoreIC);
975     return icRuntime.StoreMiss(receiverHandle, keyHandle, valueHandle).GetRawData();
976 }
977 
DEF_RUNTIME_STUBS(SetFunctionNameNoPrefix)978 DEF_RUNTIME_STUBS(SetFunctionNameNoPrefix)
979 {
980     RUNTIME_STUBS_HEADER(SetFunctionNameNoPrefix);
981     JSTaggedType argFunc = GetTArg(argv, argc, 0);  // 0: means the zeroth parameter
982     JSTaggedValue argName = GetArg(argv, argc, 1);  // 1: means the first parameter
983     JSFunction::SetFunctionNameNoPrefix(thread, reinterpret_cast<JSFunction *>(argFunc), argName);
984     return JSTaggedValue::Hole().GetRawData();
985 }
986 
DEF_RUNTIME_STUBS(StOwnByValueWithNameSet)987 DEF_RUNTIME_STUBS(StOwnByValueWithNameSet)
988 {
989     RUNTIME_STUBS_HEADER(StOwnByValueWithNameSet);
990     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
991     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
992     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
993     return RuntimeStOwnByValueWithNameSet(thread, obj, prop, value).GetRawData();
994 }
995 
DEF_RUNTIME_STUBS(StOwnByName)996 DEF_RUNTIME_STUBS(StOwnByName)
997 {
998     RUNTIME_STUBS_HEADER(StOwnByName);
999     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1000     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1001     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1002     return RuntimeStOwnByName(thread, obj, prop, value).GetRawData();
1003 }
1004 
DEF_RUNTIME_STUBS(StOwnByNameWithNameSet)1005 DEF_RUNTIME_STUBS(StOwnByNameWithNameSet)
1006 {
1007     RUNTIME_STUBS_HEADER(StOwnByNameWithNameSet);
1008     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1009     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1010     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1011     return RuntimeStOwnByValueWithNameSet(thread, obj, prop, value).GetRawData();
1012 }
1013 
DEF_RUNTIME_STUBS(SuspendGenerator)1014 DEF_RUNTIME_STUBS(SuspendGenerator)
1015 {
1016     RUNTIME_STUBS_HEADER(SuspendGenerator);
1017     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1018     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1019     return RuntimeSuspendGenerator(thread, obj, value).GetRawData();
1020 }
1021 
DEF_RUNTIME_STUBS(OptSuspendGenerator)1022 DEF_RUNTIME_STUBS(OptSuspendGenerator)
1023 {
1024     RUNTIME_STUBS_HEADER(OptSuspendGenerator);
1025     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1026     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1027     return RuntimeOptSuspendGenerator(thread, obj, value).GetRawData();
1028 }
1029 
DEF_RUNTIME_STUBS(UpFrame)1030 DEF_RUNTIME_STUBS(UpFrame)
1031 {
1032     RUNTIME_STUBS_HEADER(UpFrame);
1033     FrameHandler frameHandler(thread);
1034     uint32_t pcOffset = panda_file::INVALID_OFFSET;
1035     for (; frameHandler.HasFrame(); frameHandler.PrevJSFrame()) {
1036         if (frameHandler.IsEntryFrame() || frameHandler.IsBuiltinFrame()) {
1037             thread->SetCurrentFrame(frameHandler.GetSp());
1038             thread->SetLastFp(frameHandler.GetFp());
1039             return JSTaggedValue(static_cast<uint64_t>(0)).GetRawData();
1040         }
1041         auto method = frameHandler.GetMethod();
1042         pcOffset = InterpreterAssembly::FindCatchBlock(method, frameHandler.GetBytecodeOffset());
1043         if (pcOffset != panda_file::INVALID_OFFSET) {
1044             thread->SetCurrentFrame(frameHandler.GetSp());
1045             thread->SetLastFp(frameHandler.GetFp());
1046             uintptr_t pc = reinterpret_cast<uintptr_t>(method->GetBytecodeArray() + pcOffset);
1047             return JSTaggedValue(static_cast<uint64_t>(pc)).GetRawData();
1048         }
1049     }
1050     return JSTaggedValue(static_cast<uint64_t>(0)).GetRawData();
1051 }
1052 
DEF_RUNTIME_STUBS(GetModuleNamespaceByIndex)1053 DEF_RUNTIME_STUBS(GetModuleNamespaceByIndex)
1054 {
1055     RUNTIME_STUBS_HEADER(GetModuleNamespaceByIndex);
1056     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1057     return RuntimeGetModuleNamespace(thread, index.GetInt()).GetRawData();
1058 }
1059 
DEF_RUNTIME_STUBS(GetModuleNamespaceByIndexOnJSFunc)1060 DEF_RUNTIME_STUBS(GetModuleNamespaceByIndexOnJSFunc)
1061 {
1062     RUNTIME_STUBS_HEADER(GetModuleNamespaceByIndexOnJSFunc);
1063     JSTaggedValue index = GetArg(argv, argc, 0);
1064     JSTaggedValue jsFunc = GetArg(argv, argc, 1);
1065     return RuntimeGetModuleNamespace(thread, index.GetInt(), jsFunc).GetRawData();
1066 }
1067 
DEF_RUNTIME_STUBS(GetModuleNamespace)1068 DEF_RUNTIME_STUBS(GetModuleNamespace)
1069 {
1070     RUNTIME_STUBS_HEADER(GetModuleNamespace);
1071     JSTaggedValue localName = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1072     return RuntimeGetModuleNamespace(thread, localName).GetRawData();
1073 }
1074 
DEF_RUNTIME_STUBS(StModuleVarByIndex)1075 DEF_RUNTIME_STUBS(StModuleVarByIndex)
1076 {
1077     RUNTIME_STUBS_HEADER(StModuleVar);
1078     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1079     JSTaggedValue value = GetArg(argv, argc, 1);  // 1: means the first parameter
1080     RuntimeStModuleVar(thread, index.GetInt(), value);
1081     return JSTaggedValue::Hole().GetRawData();
1082 }
1083 
DEF_RUNTIME_STUBS(StModuleVarByIndexOnJSFunc)1084 DEF_RUNTIME_STUBS(StModuleVarByIndexOnJSFunc)
1085 {
1086     RUNTIME_STUBS_HEADER(StModuleVarByIndexOnJSFunc);
1087     JSTaggedValue index = GetArg(argv, argc, 0);
1088     JSTaggedValue value = GetArg(argv, argc, 1);
1089     JSTaggedValue jsFunc = GetArg(argv, argc, 2);
1090     RuntimeStModuleVar(thread, index.GetInt(), value, jsFunc);
1091     return JSTaggedValue::Hole().GetRawData();
1092 }
1093 
DEF_RUNTIME_STUBS(StModuleVar)1094 DEF_RUNTIME_STUBS(StModuleVar)
1095 {
1096     RUNTIME_STUBS_HEADER(StModuleVar);
1097     JSTaggedValue key = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1098     JSTaggedValue value = GetArg(argv, argc, 1);  // 1: means the first parameter
1099     RuntimeStModuleVar(thread, key, value);
1100     return JSTaggedValue::Hole().GetRawData();
1101 }
1102 
DEF_RUNTIME_STUBS(LdLocalModuleVarByIndex)1103 DEF_RUNTIME_STUBS(LdLocalModuleVarByIndex)
1104 {
1105     RUNTIME_STUBS_HEADER(LdLocalModuleVarByIndex);
1106     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1107     return RuntimeLdLocalModuleVar(thread, index.GetInt()).GetRawData();
1108 }
1109 
DEF_RUNTIME_STUBS(LdExternalModuleVarByIndex)1110 DEF_RUNTIME_STUBS(LdExternalModuleVarByIndex)
1111 {
1112     RUNTIME_STUBS_HEADER(LdExternalModuleVarByIndex);
1113     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1114     return RuntimeLdExternalModuleVar(thread, index.GetInt()).GetRawData();
1115 }
1116 
DEF_RUNTIME_STUBS(LdLocalModuleVarByIndexOnJSFunc)1117 DEF_RUNTIME_STUBS(LdLocalModuleVarByIndexOnJSFunc)
1118 {
1119     RUNTIME_STUBS_HEADER(LdLocalModuleVarByIndexOnJSFunc);
1120     JSTaggedValue index = GetArg(argv, argc, 0);
1121     JSTaggedValue jsFunc = GetArg(argv, argc, 1);
1122     return RuntimeLdLocalModuleVar(thread, index.GetInt(), jsFunc).GetRawData();
1123 }
1124 
DEF_RUNTIME_STUBS(LdExternalModuleVarByIndexOnJSFunc)1125 DEF_RUNTIME_STUBS(LdExternalModuleVarByIndexOnJSFunc)
1126 {
1127     RUNTIME_STUBS_HEADER(LdExternalModuleVarByIndexOnJSFunc);
1128     JSTaggedValue index = GetArg(argv, argc, 0);
1129     JSTaggedValue jsFunc = GetArg(argv, argc, 1);
1130     return RuntimeLdExternalModuleVar(thread, index.GetInt(), jsFunc).GetRawData();
1131 }
1132 
DEF_RUNTIME_STUBS(LdModuleVar)1133 DEF_RUNTIME_STUBS(LdModuleVar)
1134 {
1135     RUNTIME_STUBS_HEADER(LdModuleVar);
1136     JSTaggedValue key = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1137     JSTaggedValue taggedFlag = GetArg(argv, argc, 1);  // 1: means the first parameter
1138     bool innerFlag = taggedFlag.GetInt() != 0;
1139     return RuntimeLdModuleVar(thread, key, innerFlag).GetRawData();
1140 }
1141 
DEF_RUNTIME_STUBS(GetPropIterator)1142 DEF_RUNTIME_STUBS(GetPropIterator)
1143 {
1144     RUNTIME_STUBS_HEADER(GetPropIterator);
1145     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1146     return RuntimeGetPropIterator(thread, value).GetRawData();
1147 }
1148 
DEF_RUNTIME_STUBS(AsyncFunctionEnter)1149 DEF_RUNTIME_STUBS(AsyncFunctionEnter)
1150 {
1151     RUNTIME_STUBS_HEADER(AsyncFunctionEnter);
1152     return RuntimeAsyncFunctionEnter(thread).GetRawData();
1153 }
1154 
DEF_RUNTIME_STUBS(GetIterator)1155 DEF_RUNTIME_STUBS(GetIterator)
1156 {
1157     RUNTIME_STUBS_HEADER(GetIterator);
1158     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1159     return RuntimeGetIterator(thread, obj).GetRawData();
1160 }
1161 
DEF_RUNTIME_STUBS(GetAsyncIterator)1162 DEF_RUNTIME_STUBS(GetAsyncIterator)
1163 {
1164     RUNTIME_STUBS_HEADER(GetAsyncIterator);
1165     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1166     return RuntimeGetAsyncIterator(thread, obj).GetRawData();
1167 }
1168 
DEF_RUNTIME_STUBS(Throw)1169 DEF_RUNTIME_STUBS(Throw)
1170 {
1171     RUNTIME_STUBS_HEADER(Throw);
1172     JSTaggedValue value = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1173     RuntimeThrow(thread, value);
1174     return JSTaggedValue::Hole().GetRawData();
1175 }
1176 
DEF_RUNTIME_STUBS(ThrowThrowNotExists)1177 DEF_RUNTIME_STUBS(ThrowThrowNotExists)
1178 {
1179     RUNTIME_STUBS_HEADER(ThrowThrowNotExists);
1180     RuntimeThrowThrowNotExists(thread);
1181     return JSTaggedValue::Hole().GetRawData();
1182 }
1183 
DEF_RUNTIME_STUBS(ThrowPatternNonCoercible)1184 DEF_RUNTIME_STUBS(ThrowPatternNonCoercible)
1185 {
1186     RUNTIME_STUBS_HEADER(ThrowPatternNonCoercible);
1187     RuntimeThrowPatternNonCoercible(thread);
1188     return JSTaggedValue::Hole().GetRawData();
1189 }
1190 
DEF_RUNTIME_STUBS(ThrowDeleteSuperProperty)1191 DEF_RUNTIME_STUBS(ThrowDeleteSuperProperty)
1192 {
1193     RUNTIME_STUBS_HEADER(ThrowDeleteSuperProperty);
1194     RuntimeThrowDeleteSuperProperty(thread);
1195     return JSTaggedValue::Hole().GetRawData();
1196 }
1197 
DEF_RUNTIME_STUBS(ThrowUndefinedIfHole)1198 DEF_RUNTIME_STUBS(ThrowUndefinedIfHole)
1199 {
1200     RUNTIME_STUBS_HEADER(ThrowUndefinedIfHole);
1201     JSHandle<EcmaString> obj = GetHArg<EcmaString>(argv, argc, 0);  // 0: means the zeroth parameter
1202     RuntimeThrowUndefinedIfHole(thread, obj);
1203     return JSTaggedValue::Hole().GetRawData();
1204 }
1205 
DEF_RUNTIME_STUBS(ThrowIfNotObject)1206 DEF_RUNTIME_STUBS(ThrowIfNotObject)
1207 {
1208     RUNTIME_STUBS_HEADER(ThrowIfNotObject);
1209     RuntimeThrowIfNotObject(thread);
1210     return JSTaggedValue::Hole().GetRawData();
1211 }
1212 
DEF_RUNTIME_STUBS(ThrowConstAssignment)1213 DEF_RUNTIME_STUBS(ThrowConstAssignment)
1214 {
1215     RUNTIME_STUBS_HEADER(ThrowConstAssignment);
1216     JSHandle<EcmaString> value = GetHArg<EcmaString>(argv, argc, 0);  // 0: means the zeroth parameter
1217     RuntimeThrowConstAssignment(thread, value);
1218     return JSTaggedValue::Hole().GetRawData();
1219 }
1220 
DEF_RUNTIME_STUBS(ThrowTypeError)1221 DEF_RUNTIME_STUBS(ThrowTypeError)
1222 {
1223     RUNTIME_STUBS_HEADER(ThrowTypeError);
1224     JSTaggedValue argMessageStringId = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1225     std::string message = MessageString::GetMessageString(argMessageStringId.GetInt());
1226     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1227     JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR, message.c_str());
1228     THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error.GetTaggedValue(), JSTaggedValue::Hole().GetRawData());
1229 }
1230 
DEF_RUNTIME_STUBS(LoadMiss)1231 DEF_RUNTIME_STUBS(LoadMiss)
1232 {
1233     RUNTIME_STUBS_HEADER(LoadMiss);
1234     JSTaggedType profileTypeInfo = GetTArg(argv, argc, 0);  // 0: means the zeroth parameter
1235     JSTaggedValue receiver = GetArg(argv, argc, 1);  // 1: means the first parameter
1236     JSTaggedValue key = GetArg(argv, argc, 2);  // 2: means the second parameter
1237     JSTaggedValue slotId = GetArg(argv, argc, 3);  // 3: means the third parameter
1238     JSTaggedValue kind = GetArg(argv, argc, 4);   // 4: means the fourth parameter
1239     return ICRuntimeStub::LoadMiss(thread, reinterpret_cast<ProfileTypeInfo *>(profileTypeInfo), receiver, key,
1240         slotId.GetInt(), static_cast<ICKind>(kind.GetInt())).GetRawData();
1241 }
1242 
DEF_RUNTIME_STUBS(StoreMiss)1243 DEF_RUNTIME_STUBS(StoreMiss)
1244 {
1245     RUNTIME_STUBS_HEADER(StoreMiss);
1246     JSTaggedType profileTypeInfo = GetTArg(argv, argc, 0);  // 0: means the zeroth parameter
1247     JSTaggedValue receiver = GetArg(argv, argc, 1);  // 1: means the first parameter
1248     JSTaggedValue key = GetArg(argv, argc, 2);  // 2: means the second parameter
1249     JSTaggedValue value = GetArg(argv, argc, 3);  // 3: means the third parameter
1250     JSTaggedValue slotId = GetArg(argv, argc, 4);  // 4: means the fourth parameter
1251     JSTaggedValue kind = GetArg(argv, argc, 5);  // 5: means the fifth parameter
1252     return ICRuntimeStub::StoreMiss(thread, reinterpret_cast<ProfileTypeInfo *>(profileTypeInfo), receiver, key, value,
1253         slotId.GetInt(), static_cast<ICKind>(kind.GetInt())).GetRawData();
1254 }
1255 
DEF_RUNTIME_STUBS(TryUpdateGlobalRecord)1256 DEF_RUNTIME_STUBS(TryUpdateGlobalRecord)
1257 {
1258     RUNTIME_STUBS_HEADER(TryUpdateGlobalRecord);
1259     JSTaggedValue prop = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1260     JSTaggedValue value = GetArg(argv, argc, 1);  // 1: means the first parameter
1261     return RuntimeTryUpdateGlobalRecord(thread, prop, value).GetRawData();
1262 }
1263 
DEF_RUNTIME_STUBS(ThrowReferenceError)1264 DEF_RUNTIME_STUBS(ThrowReferenceError)
1265 {
1266     RUNTIME_STUBS_HEADER(ThrowReferenceError);
1267     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1268     return RuntimeThrowReferenceError(thread, prop, " is not defined").GetRawData();
1269 }
1270 
DEF_RUNTIME_STUBS(LdGlobalICVar)1271 DEF_RUNTIME_STUBS(LdGlobalICVar)
1272 {
1273     RUNTIME_STUBS_HEADER(LdGlobalICVar);
1274     JSHandle<JSTaggedValue> global = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1275     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1276     JSHandle<JSTaggedValue> profileHandle = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1277     JSTaggedValue slotId = GetArg(argv, argc, 3);  // 3: means the third parameter
1278 
1279     if (profileHandle->IsUndefined()) {
1280         return RuntimeLdGlobalVarFromProto(thread, global, prop).GetRawData();
1281     }
1282     LoadICRuntime icRuntime(
1283         thread, JSHandle<ProfileTypeInfo>::Cast(profileHandle), slotId.GetInt(), ICKind::NamedGlobalLoadIC);
1284     return icRuntime.LoadMiss(global, prop).GetRawData();
1285 }
1286 
DEF_RUNTIME_STUBS(StGlobalVar)1287 DEF_RUNTIME_STUBS(StGlobalVar)
1288 {
1289     RUNTIME_STUBS_HEADER(StGlobalVar);
1290     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1291     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1292     return RuntimeStGlobalVar(thread, prop, value).GetRawData();
1293 }
1294 
DEF_RUNTIME_STUBS(ToNumber)1295 DEF_RUNTIME_STUBS(ToNumber)
1296 {
1297     RUNTIME_STUBS_HEADER(ToNumber);
1298     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1299     return RuntimeToNumber(thread, value).GetRawData();
1300 }
1301 
DEF_RUNTIME_STUBS(ToBoolean)1302 DEF_RUNTIME_STUBS(ToBoolean)
1303 {
1304     RUNTIME_STUBS_HEADER(ToBoolean);
1305     JSTaggedValue value = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1306     bool result = value.ToBoolean();
1307     return JSTaggedValue(result).GetRawData();
1308 }
1309 
DEF_RUNTIME_STUBS(Eq)1310 DEF_RUNTIME_STUBS(Eq)
1311 {
1312     RUNTIME_STUBS_HEADER(Eq);
1313     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1314     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1315     return RuntimeEq(thread, left, right).GetRawData();
1316 }
1317 
DEF_RUNTIME_STUBS(NotEq)1318 DEF_RUNTIME_STUBS(NotEq)
1319 {
1320     RUNTIME_STUBS_HEADER(NotEq);
1321     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1322     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1323     return RuntimeNotEq(thread, left, right).GetRawData();
1324 }
1325 
DEF_RUNTIME_STUBS(Less)1326 DEF_RUNTIME_STUBS(Less)
1327 {
1328     RUNTIME_STUBS_HEADER(Less);
1329     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1330     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1331     return RuntimeLess(thread, left, right).GetRawData();
1332 }
1333 
DEF_RUNTIME_STUBS(LessEq)1334 DEF_RUNTIME_STUBS(LessEq)
1335 {
1336     RUNTIME_STUBS_HEADER(LessEq);
1337     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1338     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1339     return RuntimeLessEq(thread, left, right).GetRawData();
1340 }
1341 
DEF_RUNTIME_STUBS(Greater)1342 DEF_RUNTIME_STUBS(Greater)
1343 {
1344     RUNTIME_STUBS_HEADER(Greater);
1345     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1346     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1347     return RuntimeGreater(thread, left, right).GetRawData();
1348 }
1349 
DEF_RUNTIME_STUBS(GreaterEq)1350 DEF_RUNTIME_STUBS(GreaterEq)
1351 {
1352     RUNTIME_STUBS_HEADER(GreaterEq);
1353     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1354     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1355     return RuntimeGreaterEq(thread, left, right).GetRawData();
1356 }
1357 
DEF_RUNTIME_STUBS(Add2)1358 DEF_RUNTIME_STUBS(Add2)
1359 {
1360     RUNTIME_STUBS_HEADER(Add2);
1361     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1362     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1363     JSTaggedValue res = RuntimeAdd2(thread, left, right);
1364     return res.GetRawData();
1365 }
1366 
DEF_RUNTIME_STUBS(Sub2)1367 DEF_RUNTIME_STUBS(Sub2)
1368 {
1369     RUNTIME_STUBS_HEADER(Sub2);
1370     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1371     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1372     return RuntimeSub2(thread, left, right).GetRawData();
1373 }
1374 
DEF_RUNTIME_STUBS(Mul2)1375 DEF_RUNTIME_STUBS(Mul2)
1376 {
1377     RUNTIME_STUBS_HEADER(Mul2);
1378     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1379     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1380     return RuntimeMul2(thread, left, right).GetRawData();
1381 }
1382 
DEF_RUNTIME_STUBS(Div2)1383 DEF_RUNTIME_STUBS(Div2)
1384 {
1385     RUNTIME_STUBS_HEADER(Div2);
1386     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1387     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1388     return RuntimeDiv2(thread, left, right).GetRawData();
1389 }
1390 
DEF_RUNTIME_STUBS(Mod2)1391 DEF_RUNTIME_STUBS(Mod2)
1392 {
1393     RUNTIME_STUBS_HEADER(Mod2);
1394     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1395     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1396     return RuntimeMod2(thread, left, right).GetRawData();
1397 }
1398 
DEF_RUNTIME_STUBS(JumpToCInterpreter)1399 DEF_RUNTIME_STUBS(JumpToCInterpreter)
1400 {
1401     RUNTIME_STUBS_HEADER(JumpToCInterpreter);
1402     JSTaggedValue constpool = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1403     JSTaggedValue profileTypeInfo = GetArg(argv, argc, 1);  // 1: means the first parameter
1404     JSTaggedValue acc = GetArg(argv, argc, 2);  // 2: means the second parameter
1405     JSTaggedValue hotnessCounter = GetArg(argv, argc, 3);  // 3: means the third parameter
1406 
1407     auto sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1408     const uint8_t *currentPc = reinterpret_cast<const uint8_t*>(GET_ASM_FRAME(sp)->pc);
1409 
1410     uint8_t opcode = currentPc[0];
1411     asmDispatchTable[opcode](thread, currentPc, sp, constpool, profileTypeInfo, acc, hotnessCounter.GetInt());
1412     sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1413     return JSTaggedValue(reinterpret_cast<uint64_t>(sp)).GetRawData();
1414 }
1415 
DEF_RUNTIME_STUBS(JumpToDeprecatedInst)1416 DEF_RUNTIME_STUBS(JumpToDeprecatedInst)
1417 {
1418     RUNTIME_STUBS_HEADER(JumpToDeprecatedInst);
1419     JSTaggedValue constpool = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1420     JSTaggedValue profileTypeInfo = GetArg(argv, argc, 1);  // 1: means the first parameter
1421     JSTaggedValue acc = GetArg(argv, argc, 2);  // 2: means the second parameter
1422     JSTaggedValue hotnessCounter = GetArg(argv, argc, 3);  // 3: means the third parameter
1423 
1424     auto sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1425     const uint8_t *currentPc = reinterpret_cast<const uint8_t*>(GET_ASM_FRAME(sp)->pc);
1426 
1427     uint8_t opcode = currentPc[0];
1428     deprecatedDispatchTable[opcode](thread, currentPc, sp, constpool, profileTypeInfo, acc, hotnessCounter.GetInt());
1429     sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1430     return JSTaggedValue(reinterpret_cast<uint64_t>(sp)).GetRawData();
1431 }
1432 
DEF_RUNTIME_STUBS(JumpToWideInst)1433 DEF_RUNTIME_STUBS(JumpToWideInst)
1434 {
1435     RUNTIME_STUBS_HEADER(JumpToWideInst);
1436     JSTaggedValue constpool = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1437     JSTaggedValue profileTypeInfo = GetArg(argv, argc, 1);  // 1: means the first parameter
1438     JSTaggedValue acc = GetArg(argv, argc, 2);  // 2: means the second parameter
1439     JSTaggedValue hotnessCounter = GetArg(argv, argc, 3);  // 3: means the third parameter
1440 
1441     auto sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1442     const uint8_t *currentPc = reinterpret_cast<const uint8_t*>(GET_ASM_FRAME(sp)->pc);
1443 
1444     uint8_t opcode = currentPc[0];
1445     wideDispatchTable[opcode](thread, currentPc, sp, constpool, profileTypeInfo, acc, hotnessCounter.GetInt());
1446     sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1447     return JSTaggedValue(reinterpret_cast<uint64_t>(sp)).GetRawData();
1448 }
1449 
DEF_RUNTIME_STUBS(JumpToThrowInst)1450 DEF_RUNTIME_STUBS(JumpToThrowInst)
1451 {
1452     RUNTIME_STUBS_HEADER(JumpToThrowInst);
1453     JSTaggedValue constpool = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1454     JSTaggedValue profileTypeInfo = GetArg(argv, argc, 1);  // 1: means the first parameter
1455     JSTaggedValue acc = GetArg(argv, argc, 2);  // 2: means the second parameter
1456     JSTaggedValue hotnessCounter = GetArg(argv, argc, 3);  // 3: means the third parameter
1457 
1458     auto sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1459     const uint8_t *currentPc = reinterpret_cast<const uint8_t*>(GET_ASM_FRAME(sp)->pc);
1460 
1461     uint8_t opcode = currentPc[0];
1462     throwDispatchTable[opcode](thread, currentPc, sp, constpool, profileTypeInfo, acc, hotnessCounter.GetInt());
1463     sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1464     return JSTaggedValue(reinterpret_cast<uint64_t>(sp)).GetRawData();
1465 }
1466 
DEF_RUNTIME_STUBS(NotifyBytecodePcChanged)1467 DEF_RUNTIME_STUBS(NotifyBytecodePcChanged)
1468 {
1469     RUNTIME_STUBS_HEADER(NotifyBytecodePcChanged);
1470     FrameHandler frameHandler(thread);
1471     for (; frameHandler.HasFrame(); frameHandler.PrevJSFrame()) {
1472         if (frameHandler.IsEntryFrame() || frameHandler.IsBuiltinFrame()) {
1473             continue;
1474         }
1475         Method *method = frameHandler.GetMethod();
1476         // Skip builtins method
1477         if (method->IsNativeWithCallField()) {
1478             continue;
1479         }
1480         auto bcOffset = frameHandler.GetBytecodeOffset();
1481         auto *debuggerMgr = thread->GetEcmaVM()->GetJsDebuggerManager();
1482         debuggerMgr->GetNotificationManager()->BytecodePcChangedEvent(thread, method, bcOffset);
1483         return JSTaggedValue::Hole().GetRawData();
1484     }
1485     return JSTaggedValue::Hole().GetRawData();
1486 }
1487 
DEF_RUNTIME_STUBS(CreateEmptyObject)1488 DEF_RUNTIME_STUBS(CreateEmptyObject)
1489 {
1490     RUNTIME_STUBS_HEADER(CreateEmptyObject);
1491     EcmaVM *ecmaVm = thread->GetEcmaVM();
1492     ObjectFactory *factory = ecmaVm->GetFactory();
1493     JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
1494     return RuntimeCreateEmptyObject(thread, factory, globalEnv).GetRawData();
1495 }
1496 
DEF_RUNTIME_STUBS(CreateEmptyArray)1497 DEF_RUNTIME_STUBS(CreateEmptyArray)
1498 {
1499     RUNTIME_STUBS_HEADER(CreateEmptyArray);
1500     EcmaVM *ecmaVm = thread->GetEcmaVM();
1501     ObjectFactory *factory = ecmaVm->GetFactory();
1502     JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
1503     return RuntimeCreateEmptyArray(thread, factory, globalEnv).GetRawData();
1504 }
1505 
DEF_RUNTIME_STUBS(GetSymbolFunction)1506 DEF_RUNTIME_STUBS(GetSymbolFunction)
1507 {
1508     RUNTIME_STUBS_HEADER(GetSymbolFunction);
1509     EcmaVM *ecmaVm = thread->GetEcmaVM();
1510     JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
1511     return globalEnv->GetSymbolFunction().GetTaggedValue().GetRawData();
1512 }
1513 
DEF_RUNTIME_STUBS(GetUnmapedArgs)1514 DEF_RUNTIME_STUBS(GetUnmapedArgs)
1515 {
1516     RUNTIME_STUBS_HEADER(GetUnmapedArgs);
1517     auto sp = const_cast<JSTaggedType*>(thread->GetCurrentInterpretedFrame());
1518     uint32_t startIdx = 0;
1519     // 0: means restIdx
1520     uint32_t actualNumArgs = InterpreterAssembly::GetNumArgs(sp, 0, startIdx);
1521     return RuntimeGetUnmapedArgs(thread, sp, actualNumArgs, startIdx).GetRawData();
1522 }
1523 
DEF_RUNTIME_STUBS(CopyRestArgs)1524 DEF_RUNTIME_STUBS(CopyRestArgs)
1525 {
1526     RUNTIME_STUBS_HEADER(CopyRestArgs);
1527     JSTaggedValue restIdx = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1528     auto sp = const_cast<JSTaggedType*>(thread->GetCurrentInterpretedFrame());
1529     uint32_t startIdx = 0;
1530     uint32_t restNumArgs = InterpreterAssembly::GetNumArgs(sp, restIdx.GetInt(), startIdx);
1531     return RuntimeCopyRestArgs(thread, sp, restNumArgs, startIdx).GetRawData();
1532 }
1533 
DEF_RUNTIME_STUBS(CreateArrayWithBuffer)1534 DEF_RUNTIME_STUBS(CreateArrayWithBuffer)
1535 {
1536     RUNTIME_STUBS_HEADER(CreateArrayWithBuffer);
1537     JSHandle<JSTaggedValue> argArray = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1538     EcmaVM *ecmaVm = thread->GetEcmaVM();
1539     ObjectFactory *factory = ecmaVm->GetFactory();
1540     return RuntimeCreateArrayWithBuffer(thread, factory, argArray).GetRawData();
1541 }
1542 
DEF_RUNTIME_STUBS(CreateObjectWithBuffer)1543 DEF_RUNTIME_STUBS(CreateObjectWithBuffer)
1544 {
1545     RUNTIME_STUBS_HEADER(CreateObjectWithBuffer);
1546     JSHandle<JSObject> argObj = GetHArg<JSObject>(argv, argc, 0);  // 0: means the zeroth parameter
1547     EcmaVM *ecmaVm = thread->GetEcmaVM();
1548     ObjectFactory *factory = ecmaVm->GetFactory();
1549     return RuntimeCreateObjectWithBuffer(thread, factory, argObj).GetRawData();
1550 }
1551 
DEF_RUNTIME_STUBS(NewThisObject)1552 DEF_RUNTIME_STUBS(NewThisObject)
1553 {
1554     RUNTIME_STUBS_HEADER(NewThisObject);
1555     JSHandle<JSFunction> ctor(GetHArg<JSTaggedValue>(argv, argc, 0));  // 0: means the zeroth parameter
1556 
1557     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1558     JSHandle<JSObject> obj = factory->NewJSObjectByConstructor(ctor);
1559     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
1560     return obj.GetTaggedType();  // state is not set here
1561 }
1562 
DEF_RUNTIME_STUBS(NewObjRange)1563 DEF_RUNTIME_STUBS(NewObjRange)
1564 {
1565     RUNTIME_STUBS_HEADER(NewObjRange);
1566     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1567     JSHandle<JSTaggedValue> newTarget = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1568     JSTaggedValue firstArgIdx = GetArg(argv, argc, 2);  // 2: means the second parameter
1569     JSTaggedValue length = GetArg(argv, argc, 3);  // 3: means the third parameter
1570     return RuntimeNewObjRange(thread, func, newTarget, static_cast<uint16_t>(firstArgIdx.GetInt()),
1571                                  static_cast<uint16_t>(length.GetInt())).GetRawData();
1572 }
1573 
DEF_RUNTIME_STUBS(DefineFunc)1574 DEF_RUNTIME_STUBS(DefineFunc)
1575 {
1576     RUNTIME_STUBS_HEADER(DefineFunc);
1577     JSHandle<Method> method = GetHArg<Method>(argv, argc, 0);  // 0: means the zeroth parameter
1578     return RuntimeDefinefunc(thread, method).GetRawData();
1579 }
1580 
DEF_RUNTIME_STUBS(CreateRegExpWithLiteral)1581 DEF_RUNTIME_STUBS(CreateRegExpWithLiteral)
1582 {
1583     RUNTIME_STUBS_HEADER(CreateRegExpWithLiteral);
1584     JSHandle<JSTaggedValue> pattern = GetHArg<JSTaggedValue>(argv, argc, 0);
1585     JSTaggedValue flags = GetArg(argv, argc, 1);
1586     return RuntimeCreateRegExpWithLiteral(thread, pattern, static_cast<uint8_t>(flags.GetInt())).GetRawData();
1587 }
1588 
DEF_RUNTIME_STUBS(ThrowIfSuperNotCorrectCall)1589 DEF_RUNTIME_STUBS(ThrowIfSuperNotCorrectCall)
1590 {
1591     RUNTIME_STUBS_HEADER(ThrowIfSuperNotCorrectCall);
1592     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1593     JSTaggedValue thisValue = GetArg(argv, argc, 1);  // 1: means the first parameter
1594     return RuntimeThrowIfSuperNotCorrectCall(thread, static_cast<uint16_t>(index.GetInt()), thisValue).GetRawData();
1595 }
1596 
DEF_RUNTIME_STUBS(CreateObjectHavingMethod)1597 DEF_RUNTIME_STUBS(CreateObjectHavingMethod)
1598 {
1599     RUNTIME_STUBS_HEADER(CreateObjectHavingMethod);
1600     JSHandle<JSObject> literal = GetHArg<JSObject>(argv, argc, 0);  // 0: means the zeroth parameter
1601     JSHandle<JSTaggedValue> env = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1602     EcmaVM *ecmaVm = thread->GetEcmaVM();
1603     ObjectFactory *factory = ecmaVm->GetFactory();
1604     return RuntimeCreateObjectHavingMethod(thread, factory, literal, env).GetRawData();
1605 }
1606 
DEF_RUNTIME_STUBS(CreateObjectWithExcludedKeys)1607 DEF_RUNTIME_STUBS(CreateObjectWithExcludedKeys)
1608 {
1609     RUNTIME_STUBS_HEADER(CreateObjectWithExcludedKeys);
1610     JSTaggedValue numKeys = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1611     JSHandle<JSTaggedValue> objVal = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1612     JSTaggedValue firstArgRegIdx = GetArg(argv, argc, 2);  // 2: means the second parameter
1613     return RuntimeCreateObjectWithExcludedKeys(thread, static_cast<uint16_t>(numKeys.GetInt()), objVal,
1614         static_cast<uint16_t>(firstArgRegIdx.GetInt())).GetRawData();
1615 }
1616 
DEF_RUNTIME_STUBS(DefineMethod)1617 DEF_RUNTIME_STUBS(DefineMethod)
1618 {
1619     RUNTIME_STUBS_HEADER(DefineMethod);
1620     JSHandle<Method> method = GetHArg<Method>(argv, argc, 0);  // 0: means the zeroth parameter
1621     JSHandle<JSTaggedValue> homeObject = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1622     return RuntimeDefineMethod(thread, method, homeObject).GetRawData();
1623 }
1624 
DEF_RUNTIME_STUBS(CallSpread)1625 DEF_RUNTIME_STUBS(CallSpread)
1626 {
1627     RUNTIME_STUBS_HEADER(CallSpread);
1628     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1629     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1630     JSHandle<JSTaggedValue> array = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1631     return RuntimeCallSpread(thread, func, obj, array).GetRawData();
1632 }
1633 
DEF_RUNTIME_STUBS(DefineGetterSetterByValue)1634 DEF_RUNTIME_STUBS(DefineGetterSetterByValue)
1635 {
1636     RUNTIME_STUBS_HEADER(DefineGetterSetterByValue);
1637     JSHandle<JSObject> obj = GetHArg<JSObject>(argv, argc, 0);  // 0: means the zeroth parameter
1638     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1639     JSHandle<JSTaggedValue> getter = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1640     JSHandle<JSTaggedValue> setter = GetHArg<JSTaggedValue>(argv, argc, 3);  // 3: means the third parameter
1641     JSTaggedValue flag = GetArg(argv, argc, 4);  // 4: means the fourth parameter
1642     bool bFlag = flag.ToBoolean();
1643     return RuntimeDefineGetterSetterByValue(thread, obj, prop, getter, setter, bFlag).GetRawData();
1644 }
1645 
DEF_RUNTIME_STUBS(SuperCall)1646 DEF_RUNTIME_STUBS(SuperCall)
1647 {
1648     RUNTIME_STUBS_HEADER(SuperCall);
1649     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1650     JSTaggedValue firstVRegIdx = GetArg(argv, argc, 1);  // 1: means the first parameter
1651     JSTaggedValue length = GetArg(argv, argc, 2);  // 2: means the second parameter
1652     auto sp = const_cast<JSTaggedType*>(thread->GetCurrentInterpretedFrame());
1653     JSTaggedValue newTarget = InterpreterAssembly::GetNewTarget(sp);
1654     return RuntimeSuperCall(thread, func, JSHandle<JSTaggedValue>(thread, newTarget),
1655         static_cast<uint16_t>(firstVRegIdx.GetInt()),
1656         static_cast<uint16_t>(length.GetInt())).GetRawData();
1657 }
1658 
DEF_RUNTIME_STUBS(OptSuperCall)1659 DEF_RUNTIME_STUBS(OptSuperCall)
1660 {
1661     RUNTIME_STUBS_HEADER(OptSuperCall);
1662     return RuntimeOptSuperCall(thread, argv, argc).GetRawData();
1663 }
1664 
DEF_RUNTIME_STUBS(ThrowNotCallableException)1665 DEF_RUNTIME_STUBS(ThrowNotCallableException)
1666 {
1667     RUNTIME_STUBS_HEADER(ThrowNotCallableException);
1668     EcmaVM *ecmaVm = thread->GetEcmaVM();
1669     ObjectFactory *factory = ecmaVm->GetFactory();
1670     JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR, "is not callable");
1671     thread->SetException(error.GetTaggedValue());
1672     return JSTaggedValue::Exception().GetRawData();
1673 }
1674 
DEF_RUNTIME_STUBS(ThrowSetterIsUndefinedException)1675 DEF_RUNTIME_STUBS(ThrowSetterIsUndefinedException)
1676 {
1677     RUNTIME_STUBS_HEADER(ThrowSetterIsUndefinedException);
1678     EcmaVM *ecmaVm = thread->GetEcmaVM();
1679     ObjectFactory *factory = ecmaVm->GetFactory();
1680     JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR,
1681         "Cannot set property when setter is undefined");
1682     thread->SetException(error.GetTaggedValue());
1683     return JSTaggedValue::Exception().GetRawData();
1684 }
1685 
DEF_RUNTIME_STUBS(ThrowCallConstructorException)1686 DEF_RUNTIME_STUBS(ThrowCallConstructorException)
1687 {
1688     RUNTIME_STUBS_HEADER(ThrowCallConstructorException);
1689     EcmaVM *ecmaVm = thread->GetEcmaVM();
1690     ObjectFactory *factory = ecmaVm->GetFactory();
1691     JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR,
1692                                                    "class constructor cannot called without 'new'");
1693     thread->SetException(error.GetTaggedValue());
1694     return JSTaggedValue::Exception().GetRawData();
1695 }
1696 
DEF_RUNTIME_STUBS(ThrowNonConstructorException)1697 DEF_RUNTIME_STUBS(ThrowNonConstructorException)
1698 {
1699     RUNTIME_STUBS_HEADER(ThrowNonConstructorException);
1700     EcmaVM *ecmaVm = thread->GetEcmaVM();
1701     ObjectFactory *factory = ecmaVm->GetFactory();
1702     JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR,
1703                                                    "function is non-constructor");
1704     thread->SetException(error.GetTaggedValue());
1705     return JSTaggedValue::Exception().GetRawData();
1706 }
1707 
DEF_RUNTIME_STUBS(ThrowStackOverflowException)1708 DEF_RUNTIME_STUBS(ThrowStackOverflowException)
1709 {
1710     RUNTIME_STUBS_HEADER(ThrowStackOverflowException);
1711     EcmaVM *ecmaVm = thread->GetEcmaVM();
1712     // Multi-thread could cause stack-overflow-check failed too,
1713     // so check thread here to distinguish it with the actual stack overflow.
1714     ecmaVm->CheckThread();
1715     ObjectFactory *factory = ecmaVm->GetFactory();
1716     JSHandle<JSObject> error = factory->GetJSError(ErrorType::RANGE_ERROR, "Stack overflow!", false);
1717     if (LIKELY(!thread->HasPendingException())) {
1718         thread->SetException(error.GetTaggedValue());
1719     }
1720     return JSTaggedValue::Exception().GetRawData();
1721 }
1722 
DEF_RUNTIME_STUBS(ThrowDerivedMustReturnException)1723 DEF_RUNTIME_STUBS(ThrowDerivedMustReturnException)
1724 {
1725     RUNTIME_STUBS_HEADER(ThrowDerivedMustReturnException);
1726     EcmaVM *ecmaVm = thread->GetEcmaVM();
1727     ObjectFactory *factory = ecmaVm->GetFactory();
1728     JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR,
1729                                                    "Derived constructor must return object or undefined");
1730     thread->SetException(error.GetTaggedValue());
1731     return JSTaggedValue::Exception().GetRawData();
1732 }
1733 
DEF_RUNTIME_STUBS(LdBigInt)1734 DEF_RUNTIME_STUBS(LdBigInt)
1735 {
1736     RUNTIME_STUBS_HEADER(LdBigInt);
1737     JSHandle<JSTaggedValue> numberBigInt = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1738     return RuntimeLdBigInt(thread, numberBigInt).GetRawData();
1739 }
1740 
DEF_RUNTIME_STUBS(ToNumeric)1741 DEF_RUNTIME_STUBS(ToNumeric)
1742 {
1743     RUNTIME_STUBS_HEADER(ToNumeric);
1744     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1745     return RuntimeToNumeric(thread, value).GetRawData();
1746 }
1747 
DEF_RUNTIME_STUBS(DynamicImport)1748 DEF_RUNTIME_STUBS(DynamicImport)
1749 {
1750     RUNTIME_STUBS_HEADER(DynamicImport);
1751     JSHandle<JSTaggedValue> specifier = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1752     JSHandle<JSTaggedValue> currentFunc = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the zeroth parameter
1753     return RuntimeDynamicImport(thread, specifier, currentFunc).GetRawData();
1754 }
1755 
DEF_RUNTIME_STUBS(NewLexicalEnvWithName)1756 DEF_RUNTIME_STUBS(NewLexicalEnvWithName)
1757 {
1758     RUNTIME_STUBS_HEADER(NewLexicalEnvWithName);
1759     JSTaggedValue numVars = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1760     JSTaggedValue scopeId = GetArg(argv, argc, 1);  // 1: means the first parameter
1761     return RuntimeNewLexicalEnvWithName(thread,
1762         static_cast<uint16_t>(numVars.GetInt()),
1763         static_cast<uint16_t>(scopeId.GetInt())).GetRawData();
1764 }
1765 
DEF_RUNTIME_STUBS(OptGetUnmapedArgs)1766 DEF_RUNTIME_STUBS(OptGetUnmapedArgs)
1767 {
1768     RUNTIME_STUBS_HEADER(OptGetUnmapedArgs);
1769     JSTaggedValue actualNumArgs = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1770     return RuntimeOptGetUnmapedArgs(thread, actualNumArgs.GetInt()).GetRawData();
1771 }
1772 
DEF_RUNTIME_STUBS(OptNewLexicalEnvWithName)1773 DEF_RUNTIME_STUBS(OptNewLexicalEnvWithName)
1774 {
1775     RUNTIME_STUBS_HEADER(OptNewLexicalEnvWithName);
1776     JSTaggedValue taggedNumVars = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1777     JSTaggedValue taggedScopeId = GetArg(argv, argc, 1);  // 1: means the first parameter
1778     JSHandle<JSTaggedValue> currentLexEnv = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1779     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 3);  // 3: means the third parameter
1780     uint16_t numVars = static_cast<uint16_t>(taggedNumVars.GetInt());
1781     uint16_t scopeId = static_cast<uint16_t>(taggedScopeId.GetInt());
1782     return RuntimeOptNewLexicalEnvWithName(thread, numVars, scopeId, currentLexEnv, func).GetRawData();
1783 }
1784 
DEF_RUNTIME_STUBS(OptCopyRestArgs)1785 DEF_RUNTIME_STUBS(OptCopyRestArgs)
1786 {
1787     RUNTIME_STUBS_HEADER(OptCopyRestArgs);
1788     JSTaggedValue actualArgc = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1789     JSTaggedValue restIndex = GetArg(argv, argc, 1);  // 1: means the first parameter
1790     return RuntimeOptCopyRestArgs(thread, actualArgc.GetInt(), restIndex.GetInt()).GetRawData();
1791 }
1792 
DEF_RUNTIME_STUBS(OptNewObjRange)1793 DEF_RUNTIME_STUBS(OptNewObjRange)
1794 {
1795     RUNTIME_STUBS_HEADER(OptNewObjRange);
1796     return RuntimeOptNewObjRange(thread, argv, argc).GetRawData();
1797 }
1798 
DEF_RUNTIME_STUBS(GetTypeArrayPropertyByIndex)1799 DEF_RUNTIME_STUBS(GetTypeArrayPropertyByIndex)
1800 {
1801     RUNTIME_STUBS_HEADER(GetTypeArrayPropertyByIndex);
1802     JSTaggedValue obj = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1803     JSTaggedValue idx = GetArg(argv, argc, 1);  // 1: means the first parameter
1804     JSTaggedValue jsType = GetArg(argv, argc, 2); // 2: means the second parameter
1805     return JSTypedArray::FastGetPropertyByIndex(thread, obj, idx.GetInt(), JSType(jsType.GetInt())).GetRawData();
1806 }
1807 
DEF_RUNTIME_STUBS(SetTypeArrayPropertyByIndex)1808 DEF_RUNTIME_STUBS(SetTypeArrayPropertyByIndex)
1809 {
1810     RUNTIME_STUBS_HEADER(SetTypeArrayPropertyByIndex);
1811     JSTaggedValue obj = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1812     JSTaggedValue idx = GetArg(argv, argc, 1);  // 1: means the first parameter
1813     JSTaggedValue value = GetArg(argv, argc, 2);  // 2: means the second parameter
1814     JSTaggedValue jsType = GetArg(argv, argc, 3); // 3: means the third parameter
1815     return JSTypedArray::FastSetPropertyByIndex(thread, obj, idx.GetInt(), value, JSType(jsType.GetInt())).GetRawData();
1816 }
1817 
DEF_RUNTIME_STUBS(DebugAOTPrint)1818 DEF_RUNTIME_STUBS(DebugAOTPrint)
1819 {
1820     RUNTIME_STUBS_HEADER(DebugAOTPrint);
1821     auto ecmaOpcode = GetArg(argv, argc, 0).GetInt();
1822     std::string result = kungfu::GetEcmaOpcodeStr(static_cast<EcmaOpcode>(ecmaOpcode));
1823     LOG_ECMA(INFO) << "aot slowpath " << result;
1824     return JSTaggedValue::Undefined().GetRawData();
1825 }
1826 
DEF_RUNTIME_STUBS(ProfileOptimizedCode)1827 DEF_RUNTIME_STUBS(ProfileOptimizedCode)
1828 {
1829     RUNTIME_STUBS_HEADER(ProfileOptimizedCode);
1830     EcmaOpcode ecmaOpcode = static_cast<EcmaOpcode>(GetArg(argv, argc, 0).GetInt());
1831     OptCodeProfiler::Mode mode = static_cast<OptCodeProfiler::Mode>(GetArg(argv, argc, 1).GetInt());
1832     OptCodeProfiler *profiler = thread->GetEcmaVM()->GetOptCodeProfiler();
1833     profiler->Update(ecmaOpcode, mode);
1834     return JSTaggedValue::Undefined().GetRawData();
1835 }
1836 
DEF_RUNTIME_STUBS(JSObjectGetMethod)1837 DEF_RUNTIME_STUBS(JSObjectGetMethod)
1838 {
1839     RUNTIME_STUBS_HEADER(JSObjectGetMethod);
1840     JSHandle<JSTaggedValue> obj(thread, GetArg(argv, argc, 0));
1841     JSHandle<JSTaggedValue> key(thread, GetArg(argv, argc, 1));
1842     JSHandle<JSTaggedValue> result = JSObject::GetMethod(thread, obj, key);
1843     return result->GetRawData();
1844 }
1845 
DEF_RUNTIME_STUBS(BigIntEqual)1846 DEF_RUNTIME_STUBS(BigIntEqual)
1847 {
1848     RUNTIME_STUBS_HEADER(BigIntEqual);
1849     JSTaggedValue left = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1850     JSTaggedValue right = GetArg(argv, argc, 1);  // 1: means the first parameter
1851     if (BigInt::Equal(left, right)) {
1852         return JSTaggedValue::VALUE_TRUE;
1853     }
1854     return JSTaggedValue::VALUE_FALSE;
1855 }
1856 
DEF_RUNTIME_STUBS(StringEqual)1857 DEF_RUNTIME_STUBS(StringEqual)
1858 {
1859     RUNTIME_STUBS_HEADER(StringEqual);
1860     JSTaggedValue left = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1861     JSTaggedValue right = GetArg(argv, argc, 1);  // 1: means the first parameter
1862     auto leftStr = EcmaString::Cast(left.GetTaggedObject());
1863     auto rightStr = EcmaString::Cast(right.GetTaggedObject());
1864     if (EcmaStringAccessor::StringsAreEqualSameUtfEncoding(leftStr, rightStr)) {
1865         return JSTaggedValue::VALUE_TRUE;
1866     }
1867     return JSTaggedValue::VALUE_FALSE;
1868 }
1869 
DEF_RUNTIME_STUBS(LdPatchVar)1870 DEF_RUNTIME_STUBS(LdPatchVar)
1871 {
1872     RUNTIME_STUBS_HEADER(LdPatchVar);
1873     JSTaggedValue idx = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1874     return RuntimeLdPatchVar(thread, idx.GetInt()).GetRawData();
1875 }
1876 
DEF_RUNTIME_STUBS(StPatchVar)1877 DEF_RUNTIME_STUBS(StPatchVar)
1878 {
1879     RUNTIME_STUBS_HEADER(StPatchVar);
1880     JSTaggedValue idx = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1881     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1882     return RuntimeStPatchVar(thread, idx.GetInt(), value).GetRawData();
1883 }
1884 
DEF_RUNTIME_STUBS(NotifyConcurrentResult)1885 DEF_RUNTIME_STUBS(NotifyConcurrentResult)
1886 {
1887     RUNTIME_STUBS_HEADER(NotifyConcurrentResult);
1888     JSTaggedValue result = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1889     JSTaggedValue hint = GetArg(argv, argc, 1);  // 1: means the first parameter
1890     return RuntimeNotifyConcurrentResult(thread, result, hint).GetRawData();
1891 }
1892 
DEF_RUNTIME_STUBS(ContainerRBTreeForEach)1893 DEF_RUNTIME_STUBS(ContainerRBTreeForEach)
1894 {
1895     RUNTIME_STUBS_HEADER(ContainerRBTreeForEach);
1896     JSHandle<JSTaggedValue> node = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: param index
1897     JSHandle<JSTaggedValue> callbackFnHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: param index
1898     JSHandle<JSTaggedValue> thisArgHandle = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: param index
1899     JSHandle<JSTaggedValue> thisHandle = GetHArg<JSTaggedValue>(argv, argc, 3);  // 3: param index
1900     JSHandle<JSTaggedValue> type = GetHArg<JSTaggedValue>(argv, argc, 4);  // 4: param index
1901 
1902     ASSERT(node->IsRBTreeNode());
1903     ASSERT(callbackFnHandle->IsCallable());
1904     ASSERT(type->IsInt());
1905     JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
1906     auto containersType = static_cast<kungfu::ContainersType>(type->GetInt());
1907     JSMutableHandle<TaggedQueue> queue(thread, thread->GetEcmaVM()->GetFactory()->NewTaggedQueue(0));
1908     JSMutableHandle<RBTreeNode> treeNode(thread, JSTaggedValue::Undefined());
1909     queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, node)));
1910     while (!queue->Empty()) {
1911         treeNode.Update(queue->Pop(thread));
1912         EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle,
1913                                                                         undefined, 3); // 3: three args
1914         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
1915         info->SetCallArg(containersType == kungfu::ContainersType::HASHSET_FOREACH ?
1916                          treeNode->GetKey() : treeNode->GetValue(), treeNode->GetKey(), thisHandle.GetTaggedValue());
1917         JSTaggedValue funcResult = JSFunction::Call(info);
1918         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult.GetRawData());
1919         if (!treeNode->GetLeft().IsHole()) {
1920             JSHandle<JSTaggedValue> left(thread, treeNode->GetLeft());
1921             queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, left)));
1922         }
1923         if (!treeNode->GetRight().IsHole()) {
1924             JSHandle<JSTaggedValue> right(thread, treeNode->GetRight());
1925             queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, right)));
1926         }
1927     }
1928     return JSTaggedValue::True().GetRawData();
1929 }
1930 
CreateArrayFromList(uintptr_t argGlue,int32_t argc,JSTaggedValue * argvPtr)1931 JSTaggedType RuntimeStubs::CreateArrayFromList([[maybe_unused]]uintptr_t argGlue, int32_t argc, JSTaggedValue *argvPtr)
1932 {
1933     auto thread = JSThread::GlueToJSThread(argGlue);
1934     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1935     JSHandle<TaggedArray> taggedArray = factory->NewTaggedArray(argc - NUM_MANDATORY_JSFUNC_ARGS);
1936     for (int index = NUM_MANDATORY_JSFUNC_ARGS; index < argc; ++index) {
1937         taggedArray->Set(thread, index - NUM_MANDATORY_JSFUNC_ARGS, argvPtr[index]);
1938     }
1939     JSHandle<JSArray> arrHandle = JSArray::CreateArrayFromList(thread, taggedArray);
1940     return arrHandle.GetTaggedValue().GetRawData();
1941 }
1942 
FindElementWithCache(uintptr_t argGlue,JSTaggedType hclass,JSTaggedType key,int32_t num)1943 int32_t RuntimeStubs::FindElementWithCache(uintptr_t argGlue, JSTaggedType hclass,
1944                                            JSTaggedType key, int32_t num)
1945 {
1946     auto thread = JSThread::GlueToJSThread(argGlue);
1947     auto cls  = reinterpret_cast<JSHClass *>(hclass);
1948     JSTaggedValue propKey = JSTaggedValue(key);
1949     auto layoutInfo = LayoutInfo::Cast(cls->GetLayout().GetTaggedObject());
1950     PropertiesCache *cache = thread->GetPropertiesCache();
1951     int index = cache->Get(cls, propKey);
1952     if (index == PropertiesCache::NOT_FOUND) {
1953         index = layoutInfo->BinarySearch(propKey, num);
1954         cache->Set(cls, propKey, index);
1955     }
1956     return index;
1957 }
1958 
GetActualArgvNoGC(uintptr_t argGlue)1959 JSTaggedType RuntimeStubs::GetActualArgvNoGC(uintptr_t argGlue)
1960 {
1961     auto thread = JSThread::GlueToJSThread(argGlue);
1962     JSTaggedType *current = const_cast<JSTaggedType *>(thread->GetLastLeaveFrame());
1963     FrameIterator it(current, thread);
1964     ASSERT(it.IsOptimizedFrame());
1965     it.Advance<GCVisitedFlag::VISITED>();
1966     ASSERT(it.IsOptimizedJSFunctionFrame());
1967     auto optimizedJSFunctionFrame = it.GetFrame<OptimizedJSFunctionFrame>();
1968     return reinterpret_cast<uintptr_t>(optimizedJSFunctionFrame->GetArgv(it));
1969 }
1970 
FloatMod(double x,double y)1971 JSTaggedType RuntimeStubs::FloatMod(double x, double y)
1972 {
1973     double result = std::fmod(x, y);
1974     return JSTaggedValue(result).GetRawData();
1975 }
1976 
FloatSqrt(double x)1977 JSTaggedType RuntimeStubs::FloatSqrt(double x)
1978 {
1979     double result = std::sqrt(x);
1980     return JSTaggedValue(result).GetRawData();
1981 }
1982 
FloatCos(double x)1983 JSTaggedType RuntimeStubs::FloatCos(double x)
1984 {
1985     double result = std::cos(x);
1986     return JSTaggedValue(result).GetRawData();
1987 }
1988 
FloatSin(double x)1989 JSTaggedType RuntimeStubs::FloatSin(double x)
1990 {
1991     double result = std::sin(x);
1992     return JSTaggedValue(result).GetRawData();
1993 }
1994 
FloatACos(double x)1995 JSTaggedType RuntimeStubs::FloatACos(double x)
1996 {
1997     double result = std::acos(x);
1998     return JSTaggedValue(result).GetRawData();
1999 }
2000 
FloatATan(double x)2001 JSTaggedType RuntimeStubs::FloatATan(double x)
2002 {
2003     double result = std::atan(x);
2004     return JSTaggedValue(result).GetRawData();
2005 }
2006 
FloatFloor(double x)2007 JSTaggedType RuntimeStubs::FloatFloor(double x)
2008 {
2009     ASSERT(!std::isnan(x));
2010     double result = std::floor(x);
2011     return JSTaggedValue(result).GetRawData();
2012 }
2013 
DoubleToInt(double x)2014 int32_t RuntimeStubs::DoubleToInt(double x)
2015 {
2016     return base::NumberHelper::DoubleToInt(x, base::INT32_BITS);
2017 }
2018 
InsertOldToNewRSet(uintptr_t argGlue,uintptr_t object,size_t offset)2019 void RuntimeStubs::InsertOldToNewRSet([[maybe_unused]]uintptr_t argGlue,
2020     uintptr_t object, size_t offset)
2021 {
2022     Region *region = Region::ObjectAddressToRange(object);
2023     uintptr_t slotAddr = object + offset;
2024     return region->InsertOldToNewRSet(slotAddr);
2025 }
2026 
MarkingBarrier(uintptr_t argGlue,uintptr_t object,size_t offset,TaggedObject * value)2027 void RuntimeStubs::MarkingBarrier([[maybe_unused]]uintptr_t argGlue,
2028     uintptr_t object, size_t offset, TaggedObject *value)
2029 {
2030     uintptr_t slotAddr = object + offset;
2031     Region *objectRegion = Region::ObjectAddressToRange(object);
2032     Region *valueRegion = Region::ObjectAddressToRange(value);
2033     if (!valueRegion->IsMarking()) {
2034         return;
2035     }
2036     Barriers::Update(slotAddr, objectRegion, value, valueRegion);
2037 }
2038 
StoreBarrier(uintptr_t argGlue,uintptr_t object,size_t offset,TaggedObject * value)2039 void RuntimeStubs::StoreBarrier([[maybe_unused]]uintptr_t argGlue,
2040     uintptr_t object, size_t offset, TaggedObject *value)
2041 {
2042     uintptr_t slotAddr = object + offset;
2043     Region *objectRegion = Region::ObjectAddressToRange(object);
2044     Region *valueRegion = Region::ObjectAddressToRange(value);
2045     if (!objectRegion->InYoungSpace() && valueRegion->InYoungSpace()) {
2046         // Should align with '8' in 64 and 32 bit platform
2047         ASSERT((slotAddr % static_cast<uint8_t>(MemAlignment::MEM_ALIGN_OBJECT)) == 0);
2048         objectRegion->InsertOldToNewRSet(slotAddr);
2049     }
2050     if (!valueRegion->IsMarking()) {
2051         return;
2052     }
2053     Barriers::Update(slotAddr, objectRegion, value, valueRegion);
2054 }
2055 
StringsAreEquals(EcmaString * str1,EcmaString * str2)2056 bool RuntimeStubs::StringsAreEquals(EcmaString *str1, EcmaString *str2)
2057 {
2058     return EcmaStringAccessor::StringsAreEqualSameUtfEncoding(str1, str2);
2059 }
2060 
BigIntEquals(JSTaggedType left,JSTaggedType right)2061 bool RuntimeStubs::BigIntEquals(JSTaggedType left, JSTaggedType right)
2062 {
2063     return BigInt::Equal(JSTaggedValue(left), JSTaggedValue(right));
2064 }
2065 
TimeClip(double time)2066 double RuntimeStubs::TimeClip(double time)
2067 {
2068     return JSDate::TimeClip(time);
2069 }
2070 
SetDateValues(double year,double month,double day)2071 double RuntimeStubs::SetDateValues(double year, double month, double day)
2072 {
2073     if (std::isnan(year) || !std::isfinite(year) || std::isnan(month) || !std::isfinite(month) || std::isnan(day) ||
2074         !std::isfinite(day)) {
2075         return base::NAN_VALUE;
2076     }
2077 
2078     return JSDate::SetDateValues(static_cast<int64_t>(year), static_cast<int64_t>(month), static_cast<int64_t>(day));
2079 }
2080 
NewObject(EcmaRuntimeCallInfo * info)2081 JSTaggedValue RuntimeStubs::NewObject(EcmaRuntimeCallInfo *info)
2082 {
2083     ASSERT(info);
2084     JSThread *thread = info->GetThread();
2085     JSHandle<JSTaggedValue> func(info->GetFunction());
2086     if (!func->IsHeapObject()) {
2087         THROW_TYPE_ERROR_AND_RETURN(thread, "function is nullptr", JSTaggedValue::Exception());
2088     }
2089 
2090     if (!func->IsJSFunction()) {
2091         if (func->IsBoundFunction()) {
2092             JSTaggedValue result = JSBoundFunction::ConstructInternal(info);
2093             RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
2094             return result;
2095         }
2096 
2097         if (func->IsJSProxy()) {
2098             JSTaggedValue jsObj = JSProxy::ConstructInternal(info);
2099             RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
2100             return jsObj;
2101         }
2102         THROW_TYPE_ERROR_AND_RETURN(thread, "Constructed NonConstructable", JSTaggedValue::Exception());
2103     }
2104 
2105     JSTaggedValue result = JSFunction::ConstructInternal(info);
2106     RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
2107     return result;
2108 }
2109 
SaveFrameToContext(JSThread * thread,JSHandle<GeneratorContext> context)2110 void RuntimeStubs::SaveFrameToContext(JSThread *thread, JSHandle<GeneratorContext> context)
2111 {
2112     FrameHandler frameHandler(thread);
2113     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
2114     uint32_t nregs = frameHandler.GetNumberArgs();
2115     JSHandle<TaggedArray> regsArray = factory->NewTaggedArray(nregs);
2116     for (uint32_t i = 0; i < nregs; i++) {
2117         JSTaggedValue value = frameHandler.GetVRegValue(i);
2118         regsArray->Set(thread, i, value);
2119     }
2120     context->SetRegsArray(thread, regsArray.GetTaggedValue());
2121     context->SetMethod(thread, frameHandler.GetFunction());
2122     context->SetThis(thread, frameHandler.GetThis());
2123 
2124     BytecodeInstruction ins(frameHandler.GetPc());
2125     auto offset = ins.GetSize();
2126     context->SetAcc(thread, frameHandler.GetAcc());
2127     context->SetLexicalEnv(thread, thread->GetCurrentLexenv());
2128     context->SetNRegs(nregs);
2129     context->SetBCOffset(frameHandler.GetBytecodeOffset() + offset);
2130 }
2131 
CallBoundFunction(EcmaRuntimeCallInfo * info)2132 JSTaggedValue RuntimeStubs::CallBoundFunction(EcmaRuntimeCallInfo *info)
2133 {
2134     JSThread *thread = info->GetThread();
2135     JSHandle<JSBoundFunction> boundFunc(info->GetFunction());
2136     JSHandle<JSFunction> targetFunc(thread, boundFunc->GetBoundTarget());
2137     if (targetFunc->IsClassConstructor()) {
2138         THROW_TYPE_ERROR_AND_RETURN(thread, "class constructor cannot called without 'new'",
2139                                     JSTaggedValue::Exception());
2140     }
2141 
2142     JSHandle<TaggedArray> boundArgs(thread, boundFunc->GetBoundArguments());
2143     const int32_t boundLength = static_cast<int32_t>(boundArgs->GetLength());
2144     const int32_t argsLength = static_cast<int32_t>(info->GetArgsNumber()) + boundLength;
2145     JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
2146     EcmaRuntimeCallInfo *runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle<JSTaggedValue>(targetFunc),
2147         info->GetThis(), undefined, argsLength);
2148     RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
2149     if (boundLength == 0) {
2150         runtimeInfo->SetCallArg(argsLength, 0, info, 0);
2151     } else {
2152         // 0 ~ boundLength is boundArgs; boundLength ~ argsLength is args of EcmaRuntimeCallInfo.
2153         runtimeInfo->SetCallArg(boundLength, boundArgs);
2154         runtimeInfo->SetCallArg(argsLength, boundLength, info, 0);
2155     }
2156     return EcmaInterpreter::Execute(runtimeInfo);
2157 }
2158 
DEF_RUNTIME_STUBS(DeoptHandler)2159 DEF_RUNTIME_STUBS(DeoptHandler)
2160 {
2161     RUNTIME_STUBS_HEADER(DeoptHandler);
2162 
2163     Deoptimizier deopt(thread);
2164     std::vector<kungfu::ARKDeopt> deoptBundle;
2165     deopt.CollectDeoptBundleVec(deoptBundle);
2166     ASSERT(!deoptBundle.empty());
2167     deopt.CollectVregs(deoptBundle);
2168 
2169     uintptr_t *args = reinterpret_cast<uintptr_t *>(argv);
2170     kungfu::DeoptType type = static_cast<kungfu::DeoptType>(args[0]);
2171     return deopt.ConstructAsmInterpretFrame(type);
2172 }
2173 
Initialize(JSThread * thread)2174 void RuntimeStubs::Initialize(JSThread *thread)
2175 {
2176 #define DEF_RUNTIME_STUB(name) kungfu::RuntimeStubCSigns::ID_##name
2177 #define INITIAL_RUNTIME_FUNCTIONS(name) \
2178     thread->RegisterRTInterface(DEF_RUNTIME_STUB(name), reinterpret_cast<uintptr_t>(name));
2179     RUNTIME_STUB_WITHOUT_GC_LIST(INITIAL_RUNTIME_FUNCTIONS)
2180     RUNTIME_STUB_WITH_GC_LIST(INITIAL_RUNTIME_FUNCTIONS)
2181     TEST_RUNTIME_STUB_GC_LIST(INITIAL_RUNTIME_FUNCTIONS)
2182 #undef INITIAL_RUNTIME_FUNCTIONS
2183 #undef DEF_RUNTIME_STUB
2184 }
2185 
2186 #if defined(__clang__)
2187 #pragma clang diagnostic pop
2188 #elif defined(__GNUC__)
2189 #pragma GCC diagnostic pop
2190 #endif
2191 }  // namespace panda::ecmascript
2192