• 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, static_cast<uint16_t>(methodId.GetInt()),
889         static_cast<uint16_t>(literalId.GetInt()), ihclass, module).GetRawData();
890 }
891 
DEF_RUNTIME_STUBS(SetClassConstructorLength)892 DEF_RUNTIME_STUBS(SetClassConstructorLength)
893 {
894     RUNTIME_STUBS_HEADER(SetClassConstructorLength);
895     JSTaggedValue ctor = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
896     JSTaggedValue length = GetArg(argv, argc, 1);  // 1: means the first parameter
897     return RuntimeSetClassConstructorLength(thread, ctor, length).GetRawData();
898 }
899 
900 
DEF_RUNTIME_STUBS(UpdateHotnessCounter)901 DEF_RUNTIME_STUBS(UpdateHotnessCounter)
902 {
903     RUNTIME_STUBS_HEADER(UpdateHotnessCounter);
904     JSHandle<JSFunction> thisFunc = GetHArg<JSFunction>(argv, argc, 0);  // 0: means the zeroth parameter
905     thread->CheckSafepoint();
906     JSHandle<Method> method(thread, thisFunc->GetMethod());
907     auto profileTypeInfo = method->GetProfileTypeInfo();
908     if (profileTypeInfo == JSTaggedValue::Undefined()) {
909         if (thread->IsPGOProfilerEnable()) {
910             thread->GetEcmaVM()->GetPGOProfiler()->Sample(thisFunc.GetTaggedType(), SampleMode::HOTNESS_MODE);
911         }
912         uint32_t slotSize = method->GetSlotSize();
913         auto res = RuntimeNotifyInlineCache(thread, method, slotSize);
914         return res.GetRawData();
915     }
916     return profileTypeInfo.GetRawData();
917 }
918 
DEF_RUNTIME_STUBS(LoadICByName)919 DEF_RUNTIME_STUBS(LoadICByName)
920 {
921     RUNTIME_STUBS_HEADER(LoadICByName);
922     JSHandle<JSTaggedValue> profileHandle = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
923     JSHandle<JSTaggedValue> receiverHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
924     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
925     JSTaggedValue slotId = GetArg(argv, argc, 3);  // 3: means the third parameter
926 
927     if (profileHandle->IsUndefined()) {
928         auto res = JSTaggedValue::GetProperty(thread, receiverHandle, keyHandle).GetValue().GetTaggedValue();
929         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
930         return res.GetRawData();
931     }
932     LoadICRuntime icRuntime(
933         thread, JSHandle<ProfileTypeInfo>::Cast(profileHandle), slotId.GetInt(), ICKind::NamedLoadIC);
934     return icRuntime.LoadMiss(receiverHandle, keyHandle).GetRawData();
935 }
936 
DEF_RUNTIME_STUBS(TryLdGlobalICByName)937 DEF_RUNTIME_STUBS(TryLdGlobalICByName)
938 {
939     RUNTIME_STUBS_HEADER(TryLdGlobalICByName);
940     JSHandle<JSTaggedValue> profileHandle = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
941     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
942     JSTaggedValue slotId = GetArg(argv, argc, 2);  // 2: means the third parameter
943 
944     EcmaVM *ecmaVm = thread->GetEcmaVM();
945     JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
946     JSHandle<JSTaggedValue> globalObj(thread, globalEnv->GetGlobalObject());
947     if (profileHandle->IsUndefined()) {
948         auto res = RuntimeTryLdGlobalByName(thread, globalObj, keyHandle);
949         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
950         return res.GetRawData();
951     }
952     LoadICRuntime icRuntime(
953         thread, JSHandle<ProfileTypeInfo>::Cast(profileHandle), slotId.GetInt(), ICKind::NamedGlobalTryLoadIC);
954     return icRuntime.LoadMiss(globalObj, keyHandle).GetRawData();
955 }
956 
DEF_RUNTIME_STUBS(StoreICByName)957 DEF_RUNTIME_STUBS(StoreICByName)
958 {
959     RUNTIME_STUBS_HEADER(StoreICByName);
960     JSHandle<JSTaggedValue> profileHandle = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
961     JSHandle<JSTaggedValue> receiverHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
962     JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
963     JSHandle<JSTaggedValue> valueHandle = GetHArg<JSTaggedValue>(argv, argc, 3);  // 3: means the third parameter
964     JSTaggedValue slotId = GetArg(argv, argc, 4);   // 4: means the fourth parameter
965 
966     if (profileHandle->IsUndefined()) {
967         JSTaggedValue::SetProperty(thread, receiverHandle, keyHandle, valueHandle, true);
968         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
969         return JSTaggedValue::True().GetRawData();
970     }
971     StoreICRuntime icRuntime(
972         thread, JSHandle<ProfileTypeInfo>::Cast(profileHandle), slotId.GetInt(), ICKind::NamedStoreIC);
973     return icRuntime.StoreMiss(receiverHandle, keyHandle, valueHandle).GetRawData();
974 }
975 
DEF_RUNTIME_STUBS(SetFunctionNameNoPrefix)976 DEF_RUNTIME_STUBS(SetFunctionNameNoPrefix)
977 {
978     RUNTIME_STUBS_HEADER(SetFunctionNameNoPrefix);
979     JSTaggedType argFunc = GetTArg(argv, argc, 0);  // 0: means the zeroth parameter
980     JSTaggedValue argName = GetArg(argv, argc, 1);  // 1: means the first parameter
981     JSFunction::SetFunctionNameNoPrefix(thread, reinterpret_cast<JSFunction *>(argFunc), argName);
982     return JSTaggedValue::Hole().GetRawData();
983 }
984 
DEF_RUNTIME_STUBS(StOwnByValueWithNameSet)985 DEF_RUNTIME_STUBS(StOwnByValueWithNameSet)
986 {
987     RUNTIME_STUBS_HEADER(StOwnByValueWithNameSet);
988     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
989     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
990     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
991     return RuntimeStOwnByValueWithNameSet(thread, obj, prop, value).GetRawData();
992 }
993 
DEF_RUNTIME_STUBS(StOwnByName)994 DEF_RUNTIME_STUBS(StOwnByName)
995 {
996     RUNTIME_STUBS_HEADER(StOwnByName);
997     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
998     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
999     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1000     return RuntimeStOwnByName(thread, obj, prop, value).GetRawData();
1001 }
1002 
DEF_RUNTIME_STUBS(StOwnByNameWithNameSet)1003 DEF_RUNTIME_STUBS(StOwnByNameWithNameSet)
1004 {
1005     RUNTIME_STUBS_HEADER(StOwnByNameWithNameSet);
1006     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1007     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1008     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1009     return RuntimeStOwnByValueWithNameSet(thread, obj, prop, value).GetRawData();
1010 }
1011 
DEF_RUNTIME_STUBS(SuspendGenerator)1012 DEF_RUNTIME_STUBS(SuspendGenerator)
1013 {
1014     RUNTIME_STUBS_HEADER(SuspendGenerator);
1015     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1016     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1017     return RuntimeSuspendGenerator(thread, obj, value).GetRawData();
1018 }
1019 
DEF_RUNTIME_STUBS(OptSuspendGenerator)1020 DEF_RUNTIME_STUBS(OptSuspendGenerator)
1021 {
1022     RUNTIME_STUBS_HEADER(OptSuspendGenerator);
1023     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1024     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1025     return RuntimeOptSuspendGenerator(thread, obj, value).GetRawData();
1026 }
1027 
DEF_RUNTIME_STUBS(UpFrame)1028 DEF_RUNTIME_STUBS(UpFrame)
1029 {
1030     RUNTIME_STUBS_HEADER(UpFrame);
1031     FrameHandler frameHandler(thread);
1032     uint32_t pcOffset = panda_file::INVALID_OFFSET;
1033     for (; frameHandler.HasFrame(); frameHandler.PrevJSFrame()) {
1034         if (frameHandler.IsEntryFrame() || frameHandler.IsBuiltinFrame()) {
1035             thread->SetCurrentFrame(frameHandler.GetSp());
1036             thread->SetLastFp(frameHandler.GetFp());
1037             return JSTaggedValue(static_cast<uint64_t>(0)).GetRawData();
1038         }
1039         auto method = frameHandler.GetMethod();
1040         pcOffset = InterpreterAssembly::FindCatchBlock(method, frameHandler.GetBytecodeOffset());
1041         if (pcOffset != panda_file::INVALID_OFFSET) {
1042             thread->SetCurrentFrame(frameHandler.GetSp());
1043             thread->SetLastFp(frameHandler.GetFp());
1044             uintptr_t pc = reinterpret_cast<uintptr_t>(method->GetBytecodeArray() + pcOffset);
1045             return JSTaggedValue(static_cast<uint64_t>(pc)).GetRawData();
1046         }
1047     }
1048     return JSTaggedValue(static_cast<uint64_t>(0)).GetRawData();
1049 }
1050 
DEF_RUNTIME_STUBS(GetModuleNamespaceByIndex)1051 DEF_RUNTIME_STUBS(GetModuleNamespaceByIndex)
1052 {
1053     RUNTIME_STUBS_HEADER(GetModuleNamespaceByIndex);
1054     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1055     return RuntimeGetModuleNamespace(thread, index.GetInt()).GetRawData();
1056 }
1057 
DEF_RUNTIME_STUBS(GetModuleNamespaceByIndexOnJSFunc)1058 DEF_RUNTIME_STUBS(GetModuleNamespaceByIndexOnJSFunc)
1059 {
1060     RUNTIME_STUBS_HEADER(GetModuleNamespaceByIndexOnJSFunc);
1061     JSTaggedValue index = GetArg(argv, argc, 0);
1062     JSTaggedValue jsFunc = GetArg(argv, argc, 1);
1063     return RuntimeGetModuleNamespace(thread, index.GetInt(), jsFunc).GetRawData();
1064 }
1065 
DEF_RUNTIME_STUBS(GetModuleNamespace)1066 DEF_RUNTIME_STUBS(GetModuleNamespace)
1067 {
1068     RUNTIME_STUBS_HEADER(GetModuleNamespace);
1069     JSTaggedValue localName = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1070     return RuntimeGetModuleNamespace(thread, localName).GetRawData();
1071 }
1072 
DEF_RUNTIME_STUBS(StModuleVarByIndex)1073 DEF_RUNTIME_STUBS(StModuleVarByIndex)
1074 {
1075     RUNTIME_STUBS_HEADER(StModuleVar);
1076     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1077     JSTaggedValue value = GetArg(argv, argc, 1);  // 1: means the first parameter
1078     RuntimeStModuleVar(thread, index.GetInt(), value);
1079     return JSTaggedValue::Hole().GetRawData();
1080 }
1081 
DEF_RUNTIME_STUBS(StModuleVarByIndexOnJSFunc)1082 DEF_RUNTIME_STUBS(StModuleVarByIndexOnJSFunc)
1083 {
1084     RUNTIME_STUBS_HEADER(StModuleVarByIndexOnJSFunc);
1085     JSTaggedValue index = GetArg(argv, argc, 0);
1086     JSTaggedValue value = GetArg(argv, argc, 1);
1087     JSTaggedValue jsFunc = GetArg(argv, argc, 2);
1088     RuntimeStModuleVar(thread, index.GetInt(), value, jsFunc);
1089     return JSTaggedValue::Hole().GetRawData();
1090 }
1091 
DEF_RUNTIME_STUBS(StModuleVar)1092 DEF_RUNTIME_STUBS(StModuleVar)
1093 {
1094     RUNTIME_STUBS_HEADER(StModuleVar);
1095     JSTaggedValue key = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1096     JSTaggedValue value = GetArg(argv, argc, 1);  // 1: means the first parameter
1097     RuntimeStModuleVar(thread, key, value);
1098     return JSTaggedValue::Hole().GetRawData();
1099 }
1100 
DEF_RUNTIME_STUBS(LdLocalModuleVarByIndex)1101 DEF_RUNTIME_STUBS(LdLocalModuleVarByIndex)
1102 {
1103     RUNTIME_STUBS_HEADER(LdLocalModuleVarByIndex);
1104     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1105     return RuntimeLdLocalModuleVar(thread, index.GetInt()).GetRawData();
1106 }
1107 
DEF_RUNTIME_STUBS(LdExternalModuleVarByIndex)1108 DEF_RUNTIME_STUBS(LdExternalModuleVarByIndex)
1109 {
1110     RUNTIME_STUBS_HEADER(LdExternalModuleVarByIndex);
1111     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1112     return RuntimeLdExternalModuleVar(thread, index.GetInt()).GetRawData();
1113 }
1114 
DEF_RUNTIME_STUBS(LdLocalModuleVarByIndexOnJSFunc)1115 DEF_RUNTIME_STUBS(LdLocalModuleVarByIndexOnJSFunc)
1116 {
1117     RUNTIME_STUBS_HEADER(LdLocalModuleVarByIndexOnJSFunc);
1118     JSTaggedValue index = GetArg(argv, argc, 0);
1119     JSTaggedValue jsFunc = GetArg(argv, argc, 1);
1120     return RuntimeLdLocalModuleVar(thread, index.GetInt(), jsFunc).GetRawData();
1121 }
1122 
DEF_RUNTIME_STUBS(LdExternalModuleVarByIndexOnJSFunc)1123 DEF_RUNTIME_STUBS(LdExternalModuleVarByIndexOnJSFunc)
1124 {
1125     RUNTIME_STUBS_HEADER(LdExternalModuleVarByIndexOnJSFunc);
1126     JSTaggedValue index = GetArg(argv, argc, 0);
1127     JSTaggedValue jsFunc = GetArg(argv, argc, 1);
1128     return RuntimeLdExternalModuleVar(thread, index.GetInt(), jsFunc).GetRawData();
1129 }
1130 
DEF_RUNTIME_STUBS(LdModuleVar)1131 DEF_RUNTIME_STUBS(LdModuleVar)
1132 {
1133     RUNTIME_STUBS_HEADER(LdModuleVar);
1134     JSTaggedValue key = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1135     JSTaggedValue taggedFlag = GetArg(argv, argc, 1);  // 1: means the first parameter
1136     bool innerFlag = taggedFlag.GetInt() != 0;
1137     return RuntimeLdModuleVar(thread, key, innerFlag).GetRawData();
1138 }
1139 
DEF_RUNTIME_STUBS(GetPropIterator)1140 DEF_RUNTIME_STUBS(GetPropIterator)
1141 {
1142     RUNTIME_STUBS_HEADER(GetPropIterator);
1143     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1144     return RuntimeGetPropIterator(thread, value).GetRawData();
1145 }
1146 
DEF_RUNTIME_STUBS(AsyncFunctionEnter)1147 DEF_RUNTIME_STUBS(AsyncFunctionEnter)
1148 {
1149     RUNTIME_STUBS_HEADER(AsyncFunctionEnter);
1150     return RuntimeAsyncFunctionEnter(thread).GetRawData();
1151 }
1152 
DEF_RUNTIME_STUBS(GetIterator)1153 DEF_RUNTIME_STUBS(GetIterator)
1154 {
1155     RUNTIME_STUBS_HEADER(GetIterator);
1156     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1157     return RuntimeGetIterator(thread, obj).GetRawData();
1158 }
1159 
DEF_RUNTIME_STUBS(GetAsyncIterator)1160 DEF_RUNTIME_STUBS(GetAsyncIterator)
1161 {
1162     RUNTIME_STUBS_HEADER(GetAsyncIterator);
1163     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1164     return RuntimeGetAsyncIterator(thread, obj).GetRawData();
1165 }
1166 
DEF_RUNTIME_STUBS(Throw)1167 DEF_RUNTIME_STUBS(Throw)
1168 {
1169     RUNTIME_STUBS_HEADER(Throw);
1170     JSTaggedValue value = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1171     RuntimeThrow(thread, value);
1172     return JSTaggedValue::Hole().GetRawData();
1173 }
1174 
DEF_RUNTIME_STUBS(ThrowThrowNotExists)1175 DEF_RUNTIME_STUBS(ThrowThrowNotExists)
1176 {
1177     RUNTIME_STUBS_HEADER(ThrowThrowNotExists);
1178     RuntimeThrowThrowNotExists(thread);
1179     return JSTaggedValue::Hole().GetRawData();
1180 }
1181 
DEF_RUNTIME_STUBS(ThrowPatternNonCoercible)1182 DEF_RUNTIME_STUBS(ThrowPatternNonCoercible)
1183 {
1184     RUNTIME_STUBS_HEADER(ThrowPatternNonCoercible);
1185     RuntimeThrowPatternNonCoercible(thread);
1186     return JSTaggedValue::Hole().GetRawData();
1187 }
1188 
DEF_RUNTIME_STUBS(ThrowDeleteSuperProperty)1189 DEF_RUNTIME_STUBS(ThrowDeleteSuperProperty)
1190 {
1191     RUNTIME_STUBS_HEADER(ThrowDeleteSuperProperty);
1192     RuntimeThrowDeleteSuperProperty(thread);
1193     return JSTaggedValue::Hole().GetRawData();
1194 }
1195 
DEF_RUNTIME_STUBS(ThrowUndefinedIfHole)1196 DEF_RUNTIME_STUBS(ThrowUndefinedIfHole)
1197 {
1198     RUNTIME_STUBS_HEADER(ThrowUndefinedIfHole);
1199     JSHandle<EcmaString> obj = GetHArg<EcmaString>(argv, argc, 0);  // 0: means the zeroth parameter
1200     RuntimeThrowUndefinedIfHole(thread, obj);
1201     return JSTaggedValue::Hole().GetRawData();
1202 }
1203 
DEF_RUNTIME_STUBS(ThrowIfNotObject)1204 DEF_RUNTIME_STUBS(ThrowIfNotObject)
1205 {
1206     RUNTIME_STUBS_HEADER(ThrowIfNotObject);
1207     RuntimeThrowIfNotObject(thread);
1208     return JSTaggedValue::Hole().GetRawData();
1209 }
1210 
DEF_RUNTIME_STUBS(ThrowConstAssignment)1211 DEF_RUNTIME_STUBS(ThrowConstAssignment)
1212 {
1213     RUNTIME_STUBS_HEADER(ThrowConstAssignment);
1214     JSHandle<EcmaString> value = GetHArg<EcmaString>(argv, argc, 0);  // 0: means the zeroth parameter
1215     RuntimeThrowConstAssignment(thread, value);
1216     return JSTaggedValue::Hole().GetRawData();
1217 }
1218 
DEF_RUNTIME_STUBS(ThrowTypeError)1219 DEF_RUNTIME_STUBS(ThrowTypeError)
1220 {
1221     RUNTIME_STUBS_HEADER(ThrowTypeError);
1222     JSTaggedValue argMessageStringId = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1223     std::string message = MessageString::GetMessageString(argMessageStringId.GetInt());
1224     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1225     JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR, message.c_str());
1226     THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error.GetTaggedValue(), JSTaggedValue::Hole().GetRawData());
1227 }
1228 
DEF_RUNTIME_STUBS(LoadMiss)1229 DEF_RUNTIME_STUBS(LoadMiss)
1230 {
1231     RUNTIME_STUBS_HEADER(LoadMiss);
1232     JSTaggedType profileTypeInfo = GetTArg(argv, argc, 0);  // 0: means the zeroth parameter
1233     JSTaggedValue receiver = GetArg(argv, argc, 1);  // 1: means the first parameter
1234     JSTaggedValue key = GetArg(argv, argc, 2);  // 2: means the second parameter
1235     JSTaggedValue slotId = GetArg(argv, argc, 3);  // 3: means the third parameter
1236     JSTaggedValue kind = GetArg(argv, argc, 4);   // 4: means the fourth parameter
1237     return ICRuntimeStub::LoadMiss(thread, reinterpret_cast<ProfileTypeInfo *>(profileTypeInfo), receiver, key,
1238         slotId.GetInt(), static_cast<ICKind>(kind.GetInt())).GetRawData();
1239 }
1240 
DEF_RUNTIME_STUBS(StoreMiss)1241 DEF_RUNTIME_STUBS(StoreMiss)
1242 {
1243     RUNTIME_STUBS_HEADER(StoreMiss);
1244     JSTaggedType profileTypeInfo = GetTArg(argv, argc, 0);  // 0: means the zeroth parameter
1245     JSTaggedValue receiver = GetArg(argv, argc, 1);  // 1: means the first parameter
1246     JSTaggedValue key = GetArg(argv, argc, 2);  // 2: means the second parameter
1247     JSTaggedValue value = GetArg(argv, argc, 3);  // 3: means the third parameter
1248     JSTaggedValue slotId = GetArg(argv, argc, 4);  // 4: means the fourth parameter
1249     JSTaggedValue kind = GetArg(argv, argc, 5);  // 5: means the fifth parameter
1250     return ICRuntimeStub::StoreMiss(thread, reinterpret_cast<ProfileTypeInfo *>(profileTypeInfo), receiver, key, value,
1251         slotId.GetInt(), static_cast<ICKind>(kind.GetInt())).GetRawData();
1252 }
1253 
DEF_RUNTIME_STUBS(TryUpdateGlobalRecord)1254 DEF_RUNTIME_STUBS(TryUpdateGlobalRecord)
1255 {
1256     RUNTIME_STUBS_HEADER(TryUpdateGlobalRecord);
1257     JSTaggedValue prop = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1258     JSTaggedValue value = GetArg(argv, argc, 1);  // 1: means the first parameter
1259     return RuntimeTryUpdateGlobalRecord(thread, prop, value).GetRawData();
1260 }
1261 
DEF_RUNTIME_STUBS(ThrowReferenceError)1262 DEF_RUNTIME_STUBS(ThrowReferenceError)
1263 {
1264     RUNTIME_STUBS_HEADER(ThrowReferenceError);
1265     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1266     return RuntimeThrowReferenceError(thread, prop, " is not defined").GetRawData();
1267 }
1268 
DEF_RUNTIME_STUBS(LdGlobalICVar)1269 DEF_RUNTIME_STUBS(LdGlobalICVar)
1270 {
1271     RUNTIME_STUBS_HEADER(LdGlobalICVar);
1272     JSHandle<JSTaggedValue> global = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1273     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1274     JSHandle<JSTaggedValue> profileHandle = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1275     JSTaggedValue slotId = GetArg(argv, argc, 3);  // 3: means the third parameter
1276 
1277     if (profileHandle->IsUndefined()) {
1278         return RuntimeLdGlobalVarFromProto(thread, global, prop).GetRawData();
1279     }
1280     LoadICRuntime icRuntime(
1281         thread, JSHandle<ProfileTypeInfo>::Cast(profileHandle), slotId.GetInt(), ICKind::NamedGlobalLoadIC);
1282     return icRuntime.LoadMiss(global, prop).GetRawData();
1283 }
1284 
DEF_RUNTIME_STUBS(StGlobalVar)1285 DEF_RUNTIME_STUBS(StGlobalVar)
1286 {
1287     RUNTIME_STUBS_HEADER(StGlobalVar);
1288     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1289     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1290     return RuntimeStGlobalVar(thread, prop, value).GetRawData();
1291 }
1292 
DEF_RUNTIME_STUBS(ToNumber)1293 DEF_RUNTIME_STUBS(ToNumber)
1294 {
1295     RUNTIME_STUBS_HEADER(ToNumber);
1296     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1297     return RuntimeToNumber(thread, value).GetRawData();
1298 }
1299 
DEF_RUNTIME_STUBS(ToBoolean)1300 DEF_RUNTIME_STUBS(ToBoolean)
1301 {
1302     RUNTIME_STUBS_HEADER(ToBoolean);
1303     JSTaggedValue value = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1304     bool result = value.ToBoolean();
1305     return JSTaggedValue(result).GetRawData();
1306 }
1307 
DEF_RUNTIME_STUBS(Eq)1308 DEF_RUNTIME_STUBS(Eq)
1309 {
1310     RUNTIME_STUBS_HEADER(Eq);
1311     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1312     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1313     return RuntimeEq(thread, left, right).GetRawData();
1314 }
1315 
DEF_RUNTIME_STUBS(NotEq)1316 DEF_RUNTIME_STUBS(NotEq)
1317 {
1318     RUNTIME_STUBS_HEADER(NotEq);
1319     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1320     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1321     return RuntimeNotEq(thread, left, right).GetRawData();
1322 }
1323 
DEF_RUNTIME_STUBS(Less)1324 DEF_RUNTIME_STUBS(Less)
1325 {
1326     RUNTIME_STUBS_HEADER(Less);
1327     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1328     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1329     return RuntimeLess(thread, left, right).GetRawData();
1330 }
1331 
DEF_RUNTIME_STUBS(LessEq)1332 DEF_RUNTIME_STUBS(LessEq)
1333 {
1334     RUNTIME_STUBS_HEADER(LessEq);
1335     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1336     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1337     return RuntimeLessEq(thread, left, right).GetRawData();
1338 }
1339 
DEF_RUNTIME_STUBS(Greater)1340 DEF_RUNTIME_STUBS(Greater)
1341 {
1342     RUNTIME_STUBS_HEADER(Greater);
1343     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1344     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1345     return RuntimeGreater(thread, left, right).GetRawData();
1346 }
1347 
DEF_RUNTIME_STUBS(GreaterEq)1348 DEF_RUNTIME_STUBS(GreaterEq)
1349 {
1350     RUNTIME_STUBS_HEADER(GreaterEq);
1351     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1352     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1353     return RuntimeGreaterEq(thread, left, right).GetRawData();
1354 }
1355 
DEF_RUNTIME_STUBS(Add2)1356 DEF_RUNTIME_STUBS(Add2)
1357 {
1358     RUNTIME_STUBS_HEADER(Add2);
1359     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1360     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1361     JSTaggedValue res = RuntimeAdd2(thread, left, right);
1362     return res.GetRawData();
1363 }
1364 
DEF_RUNTIME_STUBS(Sub2)1365 DEF_RUNTIME_STUBS(Sub2)
1366 {
1367     RUNTIME_STUBS_HEADER(Sub2);
1368     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1369     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1370     return RuntimeSub2(thread, left, right).GetRawData();
1371 }
1372 
DEF_RUNTIME_STUBS(Mul2)1373 DEF_RUNTIME_STUBS(Mul2)
1374 {
1375     RUNTIME_STUBS_HEADER(Mul2);
1376     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1377     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1378     return RuntimeMul2(thread, left, right).GetRawData();
1379 }
1380 
DEF_RUNTIME_STUBS(Div2)1381 DEF_RUNTIME_STUBS(Div2)
1382 {
1383     RUNTIME_STUBS_HEADER(Div2);
1384     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1385     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1386     return RuntimeDiv2(thread, left, right).GetRawData();
1387 }
1388 
DEF_RUNTIME_STUBS(Mod2)1389 DEF_RUNTIME_STUBS(Mod2)
1390 {
1391     RUNTIME_STUBS_HEADER(Mod2);
1392     JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1393     JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1394     return RuntimeMod2(thread, left, right).GetRawData();
1395 }
1396 
DEF_RUNTIME_STUBS(JumpToCInterpreter)1397 DEF_RUNTIME_STUBS(JumpToCInterpreter)
1398 {
1399     RUNTIME_STUBS_HEADER(JumpToCInterpreter);
1400     JSTaggedValue constpool = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1401     JSTaggedValue profileTypeInfo = GetArg(argv, argc, 1);  // 1: means the first parameter
1402     JSTaggedValue acc = GetArg(argv, argc, 2);  // 2: means the second parameter
1403     JSTaggedValue hotnessCounter = GetArg(argv, argc, 3);  // 3: means the third parameter
1404 
1405     auto sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1406     const uint8_t *currentPc = reinterpret_cast<const uint8_t*>(GET_ASM_FRAME(sp)->pc);
1407 
1408     uint8_t opcode = currentPc[0];
1409     asmDispatchTable[opcode](thread, currentPc, sp, constpool, profileTypeInfo, acc, hotnessCounter.GetInt());
1410     sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1411     return JSTaggedValue(reinterpret_cast<uint64_t>(sp)).GetRawData();
1412 }
1413 
DEF_RUNTIME_STUBS(JumpToDeprecatedInst)1414 DEF_RUNTIME_STUBS(JumpToDeprecatedInst)
1415 {
1416     RUNTIME_STUBS_HEADER(JumpToDeprecatedInst);
1417     JSTaggedValue constpool = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1418     JSTaggedValue profileTypeInfo = GetArg(argv, argc, 1);  // 1: means the first parameter
1419     JSTaggedValue acc = GetArg(argv, argc, 2);  // 2: means the second parameter
1420     JSTaggedValue hotnessCounter = GetArg(argv, argc, 3);  // 3: means the third parameter
1421 
1422     auto sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1423     const uint8_t *currentPc = reinterpret_cast<const uint8_t*>(GET_ASM_FRAME(sp)->pc);
1424 
1425     uint8_t opcode = currentPc[0];
1426     deprecatedDispatchTable[opcode](thread, currentPc, sp, constpool, profileTypeInfo, acc, hotnessCounter.GetInt());
1427     sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1428     return JSTaggedValue(reinterpret_cast<uint64_t>(sp)).GetRawData();
1429 }
1430 
DEF_RUNTIME_STUBS(JumpToWideInst)1431 DEF_RUNTIME_STUBS(JumpToWideInst)
1432 {
1433     RUNTIME_STUBS_HEADER(JumpToWideInst);
1434     JSTaggedValue constpool = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1435     JSTaggedValue profileTypeInfo = GetArg(argv, argc, 1);  // 1: means the first parameter
1436     JSTaggedValue acc = GetArg(argv, argc, 2);  // 2: means the second parameter
1437     JSTaggedValue hotnessCounter = GetArg(argv, argc, 3);  // 3: means the third parameter
1438 
1439     auto sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1440     const uint8_t *currentPc = reinterpret_cast<const uint8_t*>(GET_ASM_FRAME(sp)->pc);
1441 
1442     uint8_t opcode = currentPc[0];
1443     wideDispatchTable[opcode](thread, currentPc, sp, constpool, profileTypeInfo, acc, hotnessCounter.GetInt());
1444     sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1445     return JSTaggedValue(reinterpret_cast<uint64_t>(sp)).GetRawData();
1446 }
1447 
DEF_RUNTIME_STUBS(JumpToThrowInst)1448 DEF_RUNTIME_STUBS(JumpToThrowInst)
1449 {
1450     RUNTIME_STUBS_HEADER(JumpToThrowInst);
1451     JSTaggedValue constpool = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1452     JSTaggedValue profileTypeInfo = GetArg(argv, argc, 1);  // 1: means the first parameter
1453     JSTaggedValue acc = GetArg(argv, argc, 2);  // 2: means the second parameter
1454     JSTaggedValue hotnessCounter = GetArg(argv, argc, 3);  // 3: means the third parameter
1455 
1456     auto sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1457     const uint8_t *currentPc = reinterpret_cast<const uint8_t*>(GET_ASM_FRAME(sp)->pc);
1458 
1459     uint8_t opcode = currentPc[0];
1460     throwDispatchTable[opcode](thread, currentPc, sp, constpool, profileTypeInfo, acc, hotnessCounter.GetInt());
1461     sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1462     return JSTaggedValue(reinterpret_cast<uint64_t>(sp)).GetRawData();
1463 }
1464 
DEF_RUNTIME_STUBS(NotifyBytecodePcChanged)1465 DEF_RUNTIME_STUBS(NotifyBytecodePcChanged)
1466 {
1467     RUNTIME_STUBS_HEADER(NotifyBytecodePcChanged);
1468     FrameHandler frameHandler(thread);
1469     for (; frameHandler.HasFrame(); frameHandler.PrevJSFrame()) {
1470         if (frameHandler.IsEntryFrame() || frameHandler.IsBuiltinFrame()) {
1471             continue;
1472         }
1473         Method *method = frameHandler.GetMethod();
1474         // Skip builtins method
1475         if (method->IsNativeWithCallField()) {
1476             continue;
1477         }
1478         auto bcOffset = frameHandler.GetBytecodeOffset();
1479         auto *debuggerMgr = thread->GetEcmaVM()->GetJsDebuggerManager();
1480         debuggerMgr->GetNotificationManager()->BytecodePcChangedEvent(thread, method, bcOffset);
1481         return JSTaggedValue::Hole().GetRawData();
1482     }
1483     return JSTaggedValue::Hole().GetRawData();
1484 }
1485 
DEF_RUNTIME_STUBS(CreateEmptyObject)1486 DEF_RUNTIME_STUBS(CreateEmptyObject)
1487 {
1488     RUNTIME_STUBS_HEADER(CreateEmptyObject);
1489     EcmaVM *ecmaVm = thread->GetEcmaVM();
1490     ObjectFactory *factory = ecmaVm->GetFactory();
1491     JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
1492     return RuntimeCreateEmptyObject(thread, factory, globalEnv).GetRawData();
1493 }
1494 
DEF_RUNTIME_STUBS(CreateEmptyArray)1495 DEF_RUNTIME_STUBS(CreateEmptyArray)
1496 {
1497     RUNTIME_STUBS_HEADER(CreateEmptyArray);
1498     EcmaVM *ecmaVm = thread->GetEcmaVM();
1499     ObjectFactory *factory = ecmaVm->GetFactory();
1500     JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
1501     return RuntimeCreateEmptyArray(thread, factory, globalEnv).GetRawData();
1502 }
1503 
DEF_RUNTIME_STUBS(GetSymbolFunction)1504 DEF_RUNTIME_STUBS(GetSymbolFunction)
1505 {
1506     RUNTIME_STUBS_HEADER(GetSymbolFunction);
1507     EcmaVM *ecmaVm = thread->GetEcmaVM();
1508     JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
1509     return globalEnv->GetSymbolFunction().GetTaggedValue().GetRawData();
1510 }
1511 
DEF_RUNTIME_STUBS(GetUnmapedArgs)1512 DEF_RUNTIME_STUBS(GetUnmapedArgs)
1513 {
1514     RUNTIME_STUBS_HEADER(GetUnmapedArgs);
1515     auto sp = const_cast<JSTaggedType*>(thread->GetCurrentInterpretedFrame());
1516     uint32_t startIdx = 0;
1517     // 0: means restIdx
1518     uint32_t actualNumArgs = InterpreterAssembly::GetNumArgs(sp, 0, startIdx);
1519     return RuntimeGetUnmapedArgs(thread, sp, actualNumArgs, startIdx).GetRawData();
1520 }
1521 
DEF_RUNTIME_STUBS(CopyRestArgs)1522 DEF_RUNTIME_STUBS(CopyRestArgs)
1523 {
1524     RUNTIME_STUBS_HEADER(CopyRestArgs);
1525     JSTaggedValue restIdx = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1526     auto sp = const_cast<JSTaggedType*>(thread->GetCurrentInterpretedFrame());
1527     uint32_t startIdx = 0;
1528     uint32_t restNumArgs = InterpreterAssembly::GetNumArgs(sp, restIdx.GetInt(), startIdx);
1529     return RuntimeCopyRestArgs(thread, sp, restNumArgs, startIdx).GetRawData();
1530 }
1531 
DEF_RUNTIME_STUBS(CreateArrayWithBuffer)1532 DEF_RUNTIME_STUBS(CreateArrayWithBuffer)
1533 {
1534     RUNTIME_STUBS_HEADER(CreateArrayWithBuffer);
1535     JSHandle<JSTaggedValue> argArray = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1536     EcmaVM *ecmaVm = thread->GetEcmaVM();
1537     ObjectFactory *factory = ecmaVm->GetFactory();
1538     return RuntimeCreateArrayWithBuffer(thread, factory, argArray).GetRawData();
1539 }
1540 
DEF_RUNTIME_STUBS(CreateObjectWithBuffer)1541 DEF_RUNTIME_STUBS(CreateObjectWithBuffer)
1542 {
1543     RUNTIME_STUBS_HEADER(CreateObjectWithBuffer);
1544     JSHandle<JSObject> argObj = GetHArg<JSObject>(argv, argc, 0);  // 0: means the zeroth parameter
1545     EcmaVM *ecmaVm = thread->GetEcmaVM();
1546     ObjectFactory *factory = ecmaVm->GetFactory();
1547     return RuntimeCreateObjectWithBuffer(thread, factory, argObj).GetRawData();
1548 }
1549 
DEF_RUNTIME_STUBS(NewThisObject)1550 DEF_RUNTIME_STUBS(NewThisObject)
1551 {
1552     RUNTIME_STUBS_HEADER(NewThisObject);
1553     JSHandle<JSFunction> ctor(GetHArg<JSTaggedValue>(argv, argc, 0));  // 0: means the zeroth parameter
1554 
1555     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1556     JSHandle<JSObject> obj = factory->NewJSObjectByConstructor(ctor);
1557     RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
1558     return obj.GetTaggedType();  // state is not set here
1559 }
1560 
DEF_RUNTIME_STUBS(NewObjRange)1561 DEF_RUNTIME_STUBS(NewObjRange)
1562 {
1563     RUNTIME_STUBS_HEADER(NewObjRange);
1564     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1565     JSHandle<JSTaggedValue> newTarget = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1566     JSTaggedValue firstArgIdx = GetArg(argv, argc, 2);  // 2: means the second parameter
1567     JSTaggedValue length = GetArg(argv, argc, 3);  // 3: means the third parameter
1568     return RuntimeNewObjRange(thread, func, newTarget, static_cast<uint16_t>(firstArgIdx.GetInt()),
1569         static_cast<uint16_t>(length.GetInt())).GetRawData();
1570 }
1571 
DEF_RUNTIME_STUBS(DefineFunc)1572 DEF_RUNTIME_STUBS(DefineFunc)
1573 {
1574     RUNTIME_STUBS_HEADER(DefineFunc);
1575     JSHandle<Method> method = GetHArg<Method>(argv, argc, 0);  // 0: means the zeroth parameter
1576     return RuntimeDefinefunc(thread, method).GetRawData();
1577 }
1578 
DEF_RUNTIME_STUBS(CreateRegExpWithLiteral)1579 DEF_RUNTIME_STUBS(CreateRegExpWithLiteral)
1580 {
1581     RUNTIME_STUBS_HEADER(CreateRegExpWithLiteral);
1582     JSHandle<JSTaggedValue> pattern = GetHArg<JSTaggedValue>(argv, argc, 0);
1583     JSTaggedValue flags = GetArg(argv, argc, 1);
1584     return RuntimeCreateRegExpWithLiteral(thread, pattern, static_cast<uint8_t>(flags.GetInt())).GetRawData();
1585 }
1586 
DEF_RUNTIME_STUBS(ThrowIfSuperNotCorrectCall)1587 DEF_RUNTIME_STUBS(ThrowIfSuperNotCorrectCall)
1588 {
1589     RUNTIME_STUBS_HEADER(ThrowIfSuperNotCorrectCall);
1590     JSTaggedValue index = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1591     JSTaggedValue thisValue = GetArg(argv, argc, 1);  // 1: means the first parameter
1592     return RuntimeThrowIfSuperNotCorrectCall(thread, static_cast<uint16_t>(index.GetInt()), thisValue).GetRawData();
1593 }
1594 
DEF_RUNTIME_STUBS(CreateObjectHavingMethod)1595 DEF_RUNTIME_STUBS(CreateObjectHavingMethod)
1596 {
1597     RUNTIME_STUBS_HEADER(CreateObjectHavingMethod);
1598     JSHandle<JSObject> literal = GetHArg<JSObject>(argv, argc, 0);  // 0: means the zeroth parameter
1599     JSHandle<JSTaggedValue> env = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1600     EcmaVM *ecmaVm = thread->GetEcmaVM();
1601     ObjectFactory *factory = ecmaVm->GetFactory();
1602     return RuntimeCreateObjectHavingMethod(thread, factory, literal, env).GetRawData();
1603 }
1604 
DEF_RUNTIME_STUBS(CreateObjectWithExcludedKeys)1605 DEF_RUNTIME_STUBS(CreateObjectWithExcludedKeys)
1606 {
1607     RUNTIME_STUBS_HEADER(CreateObjectWithExcludedKeys);
1608     JSTaggedValue numKeys = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1609     JSHandle<JSTaggedValue> objVal = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1610     JSTaggedValue firstArgRegIdx = GetArg(argv, argc, 2);  // 2: means the second parameter
1611     return RuntimeCreateObjectWithExcludedKeys(thread, static_cast<uint16_t>(numKeys.GetInt()), objVal,
1612         static_cast<uint16_t>(firstArgRegIdx.GetInt())).GetRawData();
1613 }
1614 
DEF_RUNTIME_STUBS(DefineMethod)1615 DEF_RUNTIME_STUBS(DefineMethod)
1616 {
1617     RUNTIME_STUBS_HEADER(DefineMethod);
1618     JSHandle<Method> method = GetHArg<Method>(argv, argc, 0);  // 0: means the zeroth parameter
1619     JSHandle<JSTaggedValue> homeObject = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1620     return RuntimeDefineMethod(thread, method, homeObject).GetRawData();
1621 }
1622 
DEF_RUNTIME_STUBS(CallSpread)1623 DEF_RUNTIME_STUBS(CallSpread)
1624 {
1625     RUNTIME_STUBS_HEADER(CallSpread);
1626     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1627     JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1628     JSHandle<JSTaggedValue> array = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1629     return RuntimeCallSpread(thread, func, obj, array).GetRawData();
1630 }
1631 
DEF_RUNTIME_STUBS(DefineGetterSetterByValue)1632 DEF_RUNTIME_STUBS(DefineGetterSetterByValue)
1633 {
1634     RUNTIME_STUBS_HEADER(DefineGetterSetterByValue);
1635     JSHandle<JSObject> obj = GetHArg<JSObject>(argv, argc, 0);  // 0: means the zeroth parameter
1636     JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1637     JSHandle<JSTaggedValue> getter = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1638     JSHandle<JSTaggedValue> setter = GetHArg<JSTaggedValue>(argv, argc, 3);  // 3: means the third parameter
1639     JSTaggedValue flag = GetArg(argv, argc, 4);  // 4: means the fourth parameter
1640     bool bFlag = flag.ToBoolean();
1641     return RuntimeDefineGetterSetterByValue(thread, obj, prop, getter, setter, bFlag).GetRawData();
1642 }
1643 
DEF_RUNTIME_STUBS(SuperCall)1644 DEF_RUNTIME_STUBS(SuperCall)
1645 {
1646     RUNTIME_STUBS_HEADER(SuperCall);
1647     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1648     JSTaggedValue firstVRegIdx = GetArg(argv, argc, 1);  // 1: means the first parameter
1649     JSTaggedValue length = GetArg(argv, argc, 2);  // 2: means the second parameter
1650     auto sp = const_cast<JSTaggedType*>(thread->GetCurrentInterpretedFrame());
1651     JSTaggedValue newTarget = InterpreterAssembly::GetNewTarget(sp);
1652     return RuntimeSuperCall(thread, func, JSHandle<JSTaggedValue>(thread, newTarget),
1653         static_cast<uint16_t>(firstVRegIdx.GetInt()),
1654         static_cast<uint16_t>(length.GetInt())).GetRawData();
1655 }
1656 
DEF_RUNTIME_STUBS(OptSuperCall)1657 DEF_RUNTIME_STUBS(OptSuperCall)
1658 {
1659     RUNTIME_STUBS_HEADER(OptSuperCall);
1660     return RuntimeOptSuperCall(thread, argv, argc).GetRawData();
1661 }
1662 
DEF_RUNTIME_STUBS(ThrowNotCallableException)1663 DEF_RUNTIME_STUBS(ThrowNotCallableException)
1664 {
1665     RUNTIME_STUBS_HEADER(ThrowNotCallableException);
1666     EcmaVM *ecmaVm = thread->GetEcmaVM();
1667     ObjectFactory *factory = ecmaVm->GetFactory();
1668     JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR, "is not callable");
1669     thread->SetException(error.GetTaggedValue());
1670     return JSTaggedValue::Exception().GetRawData();
1671 }
1672 
DEF_RUNTIME_STUBS(ThrowSetterIsUndefinedException)1673 DEF_RUNTIME_STUBS(ThrowSetterIsUndefinedException)
1674 {
1675     RUNTIME_STUBS_HEADER(ThrowSetterIsUndefinedException);
1676     EcmaVM *ecmaVm = thread->GetEcmaVM();
1677     ObjectFactory *factory = ecmaVm->GetFactory();
1678     JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR,
1679         "Cannot set property when setter is undefined");
1680     thread->SetException(error.GetTaggedValue());
1681     return JSTaggedValue::Exception().GetRawData();
1682 }
1683 
DEF_RUNTIME_STUBS(ThrowCallConstructorException)1684 DEF_RUNTIME_STUBS(ThrowCallConstructorException)
1685 {
1686     RUNTIME_STUBS_HEADER(ThrowCallConstructorException);
1687     EcmaVM *ecmaVm = thread->GetEcmaVM();
1688     ObjectFactory *factory = ecmaVm->GetFactory();
1689     JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR,
1690                                                    "class constructor cannot called without 'new'");
1691     thread->SetException(error.GetTaggedValue());
1692     return JSTaggedValue::Exception().GetRawData();
1693 }
1694 
DEF_RUNTIME_STUBS(ThrowNonConstructorException)1695 DEF_RUNTIME_STUBS(ThrowNonConstructorException)
1696 {
1697     RUNTIME_STUBS_HEADER(ThrowNonConstructorException);
1698     EcmaVM *ecmaVm = thread->GetEcmaVM();
1699     ObjectFactory *factory = ecmaVm->GetFactory();
1700     JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR,
1701                                                    "function is non-constructor");
1702     thread->SetException(error.GetTaggedValue());
1703     return JSTaggedValue::Exception().GetRawData();
1704 }
1705 
DEF_RUNTIME_STUBS(ThrowStackOverflowException)1706 DEF_RUNTIME_STUBS(ThrowStackOverflowException)
1707 {
1708     RUNTIME_STUBS_HEADER(ThrowStackOverflowException);
1709     EcmaVM *ecmaVm = thread->GetEcmaVM();
1710     // Multi-thread could cause stack-overflow-check failed too,
1711     // so check thread here to distinguish it with the actual stack overflow.
1712     ecmaVm->CheckThread();
1713     ObjectFactory *factory = ecmaVm->GetFactory();
1714     JSHandle<JSObject> error = factory->GetJSError(ErrorType::RANGE_ERROR, "Stack overflow!", false);
1715     if (LIKELY(!thread->HasPendingException())) {
1716         thread->SetException(error.GetTaggedValue());
1717     }
1718     return JSTaggedValue::Exception().GetRawData();
1719 }
1720 
DEF_RUNTIME_STUBS(ThrowDerivedMustReturnException)1721 DEF_RUNTIME_STUBS(ThrowDerivedMustReturnException)
1722 {
1723     RUNTIME_STUBS_HEADER(ThrowDerivedMustReturnException);
1724     EcmaVM *ecmaVm = thread->GetEcmaVM();
1725     ObjectFactory *factory = ecmaVm->GetFactory();
1726     JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR,
1727                                                    "Derived constructor must return object or undefined");
1728     thread->SetException(error.GetTaggedValue());
1729     return JSTaggedValue::Exception().GetRawData();
1730 }
1731 
DEF_RUNTIME_STUBS(LdBigInt)1732 DEF_RUNTIME_STUBS(LdBigInt)
1733 {
1734     RUNTIME_STUBS_HEADER(LdBigInt);
1735     JSHandle<JSTaggedValue> numberBigInt = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1736     return RuntimeLdBigInt(thread, numberBigInt).GetRawData();
1737 }
1738 
DEF_RUNTIME_STUBS(ToNumeric)1739 DEF_RUNTIME_STUBS(ToNumeric)
1740 {
1741     RUNTIME_STUBS_HEADER(ToNumeric);
1742     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1743     return RuntimeToNumeric(thread, value).GetRawData();
1744 }
1745 
DEF_RUNTIME_STUBS(DynamicImport)1746 DEF_RUNTIME_STUBS(DynamicImport)
1747 {
1748     RUNTIME_STUBS_HEADER(DynamicImport);
1749     JSHandle<JSTaggedValue> specifier = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: means the zeroth parameter
1750     JSHandle<JSTaggedValue> currentFunc = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the zeroth parameter
1751     return RuntimeDynamicImport(thread, specifier, currentFunc).GetRawData();
1752 }
1753 
DEF_RUNTIME_STUBS(NewLexicalEnvWithName)1754 DEF_RUNTIME_STUBS(NewLexicalEnvWithName)
1755 {
1756     RUNTIME_STUBS_HEADER(NewLexicalEnvWithName);
1757     JSTaggedValue numVars = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1758     JSTaggedValue scopeId = GetArg(argv, argc, 1);  // 1: means the first parameter
1759     return RuntimeNewLexicalEnvWithName(thread,
1760         static_cast<uint16_t>(numVars.GetInt()),
1761         static_cast<uint16_t>(scopeId.GetInt())).GetRawData();
1762 }
1763 
DEF_RUNTIME_STUBS(OptGetUnmapedArgs)1764 DEF_RUNTIME_STUBS(OptGetUnmapedArgs)
1765 {
1766     RUNTIME_STUBS_HEADER(OptGetUnmapedArgs);
1767     JSTaggedValue actualNumArgs = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1768     return RuntimeOptGetUnmapedArgs(thread, actualNumArgs.GetInt()).GetRawData();
1769 }
1770 
DEF_RUNTIME_STUBS(OptNewLexicalEnvWithName)1771 DEF_RUNTIME_STUBS(OptNewLexicalEnvWithName)
1772 {
1773     RUNTIME_STUBS_HEADER(OptNewLexicalEnvWithName);
1774     JSTaggedValue taggedNumVars = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1775     JSTaggedValue taggedScopeId = GetArg(argv, argc, 1);  // 1: means the first parameter
1776     JSHandle<JSTaggedValue> currentLexEnv = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: means the second parameter
1777     JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 3);  // 3: means the third parameter
1778     uint16_t numVars = static_cast<uint16_t>(taggedNumVars.GetInt());
1779     uint16_t scopeId = static_cast<uint16_t>(taggedScopeId.GetInt());
1780     return RuntimeOptNewLexicalEnvWithName(thread, numVars, scopeId, currentLexEnv, func).GetRawData();
1781 }
1782 
DEF_RUNTIME_STUBS(OptCopyRestArgs)1783 DEF_RUNTIME_STUBS(OptCopyRestArgs)
1784 {
1785     RUNTIME_STUBS_HEADER(OptCopyRestArgs);
1786     JSTaggedValue actualArgc = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1787     JSTaggedValue restIndex = GetArg(argv, argc, 1);  // 1: means the first parameter
1788     return RuntimeOptCopyRestArgs(thread, actualArgc.GetInt(), restIndex.GetInt()).GetRawData();
1789 }
1790 
DEF_RUNTIME_STUBS(OptNewObjRange)1791 DEF_RUNTIME_STUBS(OptNewObjRange)
1792 {
1793     RUNTIME_STUBS_HEADER(OptNewObjRange);
1794     return RuntimeOptNewObjRange(thread, argv, argc).GetRawData();
1795 }
1796 
DEF_RUNTIME_STUBS(GetTypeArrayPropertyByIndex)1797 DEF_RUNTIME_STUBS(GetTypeArrayPropertyByIndex)
1798 {
1799     RUNTIME_STUBS_HEADER(GetTypeArrayPropertyByIndex);
1800     JSTaggedValue obj = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1801     JSTaggedValue idx = GetArg(argv, argc, 1);  // 1: means the first parameter
1802     JSTaggedValue jsType = GetArg(argv, argc, 2); // 2: means the second parameter
1803     return JSTypedArray::FastGetPropertyByIndex(thread, obj, idx.GetInt(), JSType(jsType.GetInt())).GetRawData();
1804 }
1805 
DEF_RUNTIME_STUBS(SetTypeArrayPropertyByIndex)1806 DEF_RUNTIME_STUBS(SetTypeArrayPropertyByIndex)
1807 {
1808     RUNTIME_STUBS_HEADER(SetTypeArrayPropertyByIndex);
1809     JSTaggedValue obj = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1810     JSTaggedValue idx = GetArg(argv, argc, 1);  // 1: means the first parameter
1811     JSTaggedValue value = GetArg(argv, argc, 2);  // 2: means the second parameter
1812     JSTaggedValue jsType = GetArg(argv, argc, 3); // 3: means the third parameter
1813     return JSTypedArray::FastSetPropertyByIndex(thread, obj, idx.GetInt(), value, JSType(jsType.GetInt())).GetRawData();
1814 }
1815 
DEF_RUNTIME_STUBS(DebugAOTPrint)1816 DEF_RUNTIME_STUBS(DebugAOTPrint)
1817 {
1818     RUNTIME_STUBS_HEADER(DebugAOTPrint);
1819     auto ecmaOpcode = GetArg(argv, argc, 0).GetInt();
1820     std::string result = kungfu::GetEcmaOpcodeStr(static_cast<EcmaOpcode>(ecmaOpcode));
1821     LOG_ECMA(INFO) << "aot slowpath " << result;
1822     return JSTaggedValue::Undefined().GetRawData();
1823 }
1824 
DEF_RUNTIME_STUBS(ProfileOptimizedCode)1825 DEF_RUNTIME_STUBS(ProfileOptimizedCode)
1826 {
1827     RUNTIME_STUBS_HEADER(ProfileOptimizedCode);
1828     EcmaOpcode ecmaOpcode = static_cast<EcmaOpcode>(GetArg(argv, argc, 0).GetInt());
1829     OptCodeProfiler::Mode mode = static_cast<OptCodeProfiler::Mode>(GetArg(argv, argc, 1).GetInt());
1830     OptCodeProfiler *profiler = thread->GetEcmaVM()->GetOptCodeProfiler();
1831     profiler->Update(ecmaOpcode, mode);
1832     return JSTaggedValue::Undefined().GetRawData();
1833 }
1834 
DEF_RUNTIME_STUBS(JSObjectGetMethod)1835 DEF_RUNTIME_STUBS(JSObjectGetMethod)
1836 {
1837     RUNTIME_STUBS_HEADER(JSObjectGetMethod);
1838     JSHandle<JSTaggedValue> obj(thread, GetArg(argv, argc, 0));
1839     JSHandle<JSTaggedValue> key(thread, GetArg(argv, argc, 1));
1840     JSHandle<JSTaggedValue> result = JSObject::GetMethod(thread, obj, key);
1841     return result->GetRawData();
1842 }
1843 
DEF_RUNTIME_STUBS(BigIntEqual)1844 DEF_RUNTIME_STUBS(BigIntEqual)
1845 {
1846     RUNTIME_STUBS_HEADER(BigIntEqual);
1847     JSTaggedValue left = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1848     JSTaggedValue right = GetArg(argv, argc, 1);  // 1: means the first parameter
1849     if (BigInt::Equal(left, right)) {
1850         return JSTaggedValue::VALUE_TRUE;
1851     }
1852     return JSTaggedValue::VALUE_FALSE;
1853 }
1854 
DEF_RUNTIME_STUBS(StringEqual)1855 DEF_RUNTIME_STUBS(StringEqual)
1856 {
1857     RUNTIME_STUBS_HEADER(StringEqual);
1858     JSTaggedValue left = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1859     JSTaggedValue right = GetArg(argv, argc, 1);  // 1: means the first parameter
1860     auto leftStr = EcmaString::Cast(left.GetTaggedObject());
1861     auto rightStr = EcmaString::Cast(right.GetTaggedObject());
1862     if (EcmaStringAccessor::StringsAreEqualSameUtfEncoding(leftStr, rightStr)) {
1863         return JSTaggedValue::VALUE_TRUE;
1864     }
1865     return JSTaggedValue::VALUE_FALSE;
1866 }
1867 
DEF_RUNTIME_STUBS(LdPatchVar)1868 DEF_RUNTIME_STUBS(LdPatchVar)
1869 {
1870     RUNTIME_STUBS_HEADER(LdPatchVar);
1871     JSTaggedValue idx = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1872     return RuntimeLdPatchVar(thread, idx.GetInt()).GetRawData();
1873 }
1874 
DEF_RUNTIME_STUBS(StPatchVar)1875 DEF_RUNTIME_STUBS(StPatchVar)
1876 {
1877     RUNTIME_STUBS_HEADER(StPatchVar);
1878     JSTaggedValue idx = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1879     JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: means the first parameter
1880     return RuntimeStPatchVar(thread, idx.GetInt(), value).GetRawData();
1881 }
1882 
DEF_RUNTIME_STUBS(NotifyConcurrentResult)1883 DEF_RUNTIME_STUBS(NotifyConcurrentResult)
1884 {
1885     RUNTIME_STUBS_HEADER(NotifyConcurrentResult);
1886     JSTaggedValue result = GetArg(argv, argc, 0);  // 0: means the zeroth parameter
1887     JSTaggedValue hint = GetArg(argv, argc, 1);  // 1: means the first parameter
1888     return RuntimeNotifyConcurrentResult(thread, result, hint).GetRawData();
1889 }
1890 
DEF_RUNTIME_STUBS(ContainerRBTreeForEach)1891 DEF_RUNTIME_STUBS(ContainerRBTreeForEach)
1892 {
1893     RUNTIME_STUBS_HEADER(ContainerRBTreeForEach);
1894     JSHandle<JSTaggedValue> node = GetHArg<JSTaggedValue>(argv, argc, 0);  // 0: param index
1895     JSHandle<JSTaggedValue> callbackFnHandle = GetHArg<JSTaggedValue>(argv, argc, 1);  // 1: param index
1896     JSHandle<JSTaggedValue> thisArgHandle = GetHArg<JSTaggedValue>(argv, argc, 2);  // 2: param index
1897     JSHandle<JSTaggedValue> thisHandle = GetHArg<JSTaggedValue>(argv, argc, 3);  // 3: param index
1898     JSHandle<JSTaggedValue> type = GetHArg<JSTaggedValue>(argv, argc, 4);  // 4: param index
1899 
1900     ASSERT(node->IsRBTreeNode());
1901     ASSERT(callbackFnHandle->IsCallable());
1902     ASSERT(type->IsInt());
1903     JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
1904     auto containersType = static_cast<kungfu::ContainersType>(type->GetInt());
1905     JSMutableHandle<TaggedQueue> queue(thread, thread->GetEcmaVM()->GetFactory()->NewTaggedQueue(0));
1906     JSMutableHandle<RBTreeNode> treeNode(thread, JSTaggedValue::Undefined());
1907     queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, node)));
1908     while (!queue->Empty()) {
1909         treeNode.Update(queue->Pop(thread));
1910         EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle,
1911                                                                         undefined, 3); // 3: three args
1912         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
1913         info->SetCallArg(containersType == kungfu::ContainersType::HASHSET_FOREACH ?
1914                          treeNode->GetKey() : treeNode->GetValue(), treeNode->GetKey(), thisHandle.GetTaggedValue());
1915         JSTaggedValue funcResult = JSFunction::Call(info);
1916         RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult.GetRawData());
1917         if (!treeNode->GetLeft().IsHole()) {
1918             JSHandle<JSTaggedValue> left(thread, treeNode->GetLeft());
1919             queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, left)));
1920         }
1921         if (!treeNode->GetRight().IsHole()) {
1922             JSHandle<JSTaggedValue> right(thread, treeNode->GetRight());
1923             queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, right)));
1924         }
1925     }
1926     return JSTaggedValue::True().GetRawData();
1927 }
1928 
CreateArrayFromList(uintptr_t argGlue,int32_t argc,JSTaggedValue * argvPtr)1929 JSTaggedType RuntimeStubs::CreateArrayFromList([[maybe_unused]]uintptr_t argGlue, int32_t argc, JSTaggedValue *argvPtr)
1930 {
1931     auto thread = JSThread::GlueToJSThread(argGlue);
1932     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1933     JSHandle<TaggedArray> taggedArray = factory->NewTaggedArray(argc - NUM_MANDATORY_JSFUNC_ARGS);
1934     for (int index = NUM_MANDATORY_JSFUNC_ARGS; index < argc; ++index) {
1935         taggedArray->Set(thread, index - NUM_MANDATORY_JSFUNC_ARGS, argvPtr[index]);
1936     }
1937     JSHandle<JSArray> arrHandle = JSArray::CreateArrayFromList(thread, taggedArray);
1938     return arrHandle.GetTaggedValue().GetRawData();
1939 }
1940 
FindElementWithCache(uintptr_t argGlue,JSTaggedType hclass,JSTaggedType key,int32_t num)1941 int32_t RuntimeStubs::FindElementWithCache(uintptr_t argGlue, JSTaggedType hclass,
1942                                            JSTaggedType key, int32_t num)
1943 {
1944     auto thread = JSThread::GlueToJSThread(argGlue);
1945     auto cls  = reinterpret_cast<JSHClass *>(hclass);
1946     JSTaggedValue propKey = JSTaggedValue(key);
1947     auto layoutInfo = LayoutInfo::Cast(cls->GetLayout().GetTaggedObject());
1948     PropertiesCache *cache = thread->GetPropertiesCache();
1949     int index = cache->Get(cls, propKey);
1950     if (index == PropertiesCache::NOT_FOUND) {
1951         index = layoutInfo->BinarySearch(propKey, num);
1952         cache->Set(cls, propKey, index);
1953     }
1954     return index;
1955 }
1956 
GetActualArgvNoGC(uintptr_t argGlue)1957 JSTaggedType RuntimeStubs::GetActualArgvNoGC(uintptr_t argGlue)
1958 {
1959     auto thread = JSThread::GlueToJSThread(argGlue);
1960     JSTaggedType *current = const_cast<JSTaggedType *>(thread->GetLastLeaveFrame());
1961     FrameIterator it(current, thread);
1962     ASSERT(it.IsOptimizedFrame());
1963     it.Advance<GCVisitedFlag::VISITED>();
1964     ASSERT(it.IsOptimizedJSFunctionFrame());
1965     auto optimizedJSFunctionFrame = it.GetFrame<OptimizedJSFunctionFrame>();
1966     return reinterpret_cast<uintptr_t>(optimizedJSFunctionFrame->GetArgv(it));
1967 }
1968 
FloatMod(double x,double y)1969 JSTaggedType RuntimeStubs::FloatMod(double x, double y)
1970 {
1971     double result = std::fmod(x, y);
1972     return JSTaggedValue(result).GetRawData();
1973 }
1974 
FloatSqrt(double x)1975 JSTaggedType RuntimeStubs::FloatSqrt(double x)
1976 {
1977     double result = std::sqrt(x);
1978     return JSTaggedValue(result).GetRawData();
1979 }
1980 
FloatCos(double x)1981 JSTaggedType RuntimeStubs::FloatCos(double x)
1982 {
1983     double result = std::cos(x);
1984     return JSTaggedValue(result).GetRawData();
1985 }
1986 
FloatSin(double x)1987 JSTaggedType RuntimeStubs::FloatSin(double x)
1988 {
1989     double result = std::sin(x);
1990     return JSTaggedValue(result).GetRawData();
1991 }
1992 
FloatACos(double x)1993 JSTaggedType RuntimeStubs::FloatACos(double x)
1994 {
1995     double result = std::acos(x);
1996     return JSTaggedValue(result).GetRawData();
1997 }
1998 
FloatATan(double x)1999 JSTaggedType RuntimeStubs::FloatATan(double x)
2000 {
2001     double result = std::atan(x);
2002     return JSTaggedValue(result).GetRawData();
2003 }
2004 
FloatFloor(double x)2005 JSTaggedType RuntimeStubs::FloatFloor(double x)
2006 {
2007     ASSERT(!std::isnan(x));
2008     double result = std::floor(x);
2009     return JSTaggedValue(result).GetRawData();
2010 }
2011 
DoubleToInt(double x)2012 int32_t RuntimeStubs::DoubleToInt(double x)
2013 {
2014     return base::NumberHelper::DoubleToInt(x, base::INT32_BITS);
2015 }
2016 
InsertOldToNewRSet(uintptr_t argGlue,uintptr_t object,size_t offset)2017 void RuntimeStubs::InsertOldToNewRSet([[maybe_unused]]uintptr_t argGlue,
2018     uintptr_t object, size_t offset)
2019 {
2020     Region *region = Region::ObjectAddressToRange(object);
2021     uintptr_t slotAddr = object + offset;
2022     return region->InsertOldToNewRSet(slotAddr);
2023 }
2024 
MarkingBarrier(uintptr_t argGlue,uintptr_t object,size_t offset,TaggedObject * value)2025 void RuntimeStubs::MarkingBarrier([[maybe_unused]]uintptr_t argGlue,
2026     uintptr_t object, size_t offset, TaggedObject *value)
2027 {
2028     uintptr_t slotAddr = object + offset;
2029     Region *objectRegion = Region::ObjectAddressToRange(object);
2030     Region *valueRegion = Region::ObjectAddressToRange(value);
2031     if (!valueRegion->IsMarking()) {
2032         return;
2033     }
2034     Barriers::Update(slotAddr, objectRegion, value, valueRegion);
2035 }
2036 
StoreBarrier(uintptr_t argGlue,uintptr_t object,size_t offset,TaggedObject * value)2037 void RuntimeStubs::StoreBarrier([[maybe_unused]]uintptr_t argGlue,
2038     uintptr_t object, size_t offset, TaggedObject *value)
2039 {
2040     uintptr_t slotAddr = object + offset;
2041     Region *objectRegion = Region::ObjectAddressToRange(object);
2042     Region *valueRegion = Region::ObjectAddressToRange(value);
2043     if (!objectRegion->InYoungSpace() && valueRegion->InYoungSpace()) {
2044         // Should align with '8' in 64 and 32 bit platform
2045         ASSERT((slotAddr % static_cast<uint8_t>(MemAlignment::MEM_ALIGN_OBJECT)) == 0);
2046         objectRegion->InsertOldToNewRSet(slotAddr);
2047     }
2048     if (!valueRegion->IsMarking()) {
2049         return;
2050     }
2051     Barriers::Update(slotAddr, objectRegion, value, valueRegion);
2052 }
2053 
StringsAreEquals(EcmaString * str1,EcmaString * str2)2054 bool RuntimeStubs::StringsAreEquals(EcmaString *str1, EcmaString *str2)
2055 {
2056     return EcmaStringAccessor::StringsAreEqualSameUtfEncoding(str1, str2);
2057 }
2058 
BigIntEquals(JSTaggedType left,JSTaggedType right)2059 bool RuntimeStubs::BigIntEquals(JSTaggedType left, JSTaggedType right)
2060 {
2061     return BigInt::Equal(JSTaggedValue(left), JSTaggedValue(right));
2062 }
2063 
TimeClip(double time)2064 double RuntimeStubs::TimeClip(double time)
2065 {
2066     return JSDate::TimeClip(time);
2067 }
2068 
SetDateValues(double year,double month,double day)2069 double RuntimeStubs::SetDateValues(double year, double month, double day)
2070 {
2071     if (std::isnan(year) || !std::isfinite(year) || std::isnan(month) || !std::isfinite(month) || std::isnan(day) ||
2072         !std::isfinite(day)) {
2073         return base::NAN_VALUE;
2074     }
2075 
2076     return JSDate::SetDateValues(static_cast<int64_t>(year), static_cast<int64_t>(month), static_cast<int64_t>(day));
2077 }
2078 
NewObject(EcmaRuntimeCallInfo * info)2079 JSTaggedValue RuntimeStubs::NewObject(EcmaRuntimeCallInfo *info)
2080 {
2081     ASSERT(info);
2082     JSThread *thread = info->GetThread();
2083     JSHandle<JSTaggedValue> func(info->GetFunction());
2084     if (!func->IsHeapObject()) {
2085         THROW_TYPE_ERROR_AND_RETURN(thread, "function is nullptr", JSTaggedValue::Exception());
2086     }
2087 
2088     if (!func->IsJSFunction()) {
2089         if (func->IsBoundFunction()) {
2090             JSTaggedValue result = JSBoundFunction::ConstructInternal(info);
2091             RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
2092             return result;
2093         }
2094 
2095         if (func->IsJSProxy()) {
2096             JSTaggedValue jsObj = JSProxy::ConstructInternal(info);
2097             RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
2098             return jsObj;
2099         }
2100         THROW_TYPE_ERROR_AND_RETURN(thread, "Constructed NonConstructable", JSTaggedValue::Exception());
2101     }
2102 
2103     JSTaggedValue result = JSFunction::ConstructInternal(info);
2104     RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
2105     return result;
2106 }
2107 
SaveFrameToContext(JSThread * thread,JSHandle<GeneratorContext> context)2108 void RuntimeStubs::SaveFrameToContext(JSThread *thread, JSHandle<GeneratorContext> context)
2109 {
2110     FrameHandler frameHandler(thread);
2111     ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
2112     uint32_t nregs = frameHandler.GetNumberArgs();
2113     JSHandle<TaggedArray> regsArray = factory->NewTaggedArray(nregs);
2114     for (uint32_t i = 0; i < nregs; i++) {
2115         JSTaggedValue value = frameHandler.GetVRegValue(i);
2116         regsArray->Set(thread, i, value);
2117     }
2118     context->SetRegsArray(thread, regsArray.GetTaggedValue());
2119     context->SetMethod(thread, frameHandler.GetFunction());
2120     context->SetThis(thread, frameHandler.GetThis());
2121 
2122     BytecodeInstruction ins(frameHandler.GetPc());
2123     auto offset = ins.GetSize();
2124     context->SetAcc(thread, frameHandler.GetAcc());
2125     context->SetLexicalEnv(thread, thread->GetCurrentLexenv());
2126     context->SetNRegs(nregs);
2127     context->SetBCOffset(frameHandler.GetBytecodeOffset() + offset);
2128 }
2129 
CallBoundFunction(EcmaRuntimeCallInfo * info)2130 JSTaggedValue RuntimeStubs::CallBoundFunction(EcmaRuntimeCallInfo *info)
2131 {
2132     JSThread *thread = info->GetThread();
2133     JSHandle<JSBoundFunction> boundFunc(info->GetFunction());
2134     JSHandle<JSFunction> targetFunc(thread, boundFunc->GetBoundTarget());
2135     if (targetFunc->IsClassConstructor()) {
2136         THROW_TYPE_ERROR_AND_RETURN(thread, "class constructor cannot called without 'new'",
2137                                     JSTaggedValue::Exception());
2138     }
2139 
2140     JSHandle<TaggedArray> boundArgs(thread, boundFunc->GetBoundArguments());
2141     const int32_t boundLength = static_cast<int32_t>(boundArgs->GetLength());
2142     const int32_t argsLength = static_cast<int32_t>(info->GetArgsNumber()) + boundLength;
2143     JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
2144     EcmaRuntimeCallInfo *runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle<JSTaggedValue>(targetFunc),
2145         info->GetThis(), undefined, argsLength);
2146     RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
2147     if (boundLength == 0) {
2148         runtimeInfo->SetCallArg(argsLength, 0, info, 0);
2149     } else {
2150         // 0 ~ boundLength is boundArgs; boundLength ~ argsLength is args of EcmaRuntimeCallInfo.
2151         runtimeInfo->SetCallArg(boundLength, boundArgs);
2152         runtimeInfo->SetCallArg(argsLength, boundLength, info, 0);
2153     }
2154     return EcmaInterpreter::Execute(runtimeInfo);
2155 }
2156 
DEF_RUNTIME_STUBS(DeoptHandler)2157 DEF_RUNTIME_STUBS(DeoptHandler)
2158 {
2159     RUNTIME_STUBS_HEADER(DeoptHandler);
2160 
2161     Deoptimizier deopt(thread);
2162     std::vector<kungfu::ARKDeopt> deoptBundle;
2163     deopt.CollectDeoptBundleVec(deoptBundle);
2164     ASSERT(!deoptBundle.empty());
2165     deopt.CollectVregs(deoptBundle);
2166 
2167     uintptr_t *args = reinterpret_cast<uintptr_t *>(argv);
2168     kungfu::DeoptType type = static_cast<kungfu::DeoptType>(args[0]);
2169     return deopt.ConstructAsmInterpretFrame(type);
2170 }
2171 
Initialize(JSThread * thread)2172 void RuntimeStubs::Initialize(JSThread *thread)
2173 {
2174 #define DEF_RUNTIME_STUB(name) kungfu::RuntimeStubCSigns::ID_##name
2175 #define INITIAL_RUNTIME_FUNCTIONS(name) \
2176     thread->RegisterRTInterface(DEF_RUNTIME_STUB(name), reinterpret_cast<uintptr_t>(name));
2177     RUNTIME_STUB_WITHOUT_GC_LIST(INITIAL_RUNTIME_FUNCTIONS)
2178     RUNTIME_STUB_WITH_GC_LIST(INITIAL_RUNTIME_FUNCTIONS)
2179     TEST_RUNTIME_STUB_GC_LIST(INITIAL_RUNTIME_FUNCTIONS)
2180 #undef INITIAL_RUNTIME_FUNCTIONS
2181 #undef DEF_RUNTIME_STUB
2182 }
2183 
2184 #if defined(__clang__)
2185 #pragma clang diagnostic pop
2186 #elif defined(__GNUC__)
2187 #pragma GCC diagnostic pop
2188 #endif
2189 }  // namespace panda::ecmascript
2190