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