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