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