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_OBJECT_FACTORY_H 17 #define ECMASCRIPT_OBJECT_FACTORY_H 18 19 #include "ecmascript/base/error_type.h" 20 #include "ecmascript/base/number_helper.h" 21 #include "ecmascript/compiler/builtins/builtins_call_signature.h" 22 #include "ecmascript/ecma_string.h" 23 #include "ecmascript/js_function_kind.h" 24 #include "ecmascript/js_handle.h" 25 #include "ecmascript/js_hclass.h" 26 #include "ecmascript/js_native_pointer.h" 27 #include "ecmascript/js_tagged_value.h" 28 #include "ecmascript/mem/heap_region_allocator.h" 29 #include "ecmascript/mem/machine_code.h" 30 #include "ecmascript/mem/native_area_allocator.h" 31 #include "ecmascript/mem/space.h" 32 #include "ecmascript/shared_objects/js_shared_object.h" 33 #include "ecmascript/tagged_array.h" 34 #include "ecmascript/byte_array.h" 35 #include "ecmascript/pgo_profiler/pgo_extra_profiler.h" 36 37 namespace panda::ecmascript { 38 struct MethodLiteral; 39 class Method; 40 class JSObject; 41 class JSArray; 42 class JSAPIPlainArray; 43 class JSSymbol; 44 class JSFunctionBase; 45 class JSFunction; 46 class JSBoundFunction; 47 class JSProxyRevocFunction; 48 class JSAsyncAwaitStatusFunction; 49 class JSPrimitiveRef; 50 class GlobalEnv; 51 class GlobalEnvConstants; 52 class AccessorData; 53 class JSGlobalObject; 54 class LexicalEnv; 55 class SendableEnv; 56 class JSDate; 57 class JSProxy; 58 class JSRealm; 59 class JSArguments; 60 class TaggedQueue; 61 class JSForInIterator; 62 class JSSet; 63 class JSSharedSet; 64 class JSMap; 65 class JSSharedMap; 66 class JSRegExp; 67 class JSSetIterator; 68 class JSSharedSetIterator; 69 class JSRegExpIterator; 70 class JSMapIterator; 71 class JSSharedMapIterator; 72 class JSArrayIterator; 73 class JSSharedArrayIterator; 74 class JSAPIPlainArrayIterator; 75 class JSStringIterator; 76 class JSGeneratorObject; 77 class CompletionRecord; 78 class GeneratorContext; 79 class JSArrayBuffer; 80 class JSSendableArrayBuffer; 81 class JSDataView; 82 class JSPromise; 83 class JSPromiseReactionsFunction; 84 class JSPromiseExecutorFunction; 85 class JSAsyncModuleFulfilledFunction; 86 class JSAsyncModuleRejectedFunction; 87 class JSPromiseAllResolveElementFunction; 88 class JSAsyncGeneratorResNextRetProRstFtn; 89 class JSPromiseAnyRejectElementFunction; 90 class JSPromiseAllSettledElementFunction; 91 class JSPromiseFinallyFunction; 92 class JSPromiseValueThunkOrThrowerFunction; 93 class PromiseReaction; 94 class PromiseCapability; 95 class PromiseIteratorRecord; 96 class JSAsyncFuncObject; 97 class JSAsyncFunction; 98 class JSAsyncFromSyncIterUnwarpFunction; 99 class PromiseRecord; 100 class JSLocale; 101 class ResolvingFunctionsRecord; 102 class EcmaVM; 103 class Heap; 104 class SharedHeap; 105 class ConstantPool; 106 class Program; 107 class LayoutInfo; 108 class JSIntlBoundFunction; 109 class FreeObject; 110 class JSNativePointer; 111 class JSAPIArrayList; 112 class JSAPIArrayListIterator; 113 class JSAPIDeque; 114 class JSAPIDequeIterator; 115 class TaggedHashArray; 116 class LinkedNode; 117 class RBTreeNode; 118 class JSAPIHashMap; 119 class JSAPIHashSet; 120 class JSAPIHashMapIterator; 121 class JSAPIHashSetIterator; 122 class JSAPILightWeightMap; 123 class JSAPILightWeightMapIterator; 124 class JSAPILightWeightSet; 125 class JSAPILightWeightSetIterator; 126 class JSAPIQueue; 127 class JSAPIQueueIterator; 128 class JSAPIStack; 129 class JSAPIStackIterator; 130 class JSAPITreeSet; 131 class JSAPITreeMap; 132 class JSAPITreeSetIterator; 133 class JSAPITreeMapIterator; 134 class JSAPIVector; 135 class JSAPIVectorIterator; 136 class JSAPIBitVector; 137 class JSAPIBitVectorIterator; 138 class JSAPILinkedList; 139 class JSAPIList; 140 class JSAPILinkedListIterator; 141 class JSAPIListIterator; 142 class ModuleNamespace; 143 class NativeModuleFailureInfo; 144 class ImportEntry; 145 class LocalExportEntry; 146 class IndirectExportEntry; 147 class StarExportEntry; 148 class SourceTextModule; 149 class CjsModule; 150 class CjsRequire; 151 class CjsExports; 152 class ResolvedBinding; 153 class ResolvedIndexBinding; 154 class ResolvedRecordIndexBinding; 155 class ResolvedRecordBinding; 156 class BigInt; 157 class AsyncGeneratorRequest; 158 class AsyncIteratorRecord; 159 class JSAsyncGeneratorFunction; 160 class JSAsyncGeneratorObject; 161 class CellRecord; 162 class ClassLiteral; 163 164 namespace job { 165 class MicroJobQueue; 166 class PendingJob; 167 } // namespace job 168 class TransitionHandler; 169 class PrototypeHandler; 170 class TransWithProtoHandler; 171 class StoreTSHandler; 172 class PropertyBox; 173 class ProtoChangeMarker; 174 class ProtoChangeDetails; 175 class MarkerCell; 176 class ProfileTypeInfo; 177 class MachineCode; 178 class ClassInfoExtractor; 179 class AOTLiteralInfo; 180 class ProfileTypeInfoCell; 181 class FunctionTemplate; 182 class VTable; 183 namespace kungfu { 184 class TSHClassGenerator; 185 } // namespace kungfu 186 namespace pgo { 187 class ExtraProfileTypeInfo; 188 } 189 190 enum class CompletionRecordType : uint8_t; 191 enum class PrimitiveType : uint8_t; 192 enum class IterationKind : uint8_t; 193 enum class MethodIndex : uint8_t; 194 enum class SharedTypes : uint8_t; 195 using ErrorType = base::ErrorType; 196 using base::ErrorType; 197 using ExtraProfileTypeInfo = pgo::ExtraProfileTypeInfo; 198 199 enum class RemoveSlots { YES, NO }; 200 enum class GrowMode { KEEP, GROW }; 201 enum class StackCheck { YES, NO }; 202 203 class ObjectFactory { 204 public: 205 static constexpr JSTaggedType FREE_MEMMORY_ADDRESS_ZAM_VALUE = 0xDEADFACE; 206 ObjectFactory(JSThread *thread, Heap *heap, SharedHeap *sHeap); 207 ~ObjectFactory() = default; 208 JSHandle<Method> NewMethodForNativeFunction(const void *func, FunctionKind kind = FunctionKind::NORMAL_FUNCTION, 209 kungfu::BuiltinsStubCSigns::ID builtinId = 210 kungfu::BuiltinsStubCSigns::INVALID, 211 MemSpaceType methodSpaceType = SHARED_OLD_SPACE); 212 213 JSHandle<ProfileTypeInfo> NewProfileTypeInfo(uint32_t length); 214 JSHandle<ConstantPool> NewConstantPool(uint32_t capacity); 215 JSHandle<Program> NewProgram(); 216 217 JSHandle<JSObject> PUBLIC_API GetJSError(const ErrorType &errorType, const char *data = nullptr, 218 StackCheck needCheckStack = StackCheck::YES); 219 220 JSHandle<JSObject> NewJSError(const ErrorType &errorType, const JSHandle<EcmaString> &message, 221 StackCheck needCheckStack = StackCheck::YES); 222 223 JSHandle<JSObject> NewJSAggregateError(); 224 225 JSHandle<TransitionHandler> NewTransitionHandler(); 226 227 JSHandle<PrototypeHandler> NewPrototypeHandler(); 228 229 JSHandle<TransWithProtoHandler> NewTransWithProtoHandler(); 230 231 JSHandle<StoreTSHandler> NewStoreTSHandler(); 232 233 JSHandle<JSObject> NewEmptyJSObject(uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); 234 235 // use for others create, prototype is Function.prototype 236 // use for native function 237 JSHandle<JSFunction> NewJSFunction(const JSHandle<GlobalEnv> &env, const void *nativeFunc = nullptr, 238 FunctionKind kind = FunctionKind::NORMAL_FUNCTION, 239 kungfu::BuiltinsStubCSigns::ID builtinId = kungfu::BuiltinsStubCSigns::INVALID, 240 MemSpaceType methodSpaceType = SHARED_OLD_SPACE); 241 JSHandle<JSFunction> NewSFunction(const JSHandle<GlobalEnv> &env, 242 const void *nativeFunc = nullptr, 243 FunctionKind kind = FunctionKind::NORMAL_FUNCTION, 244 kungfu::BuiltinsStubCSigns::ID builtinId = kungfu::BuiltinsStubCSigns::INVALID, 245 MemSpaceType spaceType = SHARED_OLD_SPACE); 246 void InitializeMethod(const MethodLiteral *methodLiteral, JSHandle<Method> &method); 247 // use for method 248 JSHandle<JSFunction> NewJSFunction(const JSHandle<GlobalEnv> &env, const JSHandle<Method> &method); 249 250 JSHandle<JSFunction> NewJSFunction(const JSHandle<Method> &methodHandle); 251 252 JSHandle<JSFunction> NewJSFunction(const JSHandle<Method> &methodHandle, 253 const JSHandle<JSTaggedValue> &homeObject); 254 255 JSHandle<JSFunction> NewJSNativeErrorFunction(const JSHandle<GlobalEnv> &env, const void *nativeFunc = nullptr); 256 257 JSHandle<JSFunction> NewSpecificTypedArrayFunction(const JSHandle<GlobalEnv> &env, 258 const void *nativeFunc = nullptr, 259 kungfu::BuiltinsStubCSigns::ID builtinId = 260 kungfu::BuiltinsStubCSigns::INVALID); 261 262 JSHandle<JSObject> OrdinaryNewJSObjectCreate(const JSHandle<JSTaggedValue> &proto); 263 264 JSHandle<JSObject> CreateNullJSObject(); 265 266 JSHandle<JSFunction> NewAotFunction(uint32_t numArgs, uintptr_t codeEntry); 267 268 JSHandle<JSBoundFunction> NewJSBoundFunction(const JSHandle<JSTaggedValue> &target, 269 const JSHandle<JSTaggedValue> &boundThis, 270 const JSHandle<TaggedArray> &args); 271 272 JSHandle<JSIntlBoundFunction> NewJSIntlBoundFunction(MethodIndex idx, int functionLength = 1); 273 274 JSHandle<JSProxyRevocFunction> NewJSProxyRevocFunction(const JSHandle<JSProxy> &proxy); 275 276 JSHandle<JSAsyncAwaitStatusFunction> NewJSAsyncAwaitStatusFunction(MethodIndex idx); 277 278 JSHandle<JSGeneratorObject> NewJSGeneratorObject(JSHandle<JSTaggedValue> generatorFunction); 279 280 JSHandle<JSAsyncFuncObject> NewJSAsyncFuncObject(); 281 JSHandle<JSAsyncGeneratorObject> NewJSAsyncGeneratorObject(JSHandle<JSTaggedValue> generatorFunction); 282 283 JSHandle<JSPrimitiveRef> NewJSPrimitiveRef(const JSHandle<JSFunction> &function, 284 const JSHandle<JSTaggedValue> &object); 285 JSHandle<JSPrimitiveRef> NewJSPrimitiveRef(PrimitiveType type, const JSHandle<JSTaggedValue> &object); 286 287 // get JSHClass for Ecma ClassLinker 288 JSHandle<GlobalEnv> NewGlobalEnv(JSHClass *globalEnvClass); 289 290 // get JSHClass for Ecma ClassLinker 291 JSHandle<LexicalEnv> NewLexicalEnv(int numSlots); 292 293 inline LexicalEnv *InlineNewLexicalEnv(int numSlots); 294 295 JSHandle<JSSymbol> NewEmptySymbol(); 296 297 JSHandle<JSSymbol> NewJSSymbol(); 298 299 JSHandle<JSSymbol> NewPrivateSymbol(); 300 301 JSHandle<JSSymbol> NewPrivateNameSymbol(const JSHandle<JSTaggedValue> &name); 302 303 JSHandle<JSSymbol> NewWellKnownSymbol(const JSHandle<JSTaggedValue> &name); 304 305 JSHandle<JSSymbol> NewPublicSymbol(const JSHandle<JSTaggedValue> &name); 306 307 JSHandle<JSSymbol> NewSymbolWithTable(const JSHandle<JSTaggedValue> &name); 308 309 JSHandle<JSSymbol> NewPrivateNameSymbolWithChar(std::string_view description); 310 311 JSHandle<JSSymbol> NewWellKnownSymbolWithChar(std::string_view description); 312 313 JSHandle<JSSymbol> NewPublicSymbolWithChar(std::string_view description); 314 315 JSHandle<JSSymbol> NewSymbolWithTableWithChar(std::string_view description); 316 317 JSHandle<AccessorData> NewAccessorData(); 318 JSHandle<AccessorData> NewInternalAccessor(void *setter, void *getter); 319 320 JSHandle<PromiseCapability> NewPromiseCapability(); 321 322 JSHandle<PromiseReaction> NewPromiseReaction(); 323 324 JSHandle<PromiseRecord> NewPromiseRecord(); 325 JSHandle<AsyncGeneratorRequest> NewAsyncGeneratorRequest(); 326 327 JSHandle<AsyncIteratorRecord> NewAsyncIteratorRecord(const JSHandle<JSTaggedValue> &itor, 328 const JSHandle<JSTaggedValue> &next, bool done); 329 330 JSHandle<ResolvingFunctionsRecord> NewResolvingFunctionsRecord(); 331 332 JSHandle<PromiseIteratorRecord> NewPromiseIteratorRecord(const JSHandle<JSTaggedValue> &itor, bool done); 333 334 JSHandle<job::MicroJobQueue> NewMicroJobQueue(); 335 336 JSHandle<job::PendingJob> NewPendingJob(const JSHandle<JSFunction> &func, const JSHandle<TaggedArray> &argv); 337 338 JSHandle<JSArray> NewJSArray(); 339 JSHandle<JSSharedArray> PUBLIC_API NewJSSArray(); 340 JSHandle<JSArray> PUBLIC_API NewJSArray(size_t length, JSHandle<JSHClass> &hclass); 341 JSHandle<TaggedArray> PUBLIC_API NewJsonFixedArray(size_t start, size_t length, 342 const std::vector<JSHandle<JSTaggedValue>> &vec); 343 JSHandle<TaggedArray> PUBLIC_API NewSJsonFixedArray(size_t start, size_t length, 344 const std::vector<JSHandle<JSTaggedValue>> &vec); 345 346 JSHandle<JSProxy> NewJSProxy(const JSHandle<JSTaggedValue> &target, const JSHandle<JSTaggedValue> &handler); 347 JSHandle<JSRealm> NewJSRealm(); 348 349 JSHandle<JSArguments> NewJSArguments(); 350 351 JSHandle<JSPrimitiveRef> NewJSString(const JSHandle<JSTaggedValue> &str, const JSHandle<JSTaggedValue> &newTarget); 352 353 template <typename Derived> ConvertListToArray(const JSThread * thread,const JSHandle<Derived> & list,uint32_t numberOfNodes)354 JSHandle<TaggedArray> ConvertListToArray(const JSThread *thread, const JSHandle<Derived> &list, 355 uint32_t numberOfNodes) 356 { 357 MemSpaceType spaceType = numberOfNodes < LENGTH_THRESHOLD ? MemSpaceType::SEMI_SPACE : MemSpaceType::OLD_SPACE; 358 JSHandle<TaggedArray> dstElements = NewTaggedArrayWithoutInit(numberOfNodes, spaceType); 359 if (numberOfNodes == 0) { 360 return dstElements; 361 } 362 int dataIndex = Derived::ELEMENTS_START_INDEX; 363 for (uint32_t i = 0; i < numberOfNodes; i++) { 364 dataIndex = list->GetElement(dataIndex + Derived::NEXT_PTR_OFFSET).GetInt(); 365 dstElements->Set(thread, i, list->GetElement(dataIndex)); 366 } 367 return dstElements; 368 } 369 370 JSHandle<JSObject> NewAndCopyJSArrayObject(JSHandle<JSObject> thisObjHandle, uint32_t newLength, 371 uint32_t oldLength, uint32_t k = 0); 372 JSHandle<TaggedArray> NewAndCopyTaggedArray(JSHandle<TaggedArray> &srcElements, uint32_t newLength, 373 uint32_t oldLength, uint32_t k = 0); 374 JSHandle<TaggedArray> NewAndCopyTaggedArraySkipBarrier(JSHandle<TaggedArray> &srcElements, uint32_t newLength, 375 uint32_t oldLength, uint32_t k = 0); 376 JSHandle<TaggedArray> NewAndCopySNameDictionary(JSHandle<TaggedArray> &srcElements, uint32_t length); 377 JSHandle<TaggedArray> NewAndCopyTaggedArrayByObject(JSHandle<JSObject> thisObjHandle, uint32_t newLength, 378 uint32_t oldLength, uint32_t k = 0); 379 JSHandle<MutantTaggedArray> NewAndCopyMutantTaggedArrayByObject(JSHandle<JSObject> thisObjHandle, 380 uint32_t newLength, uint32_t oldLength, 381 uint32_t k = 0); 382 JSHandle<TaggedArray> PUBLIC_API NewTaggedArray(uint32_t length, JSTaggedValue initVal = JSTaggedValue::Hole()); 383 JSHandle<TaggedArray> NewTaggedArray(uint32_t length, JSTaggedValue initVal, bool nonMovable); 384 JSHandle<TaggedArray> NewTaggedArray(uint32_t length, JSTaggedValue initVal, MemSpaceType spaceType); 385 // Copy on write array is allocated in nonmovable space by default. 386 JSHandle<COWTaggedArray> NewCOWTaggedArray(uint32_t length, JSTaggedValue initVal = JSTaggedValue::Hole()); 387 JSHandle<COWMutantTaggedArray> NewCOWMutantTaggedArray(uint32_t length, JSTaggedType initVal = base::SPECIAL_HOLE); 388 JSHandle<MutantTaggedArray> NewMutantTaggedArray(uint32_t length, JSTaggedType initVal = base::SPECIAL_HOLE); 389 JSHandle<TaggedArray> PUBLIC_API NewDictionaryArray(uint32_t length); 390 JSHandle<JSForInIterator> NewJSForinIterator(const JSHandle<JSTaggedValue> &obj, 391 const JSHandle<JSTaggedValue> keys, 392 const JSHandle<JSTaggedValue> cachedHclass); 393 394 JSHandle<ByteArray> NewByteArray(uint32_t length, uint32_t size, void *srcData = nullptr, 395 MemSpaceType spaceType = MemSpaceType::SEMI_SPACE); 396 397 JSHandle<PropertyBox> NewPropertyBox(const JSHandle<JSTaggedValue> &name); 398 399 JSHandle<ProtoChangeMarker> NewProtoChangeMarker(); 400 401 JSHandle<ProtoChangeDetails> NewProtoChangeDetails(); 402 403 JSHandle<MarkerCell> NewMarkerCell(); 404 JSHandle<BigInt> NewBigInt(uint32_t length); 405 // use for copy properties keys's array to another array 406 JSHandle<TaggedArray> ExtendArray(const JSHandle<TaggedArray> &old, uint32_t length, 407 JSTaggedValue initVal = JSTaggedValue::Hole(), 408 MemSpaceType type = MemSpaceType::SEMI_SPACE, 409 ElementsKind kind = ElementsKind::GENERIC); 410 JSHandle<TaggedArray> CopyPartArray(const JSHandle<TaggedArray> &old, uint32_t start, uint32_t end); 411 JSHandle<TaggedArray> PUBLIC_API CopyArray(const JSHandle<TaggedArray> &old, uint32_t oldLength, uint32_t newLength, 412 JSTaggedValue initVal = JSTaggedValue::Hole(), 413 MemSpaceType type = MemSpaceType::SEMI_SPACE, 414 ElementsKind kind = ElementsKind::GENERIC); 415 JSHandle<TaggedArray> CopyFromEnumCache(const JSHandle<TaggedArray> &old); 416 JSHandle<TaggedArray> CloneProperties(const JSHandle<TaggedArray> &old); 417 JSHandle<TaggedArray> CloneProperties(const JSHandle<TaggedArray> &old, const JSHandle<JSTaggedValue> &env, 418 const JSHandle<JSObject> &obj); 419 420 JSHandle<LayoutInfo> PUBLIC_API CreateLayoutInfo(int properties, MemSpaceType type = MemSpaceType::SEMI_SPACE, 421 GrowMode mode = GrowMode::GROW); 422 423 JSHandle<LayoutInfo> ExtendLayoutInfo(const JSHandle<LayoutInfo> &old, int properties); 424 425 JSHandle<LayoutInfo> CopyLayoutInfo(const JSHandle<LayoutInfo> &old); 426 427 JSHandle<LayoutInfo> CopyAndReSort(const JSHandle<LayoutInfo> &old, int end, int capacity); 428 429 JSHandle<EcmaString> GetEmptyString() const; 430 431 JSHandle<TaggedArray> EmptyArray() const; 432 433 JSHandle<MutantTaggedArray> EmptyMutantArray() const; 434 435 FreeObject *FillFreeObject(uintptr_t address, size_t size, RemoveSlots removeSlots = RemoveSlots::NO, 436 uintptr_t hugeObjectHead = 0); 437 438 TaggedObject *NewObject(const JSHandle<JSHClass> &hclass); 439 440 TaggedObject *NewNonMovableObject(const JSHandle<JSHClass> &hclass, uint32_t inobjPropCount = 0); 441 442 void InitializeExtraProperties(const JSHandle<JSHClass> &hclass, TaggedObject *obj, uint32_t inobjPropCount); 443 444 JSHandle<TaggedQueue> NewTaggedQueue(uint32_t length); 445 446 JSHandle<TaggedQueue> GetEmptyTaggedQueue() const; 447 448 JSHandle<JSSetIterator> NewJSSetIterator(const JSHandle<JSSet> &set, IterationKind kind); 449 JSHandle<JSSharedSetIterator> NewJSSetIterator(const JSHandle<JSSharedSet> &set, IterationKind kind); 450 451 JSHandle<JSRegExpIterator> NewJSRegExpIterator(const JSHandle<JSTaggedValue> &matcher, 452 const JSHandle<EcmaString> &inputStr, bool global, 453 bool fullUnicode); 454 455 JSHandle<JSMapIterator> NewJSMapIterator(const JSHandle<JSMap> &map, IterationKind kind); 456 457 JSHandle<JSSharedMapIterator> NewJSMapIterator(const JSHandle<JSSharedMap> &map, IterationKind kind); 458 459 JSHandle<JSArrayIterator> NewJSArrayIterator(const JSHandle<JSObject> &array, IterationKind kind); 460 JSHandle<JSSharedArrayIterator> NewJSSharedArrayIterator(const JSHandle<JSObject> &array, IterationKind kind); 461 462 JSHandle<CompletionRecord> NewCompletionRecord(CompletionRecordType type, JSHandle<JSTaggedValue> value); 463 464 JSHandle<GeneratorContext> NewGeneratorContext(); 465 466 JSHandle<JSPromiseReactionsFunction> CreateJSPromiseReactionsFunction(MethodIndex idx); 467 468 JSHandle<JSPromiseExecutorFunction> CreateJSPromiseExecutorFunction(); 469 470 JSHandle<JSAsyncModuleFulfilledFunction> CreateJSAsyncModuleFulfilledFunction(); 471 472 JSHandle<JSAsyncModuleRejectedFunction> CreateJSAsyncModuleRejectedFunction(); 473 474 JSHandle<JSPromiseAllResolveElementFunction> NewJSPromiseAllResolveElementFunction(); 475 476 JSHandle<JSPromiseAnyRejectElementFunction> NewJSPromiseAnyRejectElementFunction(); 477 478 JSHandle<JSPromiseAllSettledElementFunction> NewJSPromiseAllSettledResolveElementFunction(); 479 480 JSHandle<JSPromiseAllSettledElementFunction> NewJSPromiseAllSettledRejectElementFunction(); 481 482 JSHandle<JSPromiseFinallyFunction> NewJSPromiseThenFinallyFunction(); 483 484 JSHandle<JSPromiseFinallyFunction> NewJSPromiseCatchFinallyFunction(); 485 486 JSHandle<JSPromiseValueThunkOrThrowerFunction> NewJSPromiseValueThunkFunction(); 487 488 JSHandle<JSPromiseValueThunkOrThrowerFunction> NewJSPromiseThrowerFunction(); 489 490 JSHandle<JSAsyncGeneratorResNextRetProRstFtn> NewJSAsyGenResNextRetProRstFulfilledFtn(); 491 492 JSHandle<JSAsyncGeneratorResNextRetProRstFtn> NewJSAsyGenResNextRetProRstRejectedFtn(); 493 494 JSHandle<JSAsyncFromSyncIterUnwarpFunction> NewJSAsyncFromSyncIterUnwarpFunction(); 495 496 JSHandle<JSObject> CloneObjectLiteral(JSHandle<JSObject> object, const JSHandle<JSTaggedValue> &env, 497 bool canShareHClass = true); 498 JSHandle<JSObject> CloneObjectLiteral(JSHandle<JSObject> object); 499 JSHandle<JSArray> CloneArrayLiteral(JSHandle<JSArray> object); 500 JSHandle<JSFunction> CloneJSFunction(JSHandle<JSFunction> func); 501 JSHandle<JSFunction> CloneSFunction(JSHandle<JSFunction> func); 502 JSHandle<JSFunction> CloneClassCtor(JSHandle<JSFunction> ctor, const JSHandle<JSTaggedValue> &lexenv, 503 bool canShareHClass); 504 JSHandle<JSFunction> CreateJSFunctionFromTemplate(JSHandle<FunctionTemplate> funcTemp); 505 JSHandle<JSFunction> CreateSFunctionFromTemplate(JSHandle<FunctionTemplate> funcTemp); 506 507 void NewJSArrayBufferData(const JSHandle<JSArrayBuffer> &array, int32_t length); 508 void NewJSSendableArrayBufferData(const JSHandle<JSSendableArrayBuffer> &array, int32_t length); 509 JSHandle<JSSendableArrayBuffer> NewJSSendableArrayBuffer(int32_t length); 510 JSHandle<JSSendableArrayBuffer> NewJSSendableArrayBuffer(void *buffer, int32_t length, 511 const NativePointerCallback &deleter, void *data); 512 513 JSHandle<JSArrayBuffer> NewJSArrayBuffer(int32_t length); 514 515 JSHandle<JSArrayBuffer> NewJSArrayBuffer(void *buffer, int32_t length, const NativePointerCallback &deleter, 516 void *data, bool share = false); 517 518 JSHandle<JSDataView> NewJSDataView(JSHandle<JSArrayBuffer> buffer, uint32_t offset, uint32_t length); 519 520 void NewJSSharedArrayBufferData(const JSHandle<JSArrayBuffer> &array, int32_t length); 521 522 JSHandle<JSArrayBuffer> NewJSSharedArrayBuffer(int32_t length); 523 524 JSHandle<JSArrayBuffer> NewJSSharedArrayBuffer(void *buffer, int32_t length); 525 526 void NewJSRegExpByteCodeData(const JSHandle<JSRegExp> ®exp, void *buffer, size_t size); 527 528 template<typename T, typename S> 529 inline void NewJSIntlIcuData(const JSHandle<T> &obj, const S &icu, const NativePointerCallback &callback); 530 531 EcmaString *PUBLIC_API InternString(const JSHandle<JSTaggedValue> &key); 532 533 inline JSHandle<JSNativePointer> NewJSNativePointer(void *externalPointer, 534 const NativePointerCallback &callBack = nullptr, 535 void *data = nullptr, 536 bool nonMovable = false, 537 size_t nativeBindingsize = 0, 538 Concurrent isConcurrent = Concurrent::NO, 539 NativeFlag flag = NativeFlag::NO_DIV); 540 541 JSHandle<JSObject> NewOldSpaceObjLiteralByHClass(const JSHandle<JSHClass> &hclass); 542 JSHandle<JSHClass> SetLayoutInObjHClass(const JSHandle<TaggedArray> &properties, size_t length, 543 const JSHandle<JSHClass> &objClass); 544 static bool CanObjectLiteralHClassCache(size_t length); 545 JSHandle<JSHClass> CreateObjectLiteralRootHClass(size_t length); 546 JSHandle<JSHClass> GetObjectLiteralRootHClass(size_t length); 547 JSHandle<JSHClass> GetObjectLiteralHClass(const JSHandle<TaggedArray> &properties, size_t length); 548 // only use for creating Function.prototype and Function 549 JSHandle<JSFunction> NewJSFunctionByHClass(const JSHandle<Method> &method, const JSHandle<JSHClass> &clazz, 550 MemSpaceType type = MemSpaceType::SEMI_SPACE); 551 JSHandle<JSFunction> NewJSFunctionByHClass(const void *func, const JSHandle<JSHClass> &clazz, 552 FunctionKind kind = FunctionKind::NORMAL_FUNCTION); 553 JSHandle<JSFunction> NewJSFunctionByHClassWithoutAccessor(const void *func, 554 const JSHandle<JSHClass> &clazz, FunctionKind kind = FunctionKind::NORMAL_FUNCTION); 555 JSHandle<Method> NewMethod(const MethodLiteral *methodLiteral, MemSpaceType spaceType = OLD_SPACE); 556 557 JSHandle<Method> NewMethod(const JSPandaFile *jsPandaFile, MethodLiteral *methodLiteral, 558 JSHandle<ConstantPool> constpool, uint32_t entryIndex, 559 bool needSetAotFlag, bool *canFastCall = nullptr); 560 561 // used for creating jsobject by constructor 562 JSHandle<JSObject> PUBLIC_API NewJSObjectByConstructor(const JSHandle<JSFunction> &constructor, 563 const JSHandle<JSTaggedValue> &newTarget); 564 JSHandle<JSObject> NewJSObjectByConstructor(JSHandle<GlobalEnv> env, 565 const JSHandle<JSFunction> &constructor, uint32_t inlinedProps); 566 JSHandle<JSObject> NewJSObjectByConstructor(const JSHandle<JSFunction> &constructor, 567 uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); 568 void InitializeJSObject(const JSHandle<JSObject> &obj, const JSHandle<JSHClass> &jshclass); 569 570 JSHandle<JSObject> NewJSObjectWithInit(const JSHandle<JSHClass> &jshclass); 571 uintptr_t NewSpaceBySnapshotAllocator(size_t size); 572 TaggedObject *NewMachineCodeObject(size_t length, MachineCodeDesc &desc); 573 JSHandle<MachineCode> SetMachineCodeObjectData(TaggedObject *obj, size_t length, 574 const MachineCodeDesc &desc, JSHandle<Method> &method); 575 JSHandle<MachineCode> NewMachineCodeObject(size_t length, const MachineCodeDesc &desc, JSHandle<Method> &method); 576 JSHandle<ClassInfoExtractor> NewClassInfoExtractor(JSHandle<JSTaggedValue> method); 577 JSHandle<ClassLiteral> NewClassLiteral(); 578 579 // ----------------------------------- new string ---------------------------------------- 580 JSHandle<EcmaString> PUBLIC_API NewFromASCII(std::string_view data); 581 JSHandle<EcmaString> NewFromUtf8WithoutStringTable(std::string_view data); 582 JSHandle<EcmaString> PUBLIC_API NewFromUtf8(std::string_view data); 583 JSHandle<EcmaString> NewFromUtf8(std::string_view data, bool canBeCompress); 584 JSHandle<EcmaString> NewFromUtf8ReadOnly(std::string_view data); 585 JSHandle<EcmaString> NewFromASCIISkippingStringTable(std::string_view data); 586 JSHandle<EcmaString> NewFromUtf16WithoutStringTable(std::u16string_view data); 587 JSHandle<EcmaString> NewFromUtf16(std::u16string_view data); 588 589 JSHandle<EcmaString> PUBLIC_API NewFromStdString(const std::string &data); 590 591 JSHandle<EcmaString> NewFromUtf8WithoutStringTable(const uint8_t *utf8Data, uint32_t utf8Len); 592 JSHandle<EcmaString> NewFromUtf8(const uint8_t *utf8Data, uint32_t utf8Len); 593 594 JSHandle<EcmaString> NewFromUtf16WithoutStringTable(const uint16_t *utf16Data, uint32_t utf16Len); 595 JSHandle<EcmaString> PUBLIC_API NewFromUtf16(const uint16_t *utf16Data, uint32_t utf16Len); 596 JSHandle<EcmaString> NewFromUtf16Compress(const uint16_t *utf16Data, uint32_t utf16Len); 597 JSHandle<EcmaString> NewFromUtf16NotCompress(const uint16_t *utf16Data, uint32_t utf16Len); 598 599 JSHandle<EcmaString> NewFromUtf8Literal(const uint8_t *utf8Data, uint32_t utf8Len); 600 JSHandle<EcmaString> PUBLIC_API NewFromUtf8LiteralCompress(const uint8_t *utf8Data, uint32_t utf8Len); 601 JSHandle<EcmaString> PUBLIC_API NewFromUtf8LiteralCompressSubString(const JSHandle<EcmaString> &string, 602 uint32_t offset, uint32_t utf8Len); 603 JSHandle<EcmaString> PUBLIC_API NewCompressedUtf8(const uint8_t *utf8Data, uint32_t utf8Len); 604 JSHandle<EcmaString> PUBLIC_API NewCompressedUtf8SubString(const JSHandle<EcmaString> &string, 605 uint32_t offset, uint32_t utf8Len); 606 JSHandle<EcmaString> NewFromUtf16Literal(const uint16_t *utf16Data, uint32_t utf16Len); 607 JSHandle<EcmaString> NewFromUtf16LiteralCompress(const uint16_t *utf16Data, uint32_t utf16Len); 608 JSHandle<EcmaString> PUBLIC_API NewFromUtf16LiteralNotCompress(const uint16_t *utf16Data, uint32_t utf16Len); 609 610 inline EcmaString *AllocLineStringObject(size_t size); 611 inline EcmaString *AllocLineStringObjectNoGC(size_t size); 612 inline EcmaString *AllocOldSpaceLineStringObject(size_t size); 613 inline EcmaString *AllocReadOnlyLineStringObject(size_t size); 614 inline EcmaString *AllocNonMovableLineStringObject(size_t size); 615 inline EcmaString *AllocSlicedStringObject(MemSpaceType type); 616 inline EcmaString *AllocConstantStringObject(MemSpaceType type); 617 inline EcmaString *AllocTreeStringObject(); 618 619 JSHandle<EcmaString> ConcatFromString(const JSHandle<EcmaString> &firstString, 620 const JSHandle<EcmaString> &secondString); 621 622 // used for creating Function 623 JSHandle<JSObject> PUBLIC_API NewJSObject(const JSHandle<JSHClass> &jshclass); 624 625 // used for creating jshclass in Builtins, Function, Class_Linker 626 JSHandle<JSHClass> NewEcmaHClass(uint32_t size, JSType type, const JSHandle<JSTaggedValue> &prototype); 627 JSHandle<JSHClass> NewEcmaHClass(uint32_t size, uint32_t inlinedProps, JSType type, 628 const JSHandle<JSTaggedValue> &prototype); 629 630 // used for creating jshclass in Builtins, Function, Class_Linker 631 JSHandle<JSHClass> PUBLIC_API NewEcmaHClass(uint32_t size, JSType type, 632 uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); 633 634 JSHandle<JSHClass> PUBLIC_API NewEcmaHClass(uint32_t size, uint32_t inlinedProps, JSType type, 635 const JSHandle<JSTaggedValue> &prototype, const JSHandle<JSTaggedValue> &layout); 636 637 // It is used to provide iterators for non ECMA standard jsapi containers. 638 JSHandle<JSAPIPlainArray> NewJSAPIPlainArray(uint32_t capacity); 639 JSHandle<JSAPIPlainArrayIterator> NewJSAPIPlainArrayIterator(const JSHandle<JSAPIPlainArray> &plainarray, 640 IterationKind kind); 641 JSHandle<JSAPIArrayList> NewJSAPIArrayList(uint32_t capacity); 642 643 JSHandle<JSAPILightWeightMapIterator> NewJSAPILightWeightMapIterator(const JSHandle<JSAPILightWeightMap> &obj, 644 IterationKind kind); 645 JSHandle<JSAPILightWeightSetIterator> NewJSAPILightWeightSetIterator(const JSHandle<JSAPILightWeightSet> &obj, 646 IterationKind kind); 647 JSHandle<TaggedArray> CopyQueue(const JSHandle<TaggedArray> &old, uint32_t newLength, 648 uint32_t front, uint32_t tail); 649 JSHandle<JSAPIQueueIterator> NewJSAPIQueueIterator(const JSHandle<JSAPIQueue> &queue); 650 JSHandle<TaggedArray> CopyDeque(const JSHandle<TaggedArray> &old, uint32_t newLength, uint32_t oldLength, 651 uint32_t first, uint32_t last); 652 JSHandle<JSAPIDequeIterator> NewJSAPIDequeIterator(const JSHandle<JSAPIDeque> &deque); 653 JSHandle<JSAPIArrayListIterator> NewJSAPIArrayListIterator(const JSHandle<JSAPIArrayList> &arrayList); 654 JSHandle<JSAPIList> NewJSAPIList(); 655 JSHandle<JSAPILinkedList> NewJSAPILinkedList(); 656 JSHandle<JSAPILinkedListIterator> NewJSAPILinkedListIterator(const JSHandle<JSAPILinkedList> &linkedList); 657 JSHandle<JSAPIListIterator> NewJSAPIListIterator(const JSHandle<JSAPIList> &list); 658 JSHandle<JSAPITreeMapIterator> NewJSAPITreeMapIterator(const JSHandle<JSAPITreeMap> &map, IterationKind kind); 659 JSHandle<JSAPITreeSetIterator> NewJSAPITreeSetIterator(const JSHandle<JSAPITreeSet> &set, IterationKind kind); 660 JSHandle<JSAPIStackIterator> NewJSAPIStackIterator(const JSHandle<JSAPIStack> &stack); 661 JSHandle<JSAPIVector> NewJSAPIVector(uint32_t capacity); 662 JSHandle<JSAPIVectorIterator> NewJSAPIVectorIterator(const JSHandle<JSAPIVector> &vector); 663 JSHandle<JSAPIBitVector> NewJSAPIBitVector(uint32_t capacity); 664 JSHandle<JSAPIBitVectorIterator> NewJSAPIBitVectorIterator(const JSHandle<JSAPIBitVector> &bitVector); 665 JSHandle<JSAPIHashMapIterator> NewJSAPIHashMapIterator(const JSHandle<JSAPIHashMap> &hashMap, IterationKind kind); 666 JSHandle<JSAPIHashSetIterator> NewJSAPIHashSetIterator(const JSHandle<JSAPIHashSet> &hashSet, IterationKind kind); 667 JSHandle<TaggedHashArray> NewTaggedHashArray(uint32_t length); 668 JSHandle<LinkedNode> NewLinkedNode(int hash, const JSHandle<JSTaggedValue> &key, 669 const JSHandle<JSTaggedValue> &value, 670 const JSHandle<LinkedNode> &next); 671 JSHandle<RBTreeNode> NewTreeNode(int hash, const JSHandle<JSTaggedValue> &key, 672 const JSHandle<JSTaggedValue> &value); 673 // --------------------------------------module-------------------------------------------- 674 JSHandle<ModuleNamespace> NewModuleNamespace(); 675 JSHandle<NativeModuleFailureInfo> NewNativeModuleFailureInfo(); 676 JSHandle<ImportEntry> NewImportEntry(); 677 JSHandle<ImportEntry> NewImportEntry(const JSHandle<JSTaggedValue> &moduleRequest, 678 const JSHandle<JSTaggedValue> &importName, 679 const JSHandle<JSTaggedValue> &localName, 680 SharedTypes sharedTypes); 681 JSHandle<LocalExportEntry> NewLocalExportEntry(); 682 JSHandle<LocalExportEntry> NewLocalExportEntry( 683 const JSHandle<JSTaggedValue> &exportName, const JSHandle<JSTaggedValue> &localName, 684 const uint32_t index, SharedTypes sharedTypes); 685 JSHandle<IndirectExportEntry> NewIndirectExportEntry(); 686 JSHandle<IndirectExportEntry> NewIndirectExportEntry(const JSHandle<JSTaggedValue> &exportName, 687 const JSHandle<JSTaggedValue> &moduleRequest, 688 const JSHandle<JSTaggedValue> &importName, 689 SharedTypes sharedTypes); 690 JSHandle<StarExportEntry> NewStarExportEntry(); 691 JSHandle<StarExportEntry> NewStarExportEntry(const JSHandle<JSTaggedValue> &moduleRequest, 692 SharedTypes sharedTypes); 693 JSHandle<SourceTextModule> NewSourceTextModule(); 694 JSHandle<ResolvedBinding> NewResolvedBindingRecord(); 695 JSHandle<ResolvedBinding> NewResolvedBindingRecord(const JSHandle<SourceTextModule> &module, 696 const JSHandle<JSTaggedValue> &bindingName); 697 JSHandle<ResolvedIndexBinding> NewResolvedIndexBindingRecord(); 698 JSHandle<ResolvedIndexBinding> NewResolvedIndexBindingRecord( 699 const JSHandle<SourceTextModule> &module, int32_t index); 700 701 JSHandle<CellRecord> NewCellRecord(); 702 JSHandle<JSFunction> NewJSAsyncGeneratorFunction(const JSHandle<Method> &method); 703 // --------------------------------------require-------------------------------------------- 704 JSHandle<CjsModule> NewCjsModule(); 705 JSHandle<CjsExports> NewCjsExports(); 706 JSHandle<CjsRequire> NewCjsRequire(); 707 708 JSHandle<JSHClass> CreateIteratorResultInstanceClass(const JSHandle<GlobalEnv> &env); 709 710 // --------------------------------------old space object-------------------------------------------- 711 JSHandle<JSObject> NewOldSpaceJSObject(const JSHandle<JSHClass> &jshclass); 712 TaggedObject *NewOldSpaceObject(const JSHandle<JSHClass> &hclass); 713 JSHandle<TaggedArray> NewOldSpaceTaggedArray(uint32_t length, JSTaggedValue initVal = JSTaggedValue::Hole()); 714 715 // ---------------------------------New objects used internally-------------------------------------- 716 JSHandle<JSArray> NewJSStableArrayWithElements(const JSHandle<TaggedArray> &elements); 717 718 // ---------------------------------------Used by AOT------------------------------------------------ 719 JSHandle<AOTLiteralInfo> NewAOTLiteralInfo(uint32_t length, JSTaggedValue initVal = JSTaggedValue::Hole()); 720 JSHandle<ExtraProfileTypeInfo> NewExtraProfileTypeInfo(); 721 JSHandle<ProfileTypeInfoCell> NewProfileTypeInfoCell(const JSHandle<JSTaggedValue> &value); 722 723 JSHandle<FunctionTemplate> NewFunctionTemplate( 724 const JSHandle<Method> &method, const JSHandle<JSTaggedValue> &module, int32_t length); 725 JSHandle<VTable> NewVTable(uint32_t length, JSTaggedValue initVal = JSTaggedValue::Hole()); 726 JSHandle<JSHClass> NewEcmaHClass(JSHClass *hclass, uint32_t size, JSType type, 727 uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); 728 729 // napi interface to create object with initial inline properties 730 JSHandle<JSTaggedValue> CreateJSObjectWithProperties(size_t propertyCount, const Local<JSValueRef> *keys, 731 const PropertyDescriptor *attributes); 732 JSHandle<JSTaggedValue> CreateJSObjectWithNamedProperties(size_t propertyCount, const char **keys, 733 const Local<JSValueRef> *values); 734 // Fill the given free memory range with special zam value. 735 void FillFreeMemoryRange(uintptr_t start, uintptr_t end); 736 737 // -----------------------------------shared object----------------------------------------- 738 JSHandle<JSObject> PUBLIC_API NewSharedOldSpaceJSObject(const JSHandle<JSHClass> &jshclass); 739 740 JSHandle<JSObject> PUBLIC_API NewSharedOldSpaceJSObjectWithInit(const JSHandle<JSHClass> &jshclass); 741 742 TaggedObject *NewSharedOldSpaceObject(const JSHandle<JSHClass> &hclass); 743 744 JSHandle<JSTaggedValue> CreateSObjectWithProperties(std::vector<PropertyDescriptor> &descs); 745 746 JSHandle<JSHClass> PUBLIC_API NewSEcmaHClass(uint32_t size, JSType type, uint32_t inlinedProps); 747 748 JSHandle<JSHClass> PUBLIC_API NewSEcmaHClass(JSHClass *hclass, uint32_t size, JSType type, 749 uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); 750 751 JSHandle<JSHClass> PUBLIC_API NewSEcmaHClass(uint32_t size, uint32_t inlinedProps, JSType type, 752 const JSHandle<JSTaggedValue> &prototype, const JSHandle<JSTaggedValue> &layout); 753 754 JSHandle<JSHClass> PUBLIC_API NewSEcmaHClassDictMode(uint32_t size, uint32_t inlinedProps, JSType type, 755 const JSHandle<JSTaggedValue> &prototype); 756 757 JSHandle<JSHClass> NewSEcmaHClassClass(JSHClass *hclass, uint32_t size, JSType type); 758 759 JSHandle<JSHClass> InitSClassClass(); 760 761 JSHandle<JSHClass> NewSEcmaReadOnlyHClass(JSHClass *hclass, uint32_t size, JSType type, 762 uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); 763 764 JSHandle<TaggedArray> SharedEmptyArray() const; 765 766 JSHandle<TaggedArray> CopySArray(const JSHandle<TaggedArray> &old, uint32_t oldLength, uint32_t newLength, 767 JSTaggedValue initVal = JSTaggedValue::Hole(), 768 ElementsKind kind = ElementsKind::GENERIC); 769 770 JSHandle<TaggedArray> ExtendSArray(const JSHandle<TaggedArray> &old, uint32_t length, 771 JSTaggedValue initVal, [[maybe_unused]] ElementsKind kind); 772 773 JSHandle<Method> NewSMethodForNativeFunction(const void *func, FunctionKind kind = FunctionKind::NORMAL_FUNCTION, 774 kungfu::BuiltinsStubCSigns::ID builtinId = 775 kungfu::BuiltinsStubCSigns::INVALID, 776 MemSpaceType spaceType = SHARED_OLD_SPACE); 777 778 JSHandle<JSFunction> NewSFunctionByHClass(const JSHandle<Method> &methodHandle, 779 const JSHandle<JSHClass> &hclass); 780 JSHandle<JSFunction> NewSFunctionByHClass(const void *func, const JSHandle<JSHClass> &hclass, 781 FunctionKind kind, 782 kungfu::BuiltinsStubCSigns::ID builtinId = kungfu::BuiltinsStubCSigns::INVALID, 783 MemSpaceType spaceType = SHARED_OLD_SPACE); 784 785 JSHandle<JSFunction> NewSFunctionWithAccessor( 786 const void *func, 787 const JSHandle<JSHClass> &hclass, 788 FunctionKind kind, 789 kungfu::BuiltinsStubCSigns::ID builtinId = kungfu::BuiltinsStubCSigns::INVALID, 790 MemSpaceType spaceType = SHARED_OLD_SPACE); 791 792 JSHandle<Method> NewSMethod(const MethodLiteral *methodLiteral, MemSpaceType methodSpaceType = SHARED_OLD_SPACE); 793 794 JSHandle<Method> PUBLIC_API NewSMethod(const JSPandaFile *jsPandaFile, 795 MethodLiteral *methodLiteral, 796 JSHandle<ConstantPool> constpool, 797 uint32_t entryIndex, 798 bool needSetAotFlag, 799 bool *canFastCall = nullptr); 800 801 JSHandle<ConstantPool> NewSConstantPool(uint32_t capacity); 802 803 JSHandle<AOTLiteralInfo> NewSAOTLiteralInfo(uint32_t length, JSTaggedValue initVal = JSTaggedValue::Hole()); 804 805 JSHandle<COWTaggedArray> NewSCOWTaggedArray(uint32_t length, JSTaggedValue initVal = JSTaggedValue::Hole()); 806 807 JSHandle<ClassLiteral> NewSClassLiteral(); 808 809 JSHandle<ClassInfoExtractor> NewSClassInfoExtractor(JSHandle<JSTaggedValue> method); 810 811 JSHandle<TaggedArray> NewSOldSpaceTaggedArray(uint32_t length, JSTaggedValue initVal = JSTaggedValue::Hole()); 812 813 JSHandle<TaggedArray> PUBLIC_API NewSTaggedArray(uint32_t length, 814 JSTaggedValue initVal = JSTaggedValue::Hole(), 815 MemSpaceType spaceType = SHARED_OLD_SPACE); 816 817 JSHandle<AccessorData> NewSAccessorData(); 818 819 JSHandle<SourceTextModule> NewSSourceTextModule(); 820 821 JSHandle<ModuleNamespace> NewSModuleNamespace(); 822 823 JSHandle<ImportEntry> NewSImportEntry(const JSHandle<JSTaggedValue> &moduleRequest, 824 const JSHandle<JSTaggedValue> &importName, 825 const JSHandle<JSTaggedValue> &localName); 826 827 JSHandle<LocalExportEntry> NewSLocalExportEntry(const JSHandle<JSTaggedValue> &exportName, 828 const JSHandle<JSTaggedValue> &localName, const uint32_t index); 829 830 JSHandle<IndirectExportEntry> NewSIndirectExportEntry(const JSHandle<JSTaggedValue> &exportName, 831 const JSHandle<JSTaggedValue> &moduleRequest, 832 const JSHandle<JSTaggedValue> &importName); 833 834 JSHandle<StarExportEntry> NewSStarExportEntry(const JSHandle<JSTaggedValue> &moduleRequest); 835 836 JSHandle<ResolvedIndexBinding> NewSResolvedIndexBindingRecord(); 837 838 JSHandle<ResolvedIndexBinding> NewSResolvedIndexBindingRecord(const JSHandle<SourceTextModule> &module, 839 int32_t index); 840 841 JSHandle<ResolvedBinding> NewSResolvedBindingRecord(); 842 843 JSHandle<ResolvedBinding> NewSResolvedBindingRecord(const JSHandle<SourceTextModule> &module, 844 const JSHandle<JSTaggedValue> &bindingName); 845 846 JSHandle<ResolvedRecordIndexBinding> NewSResolvedRecordIndexBindingRecord(); 847 848 JSHandle<ResolvedRecordIndexBinding> NewSResolvedRecordIndexBindingRecord( 849 const JSHandle<EcmaString> &moduleRecord, const JSHandle<EcmaString> &abcFileName, int32_t index); 850 851 JSHandle<ResolvedRecordBinding> NewSResolvedRecordBindingRecord(); 852 853 JSHandle<ResolvedRecordBinding> NewSResolvedRecordBindingRecord( 854 const JSHandle<EcmaString> &moduleRecord, const JSHandle<JSTaggedValue> &bindingName); 855 856 JSHandle<LayoutInfo> CopyAndReSortSLayoutInfo(const JSHandle<LayoutInfo> &old, int end, int capacity); 857 858 JSHandle<LayoutInfo> PUBLIC_API CreateSLayoutInfo(uint32_t properties); 859 860 JSHandle<LayoutInfo> PUBLIC_API NewSEmptyLayoutInfo(); 861 862 JSHandle<ProfileTypeInfoCell> NewSEmptyProfileTypeInfoCell(); 863 864 JSHandle<FunctionTemplate> NewSFunctionTemplate( 865 const JSHandle<Method> &method, const JSHandle<JSTaggedValue> &module, int32_t length); 866 867 JSHandle<TaggedArray> NewSEmptyArray(); // only used for EcmaVM. 868 869 JSHandle<MutantTaggedArray> NewSEmptyMutantArray(); 870 871 JSHandle<TaggedArray> PUBLIC_API NewSDictionaryArray(uint32_t length); 872 873 JSHandle<TaggedArray> NewSTaggedArrayWithoutInit(uint32_t length, 874 MemSpaceType spaceType = MemSpaceType::SHARED_OLD_SPACE); 875 876 JSHandle<JSHClass> CreateSFunctionClass(uint32_t size, JSType type, 877 const JSHandle<JSTaggedValue> &prototype, 878 bool isAccessor = true, bool setProto = false); 879 880 JSHandle<JSNativePointer> NewSJSNativePointer(void *externalPointer, 881 const NativePointerCallback &callBack, 882 void *data = nullptr, 883 bool nonMovable = false, 884 size_t nativeBindingsize = 0, 885 NativeFlag flag = NativeFlag::NO_DIV); 886 887 JSHandle<JSNativePointer> NewSReadOnlyJSNativePointer(void *externalPointer); 888 889 JSHandle<AccessorData> NewSInternalAccessor(void *setter, void *getter); 890 891 JSHandle<JSSymbol> NewSWellKnownSymbol(const JSHandle<JSTaggedValue> &name); 892 JSHandle<JSSymbol> NewSEmptySymbol(); 893 JSHandle<JSSymbol> NewSWellKnownSymbolWithChar(std::string_view description); 894 JSHandle<JSSymbol> NewSPublicSymbolWithChar(std::string_view description); 895 JSHandle<JSSymbol> NewSPublicSymbol(const JSHandle<JSTaggedValue> &name); 896 JSHandle<SendableEnv> NewSendableEnv(int numSlots); 897 JSHandle<JSFunction> NewJSSendableFunction(const JSHandle<Method> &methodHandle); 898 899 void SetCodeEntryToFunctionFromMethod(const JSHandle<JSFunction> &func, const JSHandle<Method> &mothed); 900 901 private: 902 friend class GlobalEnv; 903 friend class GlobalEnvConstants; 904 friend class EcmaString; 905 friend class SnapshotProcessor; 906 friend class SingleCharTable; 907 void InitObjectFields(const TaggedObject *object); 908 909 JSThread *thread_ {nullptr}; 910 bool isTriggerGc_ {false}; 911 bool triggerSemiGC_ {false}; 912 913 EcmaVM *vm_ {nullptr}; 914 Heap *heap_ {nullptr}; 915 SharedHeap *sHeap_ {nullptr}; 916 917 static constexpr uint32_t LENGTH_THRESHOLD = 50; 918 static constexpr int MAX_LITERAL_HCLASS_CACHE_SIZE = 63; 919 920 NO_COPY_SEMANTIC(ObjectFactory); 921 NO_MOVE_SEMANTIC(ObjectFactory); 922 923 void NewObjectHook() const; 924 void NewSObjectHook() const; 925 // used for creating jshclass in GlobalEnv, EcmaVM 926 JSHandle<JSHClass> NewEcmaHClassClass(JSHClass *hclass, uint32_t size, JSType type); 927 928 JSHandle<JSHClass> NewEcmaReadOnlyHClass(JSHClass *hclass, uint32_t size, JSType type, 929 uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); 930 JSHandle<JSHClass> InitClassClass(); 931 932 // used to create nonmovable js_object 933 JSHandle<JSObject> NewNonMovableJSObject(const JSHandle<JSHClass> &jshclass); 934 935 // used to create nonmovable utf8 string at global constants 936 JSHandle<EcmaString> NewFromASCIINonMovable(std::string_view data); 937 // used to create read only utf8 string at global constants 938 JSHandle<EcmaString> NewFromASCIIReadOnly(std::string_view data); 939 940 // used for creating Function 941 JSHandle<JSFunction> NewJSFunction(const JSHandle<GlobalEnv> &env, const JSHandle<JSHClass> &hclass); 942 JSHandle<JSHClass> CreateObjectClass(const JSHandle<TaggedArray> &keys, const JSHandle<TaggedArray> &values); 943 JSHandle<JSHClass> CreateObjectClass(const JSHandle<TaggedArray> &properties, size_t length); 944 JSHandle<JSHClass> CreateFunctionClass(FunctionKind kind, uint32_t size, JSType type, 945 const JSHandle<JSTaggedValue> &prototype); 946 JSHandle<JSHClass> CreateBoundFunctionClass(); 947 JSHandle<JSHClass> CreateDefaultClassPrototypeHClass(JSHClass *hclass); 948 JSHandle<JSHClass> CreateDefaultClassConstructorHClass(JSHClass *hclass); 949 950 // used for creating ref.prototype in buildins, such as Number.prototype 951 JSHandle<JSPrimitiveRef> NewJSPrimitiveRef(const JSHandle<JSHClass> &hclass, 952 const JSHandle<JSTaggedValue> &object); 953 954 JSHandle<EcmaString> GetStringFromStringTable(const uint8_t *utf8Data, uint32_t utf8Len, bool canBeCompress) const; 955 JSHandle<EcmaString> GetCompressedSubStringFromStringTable(const JSHandle<EcmaString> &string, uint32_t offset, 956 uint32_t utf8Len) const; 957 JSHandle<EcmaString> GetStringFromStringTableNonMovable(const uint8_t *utf8Data, uint32_t utf8Len) const; 958 JSHandle<EcmaString> GetStringFromStringTableReadOnly(const uint8_t *utf8Data, uint32_t utf8Len, 959 bool canBeCompress = true) const; 960 // For MUtf-8 string data 961 EcmaString *PUBLIC_API GetRawStringFromStringTable(StringData sd, 962 MemSpaceType type = MemSpaceType::SHARED_OLD_SPACE, 963 bool isConstantString = false, uint32_t idOffset = 0) const; 964 EcmaString *GetRawStringFromStringTableWithoutJSHandle(StringData sd, 965 MemSpaceType type = MemSpaceType::SHARED_OLD_SPACE, 966 bool isConstantString = false, 967 uint32_t idOffset = 0) const; 968 969 JSHandle<EcmaString> GetStringFromStringTable(const uint16_t *utf16Data, uint32_t utf16Len, 970 bool canBeCompress) const; 971 972 JSHandle<EcmaString> GetStringFromStringTable(EcmaString *string) const; 973 974 JSHandle<EcmaString> GetStringFromStringTable(const JSHandle<EcmaString> &firstString, 975 const JSHandle<EcmaString> &secondString); 976 977 JSHandle<JSHClass> CreateJSArguments(const JSHandle<GlobalEnv> &env); 978 JSHandle<JSHClass> CreateJSArrayInstanceClass(JSHandle<JSTaggedValue> proto, 979 uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); 980 JSHandle<JSHClass> CreateJSRegExpInstanceClass(JSHandle<JSTaggedValue> proto); 981 982 inline TaggedObject *AllocObjectWithSpaceType(size_t size, JSHClass *cls, MemSpaceType type); 983 JSHandle<TaggedArray> NewTaggedArrayWithoutInit(uint32_t length, MemSpaceType spaceType); 984 985 // For object with many properties, directly create new HClass instead of searching on transitions 986 JSHandle<JSTaggedValue> CreateLargeJSObjectWithProperties(size_t propertyCount, 987 const Local<JSValueRef> *keys, 988 const PropertyDescriptor *descs); 989 JSHandle<JSTaggedValue> CreateLargeJSObjectWithNamedProperties(size_t propertyCount, const char **keys, 990 const Local<JSValueRef> *values); 991 // For object with numerous properties, directly create it in dictionary mode 992 JSHandle<JSTaggedValue> CreateDictionaryJSObjectWithProperties(size_t propertyCount, 993 const Local<JSValueRef> *keys, 994 const PropertyDescriptor *descs); 995 JSHandle<JSTaggedValue> CreateDictionaryJSObjectWithNamedProperties(size_t propertyCount, const char **keys, 996 const Local<JSValueRef> *values); 997 998 JSHandle<MutantTaggedArray> NewMutantTaggedArrayWithoutInit(uint32_t length, MemSpaceType spaceType); 999 1000 friend class Builtins; // create builtins object need hclass 1001 friend class JSFunction; // create prototype_or_hclass need hclass 1002 friend class JSHClass; // HC transition need hclass 1003 friend class EcmaVM; // hold the factory instance 1004 friend class JsVerificationTest; 1005 friend class PandaFileTranslator; 1006 friend class LiteralDataExtractor; 1007 friend class RuntimeStubs; 1008 friend class ClassInfoExtractor; 1009 friend class ModuleDataExtractor; 1010 friend class ModuleDataAccessor; 1011 friend class ConstantPool; 1012 friend class EcmaContext; 1013 friend class kungfu::TSHClassGenerator; 1014 friend class panda::FunctionRef; 1015 }; 1016 1017 class ClassLinkerFactory { 1018 private: 1019 friend class GlobalEnv; // root class in class_linker need hclass 1020 friend class EcmaVM; // root class in class_linker need hclass 1021 }; 1022 } // namespace panda::ecmascript 1023 #endif // ECMASCRIPT_OBJECT_FACTORY_H 1024