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