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); // 2: means the second parameter
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 if (baseValue.IsNumber() && exponentValue.IsNumber()) {
515 // fast path
516 double doubleBase = baseValue.IsInt() ? baseValue.GetInt() : baseValue.GetDouble();
517 double doubleExponent = exponentValue.IsInt() ? exponentValue.GetInt() : exponentValue.GetDouble();
518 if (std::abs(doubleBase) == 1 && std::isinf(doubleExponent)) {
519 return JSTaggedValue(base::NAN_VALUE).GetRawData();
520 }
521 if ((doubleBase == 0 &&
522 ((base::bit_cast<uint64_t>(doubleBase)) & base::DOUBLE_SIGN_MASK) == base::DOUBLE_SIGN_MASK) &&
523 std::isfinite(doubleExponent) && base::NumberHelper::TruncateDouble(doubleExponent) == doubleExponent &&
524 base::NumberHelper::TruncateDouble(doubleExponent / 2) + base::HALF == // 2 : half
525 (doubleExponent / 2)) { // 2 : half
526 if (doubleExponent > 0) {
527 return JSTaggedValue(-0.0).GetRawData();
528 }
529 if (doubleExponent < 0) {
530 return JSTaggedValue(-base::POSITIVE_INFINITY).GetRawData();
531 }
532 }
533 return JSTaggedValue(std::pow(doubleBase, doubleExponent)).GetRawData();
534 }
535 // Slow path
536 JSTaggedValue res = RuntimeExp(thread, baseValue, exponentValue);
537 return res.GetRawData();
538 }
539
DEF_RUNTIME_STUBS(IsIn)540 DEF_RUNTIME_STUBS(IsIn)
541 {
542 RUNTIME_STUBS_HEADER(IsIn);
543 JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
544 JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
545 return RuntimeIsIn(thread, prop, obj).GetRawData();
546 }
547
DEF_RUNTIME_STUBS(InstanceOf)548 DEF_RUNTIME_STUBS(InstanceOf)
549 {
550 RUNTIME_STUBS_HEADER(InstanceOf);
551 JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
552 JSHandle<JSTaggedValue> target = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
553 return RuntimeInstanceof(thread, obj, target).GetRawData();
554 }
555
DEF_RUNTIME_STUBS(CreateGeneratorObj)556 DEF_RUNTIME_STUBS(CreateGeneratorObj)
557 {
558 RUNTIME_STUBS_HEADER(CreateGeneratorObj);
559 JSHandle<JSTaggedValue> genFunc = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
560 return RuntimeCreateGeneratorObj(thread, genFunc).GetRawData();
561 }
562
DEF_RUNTIME_STUBS(CreateAsyncGeneratorObj)563 DEF_RUNTIME_STUBS(CreateAsyncGeneratorObj)
564 {
565 RUNTIME_STUBS_HEADER(CreateAsyncGeneratorObj);
566 JSHandle<JSTaggedValue> genFunc = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
567 return RuntimeCreateAsyncGeneratorObj(thread, genFunc).GetRawData();
568 }
569
DEF_RUNTIME_STUBS(GetTemplateObject)570 DEF_RUNTIME_STUBS(GetTemplateObject)
571 {
572 RUNTIME_STUBS_HEADER(GetTemplateObject);
573 JSHandle<JSTaggedValue> literal = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
574 return RuntimeGetTemplateObject(thread, literal).GetRawData();
575 }
576
DEF_RUNTIME_STUBS(GetNextPropName)577 DEF_RUNTIME_STUBS(GetNextPropName)
578 {
579 RUNTIME_STUBS_HEADER(GetNextPropName);
580 JSHandle<JSTaggedValue> iter = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
581 return RuntimeGetNextPropName(thread, iter).GetRawData();
582 }
583
DEF_RUNTIME_STUBS(IterNext)584 DEF_RUNTIME_STUBS(IterNext)
585 {
586 RUNTIME_STUBS_HEADER(IterNext);
587 JSHandle<JSTaggedValue> iter = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
588 return RuntimeIterNext(thread, iter).GetRawData();
589 }
590
DEF_RUNTIME_STUBS(CloseIterator)591 DEF_RUNTIME_STUBS(CloseIterator)
592 {
593 RUNTIME_STUBS_HEADER(CloseIterator);
594 JSHandle<JSTaggedValue> iter = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
595 return RuntimeCloseIterator(thread, iter).GetRawData();
596 }
597
DEF_RUNTIME_STUBS(SuperCallSpread)598 DEF_RUNTIME_STUBS(SuperCallSpread)
599 {
600 RUNTIME_STUBS_HEADER(SuperCallSpread);
601 JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
602 JSHandle<JSTaggedValue> array = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
603 auto sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
604 JSTaggedValue function = InterpreterAssembly::GetNewTarget(sp);
605 return RuntimeSuperCallSpread(thread, func, JSHandle<JSTaggedValue>(thread, function), array).GetRawData();
606 }
607
DEF_RUNTIME_STUBS(OptSuperCallSpread)608 DEF_RUNTIME_STUBS(OptSuperCallSpread)
609 {
610 RUNTIME_STUBS_HEADER(OptSuperCallSpread);
611 JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
612 JSHandle<JSTaggedValue> newTarget = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
613 JSHandle<JSTaggedValue> array = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
614 return RuntimeSuperCallSpread(thread, func, newTarget, array).GetRawData();
615 }
616
DEF_RUNTIME_STUBS(DelObjProp)617 DEF_RUNTIME_STUBS(DelObjProp)
618 {
619 RUNTIME_STUBS_HEADER(DelObjProp);
620 JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
621 JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
622 return RuntimeDelObjProp(thread, obj, prop).GetRawData();
623 }
624
DEF_RUNTIME_STUBS(NewObjApply)625 DEF_RUNTIME_STUBS(NewObjApply)
626 {
627 RUNTIME_STUBS_HEADER(NewObjApply);
628 JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
629 JSHandle<JSTaggedValue> array = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
630 return RuntimeNewObjApply(thread, func, array).GetRawData();
631 }
632
DEF_RUNTIME_STUBS(CreateIterResultObj)633 DEF_RUNTIME_STUBS(CreateIterResultObj)
634 {
635 RUNTIME_STUBS_HEADER(CreateIterResultObj);
636 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
637 JSTaggedValue flag = GetArg(argv, argc, 1); // 1: means the first parameter
638 return RuntimeCreateIterResultObj(thread, value, flag).GetRawData();
639 }
640
DEF_RUNTIME_STUBS(AsyncFunctionAwaitUncaught)641 DEF_RUNTIME_STUBS(AsyncFunctionAwaitUncaught)
642 {
643 RUNTIME_STUBS_HEADER(AsyncFunctionAwaitUncaught);
644 JSHandle<JSTaggedValue> asyncFuncObj = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
645 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
646 return RuntimeAsyncFunctionAwaitUncaught(thread, asyncFuncObj, value).GetRawData();
647 }
648
DEF_RUNTIME_STUBS(AsyncFunctionResolveOrReject)649 DEF_RUNTIME_STUBS(AsyncFunctionResolveOrReject)
650 {
651 RUNTIME_STUBS_HEADER(AsyncFunctionResolveOrReject);
652 JSHandle<JSTaggedValue> asyncFuncObj = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
653 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
654 JSTaggedValue isResolve = GetArg(argv, argc, 2); // 2: means the second parameter
655 return RuntimeAsyncFunctionResolveOrReject(thread, asyncFuncObj, value, isResolve.IsTrue()).GetRawData();
656 }
657
DEF_RUNTIME_STUBS(AsyncGeneratorResolve)658 DEF_RUNTIME_STUBS(AsyncGeneratorResolve)
659 {
660 RUNTIME_STUBS_HEADER(AsyncGeneratorResolve);
661 JSHandle<JSTaggedValue> asyncGenerator = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
662 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
663 JSTaggedValue flag = GetArg(argv, argc, 2); // 2: means the second parameter
664 return RuntimeAsyncGeneratorResolve(thread, asyncGenerator, value, flag).GetRawData();
665 }
666
DEF_RUNTIME_STUBS(AsyncGeneratorReject)667 DEF_RUNTIME_STUBS(AsyncGeneratorReject)
668 {
669 RUNTIME_STUBS_HEADER(AsyncGeneratorReject);
670 JSHandle<JSTaggedValue> asyncGenerator = GetHArg<JSTaggedValue>(argv, argc, 0);
671 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1);
672 return RuntimeAsyncGeneratorReject(thread, asyncGenerator, value).GetRawData();
673 }
674
DEF_RUNTIME_STUBS(SetGeneratorState)675 DEF_RUNTIME_STUBS(SetGeneratorState)
676 {
677 RUNTIME_STUBS_HEADER(SetGeneratorState);
678 JSHandle<JSTaggedValue> asyncGenerator = GetHArg<JSTaggedValue>(argv, argc, 0);
679 JSTaggedValue index = GetArg(argv, argc, 1);
680 RuntimeSetGeneratorState(thread, asyncGenerator, index.GetInt());
681 return JSTaggedValue::Hole().GetRawData();
682 }
683
DEF_RUNTIME_STUBS(CopyDataProperties)684 DEF_RUNTIME_STUBS(CopyDataProperties)
685 {
686 RUNTIME_STUBS_HEADER(CopyDataProperties);
687 JSHandle<JSTaggedValue> dst = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
688 JSHandle<JSTaggedValue> src = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
689 return RuntimeCopyDataProperties(thread, dst, src).GetRawData();
690 }
691
DEF_RUNTIME_STUBS(StArraySpread)692 DEF_RUNTIME_STUBS(StArraySpread)
693 {
694 RUNTIME_STUBS_HEADER(StArraySpread);
695 JSHandle<JSTaggedValue> dst = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
696 JSTaggedValue index = GetArg(argv, argc, 1); // 1: means the first parameter
697 JSHandle<JSTaggedValue> src = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
698 return RuntimeStArraySpread(thread, dst, index, src).GetRawData();
699 }
700
DEF_RUNTIME_STUBS(GetIteratorNext)701 DEF_RUNTIME_STUBS(GetIteratorNext)
702 {
703 RUNTIME_STUBS_HEADER(GetIteratorNext);
704 JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
705 JSHandle<JSTaggedValue> method = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
706 return RuntimeGetIteratorNext(thread, obj, method).GetRawData();
707 }
708
DEF_RUNTIME_STUBS(SetObjectWithProto)709 DEF_RUNTIME_STUBS(SetObjectWithProto)
710 {
711 RUNTIME_STUBS_HEADER(SetObjectWithProto);
712 JSHandle<JSTaggedValue> proto = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
713 JSHandle<JSObject> obj = GetHArg<JSObject>(argv, argc, 1); // 1: means the first parameter
714 return RuntimeSetObjectWithProto(thread, proto, obj).GetRawData();
715 }
716
DEF_RUNTIME_STUBS(LoadICByValue)717 DEF_RUNTIME_STUBS(LoadICByValue)
718 {
719 RUNTIME_STUBS_HEADER(LoadICByValue);
720 JSHandle<JSTaggedValue> profileTypeInfo = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
721 JSHandle<JSTaggedValue> receiver = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
722 JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
723 JSTaggedValue slotId = GetArg(argv, argc, 3); // 3: means the third parameter
724
725 if (profileTypeInfo->IsUndefined()) {
726 return RuntimeLdObjByValue(thread, receiver, key, false, JSTaggedValue::Undefined()).GetRawData();
727 }
728 JSHandle<JSTaggedValue> propKey = JSTaggedValue::ToPropertyKey(thread, key);
729 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
730 LoadICRuntime icRuntime(thread, JSHandle<ProfileTypeInfo>::Cast(profileTypeInfo), slotId.GetInt(), ICKind::LoadIC);
731 return icRuntime.LoadMiss(receiver, propKey).GetRawData();
732 }
733
DEF_RUNTIME_STUBS(StoreICByValue)734 DEF_RUNTIME_STUBS(StoreICByValue)
735 {
736 RUNTIME_STUBS_HEADER(StoreICByValue);
737 JSHandle<JSTaggedValue> profileTypeInfo = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
738 JSHandle<JSTaggedValue> receiver = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
739 JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
740 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 3); // 3: means the third parameter
741 JSTaggedValue slotId = GetArg(argv, argc, 4); // 4: means the fourth parameter
742
743 if (profileTypeInfo->IsUndefined()) {
744 return RuntimeStObjByValue(thread, receiver, key, value).GetRawData();
745 }
746 JSHandle<JSTaggedValue> propKey = JSTaggedValue::ToPropertyKey(thread, key);
747 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
748 StoreICRuntime icRuntime(thread, JSHandle<ProfileTypeInfo>::Cast(profileTypeInfo), slotId.GetInt(),
749 ICKind::StoreIC);
750 return icRuntime.StoreMiss(receiver, propKey, value).GetRawData();
751 }
752
DEF_RUNTIME_STUBS(StOwnByValue)753 DEF_RUNTIME_STUBS(StOwnByValue)
754 {
755 RUNTIME_STUBS_HEADER(StOwnByValue);
756 JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
757 JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
758 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
759
760 return RuntimeStOwnByValue(thread, obj, key, value).GetRawData();
761 }
762
DEF_RUNTIME_STUBS(LdSuperByValue)763 DEF_RUNTIME_STUBS(LdSuperByValue)
764 {
765 RUNTIME_STUBS_HEADER(LdSuperByValue);
766 JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
767 JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
768 auto sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
769 JSTaggedValue thisFunc = InterpreterAssembly::GetFunction(sp);
770 return RuntimeLdSuperByValue(thread, obj, key, thisFunc).GetRawData();
771 }
772
DEF_RUNTIME_STUBS(OptLdSuperByValue)773 DEF_RUNTIME_STUBS(OptLdSuperByValue)
774 {
775 RUNTIME_STUBS_HEADER(OptLdSuperByValue);
776 JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
777 JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
778 JSTaggedValue thisFunc = GetArg(argv, argc, 2); // 2: means the second parameter
779 return RuntimeLdSuperByValue(thread, obj, key, thisFunc).GetRawData();
780 }
781
DEF_RUNTIME_STUBS(StSuperByValue)782 DEF_RUNTIME_STUBS(StSuperByValue)
783 {
784 RUNTIME_STUBS_HEADER(StSuperByValue);
785 JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
786 JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
787 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
788 auto sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
789 JSTaggedValue thisFunc = InterpreterAssembly::GetFunction(sp);
790 return RuntimeStSuperByValue(thread, obj, key, value, thisFunc).GetRawData();
791 }
792
DEF_RUNTIME_STUBS(OptStSuperByValue)793 DEF_RUNTIME_STUBS(OptStSuperByValue)
794 {
795 RUNTIME_STUBS_HEADER(OptStSuperByValue);
796 JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
797 JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
798 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
799 JSTaggedValue thisFunc = GetArg(argv, argc, 3); // 3: means the third parameter
800 return RuntimeStSuperByValue(thread, obj, key, value, thisFunc).GetRawData();
801 }
802
DEF_RUNTIME_STUBS(GetMethodFromCache)803 DEF_RUNTIME_STUBS(GetMethodFromCache)
804 {
805 RUNTIME_STUBS_HEADER(GetMethodFromCache);
806 JSHandle<JSTaggedValue> constpool = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
807 JSTaggedValue index = GetArg(argv, argc, 1); // 1: means the first parameter
808 return ConstantPool::GetMethodFromCache(
809 thread, constpool.GetTaggedValue(), index.GetInt()).GetRawData();
810 }
811
DEF_RUNTIME_STUBS(GetStringFromCache)812 DEF_RUNTIME_STUBS(GetStringFromCache)
813 {
814 RUNTIME_STUBS_HEADER(GetStringFromCache);
815 JSHandle<JSTaggedValue> constpool = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
816 JSTaggedValue index = GetArg(argv, argc, 1); // 1: means the first parameter
817 return ConstantPool::GetStringFromCache(
818 thread, constpool.GetTaggedValue(), index.GetInt()).GetRawData();
819 }
820
DEF_RUNTIME_STUBS(GetObjectLiteralFromCache)821 DEF_RUNTIME_STUBS(GetObjectLiteralFromCache)
822 {
823 RUNTIME_STUBS_HEADER(GetObjectLiteralFromCache);
824 JSHandle<JSTaggedValue> constpool = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
825 JSTaggedValue index = GetArg(argv, argc, 1); // 1: means the first parameter
826 JSHandle<JSTaggedValue> module = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
827 return ConstantPool::GetLiteralFromCache<ConstPoolType::OBJECT_LITERAL>(
828 thread, constpool.GetTaggedValue(), index.GetInt(), module.GetTaggedValue()).GetRawData();
829 }
830
DEF_RUNTIME_STUBS(GetArrayLiteralFromCache)831 DEF_RUNTIME_STUBS(GetArrayLiteralFromCache)
832 {
833 RUNTIME_STUBS_HEADER(GetArrayLiteralFromCache);
834 JSHandle<JSTaggedValue> constpool = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
835 JSTaggedValue index = GetArg(argv, argc, 1); // 1: means the first parameter
836 JSHandle<JSTaggedValue> module = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
837 return ConstantPool::GetLiteralFromCache<ConstPoolType::ARRAY_LITERAL>(
838 thread, constpool.GetTaggedValue(), index.GetInt(), module.GetTaggedValue()).GetRawData();
839 }
840
DEF_RUNTIME_STUBS(LdObjByIndex)841 DEF_RUNTIME_STUBS(LdObjByIndex)
842 {
843 RUNTIME_STUBS_HEADER(LdObjByIndex);
844 JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
845 JSTaggedValue idx = GetArg(argv, argc, 1); // 1: means the first parameter
846 JSTaggedValue callGetter = GetArg(argv, argc, 2); // 2: means the second parameter
847 JSTaggedValue receiver = GetArg(argv, argc, 3); // 3: means the third parameter
848 return RuntimeLdObjByIndex(thread, obj, idx.GetInt(), callGetter.IsTrue(), receiver).GetRawData();
849 }
850
DEF_RUNTIME_STUBS(StObjByIndex)851 DEF_RUNTIME_STUBS(StObjByIndex)
852 {
853 RUNTIME_STUBS_HEADER(StObjByIndex);
854 JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
855 JSTaggedValue idx = GetArg(argv, argc, 1); // 1: means the first parameter
856 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
857 return RuntimeStObjByIndex(thread, obj, idx.GetInt(), value).GetRawData();
858 }
859
DEF_RUNTIME_STUBS(StOwnByIndex)860 DEF_RUNTIME_STUBS(StOwnByIndex)
861 {
862 RUNTIME_STUBS_HEADER(StOwnByIndex);
863 JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
864 JSHandle<JSTaggedValue> idx = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
865 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
866 return RuntimeStOwnByIndex(thread, obj, idx, value).GetRawData();
867 }
868
DEF_RUNTIME_STUBS(StGlobalRecord)869 DEF_RUNTIME_STUBS(StGlobalRecord)
870 {
871 RUNTIME_STUBS_HEADER(StGlobalRecord);
872 JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
873 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
874 JSTaggedValue isConst = GetArg(argv, argc, 2);
875 return RuntimeStGlobalRecord(thread, prop, value, isConst.IsTrue()).GetRawData();
876 }
877
DEF_RUNTIME_STUBS(Neg)878 DEF_RUNTIME_STUBS(Neg)
879 {
880 RUNTIME_STUBS_HEADER(Neg);
881 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
882 return RuntimeNeg(thread, value).GetRawData();
883 }
884
DEF_RUNTIME_STUBS(Not)885 DEF_RUNTIME_STUBS(Not)
886 {
887 RUNTIME_STUBS_HEADER(Not);
888 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
889 return RuntimeNot(thread, value).GetRawData();
890 }
891
DEF_RUNTIME_STUBS(Shl2)892 DEF_RUNTIME_STUBS(Shl2)
893 {
894 RUNTIME_STUBS_HEADER(Shl2);
895 JSTaggedValue left = GetArg(argv, argc, 0); // 0: means the zeroth parameter
896 JSTaggedValue right = GetArg(argv, argc, 1); // 1: means the first parameter
897
898 auto res = SlowRuntimeStub::Shl2(thread, left, right);
899 return JSTaggedValue(res).GetRawData();
900 }
901
DEF_RUNTIME_STUBS(Shr2)902 DEF_RUNTIME_STUBS(Shr2)
903 {
904 RUNTIME_STUBS_HEADER(Shr2);
905 JSTaggedValue left = GetArg(argv, argc, 0); // 0: means the zeroth parameter
906 JSTaggedValue right = GetArg(argv, argc, 1); // 1: means the first parameter
907
908 auto res = SlowRuntimeStub::Shr2(thread, left, right);
909 return JSTaggedValue(res).GetRawData();
910 }
911
DEF_RUNTIME_STUBS(Ashr2)912 DEF_RUNTIME_STUBS(Ashr2)
913 {
914 RUNTIME_STUBS_HEADER(Ashr2);
915 JSTaggedValue left = GetArg(argv, argc, 0); // 0: means the zeroth parameter
916 JSTaggedValue right = GetArg(argv, argc, 1); // 1: means the first parameter
917
918 auto res = SlowRuntimeStub::Ashr2(thread, left, right);
919 return JSTaggedValue(res).GetRawData();
920 }
921
DEF_RUNTIME_STUBS(And2)922 DEF_RUNTIME_STUBS(And2)
923 {
924 RUNTIME_STUBS_HEADER(And2);
925 JSTaggedValue left = GetArg(argv, argc, 0); // 0: means the zeroth parameter
926 JSTaggedValue right = GetArg(argv, argc, 1); // 1: means the first parameter
927
928 auto res = SlowRuntimeStub::And2(thread, left, right);
929 return JSTaggedValue(res).GetRawData();
930 }
931
DEF_RUNTIME_STUBS(Xor2)932 DEF_RUNTIME_STUBS(Xor2)
933 {
934 RUNTIME_STUBS_HEADER(Xor2);
935 JSTaggedValue left = GetArg(argv, argc, 0); // 0: means the zeroth parameter
936 JSTaggedValue right = GetArg(argv, argc, 1); // 1: means the first parameter
937
938 auto res = SlowRuntimeStub::Xor2(thread, left, right);
939 return JSTaggedValue(res).GetRawData();
940 }
941
DEF_RUNTIME_STUBS(Or2)942 DEF_RUNTIME_STUBS(Or2)
943 {
944 RUNTIME_STUBS_HEADER(Or2);
945 JSTaggedValue left = GetArg(argv, argc, 0); // 0: means the zeroth parameter
946 JSTaggedValue right = GetArg(argv, argc, 1); // 1: means the first parameter
947
948 auto res = SlowRuntimeStub::Or2(thread, left, right);
949 return JSTaggedValue(res).GetRawData();
950 }
951
DEF_RUNTIME_STUBS(CreateClassWithBuffer)952 DEF_RUNTIME_STUBS(CreateClassWithBuffer)
953 {
954 RUNTIME_STUBS_HEADER(CreateClassWithBuffer);
955 JSHandle<JSTaggedValue> base = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
956 JSHandle<JSTaggedValue> lexenv = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
957 JSHandle<JSTaggedValue> constpool = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
958 JSTaggedValue methodId = GetArg(argv, argc, 3); // 3: means the third parameter
959 JSTaggedValue literalId = GetArg(argv, argc, 4); // 4: means the four parameter
960 JSHandle<JSTaggedValue> module = GetHArg<JSTaggedValue>(argv, argc, 5); // 5: means the fifth parameter
961 return RuntimeCreateClassWithBuffer(thread, base, lexenv, constpool,
962 static_cast<uint16_t>(methodId.GetInt()),
963 static_cast<uint16_t>(literalId.GetInt()), module).GetRawData();
964 }
965
DEF_RUNTIME_STUBS(SetClassConstructorLength)966 DEF_RUNTIME_STUBS(SetClassConstructorLength)
967 {
968 RUNTIME_STUBS_HEADER(SetClassConstructorLength);
969 JSTaggedValue ctor = GetArg(argv, argc, 0); // 0: means the zeroth parameter
970 JSTaggedValue length = GetArg(argv, argc, 1); // 1: means the first parameter
971 return RuntimeSetClassConstructorLength(thread, ctor, length).GetRawData();
972 }
973
DEF_RUNTIME_STUBS(UpdateHotnessCounter)974 DEF_RUNTIME_STUBS(UpdateHotnessCounter)
975 {
976 RUNTIME_STUBS_HEADER(UpdateHotnessCounter);
977 JSHandle<JSFunction> thisFunc = GetHArg<JSFunction>(argv, argc, 0); // 0: means the zeroth parameter
978 thread->CheckSafepoint();
979 JSHandle<Method> method(thread, thisFunc->GetMethod());
980 auto profileTypeInfo = method->GetProfileTypeInfo();
981 if (profileTypeInfo.IsUndefined()) {
982 uint32_t slotSize = method->GetSlotSize();
983 auto res = RuntimeNotifyInlineCache(thread, method, slotSize);
984 return res.GetRawData();
985 }
986 return profileTypeInfo.GetRawData();
987 }
988
DEF_RUNTIME_STUBS(UpdateHotnessCounterWithProf)989 DEF_RUNTIME_STUBS(UpdateHotnessCounterWithProf)
990 {
991 RUNTIME_STUBS_HEADER(UpdateHotnessCounterWithProf);
992 JSHandle<JSFunction> thisFunc = GetHArg<JSFunction>(argv, argc, 0); // 0: means the zeroth parameter
993 thread->CheckSafepoint();
994 JSHandle<Method> method(thread, thisFunc->GetMethod());
995 auto profileTypeInfo = method->GetProfileTypeInfo();
996 if (profileTypeInfo.IsUndefined()) {
997 thread->GetEcmaVM()->GetPGOProfiler()->ProfileCall(
998 JSTaggedValue::VALUE_UNDEFINED, thisFunc.GetTaggedType(), -1, SampleMode::HOTNESS_MODE);
999 uint32_t slotSize = method->GetSlotSize();
1000 auto res = RuntimeNotifyInlineCache(thread, method, slotSize);
1001 return res.GetRawData();
1002 }
1003 return profileTypeInfo.GetRawData();
1004 }
1005
DEF_RUNTIME_STUBS(CheckSafePoint)1006 DEF_RUNTIME_STUBS(CheckSafePoint)
1007 {
1008 auto thread = JSThread::GlueToJSThread(argGlue);
1009 thread->CheckSafepoint();
1010 return JSTaggedValue::Undefined().GetRawData();
1011 }
1012
DEF_RUNTIME_STUBS(LoadICByName)1013 DEF_RUNTIME_STUBS(LoadICByName)
1014 {
1015 RUNTIME_STUBS_HEADER(LoadICByName);
1016 JSHandle<JSTaggedValue> profileHandle = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1017 JSHandle<JSTaggedValue> receiverHandle = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1018 JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
1019 JSTaggedValue slotId = GetArg(argv, argc, 3); // 3: means the third parameter
1020
1021 if (profileHandle->IsUndefined()) {
1022 auto res = JSTaggedValue::GetProperty(thread, receiverHandle, keyHandle).GetValue().GetTaggedValue();
1023 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
1024 return res.GetRawData();
1025 }
1026 LoadICRuntime icRuntime(
1027 thread, JSHandle<ProfileTypeInfo>::Cast(profileHandle), slotId.GetInt(), ICKind::NamedLoadIC);
1028 return icRuntime.LoadMiss(receiverHandle, keyHandle).GetRawData();
1029 }
1030
DEF_RUNTIME_STUBS(TryLdGlobalICByName)1031 DEF_RUNTIME_STUBS(TryLdGlobalICByName)
1032 {
1033 RUNTIME_STUBS_HEADER(TryLdGlobalICByName);
1034 JSHandle<JSTaggedValue> profileHandle = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1035 JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1036 JSTaggedValue slotId = GetArg(argv, argc, 2); // 2: means the third parameter
1037
1038 EcmaVM *ecmaVm = thread->GetEcmaVM();
1039 JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
1040 JSHandle<JSTaggedValue> globalObj(thread, globalEnv->GetGlobalObject());
1041 if (profileHandle->IsUndefined()) {
1042 auto res = RuntimeTryLdGlobalByName(thread, globalObj, keyHandle);
1043 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
1044 return res.GetRawData();
1045 }
1046 LoadICRuntime icRuntime(
1047 thread, JSHandle<ProfileTypeInfo>::Cast(profileHandle), slotId.GetInt(), ICKind::NamedGlobalTryLoadIC);
1048 return icRuntime.LoadMiss(globalObj, keyHandle).GetRawData();
1049 }
1050
DEF_RUNTIME_STUBS(StoreICByName)1051 DEF_RUNTIME_STUBS(StoreICByName)
1052 {
1053 RUNTIME_STUBS_HEADER(StoreICByName);
1054 JSHandle<JSTaggedValue> profileHandle = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1055 JSHandle<JSTaggedValue> receiverHandle = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1056 JSHandle<JSTaggedValue> keyHandle = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
1057 JSHandle<JSTaggedValue> valueHandle = GetHArg<JSTaggedValue>(argv, argc, 3); // 3: means the third parameter
1058 JSTaggedValue slotId = GetArg(argv, argc, 4); // 4: means the fourth parameter
1059
1060 if (profileHandle->IsUndefined()) {
1061 JSTaggedValue::SetProperty(thread, receiverHandle, keyHandle, valueHandle, true);
1062 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
1063 return JSTaggedValue::True().GetRawData();
1064 }
1065 StoreICRuntime icRuntime(
1066 thread, JSHandle<ProfileTypeInfo>::Cast(profileHandle), slotId.GetInt(), ICKind::NamedStoreIC);
1067 return icRuntime.StoreMiss(receiverHandle, keyHandle, valueHandle).GetRawData();
1068 }
1069
DEF_RUNTIME_STUBS(SetFunctionNameNoPrefix)1070 DEF_RUNTIME_STUBS(SetFunctionNameNoPrefix)
1071 {
1072 RUNTIME_STUBS_HEADER(SetFunctionNameNoPrefix);
1073 JSTaggedType argFunc = GetTArg(argv, argc, 0); // 0: means the zeroth parameter
1074 JSTaggedValue argName = GetArg(argv, argc, 1); // 1: means the first parameter
1075 JSFunction::SetFunctionNameNoPrefix(thread, reinterpret_cast<JSFunction *>(argFunc), argName);
1076 return JSTaggedValue::Hole().GetRawData();
1077 }
1078
DEF_RUNTIME_STUBS(StOwnByValueWithNameSet)1079 DEF_RUNTIME_STUBS(StOwnByValueWithNameSet)
1080 {
1081 RUNTIME_STUBS_HEADER(StOwnByValueWithNameSet);
1082 JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1083 JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1084 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
1085 return RuntimeStOwnByValueWithNameSet(thread, obj, prop, value).GetRawData();
1086 }
1087
DEF_RUNTIME_STUBS(StOwnByName)1088 DEF_RUNTIME_STUBS(StOwnByName)
1089 {
1090 RUNTIME_STUBS_HEADER(StOwnByName);
1091 JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1092 JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1093 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
1094 return RuntimeStOwnByName(thread, obj, prop, value).GetRawData();
1095 }
1096
DEF_RUNTIME_STUBS(StOwnByNameWithNameSet)1097 DEF_RUNTIME_STUBS(StOwnByNameWithNameSet)
1098 {
1099 RUNTIME_STUBS_HEADER(StOwnByNameWithNameSet);
1100 JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1101 JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1102 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
1103 return RuntimeStOwnByValueWithNameSet(thread, obj, prop, value).GetRawData();
1104 }
1105
DEF_RUNTIME_STUBS(SuspendGenerator)1106 DEF_RUNTIME_STUBS(SuspendGenerator)
1107 {
1108 RUNTIME_STUBS_HEADER(SuspendGenerator);
1109 JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1110 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1111 return RuntimeSuspendGenerator(thread, obj, value).GetRawData();
1112 }
1113
DEF_RUNTIME_STUBS(OptSuspendGenerator)1114 DEF_RUNTIME_STUBS(OptSuspendGenerator)
1115 {
1116 RUNTIME_STUBS_HEADER(OptSuspendGenerator);
1117 JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1118 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1119 return RuntimeOptSuspendGenerator(thread, obj, value).GetRawData();
1120 }
1121
DEF_RUNTIME_STUBS(OptAsyncGeneratorResolve)1122 DEF_RUNTIME_STUBS(OptAsyncGeneratorResolve)
1123 {
1124 RUNTIME_STUBS_HEADER(OptAsyncGeneratorResolve);
1125 JSHandle<JSTaggedValue> asyncGenerator = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1126 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1127 JSTaggedValue flag = GetArg(argv, argc, 2); // 2: means the second parameter
1128 return RuntimeOptAsyncGeneratorResolve(thread, asyncGenerator, value, flag).GetRawData();
1129 }
1130
DEF_RUNTIME_STUBS(OptCreateObjectWithExcludedKeys)1131 DEF_RUNTIME_STUBS(OptCreateObjectWithExcludedKeys)
1132 {
1133 RUNTIME_STUBS_HEADER(OptCreateObjectWithExcludedKeys);
1134 JSTaggedValue numKeys = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1135 JSHandle<JSTaggedValue> objVal = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1136 JSTaggedValue firstArgRegIdx = GetArg(argv, argc, 2); // 2: means the second parameter
1137 return RuntimeOptCreateObjectWithExcludedKeys(thread, static_cast<uint16_t>(numKeys.GetInt()), objVal,
1138 static_cast<uint16_t>(firstArgRegIdx.GetInt()), argv, argc).GetRawData();
1139 }
1140
DEF_RUNTIME_STUBS(UpFrame)1141 DEF_RUNTIME_STUBS(UpFrame)
1142 {
1143 RUNTIME_STUBS_HEADER(UpFrame);
1144 FrameHandler frameHandler(thread);
1145 uint32_t pcOffset = panda_file::INVALID_OFFSET;
1146 for (; frameHandler.HasFrame(); frameHandler.PrevJSFrame()) {
1147 if (frameHandler.IsEntryFrame() || frameHandler.IsBuiltinFrame()) {
1148 thread->SetCurrentFrame(frameHandler.GetSp());
1149 thread->SetLastFp(frameHandler.GetFp());
1150 return JSTaggedValue(static_cast<uint64_t>(0)).GetRawData();
1151 }
1152 auto method = frameHandler.GetMethod();
1153 pcOffset = method->FindCatchBlock(frameHandler.GetBytecodeOffset());
1154 if (pcOffset != INVALID_INDEX) {
1155 thread->SetCurrentFrame(frameHandler.GetSp());
1156 thread->SetLastFp(frameHandler.GetFp());
1157 uintptr_t pc = reinterpret_cast<uintptr_t>(method->GetBytecodeArray() + pcOffset);
1158 return JSTaggedValue(static_cast<uint64_t>(pc)).GetRawData();
1159 }
1160 }
1161 return JSTaggedValue(static_cast<uint64_t>(0)).GetRawData();
1162 }
1163
DEF_RUNTIME_STUBS(GetModuleNamespaceByIndex)1164 DEF_RUNTIME_STUBS(GetModuleNamespaceByIndex)
1165 {
1166 RUNTIME_STUBS_HEADER(GetModuleNamespaceByIndex);
1167 JSTaggedValue index = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1168 return RuntimeGetModuleNamespace(thread, index.GetInt()).GetRawData();
1169 }
1170
DEF_RUNTIME_STUBS(GetModuleNamespaceByIndexOnJSFunc)1171 DEF_RUNTIME_STUBS(GetModuleNamespaceByIndexOnJSFunc)
1172 {
1173 RUNTIME_STUBS_HEADER(GetModuleNamespaceByIndexOnJSFunc);
1174 JSTaggedValue index = GetArg(argv, argc, 0);
1175 JSTaggedValue jsFunc = GetArg(argv, argc, 1);
1176 return RuntimeGetModuleNamespace(thread, index.GetInt(), jsFunc).GetRawData();
1177 }
1178
DEF_RUNTIME_STUBS(GetModuleNamespace)1179 DEF_RUNTIME_STUBS(GetModuleNamespace)
1180 {
1181 RUNTIME_STUBS_HEADER(GetModuleNamespace);
1182 JSTaggedValue localName = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1183 return RuntimeGetModuleNamespace(thread, localName).GetRawData();
1184 }
1185
DEF_RUNTIME_STUBS(StModuleVarByIndex)1186 DEF_RUNTIME_STUBS(StModuleVarByIndex)
1187 {
1188 RUNTIME_STUBS_HEADER(StModuleVar);
1189 JSTaggedValue index = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1190 JSTaggedValue value = GetArg(argv, argc, 1); // 1: means the first parameter
1191 RuntimeStModuleVar(thread, index.GetInt(), value);
1192 return JSTaggedValue::Hole().GetRawData();
1193 }
1194
DEF_RUNTIME_STUBS(StModuleVarByIndexOnJSFunc)1195 DEF_RUNTIME_STUBS(StModuleVarByIndexOnJSFunc)
1196 {
1197 RUNTIME_STUBS_HEADER(StModuleVarByIndexOnJSFunc);
1198 JSTaggedValue index = GetArg(argv, argc, 0);
1199 JSTaggedValue value = GetArg(argv, argc, 1);
1200 JSTaggedValue jsFunc = GetArg(argv, argc, 2);
1201 RuntimeStModuleVar(thread, index.GetInt(), value, jsFunc);
1202 return JSTaggedValue::Hole().GetRawData();
1203 }
1204
DEF_RUNTIME_STUBS(StModuleVar)1205 DEF_RUNTIME_STUBS(StModuleVar)
1206 {
1207 RUNTIME_STUBS_HEADER(StModuleVar);
1208 JSTaggedValue key = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1209 JSTaggedValue value = GetArg(argv, argc, 1); // 1: means the first parameter
1210 RuntimeStModuleVar(thread, key, value);
1211 return JSTaggedValue::Hole().GetRawData();
1212 }
1213
DEF_RUNTIME_STUBS(LdLocalModuleVarByIndex)1214 DEF_RUNTIME_STUBS(LdLocalModuleVarByIndex)
1215 {
1216 RUNTIME_STUBS_HEADER(LdLocalModuleVarByIndex);
1217 JSTaggedValue index = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1218 return RuntimeLdLocalModuleVar(thread, index.GetInt()).GetRawData();
1219 }
1220
DEF_RUNTIME_STUBS(LdExternalModuleVarByIndex)1221 DEF_RUNTIME_STUBS(LdExternalModuleVarByIndex)
1222 {
1223 RUNTIME_STUBS_HEADER(LdExternalModuleVarByIndex);
1224 JSTaggedValue index = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1225 return RuntimeLdExternalModuleVar(thread, index.GetInt()).GetRawData();
1226 }
1227
DEF_RUNTIME_STUBS(LdLocalModuleVarByIndexOnJSFunc)1228 DEF_RUNTIME_STUBS(LdLocalModuleVarByIndexOnJSFunc)
1229 {
1230 RUNTIME_STUBS_HEADER(LdLocalModuleVarByIndexOnJSFunc);
1231 JSTaggedValue index = GetArg(argv, argc, 0);
1232 JSTaggedValue jsFunc = GetArg(argv, argc, 1);
1233 return RuntimeLdLocalModuleVar(thread, index.GetInt(), jsFunc).GetRawData();
1234 }
1235
DEF_RUNTIME_STUBS(LdExternalModuleVarByIndexOnJSFunc)1236 DEF_RUNTIME_STUBS(LdExternalModuleVarByIndexOnJSFunc)
1237 {
1238 RUNTIME_STUBS_HEADER(LdExternalModuleVarByIndexOnJSFunc);
1239 JSTaggedValue index = GetArg(argv, argc, 0);
1240 JSTaggedValue jsFunc = GetArg(argv, argc, 1);
1241 return RuntimeLdExternalModuleVar(thread, index.GetInt(), jsFunc).GetRawData();
1242 }
1243
DEF_RUNTIME_STUBS(LdModuleVar)1244 DEF_RUNTIME_STUBS(LdModuleVar)
1245 {
1246 RUNTIME_STUBS_HEADER(LdModuleVar);
1247 JSTaggedValue key = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1248 JSTaggedValue taggedFlag = GetArg(argv, argc, 1); // 1: means the first parameter
1249 bool innerFlag = taggedFlag.GetInt() != 0;
1250 return RuntimeLdModuleVar(thread, key, innerFlag).GetRawData();
1251 }
1252
DEF_RUNTIME_STUBS(GetPropIterator)1253 DEF_RUNTIME_STUBS(GetPropIterator)
1254 {
1255 RUNTIME_STUBS_HEADER(GetPropIterator);
1256 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1257 return RuntimeGetPropIterator(thread, value).GetRawData();
1258 }
1259
DEF_RUNTIME_STUBS(AsyncFunctionEnter)1260 DEF_RUNTIME_STUBS(AsyncFunctionEnter)
1261 {
1262 RUNTIME_STUBS_HEADER(AsyncFunctionEnter);
1263 return RuntimeAsyncFunctionEnter(thread).GetRawData();
1264 }
1265
DEF_RUNTIME_STUBS(GetIterator)1266 DEF_RUNTIME_STUBS(GetIterator)
1267 {
1268 RUNTIME_STUBS_HEADER(GetIterator);
1269 JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1270 return RuntimeGetIterator(thread, obj).GetRawData();
1271 }
1272
DEF_RUNTIME_STUBS(GetAsyncIterator)1273 DEF_RUNTIME_STUBS(GetAsyncIterator)
1274 {
1275 RUNTIME_STUBS_HEADER(GetAsyncIterator);
1276 JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1277 return RuntimeGetAsyncIterator(thread, obj).GetRawData();
1278 }
1279
DEF_RUNTIME_STUBS(Throw)1280 DEF_RUNTIME_STUBS(Throw)
1281 {
1282 RUNTIME_STUBS_HEADER(Throw);
1283 JSTaggedValue value = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1284 RuntimeThrow(thread, value);
1285 return JSTaggedValue::Hole().GetRawData();
1286 }
1287
DEF_RUNTIME_STUBS(ThrowThrowNotExists)1288 DEF_RUNTIME_STUBS(ThrowThrowNotExists)
1289 {
1290 RUNTIME_STUBS_HEADER(ThrowThrowNotExists);
1291 RuntimeThrowThrowNotExists(thread);
1292 return JSTaggedValue::Hole().GetRawData();
1293 }
1294
DEF_RUNTIME_STUBS(ThrowPatternNonCoercible)1295 DEF_RUNTIME_STUBS(ThrowPatternNonCoercible)
1296 {
1297 RUNTIME_STUBS_HEADER(ThrowPatternNonCoercible);
1298 RuntimeThrowPatternNonCoercible(thread);
1299 return JSTaggedValue::Hole().GetRawData();
1300 }
1301
DEF_RUNTIME_STUBS(ThrowDeleteSuperProperty)1302 DEF_RUNTIME_STUBS(ThrowDeleteSuperProperty)
1303 {
1304 RUNTIME_STUBS_HEADER(ThrowDeleteSuperProperty);
1305 RuntimeThrowDeleteSuperProperty(thread);
1306 return JSTaggedValue::Hole().GetRawData();
1307 }
1308
DEF_RUNTIME_STUBS(ThrowUndefinedIfHole)1309 DEF_RUNTIME_STUBS(ThrowUndefinedIfHole)
1310 {
1311 RUNTIME_STUBS_HEADER(ThrowUndefinedIfHole);
1312 JSHandle<EcmaString> obj = GetHArg<EcmaString>(argv, argc, 0); // 0: means the zeroth parameter
1313 RuntimeThrowUndefinedIfHole(thread, obj);
1314 return JSTaggedValue::Hole().GetRawData();
1315 }
1316
DEF_RUNTIME_STUBS(ThrowIfNotObject)1317 DEF_RUNTIME_STUBS(ThrowIfNotObject)
1318 {
1319 RUNTIME_STUBS_HEADER(ThrowIfNotObject);
1320 RuntimeThrowIfNotObject(thread);
1321 return JSTaggedValue::Hole().GetRawData();
1322 }
1323
DEF_RUNTIME_STUBS(ThrowConstAssignment)1324 DEF_RUNTIME_STUBS(ThrowConstAssignment)
1325 {
1326 RUNTIME_STUBS_HEADER(ThrowConstAssignment);
1327 JSHandle<EcmaString> value = GetHArg<EcmaString>(argv, argc, 0); // 0: means the zeroth parameter
1328 RuntimeThrowConstAssignment(thread, value);
1329 return JSTaggedValue::Hole().GetRawData();
1330 }
1331
DEF_RUNTIME_STUBS(ThrowTypeError)1332 DEF_RUNTIME_STUBS(ThrowTypeError)
1333 {
1334 RUNTIME_STUBS_HEADER(ThrowTypeError);
1335 JSTaggedValue argMessageStringId = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1336 std::string message = MessageString::GetMessageString(argMessageStringId.GetInt());
1337 ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1338 JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR, message.c_str());
1339 THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error.GetTaggedValue(), JSTaggedValue::Hole().GetRawData());
1340 }
1341
DEF_RUNTIME_STUBS(LoadMiss)1342 DEF_RUNTIME_STUBS(LoadMiss)
1343 {
1344 RUNTIME_STUBS_HEADER(LoadMiss);
1345 JSTaggedType profileTypeInfo = GetTArg(argv, argc, 0); // 0: means the zeroth parameter
1346 JSTaggedValue receiver = GetArg(argv, argc, 1); // 1: means the first parameter
1347 JSTaggedValue key = GetArg(argv, argc, 2); // 2: means the second parameter
1348 JSTaggedValue slotId = GetArg(argv, argc, 3); // 3: means the third parameter
1349 JSTaggedValue kind = GetArg(argv, argc, 4); // 4: means the fourth parameter
1350 return ICRuntimeStub::LoadMiss(thread, reinterpret_cast<ProfileTypeInfo *>(profileTypeInfo), receiver, key,
1351 slotId.GetInt(), static_cast<ICKind>(kind.GetInt())).GetRawData();
1352 }
1353
DEF_RUNTIME_STUBS(StoreMiss)1354 DEF_RUNTIME_STUBS(StoreMiss)
1355 {
1356 RUNTIME_STUBS_HEADER(StoreMiss);
1357 JSTaggedType profileTypeInfo = GetTArg(argv, argc, 0); // 0: means the zeroth parameter
1358 JSTaggedValue receiver = GetArg(argv, argc, 1); // 1: means the first parameter
1359 JSTaggedValue key = GetArg(argv, argc, 2); // 2: means the second parameter
1360 JSTaggedValue value = GetArg(argv, argc, 3); // 3: means the third parameter
1361 JSTaggedValue slotId = GetArg(argv, argc, 4); // 4: means the fourth parameter
1362 JSTaggedValue kind = GetArg(argv, argc, 5); // 5: means the fifth parameter
1363 return ICRuntimeStub::StoreMiss(thread, reinterpret_cast<ProfileTypeInfo *>(profileTypeInfo), receiver, key, value,
1364 slotId.GetInt(), static_cast<ICKind>(kind.GetInt())).GetRawData();
1365 }
1366
DEF_RUNTIME_STUBS(TryUpdateGlobalRecord)1367 DEF_RUNTIME_STUBS(TryUpdateGlobalRecord)
1368 {
1369 RUNTIME_STUBS_HEADER(TryUpdateGlobalRecord);
1370 JSTaggedValue prop = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1371 JSTaggedValue value = GetArg(argv, argc, 1); // 1: means the first parameter
1372 return RuntimeTryUpdateGlobalRecord(thread, prop, value).GetRawData();
1373 }
1374
DEF_RUNTIME_STUBS(ThrowReferenceError)1375 DEF_RUNTIME_STUBS(ThrowReferenceError)
1376 {
1377 RUNTIME_STUBS_HEADER(ThrowReferenceError);
1378 JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1379 return RuntimeThrowReferenceError(thread, prop, " is not defined").GetRawData();
1380 }
1381
DEF_RUNTIME_STUBS(LdGlobalICVar)1382 DEF_RUNTIME_STUBS(LdGlobalICVar)
1383 {
1384 RUNTIME_STUBS_HEADER(LdGlobalICVar);
1385 JSHandle<JSTaggedValue> global = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1386 JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1387 JSHandle<JSTaggedValue> profileHandle = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
1388 JSTaggedValue slotId = GetArg(argv, argc, 3); // 3: means the third parameter
1389
1390 if (profileHandle->IsUndefined()) {
1391 return RuntimeLdGlobalVarFromProto(thread, global, prop).GetRawData();
1392 }
1393 LoadICRuntime icRuntime(
1394 thread, JSHandle<ProfileTypeInfo>::Cast(profileHandle), slotId.GetInt(), ICKind::NamedGlobalLoadIC);
1395 return icRuntime.LoadMiss(global, prop).GetRawData();
1396 }
1397
DEF_RUNTIME_STUBS(StGlobalVar)1398 DEF_RUNTIME_STUBS(StGlobalVar)
1399 {
1400 RUNTIME_STUBS_HEADER(StGlobalVar);
1401 JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1402 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1403 return RuntimeStGlobalVar(thread, prop, value).GetRawData();
1404 }
1405
DEF_RUNTIME_STUBS(ToNumber)1406 DEF_RUNTIME_STUBS(ToNumber)
1407 {
1408 RUNTIME_STUBS_HEADER(ToNumber);
1409 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1410 return RuntimeToNumber(thread, value).GetRawData();
1411 }
1412
DEF_RUNTIME_STUBS(ToBoolean)1413 DEF_RUNTIME_STUBS(ToBoolean)
1414 {
1415 RUNTIME_STUBS_HEADER(ToBoolean);
1416 JSTaggedValue value = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1417 bool result = value.ToBoolean();
1418 return JSTaggedValue(result).GetRawData();
1419 }
1420
DEF_RUNTIME_STUBS(Eq)1421 DEF_RUNTIME_STUBS(Eq)
1422 {
1423 RUNTIME_STUBS_HEADER(Eq);
1424 JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1425 JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1426 return RuntimeEq(thread, left, right).GetRawData();
1427 }
1428
DEF_RUNTIME_STUBS(NotEq)1429 DEF_RUNTIME_STUBS(NotEq)
1430 {
1431 RUNTIME_STUBS_HEADER(NotEq);
1432 JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1433 JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1434 return RuntimeNotEq(thread, left, right).GetRawData();
1435 }
1436
DEF_RUNTIME_STUBS(Less)1437 DEF_RUNTIME_STUBS(Less)
1438 {
1439 RUNTIME_STUBS_HEADER(Less);
1440 JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1441 JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1442 return RuntimeLess(thread, left, right).GetRawData();
1443 }
1444
DEF_RUNTIME_STUBS(LessEq)1445 DEF_RUNTIME_STUBS(LessEq)
1446 {
1447 RUNTIME_STUBS_HEADER(LessEq);
1448 JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1449 JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1450 return RuntimeLessEq(thread, left, right).GetRawData();
1451 }
1452
DEF_RUNTIME_STUBS(Greater)1453 DEF_RUNTIME_STUBS(Greater)
1454 {
1455 RUNTIME_STUBS_HEADER(Greater);
1456 JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1457 JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1458 return RuntimeGreater(thread, left, right).GetRawData();
1459 }
1460
DEF_RUNTIME_STUBS(GreaterEq)1461 DEF_RUNTIME_STUBS(GreaterEq)
1462 {
1463 RUNTIME_STUBS_HEADER(GreaterEq);
1464 JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1465 JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1466 return RuntimeGreaterEq(thread, left, right).GetRawData();
1467 }
1468
DEF_RUNTIME_STUBS(Add2)1469 DEF_RUNTIME_STUBS(Add2)
1470 {
1471 RUNTIME_STUBS_HEADER(Add2);
1472 JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1473 JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1474 JSTaggedValue res = RuntimeAdd2(thread, left, right);
1475 return res.GetRawData();
1476 }
1477
DEF_RUNTIME_STUBS(Sub2)1478 DEF_RUNTIME_STUBS(Sub2)
1479 {
1480 RUNTIME_STUBS_HEADER(Sub2);
1481 JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1482 JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1483 return RuntimeSub2(thread, left, right).GetRawData();
1484 }
1485
DEF_RUNTIME_STUBS(Mul2)1486 DEF_RUNTIME_STUBS(Mul2)
1487 {
1488 RUNTIME_STUBS_HEADER(Mul2);
1489 JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1490 JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1491 return RuntimeMul2(thread, left, right).GetRawData();
1492 }
1493
DEF_RUNTIME_STUBS(Div2)1494 DEF_RUNTIME_STUBS(Div2)
1495 {
1496 RUNTIME_STUBS_HEADER(Div2);
1497 JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1498 JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1499 return RuntimeDiv2(thread, left, right).GetRawData();
1500 }
1501
DEF_RUNTIME_STUBS(Mod2)1502 DEF_RUNTIME_STUBS(Mod2)
1503 {
1504 RUNTIME_STUBS_HEADER(Mod2);
1505 JSHandle<JSTaggedValue> left = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1506 JSHandle<JSTaggedValue> right = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1507 return RuntimeMod2(thread, left, right).GetRawData();
1508 }
1509
DEF_RUNTIME_STUBS(JumpToCInterpreter)1510 DEF_RUNTIME_STUBS(JumpToCInterpreter)
1511 {
1512 #ifndef EXCLUDE_C_INTERPRETER
1513 RUNTIME_STUBS_HEADER(JumpToCInterpreter);
1514 JSTaggedValue constpool = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1515 JSTaggedValue profileTypeInfo = GetArg(argv, argc, 1); // 1: means the first parameter
1516 JSTaggedValue acc = GetArg(argv, argc, 2); // 2: means the second parameter
1517 JSTaggedValue hotnessCounter = GetArg(argv, argc, 3); // 3: means the third parameter
1518
1519 auto sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1520 const uint8_t *currentPc = reinterpret_cast<const uint8_t*>(GET_ASM_FRAME(sp)->pc);
1521
1522 uint8_t opcode = currentPc[0];
1523 asmDispatchTable[opcode](thread, currentPc, sp, constpool, profileTypeInfo, acc, hotnessCounter.GetInt());
1524 sp = const_cast<JSTaggedType *>(thread->GetCurrentInterpretedFrame());
1525 return JSTaggedValue(reinterpret_cast<uint64_t>(sp)).GetRawData();
1526 #else
1527 return JSTaggedValue::Hole().GetRawData();
1528 #endif
1529 }
1530
DEF_RUNTIME_STUBS(NotifyBytecodePcChanged)1531 DEF_RUNTIME_STUBS(NotifyBytecodePcChanged)
1532 {
1533 RUNTIME_STUBS_HEADER(NotifyBytecodePcChanged);
1534 FrameHandler frameHandler(thread);
1535 for (; frameHandler.HasFrame(); frameHandler.PrevJSFrame()) {
1536 if (frameHandler.IsEntryFrame() || frameHandler.IsBuiltinFrame()) {
1537 continue;
1538 }
1539 Method *method = frameHandler.GetMethod();
1540 // Skip builtins method
1541 if (method->IsNativeWithCallField()) {
1542 continue;
1543 }
1544 auto bcOffset = frameHandler.GetBytecodeOffset();
1545 auto *debuggerMgr = thread->GetEcmaVM()->GetJsDebuggerManager();
1546 debuggerMgr->GetNotificationManager()->BytecodePcChangedEvent(thread, method, bcOffset);
1547 return JSTaggedValue::Hole().GetRawData();
1548 }
1549 return JSTaggedValue::Hole().GetRawData();
1550 }
1551
DEF_RUNTIME_STUBS(NotifyDebuggerStatement)1552 DEF_RUNTIME_STUBS(NotifyDebuggerStatement)
1553 {
1554 RUNTIME_STUBS_HEADER(NotifyDebuggerStatement);
1555 return RuntimeNotifyDebuggerStatement(thread).GetRawData();
1556 }
1557
DEF_RUNTIME_STUBS(CreateEmptyObject)1558 DEF_RUNTIME_STUBS(CreateEmptyObject)
1559 {
1560 RUNTIME_STUBS_HEADER(CreateEmptyObject);
1561 EcmaVM *ecmaVm = thread->GetEcmaVM();
1562 ObjectFactory *factory = ecmaVm->GetFactory();
1563 JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
1564 return RuntimeCreateEmptyObject(thread, factory, globalEnv).GetRawData();
1565 }
1566
DEF_RUNTIME_STUBS(CreateEmptyArray)1567 DEF_RUNTIME_STUBS(CreateEmptyArray)
1568 {
1569 RUNTIME_STUBS_HEADER(CreateEmptyArray);
1570 EcmaVM *ecmaVm = thread->GetEcmaVM();
1571 ObjectFactory *factory = ecmaVm->GetFactory();
1572 JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
1573 return RuntimeCreateEmptyArray(thread, factory, globalEnv).GetRawData();
1574 }
1575
DEF_RUNTIME_STUBS(GetSymbolFunction)1576 DEF_RUNTIME_STUBS(GetSymbolFunction)
1577 {
1578 RUNTIME_STUBS_HEADER(GetSymbolFunction);
1579 EcmaVM *ecmaVm = thread->GetEcmaVM();
1580 JSHandle<GlobalEnv> globalEnv = ecmaVm->GetGlobalEnv();
1581 return globalEnv->GetSymbolFunction().GetTaggedValue().GetRawData();
1582 }
1583
DEF_RUNTIME_STUBS(GetUnmapedArgs)1584 DEF_RUNTIME_STUBS(GetUnmapedArgs)
1585 {
1586 RUNTIME_STUBS_HEADER(GetUnmapedArgs);
1587 auto sp = const_cast<JSTaggedType*>(thread->GetCurrentInterpretedFrame());
1588 uint32_t startIdx = 0;
1589 // 0: means restIdx
1590 uint32_t actualNumArgs = InterpreterAssembly::GetNumArgs(sp, 0, startIdx);
1591 return RuntimeGetUnmapedArgs(thread, sp, actualNumArgs, startIdx).GetRawData();
1592 }
1593
DEF_RUNTIME_STUBS(CopyRestArgs)1594 DEF_RUNTIME_STUBS(CopyRestArgs)
1595 {
1596 RUNTIME_STUBS_HEADER(CopyRestArgs);
1597 JSTaggedValue restIdx = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1598 auto sp = const_cast<JSTaggedType*>(thread->GetCurrentInterpretedFrame());
1599 uint32_t startIdx = 0;
1600 uint32_t restNumArgs = InterpreterAssembly::GetNumArgs(sp, restIdx.GetInt(), startIdx);
1601 return RuntimeCopyRestArgs(thread, sp, restNumArgs, startIdx).GetRawData();
1602 }
1603
DEF_RUNTIME_STUBS(CreateArrayWithBuffer)1604 DEF_RUNTIME_STUBS(CreateArrayWithBuffer)
1605 {
1606 RUNTIME_STUBS_HEADER(CreateArrayWithBuffer);
1607 JSHandle<JSTaggedValue> argArray = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1608 EcmaVM *ecmaVm = thread->GetEcmaVM();
1609 ObjectFactory *factory = ecmaVm->GetFactory();
1610 return RuntimeCreateArrayWithBuffer(thread, factory, argArray).GetRawData();
1611 }
1612
DEF_RUNTIME_STUBS(CreateObjectWithBuffer)1613 DEF_RUNTIME_STUBS(CreateObjectWithBuffer)
1614 {
1615 RUNTIME_STUBS_HEADER(CreateObjectWithBuffer);
1616 JSHandle<JSObject> argObj = GetHArg<JSObject>(argv, argc, 0); // 0: means the zeroth parameter
1617 EcmaVM *ecmaVm = thread->GetEcmaVM();
1618 ObjectFactory *factory = ecmaVm->GetFactory();
1619 return RuntimeCreateObjectWithBuffer(thread, factory, argObj).GetRawData();
1620 }
1621
DEF_RUNTIME_STUBS(NewThisObject)1622 DEF_RUNTIME_STUBS(NewThisObject)
1623 {
1624 RUNTIME_STUBS_HEADER(NewThisObject);
1625 JSHandle<JSFunction> ctor(GetHArg<JSTaggedValue>(argv, argc, 0)); // 0: means the zeroth parameter
1626
1627 ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1628 JSHandle<JSObject> obj = factory->NewJSObjectByConstructor(ctor);
1629 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
1630 return obj.GetTaggedType(); // state is not set here
1631 }
1632
DEF_RUNTIME_STUBS(NewObjRange)1633 DEF_RUNTIME_STUBS(NewObjRange)
1634 {
1635 RUNTIME_STUBS_HEADER(NewObjRange);
1636 JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1637 JSHandle<JSTaggedValue> newTarget = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1638 JSTaggedValue firstArgIdx = GetArg(argv, argc, 2); // 2: means the second parameter
1639 JSTaggedValue length = GetArg(argv, argc, 3); // 3: means the third parameter
1640 return RuntimeNewObjRange(thread, func, newTarget, static_cast<uint16_t>(firstArgIdx.GetInt()),
1641 static_cast<uint16_t>(length.GetInt())).GetRawData();
1642 }
1643
DEF_RUNTIME_STUBS(DefineFunc)1644 DEF_RUNTIME_STUBS(DefineFunc)
1645 {
1646 RUNTIME_STUBS_HEADER(DefineFunc);
1647 JSHandle<Method> method = GetHArg<Method>(argv, argc, 0); // 0: means the zeroth parameter
1648 return RuntimeDefinefunc(thread, method).GetRawData();
1649 }
1650
DEF_RUNTIME_STUBS(CreateRegExpWithLiteral)1651 DEF_RUNTIME_STUBS(CreateRegExpWithLiteral)
1652 {
1653 RUNTIME_STUBS_HEADER(CreateRegExpWithLiteral);
1654 JSHandle<JSTaggedValue> pattern = GetHArg<JSTaggedValue>(argv, argc, 0);
1655 JSTaggedValue flags = GetArg(argv, argc, 1);
1656 return RuntimeCreateRegExpWithLiteral(thread, pattern, static_cast<uint8_t>(flags.GetInt())).GetRawData();
1657 }
1658
DEF_RUNTIME_STUBS(ThrowIfSuperNotCorrectCall)1659 DEF_RUNTIME_STUBS(ThrowIfSuperNotCorrectCall)
1660 {
1661 RUNTIME_STUBS_HEADER(ThrowIfSuperNotCorrectCall);
1662 JSTaggedValue index = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1663 JSTaggedValue thisValue = GetArg(argv, argc, 1); // 1: means the first parameter
1664 return RuntimeThrowIfSuperNotCorrectCall(thread, static_cast<uint16_t>(index.GetInt()), thisValue).GetRawData();
1665 }
1666
DEF_RUNTIME_STUBS(CreateObjectHavingMethod)1667 DEF_RUNTIME_STUBS(CreateObjectHavingMethod)
1668 {
1669 RUNTIME_STUBS_HEADER(CreateObjectHavingMethod);
1670 JSHandle<JSObject> literal = GetHArg<JSObject>(argv, argc, 0); // 0: means the zeroth parameter
1671 JSHandle<JSTaggedValue> env = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1672 EcmaVM *ecmaVm = thread->GetEcmaVM();
1673 ObjectFactory *factory = ecmaVm->GetFactory();
1674 return RuntimeCreateObjectHavingMethod(thread, factory, literal, env).GetRawData();
1675 }
1676
DEF_RUNTIME_STUBS(CreateObjectWithExcludedKeys)1677 DEF_RUNTIME_STUBS(CreateObjectWithExcludedKeys)
1678 {
1679 RUNTIME_STUBS_HEADER(CreateObjectWithExcludedKeys);
1680 JSTaggedValue numKeys = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1681 JSHandle<JSTaggedValue> objVal = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1682 JSTaggedValue firstArgRegIdx = GetArg(argv, argc, 2); // 2: means the second parameter
1683 return RuntimeCreateObjectWithExcludedKeys(thread, static_cast<uint16_t>(numKeys.GetInt()), objVal,
1684 static_cast<uint16_t>(firstArgRegIdx.GetInt())).GetRawData();
1685 }
1686
DEF_RUNTIME_STUBS(DefineMethod)1687 DEF_RUNTIME_STUBS(DefineMethod)
1688 {
1689 RUNTIME_STUBS_HEADER(DefineMethod);
1690 JSHandle<Method> method = GetHArg<Method>(argv, argc, 0); // 0: means the zeroth parameter
1691 JSHandle<JSTaggedValue> homeObject = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1692 return RuntimeDefineMethod(thread, method, homeObject).GetRawData();
1693 }
1694
DEF_RUNTIME_STUBS(CallSpread)1695 DEF_RUNTIME_STUBS(CallSpread)
1696 {
1697 RUNTIME_STUBS_HEADER(CallSpread);
1698 JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1699 JSHandle<JSTaggedValue> obj = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1700 JSHandle<JSTaggedValue> array = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
1701 return RuntimeCallSpread(thread, func, obj, array).GetRawData();
1702 }
1703
DEF_RUNTIME_STUBS(DefineGetterSetterByValue)1704 DEF_RUNTIME_STUBS(DefineGetterSetterByValue)
1705 {
1706 RUNTIME_STUBS_HEADER(DefineGetterSetterByValue);
1707 JSHandle<JSObject> obj = GetHArg<JSObject>(argv, argc, 0); // 0: means the zeroth parameter
1708 JSHandle<JSTaggedValue> prop = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1709 JSHandle<JSTaggedValue> getter = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
1710 JSHandle<JSTaggedValue> setter = GetHArg<JSTaggedValue>(argv, argc, 3); // 3: means the third parameter
1711 JSTaggedValue flag = GetArg(argv, argc, 4); // 4: means the fourth parameter
1712 bool bFlag = flag.ToBoolean();
1713 return RuntimeDefineGetterSetterByValue(thread, obj, prop, getter, setter, bFlag).GetRawData();
1714 }
1715
DEF_RUNTIME_STUBS(SuperCall)1716 DEF_RUNTIME_STUBS(SuperCall)
1717 {
1718 RUNTIME_STUBS_HEADER(SuperCall);
1719 JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1720 JSTaggedValue firstVRegIdx = GetArg(argv, argc, 1); // 1: means the first parameter
1721 JSTaggedValue length = GetArg(argv, argc, 2); // 2: means the second parameter
1722 auto sp = const_cast<JSTaggedType*>(thread->GetCurrentInterpretedFrame());
1723 JSTaggedValue newTarget = InterpreterAssembly::GetNewTarget(sp);
1724 return RuntimeSuperCall(thread, func, JSHandle<JSTaggedValue>(thread, newTarget),
1725 static_cast<uint16_t>(firstVRegIdx.GetInt()),
1726 static_cast<uint16_t>(length.GetInt())).GetRawData();
1727 }
1728
DEF_RUNTIME_STUBS(OptSuperCall)1729 DEF_RUNTIME_STUBS(OptSuperCall)
1730 {
1731 RUNTIME_STUBS_HEADER(OptSuperCall);
1732 return RuntimeOptSuperCall(thread, argv, argc).GetRawData();
1733 }
1734
DEF_RUNTIME_STUBS(ThrowNotCallableException)1735 DEF_RUNTIME_STUBS(ThrowNotCallableException)
1736 {
1737 RUNTIME_STUBS_HEADER(ThrowNotCallableException);
1738 EcmaVM *ecmaVm = thread->GetEcmaVM();
1739 ObjectFactory *factory = ecmaVm->GetFactory();
1740 JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR, "is not callable");
1741 thread->SetException(error.GetTaggedValue());
1742 return JSTaggedValue::Exception().GetRawData();
1743 }
1744
DEF_RUNTIME_STUBS(ThrowSetterIsUndefinedException)1745 DEF_RUNTIME_STUBS(ThrowSetterIsUndefinedException)
1746 {
1747 RUNTIME_STUBS_HEADER(ThrowSetterIsUndefinedException);
1748 EcmaVM *ecmaVm = thread->GetEcmaVM();
1749 ObjectFactory *factory = ecmaVm->GetFactory();
1750 JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR,
1751 "Cannot set property when setter is undefined");
1752 thread->SetException(error.GetTaggedValue());
1753 return JSTaggedValue::Exception().GetRawData();
1754 }
1755
DEF_RUNTIME_STUBS(ThrowCallConstructorException)1756 DEF_RUNTIME_STUBS(ThrowCallConstructorException)
1757 {
1758 RUNTIME_STUBS_HEADER(ThrowCallConstructorException);
1759 EcmaVM *ecmaVm = thread->GetEcmaVM();
1760 ObjectFactory *factory = ecmaVm->GetFactory();
1761 JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR,
1762 "class constructor cannot called without 'new'");
1763 thread->SetException(error.GetTaggedValue());
1764 return JSTaggedValue::Exception().GetRawData();
1765 }
1766
DEF_RUNTIME_STUBS(ThrowNonConstructorException)1767 DEF_RUNTIME_STUBS(ThrowNonConstructorException)
1768 {
1769 RUNTIME_STUBS_HEADER(ThrowNonConstructorException);
1770 EcmaVM *ecmaVm = thread->GetEcmaVM();
1771 ObjectFactory *factory = ecmaVm->GetFactory();
1772 JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR,
1773 "function is non-constructor");
1774 thread->SetException(error.GetTaggedValue());
1775 return JSTaggedValue::Exception().GetRawData();
1776 }
1777
DEF_RUNTIME_STUBS(ThrowStackOverflowException)1778 DEF_RUNTIME_STUBS(ThrowStackOverflowException)
1779 {
1780 RUNTIME_STUBS_HEADER(ThrowStackOverflowException);
1781 EcmaVM *ecmaVm = thread->GetEcmaVM();
1782 // Multi-thread could cause stack-overflow-check failed too,
1783 // so check thread here to distinguish it with the actual stack overflow.
1784 ecmaVm->CheckThread();
1785 ObjectFactory *factory = ecmaVm->GetFactory();
1786 JSHandle<JSObject> error = factory->GetJSError(ErrorType::RANGE_ERROR, "Stack overflow!", false);
1787 if (LIKELY(!thread->HasPendingException())) {
1788 thread->SetException(error.GetTaggedValue());
1789 }
1790 return JSTaggedValue::Exception().GetRawData();
1791 }
1792
DEF_RUNTIME_STUBS(ThrowDerivedMustReturnException)1793 DEF_RUNTIME_STUBS(ThrowDerivedMustReturnException)
1794 {
1795 RUNTIME_STUBS_HEADER(ThrowDerivedMustReturnException);
1796 EcmaVM *ecmaVm = thread->GetEcmaVM();
1797 ObjectFactory *factory = ecmaVm->GetFactory();
1798 JSHandle<JSObject> error = factory->GetJSError(ErrorType::TYPE_ERROR,
1799 "Derived constructor must return object or undefined");
1800 thread->SetException(error.GetTaggedValue());
1801 return JSTaggedValue::Exception().GetRawData();
1802 }
1803
DEF_RUNTIME_STUBS(LdBigInt)1804 DEF_RUNTIME_STUBS(LdBigInt)
1805 {
1806 RUNTIME_STUBS_HEADER(LdBigInt);
1807 JSHandle<JSTaggedValue> numberBigInt = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1808 return RuntimeLdBigInt(thread, numberBigInt).GetRawData();
1809 }
1810
DEF_RUNTIME_STUBS(ToNumeric)1811 DEF_RUNTIME_STUBS(ToNumeric)
1812 {
1813 RUNTIME_STUBS_HEADER(ToNumeric);
1814 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1815 return RuntimeToNumeric(thread, value).GetRawData();
1816 }
1817
DEF_RUNTIME_STUBS(DynamicImport)1818 DEF_RUNTIME_STUBS(DynamicImport)
1819 {
1820 RUNTIME_STUBS_HEADER(DynamicImport);
1821 JSHandle<JSTaggedValue> specifier = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1822 JSHandle<JSTaggedValue> currentFunc = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the zeroth parameter
1823 return RuntimeDynamicImport(thread, specifier, currentFunc).GetRawData();
1824 }
1825
DEF_RUNTIME_STUBS(NewLexicalEnvWithName)1826 DEF_RUNTIME_STUBS(NewLexicalEnvWithName)
1827 {
1828 RUNTIME_STUBS_HEADER(NewLexicalEnvWithName);
1829 JSTaggedValue numVars = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1830 JSTaggedValue scopeId = GetArg(argv, argc, 1); // 1: means the first parameter
1831 return RuntimeNewLexicalEnvWithName(thread,
1832 static_cast<uint16_t>(numVars.GetInt()),
1833 static_cast<uint16_t>(scopeId.GetInt())).GetRawData();
1834 }
1835
DEF_RUNTIME_STUBS(OptGetUnmapedArgs)1836 DEF_RUNTIME_STUBS(OptGetUnmapedArgs)
1837 {
1838 RUNTIME_STUBS_HEADER(OptGetUnmapedArgs);
1839 JSTaggedValue actualNumArgs = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1840 return RuntimeOptGetUnmapedArgs(thread, actualNumArgs.GetInt()).GetRawData();
1841 }
1842
DEF_RUNTIME_STUBS(OptNewLexicalEnvWithName)1843 DEF_RUNTIME_STUBS(OptNewLexicalEnvWithName)
1844 {
1845 RUNTIME_STUBS_HEADER(OptNewLexicalEnvWithName);
1846 JSTaggedValue taggedNumVars = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1847 JSTaggedValue taggedScopeId = GetArg(argv, argc, 1); // 1: means the first parameter
1848 JSHandle<JSTaggedValue> currentLexEnv = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
1849 JSHandle<JSTaggedValue> func = GetHArg<JSTaggedValue>(argv, argc, 3); // 3: means the third parameter
1850 uint16_t numVars = static_cast<uint16_t>(taggedNumVars.GetInt());
1851 uint16_t scopeId = static_cast<uint16_t>(taggedScopeId.GetInt());
1852 return RuntimeOptNewLexicalEnvWithName(thread, numVars, scopeId, currentLexEnv, func).GetRawData();
1853 }
1854
DEF_RUNTIME_STUBS(OptCopyRestArgs)1855 DEF_RUNTIME_STUBS(OptCopyRestArgs)
1856 {
1857 RUNTIME_STUBS_HEADER(OptCopyRestArgs);
1858 JSTaggedValue actualArgc = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1859 JSTaggedValue restIndex = GetArg(argv, argc, 1); // 1: means the first parameter
1860 return RuntimeOptCopyRestArgs(thread, actualArgc.GetInt(), restIndex.GetInt()).GetRawData();
1861 }
1862
DEF_RUNTIME_STUBS(OptNewObjRange)1863 DEF_RUNTIME_STUBS(OptNewObjRange)
1864 {
1865 RUNTIME_STUBS_HEADER(OptNewObjRange);
1866 return RuntimeOptNewObjRange(thread, argv, argc).GetRawData();
1867 }
1868
DEF_RUNTIME_STUBS(GetTypeArrayPropertyByIndex)1869 DEF_RUNTIME_STUBS(GetTypeArrayPropertyByIndex)
1870 {
1871 RUNTIME_STUBS_HEADER(GetTypeArrayPropertyByIndex);
1872 JSTaggedValue obj = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1873 JSTaggedValue idx = GetArg(argv, argc, 1); // 1: means the first parameter
1874 JSTaggedValue jsType = GetArg(argv, argc, 2); // 2: means the second parameter
1875 return JSTypedArray::FastGetPropertyByIndex(thread, obj, idx.GetInt(), JSType(jsType.GetInt())).GetRawData();
1876 }
1877
DEF_RUNTIME_STUBS(SetTypeArrayPropertyByIndex)1878 DEF_RUNTIME_STUBS(SetTypeArrayPropertyByIndex)
1879 {
1880 RUNTIME_STUBS_HEADER(SetTypeArrayPropertyByIndex);
1881 JSTaggedValue obj = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1882 JSTaggedValue idx = GetArg(argv, argc, 1); // 1: means the first parameter
1883 JSTaggedValue value = GetArg(argv, argc, 2); // 2: means the second parameter
1884 JSTaggedValue jsType = GetArg(argv, argc, 3); // 3: means the third parameter
1885 return JSTypedArray::FastSetPropertyByIndex(thread, obj, idx.GetInt(), value, JSType(jsType.GetInt())).GetRawData();
1886 }
1887
DEF_RUNTIME_STUBS(FastCopyElementToArray)1888 DEF_RUNTIME_STUBS(FastCopyElementToArray)
1889 {
1890 RUNTIME_STUBS_HEADER(FastCopyElementToArray);
1891 JSHandle<JSTaggedValue> typedArray = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1892 JSHandle<TaggedArray> array = GetHArg<TaggedArray>(argv, argc, 1); // 1: means the first parameter
1893 return JSTaggedValue(JSTypedArray::FastCopyElementToArray(thread, typedArray, array)).GetRawData();
1894 }
1895
DEF_RUNTIME_STUBS(DebugAOTPrint)1896 DEF_RUNTIME_STUBS(DebugAOTPrint)
1897 {
1898 RUNTIME_STUBS_HEADER(DebugAOTPrint);
1899 int ecmaOpcode = GetArg(argv, argc, 0).GetInt();
1900 int path = GetArg(argv, argc, 1).GetInt();
1901 std::string result = kungfu::GetEcmaOpcodeStr(static_cast<EcmaOpcode>(ecmaOpcode));
1902 std::string pathStr = path == 0 ? "slowpath " : "typedpath ";
1903 LOG_ECMA(INFO) << "aot " << pathStr << result;
1904 return JSTaggedValue::Undefined().GetRawData();
1905 }
1906
DEF_RUNTIME_STUBS(ProfileOptimizedCode)1907 DEF_RUNTIME_STUBS(ProfileOptimizedCode)
1908 {
1909 RUNTIME_STUBS_HEADER(ProfileOptimizedCode);
1910 EcmaOpcode ecmaOpcode = static_cast<EcmaOpcode>(GetArg(argv, argc, 0).GetInt());
1911 OptCodeProfiler::Mode mode = static_cast<OptCodeProfiler::Mode>(GetArg(argv, argc, 1).GetInt());
1912 OptCodeProfiler *profiler = thread->GetCurrentEcmaContext()->GetOptCodeProfiler();
1913 profiler->Update(ecmaOpcode, mode);
1914 return JSTaggedValue::Undefined().GetRawData();
1915 }
1916
DEF_RUNTIME_STUBS(VerifyVTableLoading)1917 DEF_RUNTIME_STUBS(VerifyVTableLoading)
1918 {
1919 RUNTIME_STUBS_HEADER(VerifyVTableLoading);
1920 JSHandle<JSTaggedValue> receiver = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1921 JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1922 JSHandle<JSTaggedValue> typedPathValue = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
1923
1924 JSHandle<JSTaggedValue> verifiedPathValue = JSTaggedValue::GetProperty(thread, receiver, key).GetValue();
1925 if (UNLIKELY(!JSTaggedValue::SameValue(typedPathValue, verifiedPathValue))) {
1926 std::ostringstream oss;
1927 receiver->Dump(oss);
1928 LOG_ECMA(ERROR) << "Verify VTable Load Failed, receiver: " << oss.str();
1929 oss.str("");
1930
1931 LOG_ECMA(ERROR) << "Verify VTable Load Failed, key: "
1932 << EcmaStringAccessor(key.GetTaggedValue()).ToStdString();
1933
1934 typedPathValue->Dump(oss);
1935 LOG_ECMA(ERROR) << "Verify VTable Load Failed, typed path value: " << oss.str();
1936 oss.str("");
1937
1938 verifiedPathValue->Dump(oss);
1939 LOG_ECMA(ERROR) << "Verify VTable Load Failed, verified path value: " << oss.str();
1940 }
1941 return JSTaggedValue::Undefined().GetRawData();
1942 }
1943
DEF_RUNTIME_STUBS(VerifyVTableStoring)1944 DEF_RUNTIME_STUBS(VerifyVTableStoring)
1945 {
1946 RUNTIME_STUBS_HEADER(VerifyVTableStoring);
1947 JSHandle<JSTaggedValue> receiver = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
1948 JSHandle<JSTaggedValue> key = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
1949 JSHandle<JSTaggedValue> storeValue = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
1950
1951 JSHandle<JSTaggedValue> verifiedValue = JSTaggedValue::GetProperty(thread, receiver, key).GetValue();
1952 if (UNLIKELY(!JSTaggedValue::SameValue(storeValue, verifiedValue))) {
1953 std::ostringstream oss;
1954 receiver->Dump(oss);
1955 LOG_ECMA(ERROR) << "Verify VTable Store Failed, receiver: " << oss.str();
1956 oss.str("");
1957
1958 LOG_ECMA(ERROR) << "Verify VTable Store Failed, key: "
1959 << EcmaStringAccessor(key.GetTaggedValue()).ToStdString();
1960
1961 storeValue->Dump(oss);
1962 LOG_ECMA(ERROR) << "Verify VTable Store Failed, typed path store value: " << oss.str();
1963 oss.str("");
1964
1965 verifiedValue->Dump(oss);
1966 LOG_ECMA(ERROR) << "Verify VTable Store Failed, verified path load value: " << oss.str();
1967 }
1968 return JSTaggedValue::Undefined().GetRawData();
1969 }
1970
DEF_RUNTIME_STUBS(JSObjectGetMethod)1971 DEF_RUNTIME_STUBS(JSObjectGetMethod)
1972 {
1973 RUNTIME_STUBS_HEADER(JSObjectGetMethod);
1974 JSHandle<JSTaggedValue> obj(thread, GetArg(argv, argc, 0));
1975 JSHandle<JSTaggedValue> key(thread, GetArg(argv, argc, 1));
1976 JSHandle<JSTaggedValue> result = JSObject::GetMethod(thread, obj, key);
1977 return result->GetRawData();
1978 }
1979
DEF_RUNTIME_STUBS(BigIntEqual)1980 DEF_RUNTIME_STUBS(BigIntEqual)
1981 {
1982 RUNTIME_STUBS_HEADER(BigIntEqual);
1983 JSTaggedValue left = GetArg(argv, argc, 0); // 0: means the zeroth parameter
1984 JSTaggedValue right = GetArg(argv, argc, 1); // 1: means the first parameter
1985 if (BigInt::Equal(left, right)) {
1986 return JSTaggedValue::VALUE_TRUE;
1987 }
1988 return JSTaggedValue::VALUE_FALSE;
1989 }
1990
DEF_RUNTIME_STUBS(StringEqual)1991 DEF_RUNTIME_STUBS(StringEqual)
1992 {
1993 RUNTIME_STUBS_HEADER(StringEqual);
1994 JSHandle<EcmaString> left = GetHArg<EcmaString>(argv, argc, 0);
1995 JSHandle<EcmaString> right = GetHArg<EcmaString>(argv, argc, 1);
1996 EcmaVM *vm = thread->GetEcmaVM();
1997 left = JSHandle<EcmaString>(thread, EcmaStringAccessor::Flatten(vm, left));
1998 right = JSHandle<EcmaString>(thread, EcmaStringAccessor::Flatten(vm, right));
1999 if (EcmaStringAccessor::StringsAreEqualSameUtfEncoding(*left, *right)) {
2000 return JSTaggedValue::VALUE_TRUE;
2001 }
2002 return JSTaggedValue::VALUE_FALSE;
2003 }
2004
DEF_RUNTIME_STUBS(LdPatchVar)2005 DEF_RUNTIME_STUBS(LdPatchVar)
2006 {
2007 RUNTIME_STUBS_HEADER(LdPatchVar);
2008 JSTaggedValue idx = GetArg(argv, argc, 0); // 0: means the zeroth parameter
2009 return RuntimeLdPatchVar(thread, idx.GetInt()).GetRawData();
2010 }
2011
DEF_RUNTIME_STUBS(StPatchVar)2012 DEF_RUNTIME_STUBS(StPatchVar)
2013 {
2014 RUNTIME_STUBS_HEADER(StPatchVar);
2015 JSTaggedValue idx = GetArg(argv, argc, 0); // 0: means the zeroth parameter
2016 JSHandle<JSTaggedValue> value = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
2017 return RuntimeStPatchVar(thread, idx.GetInt(), value).GetRawData();
2018 }
2019
DEF_RUNTIME_STUBS(NotifyConcurrentResult)2020 DEF_RUNTIME_STUBS(NotifyConcurrentResult)
2021 {
2022 RUNTIME_STUBS_HEADER(NotifyConcurrentResult);
2023 JSTaggedValue result = GetArg(argv, argc, 0); // 0: means the zeroth parameter
2024 JSTaggedValue hint = GetArg(argv, argc, 1); // 1: means the first parameter
2025 return RuntimeNotifyConcurrentResult(thread, result, hint).GetRawData();
2026 }
2027
DEF_RUNTIME_STUBS(ContainerRBTreeForEach)2028 DEF_RUNTIME_STUBS(ContainerRBTreeForEach)
2029 {
2030 RUNTIME_STUBS_HEADER(ContainerRBTreeForEach);
2031 JSHandle<JSTaggedValue> node = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: param index
2032 JSHandle<JSTaggedValue> callbackFnHandle = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: param index
2033 JSHandle<JSTaggedValue> thisArgHandle = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: param index
2034 JSHandle<JSTaggedValue> thisHandle = GetHArg<JSTaggedValue>(argv, argc, 3); // 3: param index
2035 JSHandle<JSTaggedValue> type = GetHArg<JSTaggedValue>(argv, argc, 4); // 4: param index
2036
2037 ASSERT(node->IsRBTreeNode());
2038 ASSERT(callbackFnHandle->IsCallable());
2039 ASSERT(type->IsInt());
2040 JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
2041 auto containersType = static_cast<kungfu::ContainersType>(type->GetInt());
2042 JSMutableHandle<TaggedQueue> queue(thread, thread->GetEcmaVM()->GetFactory()->NewTaggedQueue(0));
2043 JSMutableHandle<RBTreeNode> treeNode(thread, JSTaggedValue::Undefined());
2044 queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, node)));
2045 while (!queue->Empty()) {
2046 treeNode.Update(queue->Pop(thread));
2047 EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle,
2048 undefined, 3); // 3: three args
2049 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
2050 info->SetCallArg(containersType == kungfu::ContainersType::HASHSET_FOREACH ?
2051 treeNode->GetKey() : treeNode->GetValue(), treeNode->GetKey(), thisHandle.GetTaggedValue());
2052 JSTaggedValue funcResult = JSFunction::Call(info);
2053 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult.GetRawData());
2054 if (!treeNode->GetLeft().IsHole()) {
2055 JSHandle<JSTaggedValue> left(thread, treeNode->GetLeft());
2056 queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, left)));
2057 }
2058 if (!treeNode->GetRight().IsHole()) {
2059 JSHandle<JSTaggedValue> right(thread, treeNode->GetRight());
2060 queue.Update(JSTaggedValue(TaggedQueue::Push(thread, queue, right)));
2061 }
2062 }
2063 return JSTaggedValue::True().GetRawData();
2064 }
2065
DEF_RUNTIME_STUBS(SlowFlattenString)2066 DEF_RUNTIME_STUBS(SlowFlattenString)
2067 {
2068 RUNTIME_STUBS_HEADER(SlowFlattenString);
2069 JSHandle<TreeEcmaString> str = GetHArg<TreeEcmaString>(argv, argc, 0); // 0: means the zeroth parameter
2070 return JSTaggedValue(EcmaStringAccessor::SlowFlatten(thread->GetEcmaVM(), str)).GetRawData();
2071 }
2072
DEF_RUNTIME_STUBS(OtherToNumber)2073 DEF_RUNTIME_STUBS(OtherToNumber)
2074 {
2075 RUNTIME_STUBS_HEADER(OtherToNumber);
2076 JSTaggedValue tagged = GetArg(argv, argc, 0); // 0: means the zeroth parameter
2077 if (tagged.IsString()) {
2078 return JSTaggedValue::StringToDouble(tagged).GetRawData();
2079 }
2080 if (tagged.IsECMAObject()) {
2081 JSHandle<JSTaggedValue> taggedHandle(thread, tagged);
2082 JSHandle<JSTaggedValue> primValue(thread, JSTaggedValue::ToPrimitive(thread, taggedHandle, PREFER_NUMBER));
2083 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
2084 return JSTaggedValue::ToNumber(thread, primValue).GetRawData();
2085 }
2086
2087 if (tagged.IsSymbol()) {
2088 THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot convert a Symbol value to a number",
2089 JSTaggedValue::VALUE_EXCEPTION);
2090 }
2091 if (tagged.IsBigInt()) {
2092 THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot convert a BigInt value to a number",
2093 JSTaggedValue::VALUE_EXCEPTION);
2094 }
2095 THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot convert a Unknown value to a number", JSTaggedValue::VALUE_EXCEPTION);
2096 }
2097
CreateArrayFromList(uintptr_t argGlue,int32_t argc,JSTaggedValue * argvPtr)2098 JSTaggedType RuntimeStubs::CreateArrayFromList([[maybe_unused]] uintptr_t argGlue, int32_t argc,
2099 JSTaggedValue *argvPtr)
2100 {
2101 auto thread = JSThread::GlueToJSThread(argGlue);
2102 ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
2103 JSHandle<TaggedArray> taggedArray = factory->NewTaggedArray(argc - NUM_MANDATORY_JSFUNC_ARGS);
2104 for (int index = NUM_MANDATORY_JSFUNC_ARGS; index < argc; ++index) {
2105 taggedArray->Set(thread, index - NUM_MANDATORY_JSFUNC_ARGS, argvPtr[index]);
2106 }
2107 JSHandle<JSArray> arrHandle = JSArray::CreateArrayFromList(thread, taggedArray);
2108 return arrHandle.GetTaggedValue().GetRawData();
2109 }
2110
FindElementWithCache(uintptr_t argGlue,JSTaggedType hclass,JSTaggedType key,int32_t num)2111 int32_t RuntimeStubs::FindElementWithCache(uintptr_t argGlue, JSTaggedType hclass,
2112 JSTaggedType key, int32_t num)
2113 {
2114 auto thread = JSThread::GlueToJSThread(argGlue);
2115 auto cls = reinterpret_cast<JSHClass *>(hclass);
2116 JSTaggedValue propKey = JSTaggedValue(key);
2117 auto layoutInfo = LayoutInfo::Cast(cls->GetLayout().GetTaggedObject());
2118 PropertiesCache *cache = thread->GetPropertiesCache();
2119 int index = cache->Get(cls, propKey);
2120 if (index == PropertiesCache::NOT_FOUND) {
2121 index = layoutInfo->BinarySearch(propKey, num);
2122 cache->Set(cls, propKey, index);
2123 }
2124 return index;
2125 }
2126
GetActualArgvNoGC(uintptr_t argGlue)2127 JSTaggedType RuntimeStubs::GetActualArgvNoGC(uintptr_t argGlue)
2128 {
2129 auto thread = JSThread::GlueToJSThread(argGlue);
2130 JSTaggedType *current = const_cast<JSTaggedType *>(thread->GetLastLeaveFrame());
2131 FrameIterator it(current, thread);
2132 ASSERT(it.IsOptimizedFrame());
2133 it.Advance<GCVisitedFlag::VISITED>();
2134 ASSERT(it.IsOptimizedJSFunctionFrame());
2135 auto optimizedJSFunctionFrame = it.GetFrame<OptimizedJSFunctionFrame>();
2136 return reinterpret_cast<uintptr_t>(optimizedJSFunctionFrame->GetArgv(it));
2137 }
2138
FloatMod(double x,double y)2139 double RuntimeStubs::FloatMod(double x, double y)
2140 {
2141 return std::fmod(x, y);
2142 }
2143
FloatSqrt(double x)2144 JSTaggedType RuntimeStubs::FloatSqrt(double x)
2145 {
2146 double result = std::sqrt(x);
2147 return JSTaggedValue(result).GetRawData();
2148 }
2149
FloatCos(double x)2150 JSTaggedType RuntimeStubs::FloatCos(double x)
2151 {
2152 double result = std::cos(x);
2153 return JSTaggedValue(result).GetRawData();
2154 }
2155
FloatSin(double x)2156 JSTaggedType RuntimeStubs::FloatSin(double x)
2157 {
2158 double result = std::sin(x);
2159 return JSTaggedValue(result).GetRawData();
2160 }
2161
FloatACos(double x)2162 JSTaggedType RuntimeStubs::FloatACos(double x)
2163 {
2164 double result = std::acos(x);
2165 return JSTaggedValue(result).GetRawData();
2166 }
2167
FloatATan(double x)2168 JSTaggedType RuntimeStubs::FloatATan(double x)
2169 {
2170 double result = std::atan(x);
2171 return JSTaggedValue(result).GetRawData();
2172 }
2173
FloatFloor(double x)2174 JSTaggedType RuntimeStubs::FloatFloor(double x)
2175 {
2176 ASSERT(!std::isnan(x));
2177 double result = std::floor(x);
2178 return JSTaggedValue(result).GetRawData();
2179 }
2180
DoubleToInt(double x)2181 int32_t RuntimeStubs::DoubleToInt(double x)
2182 {
2183 return base::NumberHelper::DoubleToInt(x, base::INT32_BITS);
2184 }
2185
InsertOldToNewRSet(uintptr_t argGlue,uintptr_t object,size_t offset)2186 void RuntimeStubs::InsertOldToNewRSet([[maybe_unused]] uintptr_t argGlue,
2187 uintptr_t object, size_t offset)
2188 {
2189 Region *region = Region::ObjectAddressToRange(object);
2190 uintptr_t slotAddr = object + offset;
2191 return region->InsertOldToNewRSet(slotAddr);
2192 }
2193
MarkingBarrier(uintptr_t argGlue,uintptr_t object,size_t offset,TaggedObject * value)2194 void RuntimeStubs::MarkingBarrier([[maybe_unused]] uintptr_t argGlue,
2195 uintptr_t object, size_t offset, TaggedObject *value)
2196 {
2197 uintptr_t slotAddr = object + offset;
2198 Region *objectRegion = Region::ObjectAddressToRange(object);
2199 Region *valueRegion = Region::ObjectAddressToRange(value);
2200 #if ECMASCRIPT_ENABLE_BARRIER_CHECK
2201 if (!valueRegion->GetJSThread()->GetEcmaVM()->GetHeap()->IsAlive(JSTaggedValue(value).GetHeapObject())) {
2202 LOG_FULL(FATAL) << "RuntimeStubs::MarkingBarrier checked value:" << value << " is invalid!";
2203 }
2204 #endif
2205 if (!valueRegion->IsMarking()) {
2206 return;
2207 }
2208 Barriers::Update(slotAddr, objectRegion, value, valueRegion);
2209 }
2210
StoreBarrier(uintptr_t argGlue,uintptr_t object,size_t offset,TaggedObject * value)2211 void RuntimeStubs::StoreBarrier([[maybe_unused]] uintptr_t argGlue,
2212 uintptr_t object, size_t offset, TaggedObject *value)
2213 {
2214 uintptr_t slotAddr = object + offset;
2215 Region *objectRegion = Region::ObjectAddressToRange(object);
2216 Region *valueRegion = Region::ObjectAddressToRange(value);
2217 #if ECMASCRIPT_ENABLE_BARRIER_CHECK
2218 if (!valueRegion->GetJSThread()->GetEcmaVM()->GetHeap()->IsAlive(JSTaggedValue(value).GetHeapObject())) {
2219 LOG_FULL(FATAL) << "RuntimeStubs::StoreBarrier checked value:" << value << " is invalid!";
2220 }
2221 #endif
2222 if (!objectRegion->InYoungSpace() && valueRegion->InYoungSpace()) {
2223 // Should align with '8' in 64 and 32 bit platform
2224 ASSERT((slotAddr % static_cast<uint8_t>(MemAlignment::MEM_ALIGN_OBJECT)) == 0);
2225 objectRegion->InsertOldToNewRSet(slotAddr);
2226 }
2227 if (!valueRegion->IsMarking()) {
2228 return;
2229 }
2230 Barriers::Update(slotAddr, objectRegion, value, valueRegion);
2231 }
2232
StringsAreEquals(EcmaString * str1,EcmaString * str2)2233 bool RuntimeStubs::StringsAreEquals(EcmaString *str1, EcmaString *str2)
2234 {
2235 return EcmaStringAccessor::StringsAreEqualSameUtfEncoding(str1, str2);
2236 }
2237
BigIntEquals(JSTaggedType left,JSTaggedType right)2238 bool RuntimeStubs::BigIntEquals(JSTaggedType left, JSTaggedType right)
2239 {
2240 return BigInt::Equal(JSTaggedValue(left), JSTaggedValue(right));
2241 }
2242
TimeClip(double time)2243 double RuntimeStubs::TimeClip(double time)
2244 {
2245 return JSDate::TimeClip(time);
2246 }
2247
SetDateValues(double year,double month,double day)2248 double RuntimeStubs::SetDateValues(double year, double month, double day)
2249 {
2250 if (std::isnan(year) || !std::isfinite(year) || std::isnan(month) || !std::isfinite(month) || std::isnan(day) ||
2251 !std::isfinite(day)) {
2252 return base::NAN_VALUE;
2253 }
2254
2255 return JSDate::SetDateValues(static_cast<int64_t>(year), static_cast<int64_t>(month), static_cast<int64_t>(day));
2256 }
2257
NewObject(EcmaRuntimeCallInfo * info)2258 JSTaggedValue RuntimeStubs::NewObject(EcmaRuntimeCallInfo *info)
2259 {
2260 ASSERT(info);
2261 JSThread *thread = info->GetThread();
2262 JSHandle<JSTaggedValue> func(info->GetFunction());
2263 if (!func->IsHeapObject()) {
2264 THROW_TYPE_ERROR_AND_RETURN(thread, "function is nullptr", JSTaggedValue::Exception());
2265 }
2266
2267 if (!func->IsJSFunction()) {
2268 if (func->IsBoundFunction()) {
2269 JSTaggedValue result = JSBoundFunction::ConstructInternal(info);
2270 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
2271 return result;
2272 }
2273
2274 if (func->IsJSProxy()) {
2275 JSTaggedValue jsObj = JSProxy::ConstructInternal(info);
2276 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
2277 return jsObj;
2278 }
2279 THROW_TYPE_ERROR_AND_RETURN(thread, "Constructed NonConstructable", JSTaggedValue::Exception());
2280 }
2281
2282 JSTaggedValue result = JSFunction::ConstructInternal(info);
2283 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
2284 return result;
2285 }
2286
SaveFrameToContext(JSThread * thread,JSHandle<GeneratorContext> context)2287 void RuntimeStubs::SaveFrameToContext(JSThread *thread, JSHandle<GeneratorContext> context)
2288 {
2289 FrameHandler frameHandler(thread);
2290 ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
2291 uint32_t nregs = frameHandler.GetNumberArgs();
2292 JSHandle<TaggedArray> regsArray = factory->NewTaggedArray(nregs);
2293 for (uint32_t i = 0; i < nregs; i++) {
2294 JSTaggedValue value = frameHandler.GetVRegValue(i);
2295 regsArray->Set(thread, i, value);
2296 }
2297 context->SetRegsArray(thread, regsArray.GetTaggedValue());
2298 JSHandle<JSFunction> function(thread, frameHandler.GetFunction());
2299 JSHandle<JSHClass> hclass(thread, function->GetClass());
2300 if (hclass->IsOptimized()) {
2301 FunctionKind kind = function->GetCallTarget()->GetFunctionKind();
2302 // instead of hclass by non_optimized hclass when method ClearAOTFlags
2303 JSHandle<JSHClass> newHClass = factory->GetNonOptimizedHclass(hclass, kind);
2304 function->SynchronizedSetClass(*newHClass);
2305 }
2306 context->SetMethod(thread, function.GetTaggedValue());
2307 context->SetThis(thread, frameHandler.GetThis());
2308
2309 BytecodeInstruction ins(frameHandler.GetPc());
2310 auto offset = ins.GetSize();
2311 context->SetAcc(thread, frameHandler.GetAcc());
2312 context->SetLexicalEnv(thread, thread->GetCurrentLexenv());
2313 context->SetNRegs(nregs);
2314 context->SetBCOffset(frameHandler.GetBytecodeOffset() + offset);
2315 }
2316
CallBoundFunction(EcmaRuntimeCallInfo * info)2317 JSTaggedValue RuntimeStubs::CallBoundFunction(EcmaRuntimeCallInfo *info)
2318 {
2319 JSThread *thread = info->GetThread();
2320 JSHandle<JSBoundFunction> boundFunc(info->GetFunction());
2321 JSHandle<JSFunction> targetFunc(thread, boundFunc->GetBoundTarget());
2322 if (targetFunc->IsClassConstructor()) {
2323 THROW_TYPE_ERROR_AND_RETURN(thread, "class constructor cannot called without 'new'",
2324 JSTaggedValue::Exception());
2325 }
2326 if (thread->IsPGOProfilerEnable()) {
2327 ECMAObject *callTarget = reinterpret_cast<ECMAObject*>(targetFunc.GetTaggedValue().GetTaggedObject());
2328 ASSERT(callTarget != nullptr);
2329 Method *method = callTarget->GetCallTarget();
2330 if (!method->IsNativeWithCallField()) {
2331 thread->GetEcmaVM()->GetPGOProfiler()->ProfileCall(
2332 JSTaggedValue::VALUE_UNDEFINED, targetFunc.GetTaggedType());
2333 }
2334 }
2335 JSHandle<TaggedArray> boundArgs(thread, boundFunc->GetBoundArguments());
2336 const uint32_t boundLength = boundArgs->GetLength();
2337 const uint32_t argsLength = info->GetArgsNumber() + boundLength;
2338 JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
2339 EcmaRuntimeCallInfo *runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle<JSTaggedValue>(targetFunc),
2340 info->GetThis(), undefined, argsLength);
2341 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
2342 if (boundLength == 0) {
2343 runtimeInfo->SetCallArg(argsLength, 0, info, 0);
2344 } else {
2345 // 0 ~ boundLength is boundArgs; boundLength ~ argsLength is args of EcmaRuntimeCallInfo.
2346 runtimeInfo->SetCallArg(boundLength, boundArgs);
2347 runtimeInfo->SetCallArg(argsLength, boundLength, info, 0);
2348 }
2349 return EcmaInterpreter::Execute(runtimeInfo);
2350 }
2351
DEF_RUNTIME_STUBS(DeoptHandler)2352 DEF_RUNTIME_STUBS(DeoptHandler)
2353 {
2354 RUNTIME_STUBS_HEADER(DeoptHandler);
2355 size_t depth = static_cast<size_t>(GetArg(argv, argc, 1).GetInt());
2356 Deoptimizier deopt(thread, depth);
2357 std::vector<kungfu::ARKDeopt> deoptBundle;
2358 deopt.CollectDeoptBundleVec(deoptBundle);
2359 ASSERT(!deoptBundle.empty());
2360 size_t shift = Deoptimizier::ComputeShift(depth);
2361 deopt.CollectVregs(deoptBundle, shift);
2362 kungfu::DeoptType type = static_cast<kungfu::DeoptType>(GetArg(argv, argc, 0).GetInt());
2363 deopt.UpdateAndDumpDeoptInfo(type);
2364 return deopt.ConstructAsmInterpretFrame();
2365 }
2366
DEF_RUNTIME_STUBS(AotInlineTrace)2367 DEF_RUNTIME_STUBS(AotInlineTrace)
2368 {
2369 RUNTIME_STUBS_HEADER(AotInlineTrace);
2370 JSTaggedValue callerFunc = GetArg(argv, argc, 0); // 0: means the zeroth parameter
2371 JSTaggedValue inlineFunc = GetArg(argv, argc, 1); // 1: means the first parameter
2372 JSFunction *callerJSFunc = JSFunction::Cast(callerFunc);
2373 JSFunction *inlineJSFunc = JSFunction::Cast(inlineFunc);
2374 Method *callerMethod = Method::Cast(JSFunction::Cast(callerJSFunc)->GetMethod());
2375 Method *inlineMethod = Method::Cast(JSFunction::Cast(inlineJSFunc)->GetMethod());
2376 auto callerRecordName = callerMethod->GetRecordName();
2377 auto inlineRecordNanme = inlineMethod->GetRecordName();
2378 const std::string callerFuncName(callerMethod->GetMethodName());
2379 const std::string inlineFuncNanme(inlineMethod->GetMethodName());
2380 std::string callerFullName = callerFuncName + "@" + std::string(callerRecordName);
2381 std::string inlineFullName = inlineFuncNanme + "@" + std::string(inlineRecordNanme);
2382
2383 LOG_TRACE(INFO) << "aot inline function name: " << inlineFullName << " caller function name: " << callerFullName;
2384 return JSTaggedValue::Undefined().GetRawData();
2385 }
2386
DEF_RUNTIME_STUBS(LocaleCompare)2387 DEF_RUNTIME_STUBS(LocaleCompare)
2388 {
2389 RUNTIME_STUBS_HEADER(LocaleCompare);
2390
2391 JSHandle<JSTaggedValue> thisTag = GetHArg<JSTaggedValue>(argv, argc, 0); // 0: means the zeroth parameter
2392 JSHandle<JSTaggedValue> thatTag = GetHArg<JSTaggedValue>(argv, argc, 1); // 1: means the first parameter
2393 JSHandle<JSTaggedValue> locales = GetHArg<JSTaggedValue>(argv, argc, 2); // 2: means the second parameter
2394 JSHandle<JSTaggedValue> options = GetHArg<JSTaggedValue>(argv, argc, 3); // 3: means the third parameter
2395
2396 JSHandle<JSTaggedValue> thisObj(JSTaggedValue::RequireObjectCoercible(thread, thisTag));
2397 [[maybe_unused]] JSHandle<EcmaString> thisHandle = JSTaggedValue::ToString(thread, thisObj);
2398 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
2399 [[maybe_unused]] JSHandle<EcmaString> thatHandle = JSTaggedValue::ToString(thread, thatTag);
2400 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
2401
2402 [[maybe_unused]] bool cacheable = options->IsUndefined() && (locales->IsUndefined() || locales->IsString());
2403 #ifdef ARK_SUPPORT_INTL
2404 if (cacheable) {
2405 auto collator = JSCollator::GetCachedIcuCollator(thread, locales);
2406 if (collator != nullptr) {
2407 JSTaggedValue result = JSCollator::CompareStrings(collator, thisHandle, thatHandle);
2408 return result.GetRawData();
2409 }
2410 }
2411 EcmaVM *ecmaVm = thread->GetEcmaVM();
2412 ObjectFactory *factory = ecmaVm->GetFactory();
2413 JSHandle<JSTaggedValue> ctor = ecmaVm->GetGlobalEnv()->GetCollatorFunction();
2414 JSHandle<JSCollator> collator =
2415 JSHandle<JSCollator>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(ctor)));
2416 JSHandle<JSCollator> initCollator =
2417 JSCollator::InitializeCollator(thread, collator, locales, options, cacheable, true);
2418 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData());
2419 icu::Collator *icuCollator = nullptr;
2420 if (cacheable) {
2421 icuCollator = JSCollator::GetCachedIcuCollator(thread, locales);
2422 ASSERT(icuCollator != nullptr);
2423 } else {
2424 icuCollator = initCollator->GetIcuCollator();
2425 }
2426 JSTaggedValue result = JSCollator::FastCompareStrings(thread, icuCollator, thisHandle, thatHandle);
2427 return result.GetRawData();
2428 #else
2429 #ifdef ARK_NOT_SUPPORT_INTL_GLOBAL
2430 ARK_SUPPORT_INTL_RETURN_JSVALUE(thread, "LocaleCompare");
2431 #else
2432 intl::GlobalIntlHelper gh(thread, intl::GlobalFormatterType::Collator);
2433 auto collator = gh.GetGlobalObject<intl::GlobalCollator>(thread,
2434 locales, options, intl::GlobalFormatterType::Collator, cacheable);
2435 if (collator == nullptr) {
2436 LOG_ECMA(ERROR) << "BuiltinsString::LocaleCompare:collator is nullptr";
2437 }
2438 ASSERT(collator != nullptr);
2439 auto result = collator->Compare(EcmaStringAccessor(thisHandle).ToStdString(),
2440 EcmaStringAccessor(thatHandle).ToStdString());
2441 return JSTaggedValue(result).GetRawData();
2442 #endif
2443 #endif
2444 }
2445
StartCallTimer(uintptr_t argGlue,JSTaggedType func,bool isAot)2446 void RuntimeStubs::StartCallTimer(uintptr_t argGlue, JSTaggedType func, bool isAot)
2447 {
2448 auto thread = JSThread::GlueToJSThread(argGlue);
2449 JSTaggedValue callTarget(func);
2450 Method *method = Method::Cast(JSFunction::Cast(callTarget)->GetMethod());
2451 if (method->IsNativeWithCallField()) {
2452 return;
2453 }
2454 size_t methodId = method->GetMethodId().GetOffset();
2455 auto callTimer = thread->GetEcmaVM()->GetCallTimer();
2456 callTimer->InitialStatAndTimer(method, methodId, isAot);
2457 callTimer->StartCount(methodId, isAot);
2458 }
2459
EndCallTimer(uintptr_t argGlue,JSTaggedType func)2460 void RuntimeStubs::EndCallTimer(uintptr_t argGlue, JSTaggedType func)
2461 {
2462 auto thread = JSThread::GlueToJSThread(argGlue);
2463 JSTaggedValue callTarget(func);
2464 Method *method = Method::Cast(JSFunction::Cast(callTarget)->GetMethod());
2465 if (method->IsNativeWithCallField()) {
2466 return;
2467 }
2468 auto callTimer = thread->GetEcmaVM()->GetCallTimer();
2469 callTimer->StopCount(method);
2470 }
2471
Initialize(JSThread * thread)2472 void RuntimeStubs::Initialize(JSThread *thread)
2473 {
2474 #define DEF_RUNTIME_STUB(name) kungfu::RuntimeStubCSigns::ID_##name
2475 #define INITIAL_RUNTIME_FUNCTIONS(name) \
2476 thread->RegisterRTInterface(DEF_RUNTIME_STUB(name), reinterpret_cast<uintptr_t>(name));
2477 RUNTIME_STUB_WITHOUT_GC_LIST(INITIAL_RUNTIME_FUNCTIONS)
2478 RUNTIME_STUB_WITH_GC_LIST(INITIAL_RUNTIME_FUNCTIONS)
2479 TEST_RUNTIME_STUB_GC_LIST(INITIAL_RUNTIME_FUNCTIONS)
2480 #undef INITIAL_RUNTIME_FUNCTIONS
2481 #undef DEF_RUNTIME_STUB
2482 }
2483
2484 #if defined(__clang__)
2485 #pragma clang diagnostic pop
2486 #elif defined(__GNUC__)
2487 #pragma GCC diagnostic pop
2488 #endif
2489 } // namespace panda::ecmascript
2490