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