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 #ifndef ECMASCRIPT_RUNTIME_STUBS_H 17 #define ECMASCRIPT_RUNTIME_STUBS_H 18 19 #include "ecmascript/frames.h" 20 #include "ecmascript/ecma_macros.h" 21 #include "ecmascript/js_tagged_value.h" 22 #include "ecmascript/jspandafile/class_literal.h" 23 #include "ecmascript/method.h" 24 #include "ecmascript/mem/c_containers.h" 25 #include "ecmascript/mem/region.h" 26 #include "ecmascript/stubs/runtime_stub_list.h" 27 28 namespace panda::ecmascript { 29 class EcmaVM; 30 class GlobalEnv; 31 class JSThread; 32 class JSFunction; 33 class ObjectFactory; 34 class JSBoundFunction; 35 class JSProxy; 36 class JSTypedArray; 37 class AOTLiteralInfo; 38 class GeneratorContext; 39 struct EcmaRuntimeCallInfo; 40 41 using JSFunctionEntryType = JSTaggedValue (*)(uintptr_t glue, uint32_t argc, const JSTaggedType argV[], 42 uintptr_t prevFp, bool needPushArgv); 43 using FastCallAotEntryType = JSTaggedValue (*)(uintptr_t glue, uint32_t argc, const JSTaggedType argV[], 44 uintptr_t prevFp); 45 46 class RuntimeStubs { 47 public: 48 static void Initialize(JSThread *thread); 49 50 #define DECLARE_RUNTIME_STUBS(name) \ 51 static JSTaggedType name(uintptr_t argGlue, uint32_t argc, uintptr_t argv); 52 RUNTIME_STUB_WITH_GC_LIST(DECLARE_RUNTIME_STUBS) RUNTIME_STUB_WITH_DFX(DECLARE_RUNTIME_STUBS)53 RUNTIME_STUB_WITH_DFX(DECLARE_RUNTIME_STUBS) 54 TEST_RUNTIME_STUB_GC_LIST(DECLARE_RUNTIME_STUBS) 55 #undef DECLARE_RUNTIME_STUBS 56 57 inline static JSTaggedType GetTArg(uintptr_t argv, [[maybe_unused]] uint32_t argc, uint32_t index) 58 { 59 ASSERT(index < argc); 60 return *(reinterpret_cast<JSTaggedType *>(argv) + (index)); 61 } 62 GetArg(uintptr_t argv,uint32_t argc,uint32_t index)63 inline static JSTaggedValue GetArg(uintptr_t argv, [[maybe_unused]] uint32_t argc, uint32_t index) 64 { 65 ASSERT(index < argc); 66 return JSTaggedValue(*(reinterpret_cast<JSTaggedType *>(argv) + (index))); 67 } 68 69 template<typename T> GetHArg(uintptr_t argv,uint32_t argc,uint32_t index)70 inline static JSHandle<T> GetHArg(uintptr_t argv, [[maybe_unused]] uint32_t argc, uint32_t index) 71 { 72 ASSERT(index < argc); 73 return JSHandle<T>(&(reinterpret_cast<JSTaggedType *>(argv)[index])); 74 } 75 76 template<typename T> GetPtrArg(uintptr_t argv,uint32_t argc,uint32_t index)77 inline static T *GetPtrArg(uintptr_t argv, [[maybe_unused]] uint32_t argc, uint32_t index) 78 { 79 ASSERT(index < argc); 80 return reinterpret_cast<T*>(*(reinterpret_cast<JSTaggedType *>(argv) + (index))); 81 } 82 83 static void Dump(JSTaggedType value); 84 static void DebugDump(JSTaggedType value); 85 static void DumpWithHint(uintptr_t hintStrAddress, JSTaggedType value); 86 static void DebugDumpWithHint(uintptr_t hintStrAddress, JSTaggedType value); 87 static void DebugPrint(int fmtMessageId, ...); 88 static void DebugPrintCustom(uintptr_t fmt, ...); 89 static void DebugPrintInstruction([[maybe_unused]] uintptr_t argGlue, const uint8_t *pc); 90 static void CollectingOpcodes([[maybe_unused]] uintptr_t argGlue, const uint8_t *pc); 91 static void DebugOsrEntry([[maybe_unused]] uintptr_t argGlue, const uint8_t *codeEntry); 92 static void Comment(uintptr_t argStr); 93 static void FatalPrint(int fmtMessageId, ...); 94 static void FatalPrintCustom(uintptr_t fmt, ...); 95 static void MarkingBarrier([[maybe_unused]] uintptr_t argGlue, 96 uintptr_t object, size_t offset, TaggedObject *value); 97 static void SharedGCMarkingBarrier(uintptr_t argGlue, uintptr_t object, size_t offset, TaggedObject *value); 98 static JSTaggedType GetActualArgvNoGC(uintptr_t argGlue); 99 static void InsertOldToNewRSet([[maybe_unused]] uintptr_t argGlue, uintptr_t object, size_t offset); 100 static void InsertLocalToShareRSet([[maybe_unused]] uintptr_t argGlue, uintptr_t object, size_t offset); 101 static void SetBitAtomic(GCBitset::GCBitsetWord *word, GCBitset::GCBitsetWord mask, 102 GCBitset::GCBitsetWord oldValue); 103 static int32_t DoubleToInt(double x, size_t bits); 104 static int32_t SaturateTruncDoubleToInt32(double x); 105 static uint8_t LrInt(double x); 106 static double FloatMod(double x, double y); 107 static double FloatAcos(double x); 108 static double FloatAcosh(double x); 109 static double FloatAsin(double x); 110 static double FloatAsinh(double x); 111 static double FloatAtan(double x); 112 static double FloatAtan2(double y, double x); 113 static double FloatAtanh(double x); 114 static double FloatCos(double x); 115 static double FloatCosh(double x); 116 static double FloatSin(double x); 117 static double FloatSinh(double x); 118 static double FloatTan(double x); 119 static double FloatTanh(double x); 120 static double FloatTrunc(double x); 121 static double FloatFloor(double x); 122 static double FloatLog(double x); 123 static double FloatLog2(double x); 124 static double FloatLog10(double x); 125 static double FloatLog1p(double x); 126 static double FloatExp(double x); 127 static double FloatExpm1(double x); 128 static double FloatPow(double base, double exp); 129 static double FloatCbrt(double x); 130 static double FloatCeil(double x); 131 static double CallDateNow(); 132 static void UpdateFieldType(JSTaggedType hclass, uint64_t value); 133 static bool BigIntEquals(JSTaggedType left, JSTaggedType right); 134 static bool BigIntSameValueZero(JSTaggedType key, JSTaggedType other); 135 static JSTaggedValue JSHClassFindProtoTransitions(JSHClass *cls, JSTaggedValue key, JSTaggedValue proto); 136 static void FinishObjSizeTracking(JSHClass *cls); 137 static JSTaggedValue NumberHelperStringToDouble(EcmaString *str); 138 static JSTaggedValue GetStringToListCacheArray(uintptr_t argGlue); 139 static int IntLexicographicCompare(JSTaggedType x, JSTaggedType y); 140 static int DoubleLexicographicCompare(JSTaggedType x, JSTaggedType y); 141 static int FastArraySortString(uintptr_t argGlue, JSTaggedValue x, JSTaggedValue y); 142 static JSTaggedValue StringToNumber(JSTaggedType numberString, int32_t radix); 143 static void ArrayTrim(uintptr_t argGlue, TaggedArray *array, int64_t newLength); 144 static double TimeClip(double time); 145 static double SetDateValues(double year, double month, double day); 146 static void StartCallTimer(uintptr_t argGlue, JSTaggedType func, bool isAot); 147 static void EndCallTimer(uintptr_t argGlue, JSTaggedType func); 148 static JSTaggedValue RuntimeArraySort(JSThread *thread, JSHandle<JSTaggedValue> thisHandle); 149 150 static JSTaggedValue CallBoundFunction(EcmaRuntimeCallInfo *info); 151 152 static int32_t StringGetStart(bool isUtf8, EcmaString *srcString, int32_t length, int32_t startIndex); 153 static int32_t StringGetEnd(bool isUtf8, EcmaString *srcString, int32_t start, int32_t length, int32_t startIndex); 154 static void CopyTypedArrayBuffer(uintptr_t argGlue, JSTypedArray *srcArray, JSTypedArray *targetArray, 155 int32_t srcStartPos, int32_t tarStartPos, int32_t count); 156 static inline uint32_t RuntimeGetBytecodePcOfstForBaseline(const JSHandle<JSFunction> &func, uintptr_t nativePc); 157 static void ReverseTypedArray(JSTypedArray *typedArray); 158 static void SortTypedArray(JSTypedArray *typedArray); 159 static inline uintptr_t RuntimeGetNativePcOfstForBaseline(const JSHandle<JSFunction> &func, uint64_t bytecodePos); 160 static void ObjectCopy(JSTaggedType *dst, JSTaggedType *src, uint32_t count); 161 static void FillObject(JSTaggedType *dst, JSTaggedType value, uint32_t count); 162 static void ReverseArray(JSTaggedType *dst, uint32_t length); 163 private: 164 static void DumpToStreamWithHint(std::ostream &out, std::string_view prompt, JSTaggedValue value); 165 166 static inline JSTaggedValue RuntimeInc(JSThread *thread, const JSHandle<JSTaggedValue> &value); 167 static inline JSTaggedValue RuntimeDec(JSThread *thread, const JSHandle<JSTaggedValue> &value); 168 static inline JSTaggedValue RuntimeExp(JSThread *thread, JSTaggedValue base, JSTaggedValue exponent); 169 static inline JSTaggedValue RuntimeIsIn(JSThread *thread, const JSHandle<JSTaggedValue> &prop, 170 const JSHandle<JSTaggedValue> &obj); 171 static inline JSTaggedValue RuntimeInstanceof(JSThread *thread, const JSHandle<JSTaggedValue> &obj, 172 const JSHandle<JSTaggedValue> &target); 173 static inline JSTaggedValue RuntimeInstanceofByHandler(JSThread *thread, JSHandle<JSTaggedValue> target, 174 JSHandle<JSTaggedValue> object, 175 JSHandle<JSTaggedValue> instOfHandler); 176 static inline JSTaggedValue RuntimeCreateGeneratorObj(JSThread *thread, const JSHandle<JSTaggedValue> &genFunc); 177 178 static inline JSTaggedValue RuntimeCreateAsyncGeneratorObj(JSThread *thread, 179 const JSHandle<JSTaggedValue> &genFunc); 180 181 static inline JSTaggedValue RuntimeAsyncGeneratorResolve(JSThread *thread, JSHandle<JSTaggedValue> asyncFuncObj, 182 JSHandle<JSTaggedValue> value, JSTaggedValue flag); 183 static inline JSTaggedValue RuntimeAsyncGeneratorReject(JSThread *thread, JSHandle<JSTaggedValue> asyncFuncObj, 184 JSHandle<JSTaggedValue> value); 185 static inline JSTaggedValue RuntimeGetTemplateObject(JSThread *thread, const JSHandle<JSTaggedValue> &literal); 186 static inline JSTaggedValue RuntimeGetNextPropName(JSThread *thread, const JSHandle<JSTaggedValue> &iter); 187 static inline JSTaggedValue RuntimeIterNext(JSThread *thread, const JSHandle<JSTaggedValue> &iter); 188 static inline JSTaggedValue RuntimeCloseIterator(JSThread *thread, const JSHandle<JSTaggedValue> &iter); 189 static inline JSTaggedValue RuntimeSuperCallSpread(JSThread *thread, const JSHandle<JSTaggedValue> &func, 190 const JSHandle<JSTaggedValue> &newTarget, 191 const JSHandle<JSTaggedValue> &array); 192 static inline JSTaggedValue RuntimeOptSuperCallSpread(JSThread *thread, const JSHandle<JSTaggedValue> &func, 193 const JSHandle<JSTaggedValue> &newTarget, 194 const JSHandle<JSTaggedValue> &taggedArray); 195 static inline JSTaggedValue RuntimeSuperCallForwardAllArgs(JSThread *thread, JSTaggedType *sp, 196 const JSHandle<JSTaggedValue> &superFunc, 197 const JSHandle<JSTaggedValue> &newTarget, 198 uint32_t restNumArgs, uint32_t startIdx); 199 static inline JSTaggedValue RuntimeDelObjProp(JSThread *thread, const JSHandle<JSTaggedValue> &obj, 200 const JSHandle<JSTaggedValue> &prop); 201 static inline JSTaggedValue RuntimeNewObjApply(JSThread *thread, const JSHandle<JSTaggedValue> &func, 202 const JSHandle<JSTaggedValue> &array); 203 static inline JSTaggedValue RuntimeCreateIterResultObj(JSThread *thread, const JSHandle<JSTaggedValue> &value, 204 JSTaggedValue flag); 205 static inline JSTaggedValue RuntimeAsyncFunctionAwaitUncaught(JSThread *thread, 206 const JSHandle<JSTaggedValue> &asyncFuncObj, 207 const JSHandle<JSTaggedValue> &value); 208 static inline JSTaggedValue RuntimeAsyncFunctionResolveOrReject(JSThread *thread, 209 const JSHandle<JSTaggedValue> &asyncFuncObj, 210 const JSHandle<JSTaggedValue> &value, 211 bool is_resolve); 212 static inline JSTaggedValue RuntimeCopyDataProperties(JSThread *thread, const JSHandle<JSTaggedValue> &dst, 213 const JSHandle<JSTaggedValue> &src); 214 static inline JSTaggedValue RuntimeStArraySpread(JSThread *thread, const JSHandle<JSTaggedValue> &dst, 215 JSTaggedValue index, const JSHandle<JSTaggedValue> &src); 216 static inline JSTaggedValue RuntimeSetObjectWithProto(JSThread *thread, const JSHandle<JSTaggedValue> &proto, 217 const JSHandle<JSObject> &obj); 218 static inline JSTaggedValue RuntimeGetIteratorNext(JSThread *thread, const JSHandle<JSTaggedValue> &obj, 219 const JSHandle<JSTaggedValue> &method); 220 static inline JSTaggedValue RuntimeLdObjByValue(JSThread *thread, const JSHandle<JSTaggedValue> &obj, 221 const JSHandle<JSTaggedValue> &prop, bool callGetter, 222 JSTaggedValue receiver); 223 static inline JSTaggedValue RuntimeStObjByValue(JSThread *thread, const JSHandle<JSTaggedValue> &obj, 224 const JSHandle<JSTaggedValue> &prop, 225 const JSHandle<JSTaggedValue> &value); 226 static inline JSTaggedValue RuntimeStOwnByValue(JSThread *thread, const JSHandle<JSTaggedValue> &obj, 227 const JSHandle<JSTaggedValue> &key, 228 const JSHandle<JSTaggedValue> &value); 229 static inline JSTaggedValue RuntimeLdSuperByValue(JSThread *thread, const JSHandle<JSTaggedValue> &obj, 230 const JSHandle<JSTaggedValue> &key, JSTaggedValue thisFunc); 231 static inline JSTaggedValue RuntimeStSuperByValue(JSThread *thread, const JSHandle<JSTaggedValue> &obj, 232 const JSHandle<JSTaggedValue> &key, 233 const JSHandle<JSTaggedValue> &value, JSTaggedValue thisFunc); 234 static inline JSTaggedValue RuntimeLdObjByIndex(JSThread *thread, const JSHandle<JSTaggedValue> &obj, uint32_t idx, 235 bool callGetter, JSTaggedValue receiver); 236 static inline JSTaggedValue RuntimeStObjByIndex(JSThread *thread, const JSHandle<JSTaggedValue> &obj, uint32_t idx, 237 const JSHandle<JSTaggedValue> &value); 238 static inline JSTaggedValue RuntimeStOwnByIndex(JSThread *thread, const JSHandle<JSTaggedValue> &obj, 239 const JSHandle<JSTaggedValue> &idx, 240 const JSHandle<JSTaggedValue> &value); 241 static inline JSTaggedValue RuntimeStGlobalRecord(JSThread *thread, const JSHandle<JSTaggedValue> &prop, 242 const JSHandle<JSTaggedValue> &value, bool isConst); 243 static inline JSTaggedValue RuntimeNeg(JSThread *thread, const JSHandle<JSTaggedValue> &value); 244 static inline JSTaggedValue RuntimeNot(JSThread *thread, const JSHandle<JSTaggedValue> &value); 245 static inline JSTaggedValue RuntimeResolveClass(JSThread *thread, const JSHandle<JSFunction> &ctor, 246 const JSHandle<TaggedArray> &literal, 247 const JSHandle<JSTaggedValue> &base, 248 const JSHandle<JSTaggedValue> &lexenv); 249 static inline JSTaggedValue RuntimeCloneClassFromTemplate(JSThread *thread, const JSHandle<JSFunction> &ctor, 250 const JSHandle<JSTaggedValue> &base, 251 const JSHandle<JSTaggedValue> &lexenv); 252 static inline JSTaggedValue RuntimeCreateClassWithBuffer(JSThread *thread, 253 const JSHandle<JSTaggedValue> &base, 254 const JSHandle<JSTaggedValue> &lexenv, 255 const JSHandle<JSTaggedValue> &constpool, 256 uint16_t methodId, uint16_t literalId, 257 const JSHandle<JSTaggedValue> &module, 258 const JSHandle<JSTaggedValue> &length); 259 static inline void SetProfileTypeInfoCellToFunction(JSThread *thread, const JSHandle<JSFunction> &jsFunc, 260 const JSHandle<JSFunction> &definedFunc, uint16_t slotId); 261 static inline JSTaggedValue RuntimeCreateSharedClass(JSThread *thread, 262 const JSHandle<JSTaggedValue> &base, 263 const JSHandle<JSTaggedValue> &constpool, 264 uint16_t methodId, uint16_t literalId, uint16_t length, 265 const JSHandle<JSTaggedValue> &module); 266 static inline JSTaggedValue RuntimeLdSendableClass(const JSHandle<JSTaggedValue> &env, uint16_t level); 267 static inline JSTaggedValue RuntimeSetClassInheritanceRelationship(JSThread *thread, 268 const JSHandle<JSTaggedValue> &ctor, 269 const JSHandle<JSTaggedValue> &base, 270 ClassKind kind = ClassKind::NON_SENDABLE); 271 static inline JSTaggedValue RuntimeSetClassConstructorLength(JSThread *thread, JSTaggedValue ctor, 272 JSTaggedValue length); 273 static inline JSTaggedValue RuntimeNotifyInlineCache(JSThread *thread, const JSHandle<JSFunction> &function, 274 uint32_t icSlotSize); 275 static inline JSTaggedValue RuntimeStOwnByValueWithNameSet(JSThread *thread, const JSHandle<JSTaggedValue> &obj, 276 const JSHandle<JSTaggedValue> &key, 277 const JSHandle<JSTaggedValue> &value); 278 static inline JSTaggedValue RuntimeStOwnByName(JSThread *thread, const JSHandle<JSTaggedValue> &obj, 279 const JSHandle<JSTaggedValue> &prop, 280 const JSHandle<JSTaggedValue> &value); 281 static inline JSTaggedValue RuntimeSuspendGenerator(JSThread *thread, const JSHandle<JSTaggedValue> &genObj, 282 const JSHandle<JSTaggedValue> &value); 283 static inline JSTaggedValue RuntimeGetModuleNamespace(JSThread *thread, int32_t index); 284 static inline JSTaggedValue RuntimeGetModuleNamespace(JSThread *thread, int32_t index, 285 JSTaggedValue jsFunc); 286 static inline JSTaggedValue RuntimeGetModuleNamespace(JSThread *thread, JSTaggedValue localName); 287 static inline JSTaggedValue RuntimeGetModuleNamespace(JSThread *thread, JSTaggedValue localName, 288 JSTaggedValue jsFunc); 289 static inline void RuntimeStModuleVar(JSThread *thread, int32_t index, JSTaggedValue value); 290 static inline void RuntimeStModuleVar(JSThread *thread, int32_t index, JSTaggedValue value, 291 JSTaggedValue jsFunc); 292 static inline void RuntimeStModuleVar(JSThread *thread, JSTaggedValue key, JSTaggedValue value); 293 static inline void RuntimeStModuleVar(JSThread *thread, JSTaggedValue key, JSTaggedValue value, 294 JSTaggedValue jsFunc); 295 static inline JSTaggedValue RuntimeLdLocalModuleVar(JSThread *thread, int32_t index); 296 static inline JSTaggedValue RuntimeLdLocalModuleVarWithModule(JSThread *thread, int32_t index, 297 JSHandle<JSTaggedValue> moduleHdl); 298 static inline JSTaggedValue RuntimeLdLocalModuleVar(JSThread *thread, int32_t index, 299 JSTaggedValue jsFunc); 300 static inline JSTaggedValue RuntimeLdExternalModuleVar(JSThread *thread, int32_t index); 301 static inline JSTaggedValue RuntimeLdExternalModuleVarWithModule(JSThread *thread, int32_t index, 302 JSHandle<JSTaggedValue> moduleHdl); 303 static inline JSTaggedValue RuntimeLdSendableExternalModuleVar(JSThread *thread, int32_t index, 304 JSTaggedValue jsFunc); 305 static inline JSTaggedValue RuntimeLdSendableLocalModuleVar(JSThread *thread, int32_t index, JSTaggedValue jsFunc); 306 static inline JSTaggedValue RuntimeLdExternalModuleVar(JSThread *thread, int32_t index, 307 JSTaggedValue jsFunc); 308 static inline JSTaggedValue RuntimeLdLazySendableExternalModuleVar(JSThread *thread, int32_t index, 309 JSTaggedValue jsFunc); 310 static inline JSTaggedValue RuntimeLdLazyExternalModuleVar(JSThread *thread, int32_t index, 311 JSTaggedValue jsFunc); 312 static inline JSTaggedValue RuntimeLdModuleVar(JSThread *thread, JSTaggedValue key, bool inner); 313 static inline JSTaggedValue RuntimeLdModuleVar(JSThread *thread, JSTaggedValue key, bool inner, 314 JSTaggedValue jsFunc); 315 static inline JSTaggedValue RuntimeGetPropIterator(JSThread *thread, const JSHandle<JSTaggedValue> &value); 316 static inline JSTaggedValue RuntimeAsyncFunctionEnter(JSThread *thread); 317 static inline JSTaggedValue RuntimeGetIterator(JSThread *thread, const JSHandle<JSTaggedValue> &obj); 318 static inline JSTaggedValue RuntimeGetAsyncIterator(JSThread *thread, const JSHandle<JSTaggedValue> &obj); 319 static inline void RuntimeSetGeneratorState(JSThread *thread, const JSHandle<JSTaggedValue> &genObj, 320 const int32_t index); 321 static inline void RuntimeThrow(JSThread *thread, JSTaggedValue value); 322 static inline void RuntimeThrowThrowNotExists(JSThread *thread); 323 static inline void RuntimeThrowPatternNonCoercible(JSThread *thread); 324 static inline void RuntimeThrowDeleteSuperProperty(JSThread *thread); 325 static inline void RuntimeThrowUndefinedIfHole(JSThread *thread, const JSHandle<EcmaString> &obj); 326 static inline void RuntimeThrowIfNotObject(JSThread *thread); 327 static inline void RuntimeThrowConstAssignment(JSThread *thread, const JSHandle<EcmaString> &value); 328 static inline JSTaggedValue RuntimeLdGlobalRecord(JSThread *thread, JSTaggedValue key); 329 static inline JSTaggedValue RuntimeTryLdGlobalByName(JSThread *thread, const JSHandle<JSTaggedValue> &obj, 330 const JSHandle<JSTaggedValue> &prop); 331 static inline JSTaggedValue RuntimeTryUpdateGlobalRecord(JSThread *thread, JSTaggedValue prop, JSTaggedValue value); 332 static inline JSTaggedValue RuntimeThrowReferenceError(JSThread *thread, const JSHandle<JSTaggedValue> &prop, 333 const char *desc); 334 static inline JSTaggedValue RuntimeLdGlobalVarFromProto(JSThread *thread, const JSHandle<JSTaggedValue> &globalObj, 335 const JSHandle<JSTaggedValue> &prop); 336 static inline JSTaggedValue RuntimeStGlobalVar(JSThread *thread, const JSHandle<JSTaggedValue> &prop, 337 const JSHandle<JSTaggedValue> &value); 338 static inline JSTaggedValue RuntimeToNumber(JSThread *thread, const JSHandle<JSTaggedValue> &value); 339 static inline JSTaggedValue RuntimeDynamicImport(JSThread *thread, const JSHandle<JSTaggedValue> &specifier, 340 const JSHandle<JSTaggedValue> &func); 341 static inline JSTaggedValue RuntimeToNumeric(JSThread *thread, const JSHandle<JSTaggedValue> &value); 342 static inline JSTaggedValue RuntimeEq(JSThread *thread, const JSHandle<JSTaggedValue> &left, 343 const JSHandle<JSTaggedValue> &right); 344 static inline JSTaggedValue RuntimeLdObjByName(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, 345 bool callGetter, JSTaggedValue receiver); 346 static inline JSTaggedValue RuntimeNotEq(JSThread *thread, const JSHandle<JSTaggedValue> &left, 347 const JSHandle<JSTaggedValue> &right); 348 static inline JSTaggedValue RuntimeLess(JSThread *thread, const JSHandle<JSTaggedValue> &left, 349 const JSHandle<JSTaggedValue> &right); 350 static inline JSTaggedValue RuntimeLessEq(JSThread *thread, const JSHandle<JSTaggedValue> &left, 351 const JSHandle<JSTaggedValue> &right); 352 static inline JSTaggedValue RuntimeGreater(JSThread *thread, const JSHandle<JSTaggedValue> &left, 353 const JSHandle<JSTaggedValue> &right); 354 static inline JSTaggedValue RuntimeGreaterEq(JSThread *thread, const JSHandle<JSTaggedValue> &left, 355 const JSHandle<JSTaggedValue> &right); 356 static inline JSTaggedValue RuntimeAdd2(JSThread *thread, const JSHandle<JSTaggedValue> &left, 357 const JSHandle<JSTaggedValue> &right); 358 static inline JSTaggedValue RuntimeShl2(JSThread *thread, const JSHandle<JSTaggedValue> &left, 359 const JSHandle<JSTaggedValue> &right); 360 static inline JSTaggedValue RuntimeShr2(JSThread *thread, const JSHandle<JSTaggedValue> &left, 361 const JSHandle<JSTaggedValue> &right); 362 static inline JSTaggedValue RuntimeSub2(JSThread *thread, const JSHandle<JSTaggedValue> &left, 363 const JSHandle<JSTaggedValue> &right); 364 static inline JSTaggedValue RuntimeMul2(JSThread *thread, const JSHandle<JSTaggedValue> &left, 365 const JSHandle<JSTaggedValue> &right); 366 static inline JSTaggedValue RuntimeDiv2(JSThread *thread, const JSHandle<JSTaggedValue> &left, 367 const JSHandle<JSTaggedValue> &right); 368 static inline JSTaggedValue RuntimeMod2(JSThread *thread, const JSHandle<JSTaggedValue> &left, 369 const JSHandle<JSTaggedValue> &right); 370 static inline JSTaggedValue RuntimeAshr2(JSThread *thread, const JSHandle<JSTaggedValue> &left, 371 const JSHandle<JSTaggedValue> &right); 372 static inline JSTaggedValue RuntimeAnd2(JSThread *thread, const JSHandle<JSTaggedValue> &left, 373 const JSHandle<JSTaggedValue> &right); 374 static inline JSTaggedValue RuntimeOr2(JSThread *thread, const JSHandle<JSTaggedValue> &left, 375 const JSHandle<JSTaggedValue> &right); 376 static inline JSTaggedValue RuntimeXor2(JSThread *thread, const JSHandle<JSTaggedValue> &left, 377 const JSHandle<JSTaggedValue> &right); 378 static inline JSTaggedValue RuntimeStOwnByNameWithNameSet(JSThread *thread, 379 const JSHandle<JSTaggedValue> &obj, 380 const JSHandle<JSTaggedValue> &prop, 381 const JSHandle<JSTaggedValue> &value); 382 static inline JSTaggedValue RuntimeStObjByName(JSThread *thread, const JSHandle<JSTaggedValue> &obj, 383 const JSHandle<JSTaggedValue> &prop, 384 const JSHandle<JSTaggedValue> &value); 385 static inline JSTaggedValue RuntimeToJSTaggedValueWithInt32(JSThread *thread, 386 const JSHandle<JSTaggedValue> &value); 387 static inline JSTaggedValue RuntimeToJSTaggedValueWithUint32(JSThread *thread, 388 const JSHandle<JSTaggedValue> &value); 389 static inline JSTaggedValue RuntimeCreateEmptyObject(JSThread *thread, ObjectFactory *factory, 390 JSHandle<GlobalEnv> globalEnv); 391 static inline JSTaggedValue RuntimeCreateEmptyArray(JSThread *thread, ObjectFactory *factory, 392 JSHandle<GlobalEnv> globalEnv); 393 static inline JSTaggedValue RuntimeGetUnmapedArgs(JSThread *thread, JSTaggedType *sp, uint32_t actualNumArgs, 394 uint32_t startIdx); 395 static inline JSTaggedValue RuntimeCopyRestArgs(JSThread *thread, JSTaggedType *sp, uint32_t restNumArgs, 396 uint32_t startIdx); 397 static inline JSTaggedValue RuntimeCreateArrayWithBuffer(JSThread *thread, ObjectFactory *factory, 398 const JSHandle<JSTaggedValue> &literal); 399 static inline JSTaggedValue RuntimeCreateObjectWithBuffer(JSThread *thread, ObjectFactory *factory, 400 const JSHandle<JSObject> &literal); 401 static inline JSTaggedValue RuntimeNewLexicalEnv(JSThread *thread, uint16_t numVars); 402 static inline JSTaggedValue RuntimeNewSendableEnv(JSThread *thread, uint16_t numVars); 403 static inline JSTaggedValue RuntimeNewObjRange(JSThread *thread, const JSHandle<JSTaggedValue> &func, 404 const JSHandle<JSTaggedValue> &newTarget, uint16_t firstArgIdx, 405 uint16_t length); 406 static inline JSTaggedValue RuntimeDefinefunc(JSThread *thread, const JSHandle<JSTaggedValue> &constpool, 407 uint16_t methodId, const JSHandle<JSTaggedValue> &module, 408 uint16_t length, const JSHandle<JSTaggedValue> &envHandle, 409 const JSHandle<JSTaggedValue> &homeObject); 410 static inline void DefineFuncTryUseAOTHClass(JSThread* thread, 411 const JSHandle<JSFunction>& func, 412 const JSHandle<JSTaggedValue>& ihc, 413 const JSHandle<AOTLiteralInfo>& aotLiteralInfo); 414 static inline JSTaggedValue RuntimeCreateRegExpWithLiteral(JSThread *thread, const JSHandle<JSTaggedValue> &pattern, 415 uint8_t flags); 416 static inline JSTaggedValue RuntimeThrowIfSuperNotCorrectCall(JSThread *thread, uint16_t index, 417 JSTaggedValue thisValue); 418 static inline JSTaggedValue RuntimeCreateObjectHavingMethod(JSThread *thread, ObjectFactory *factory, 419 const JSHandle<JSObject> &literal, 420 const JSHandle<JSTaggedValue> &env); 421 static inline JSTaggedValue RuntimeCreateObjectWithExcludedKeys(JSThread *thread, uint16_t numKeys, 422 const JSHandle<JSTaggedValue> &objVal, 423 uint16_t firstArgRegIdx); 424 static inline JSTaggedValue RuntimeDefineMethod(JSThread *thread, const JSHandle<Method> &methodHandle, 425 const JSHandle<JSTaggedValue> &homeObject, uint16_t length, 426 const JSHandle<JSTaggedValue> &env, 427 const JSHandle<JSTaggedValue> &module); 428 static inline JSTaggedValue RuntimeCallSpread(JSThread *thread, const JSHandle<JSTaggedValue> &func, 429 const JSHandle<JSTaggedValue> &obj, 430 const JSHandle<JSTaggedValue> &array); 431 static inline JSTaggedValue RuntimeDefineGetterSetterByValue(JSThread *thread, const JSHandle<JSObject> &obj, 432 const JSHandle<JSTaggedValue> &prop, 433 const JSHandle<JSTaggedValue> &getter, 434 const JSHandle<JSTaggedValue> &setter, bool flag, 435 const JSHandle<JSTaggedValue> &func, 436 int32_t pcOffset); 437 static inline JSTaggedValue RuntimeSuperCall(JSThread *thread, const JSHandle<JSTaggedValue> &func, 438 const JSHandle<JSTaggedValue> &newTarget, uint16_t firstVRegIdx, 439 uint16_t length); 440 static inline JSTaggedValue RuntimeOptSuperCall(JSThread *thread, const JSHandle<JSTaggedValue> &func, 441 const JSHandle<JSTaggedValue> &newTarget, 442 const JSHandle<TaggedArray> &argv, 443 uint16_t length); 444 static inline JSTaggedValue RuntimeThrowTypeError(JSThread *thread, const char *message); 445 static inline JSTaggedValue RuntimeGetCallSpreadArgs(JSThread *thread, const JSHandle<JSTaggedValue> &array); 446 static inline JSTaggedValue RuntimeThrowReferenceError(JSThread *thread, JSTaggedValue prop, const char *desc); 447 static inline JSTaggedValue RuntimeThrowSyntaxError(JSThread *thread, const char *message); 448 static inline JSTaggedValue RuntimeLdBigInt(JSThread *thread, const JSHandle<JSTaggedValue> &numberBigInt); 449 static inline JSTaggedValue RuntimeCallBigIntAsIntN(JSThread *thread, JSTaggedValue bits, JSTaggedValue bigint); 450 static inline JSTaggedValue RuntimeCallBigIntAsUintN(JSThread *thread, JSTaggedValue bits, JSTaggedValue bigint); 451 static inline JSTaggedValue RuntimeNewLexicalEnvWithName(JSThread *thread, uint16_t numVars, uint16_t scopeId); 452 static inline JSTaggedValue RuntimeOptGetUnmapedArgs(JSThread *thread, uint32_t actualNumArgs); 453 static inline JSTaggedValue RuntimeGetUnmapedJSArgumentObj(JSThread *thread, 454 const JSHandle<TaggedArray> &argumentsList); 455 static inline JSTaggedValue RuntimeOptNewLexicalEnvWithName(JSThread *thread, uint16_t numVars, uint16_t scopeId, 456 JSHandle<JSTaggedValue> ¤tLexEnv, 457 JSHandle<JSTaggedValue> &func); 458 static inline JSTaggedValue RuntimeOptCopyRestArgs(JSThread *thread, uint32_t actualArgc, uint32_t restIndex); 459 static inline JSTaggedValue RuntimeOptSuspendGenerator(JSThread *thread, const JSHandle<JSTaggedValue> &genObj, 460 const JSHandle<JSTaggedValue> &value); 461 static inline JSTaggedValue RuntimeOptAsyncGeneratorResolve(JSThread *thread, JSHandle<JSTaggedValue> asyncFuncObj, 462 JSHandle<JSTaggedValue> value, JSTaggedValue flag); 463 static inline JSTaggedValue CommonCreateObjectWithExcludedKeys(JSThread *thread, 464 const JSHandle<JSTaggedValue> &objVal, 465 uint32_t numExcludedKeys, 466 JSHandle<TaggedArray> excludedKeys); 467 static inline JSTaggedValue RuntimeOptCreateObjectWithExcludedKeys(JSThread *thread, uintptr_t argv, uint32_t argc); 468 static inline JSTaggedValue RuntimeOptNewObjRange(JSThread *thread, uintptr_t argv, uint32_t argc); 469 static inline JSTaggedValue RuntimeOptConstruct(JSThread *thread, JSHandle<JSTaggedValue> ctor, 470 JSHandle<JSTaggedValue> newTarget, JSHandle<JSTaggedValue> preArgs, 471 JSHandle<TaggedArray> args); 472 static inline JSTaggedValue RuntimeOptConstructProxy(JSThread *thread, JSHandle<JSProxy> ctor, 473 JSHandle<JSTaggedValue> newTgt, 474 JSHandle<JSTaggedValue> preArgs, JSHandle<TaggedArray> args); 475 static inline JSTaggedValue RuntimeOptConstructBoundFunction(JSThread *thread, JSHandle<JSBoundFunction> ctor, 476 JSHandle<JSTaggedValue> newTgt, 477 JSHandle<JSTaggedValue> preArgs, 478 JSHandle<TaggedArray> args); 479 static inline JSTaggedValue RuntimeOptConstructGeneric(JSThread *thread, JSHandle<JSFunction> ctor, 480 JSHandle<JSTaggedValue> newTgt, 481 JSHandle<JSTaggedValue> preArgs, JSHandle<TaggedArray> args); 482 static inline JSTaggedValue GetResultValue(JSThread *thread, bool isAotMethod, JSHandle<JSFunction> ctor, 483 CVector<JSTaggedType> &values, JSHandle<JSTaggedValue> newTgt, uint32_t &size, JSHandle<JSTaggedValue> obj); 484 static inline JSTaggedValue RuntimeOptGenerateScopeInfo(JSThread *thread, uint16_t scopeId, JSTaggedValue func); 485 static inline JSTaggedType *GetActualArgv(JSThread *thread); 486 static inline JSTaggedType *GetActualArgvFromStub(JSThread *thread); 487 static inline OptimizedJSFunctionFrame *GetOptimizedJSFunctionFrame(JSThread *thread); 488 static inline OptimizedJSFunctionFrame *GetOptimizedJSFunctionFrameNoGC(JSThread *thread); 489 490 static JSTaggedValue NewObject(EcmaRuntimeCallInfo *info); 491 static void SaveFrameToContext(JSThread *thread, JSHandle<GeneratorContext> context); 492 493 static inline JSTaggedValue RuntimeLdPatchVar(JSThread *thread, uint32_t index); 494 static inline JSTaggedValue RuntimeStPatchVar(JSThread *thread, uint32_t index, 495 const JSHandle<JSTaggedValue> &value); 496 static inline JSTaggedValue RuntimeNotifyConcurrentResult(JSThread *thread, JSTaggedValue result, 497 JSTaggedValue hint); 498 static inline JSTaggedValue RuntimeDefineField(JSThread *thread, JSTaggedValue obj, 499 JSTaggedValue propKey, JSTaggedValue value); 500 static inline JSTaggedValue RuntimeCreatePrivateProperty(JSThread *thread, JSTaggedValue constpool, 501 uint32_t count, JSTaggedValue lexicalEnv, uint32_t literalId, JSTaggedValue module); 502 static inline JSTaggedValue RuntimeDefinePrivateProperty(JSThread *thread, JSTaggedValue lexicalEnv, 503 uint32_t levelIndex, uint32_t slotIndex, JSTaggedValue obj, JSTaggedValue value); 504 static inline JSTaggedValue RuntimeLdPrivateProperty(JSThread *thread, JSTaggedValue lexicalEnv, 505 uint32_t levelIndex, uint32_t slotIndex, JSTaggedValue obj); 506 static inline JSTaggedValue RuntimeStPrivateProperty(JSThread *thread, JSTaggedValue lexicalEnv, 507 uint32_t levelIndex, uint32_t slotIndex, JSTaggedValue obj, JSTaggedValue value); 508 static inline JSTaggedValue RuntimeTestIn(JSThread *thread, JSTaggedValue lexicalEnv, 509 uint32_t levelIndex, uint32_t slotIndex, JSTaggedValue obj); 510 static inline JSTaggedValue RuntimeUpdateAOTHClass(JSThread *thread, const JSHandle<JSHClass> &oldhclass, 511 const JSHandle<JSHClass> &newhclass, JSTaggedValue key); 512 static inline JSTaggedValue RuntimeNotifyDebuggerStatement(JSThread *thread); 513 static inline bool CheckElementsNumber(JSHandle<TaggedArray> elements, uint32_t len); 514 static inline JSHandle<JSTaggedValue> GetOrCreateNumberString(JSThread *thread, 515 JSHandle<JSTaggedValue> presentValue, std::map<uint64_t, JSHandle<JSTaggedValue>> &cachedString); 516 static inline JSTaggedValue TryCopyCOWArray(JSThread *thread, JSHandle<JSArray> holderHandler, bool &isCOWArray); 517 static inline JSTaggedValue ArrayNumberSort(JSThread *thread, JSHandle<JSObject> thisObj, uint32_t len); 518 static inline bool ShouldUseAOTHClass(const JSHandle<JSTaggedValue> &ihc, 519 const JSHandle<JSTaggedValue> &chc, 520 const JSHandle<ClassLiteral> &classLiteral); 521 static inline JSTaggedType RuntimeTryGetInternString(uintptr_t argGlue, const JSHandle<EcmaString> &string); 522 static inline void RuntimeSetPatchModule(JSThread *thread, const JSHandle<JSFunction> &func); 523 template <typename T> 524 static inline JSTaggedValue RuntimeDecodeURIComponent(JSThread *thread, const JSHandle<EcmaString> &str, 525 const T *data); 526 template <typename T> 527 static inline uint16_t GetCodeUnit(Span<T> &sp, int32_t index, int32_t length); 528 template <typename T> 529 static inline JSTaggedValue DecodePercentEncoding(JSThread *thread, const JSHandle<EcmaString> &str, int32_t &k, 530 int32_t strLen, std::u16string &sStr, Span<T> &sp); 531 template <typename T> 532 static inline JSTaggedValue DecodePercentEncoding(JSThread *thread, int32_t &n, int32_t &k, 533 const JSHandle<EcmaString> &str, uint8_t &bb, 534 std::vector<uint8_t> &oct, Span<T> &sp, 535 int32_t strLen); 536 static inline JSTaggedValue UTF16EncodeCodePoint(JSThread *thread, const std::vector<uint8_t> &oct, 537 const JSHandle<EcmaString> &str, std::u16string &sStr); 538 static inline bool IsFastRegExp(uintptr_t argGlue, JSTaggedValue thisValue); 539 540 static inline RememberedSet* CreateLocalToShare(Region *region); 541 static inline RememberedSet* CreateOldToNew(Region *region); 542 static inline uint8_t GetValueFromTwoHex(uint8_t front, uint8_t behind); 543 friend class SlowRuntimeStub; 544 }; 545 } // namespace panda::ecmascript 546 #endif 547