/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ECMASCRIPT_OBJECT_FACTORY_H #define ECMASCRIPT_OBJECT_FACTORY_H #include "ecmascript/base/error_type.h" #include "ecmascript/ecma_string.h" #include "ecmascript/js_function_kind.h" #include "ecmascript/js_handle.h" #include "ecmascript/js_hclass.h" #include "ecmascript/js_native_pointer.h" #include "ecmascript/js_tagged_value.h" #include "ecmascript/mem/heap_region_allocator.h" #include "ecmascript/mem/machine_code.h" #include "ecmascript/mem/native_area_allocator.h" #include "ecmascript/mem/space.h" #include "ecmascript/tagged_array.h" #include "ecmascript/byte_array.h" namespace panda::ecmascript { struct MethodLiteral; class Method; class JSObject; class JSArray; class JSAPIPlainArray; class JSSymbol; class JSFunctionBase; class JSFunction; class JSBoundFunction; class JSProxyRevocFunction; class JSAsyncAwaitStatusFunction; class JSPrimitiveRef; class GlobalEnv; class GlobalEnvConstants; class AccessorData; class JSGlobalObject; class LexicalEnv; class JSDate; class JSProxy; class JSRealm; class JSArguments; class TaggedQueue; class JSForInIterator; class JSSet; class JSMap; class JSRegExp; class JSSetIterator; class JSRegExpIterator; class JSMapIterator; class JSArrayIterator; class JSAPIPlainArrayIterator; class JSStringIterator; class JSGeneratorObject; class CompletionRecord; class GeneratorContext; class JSArrayBuffer; class JSDataView; class JSPromise; class JSPromiseReactionsFunction; class JSPromiseExecutorFunction; class JSPromiseAllResolveElementFunction; class JSAsyncGeneratorResNextRetProRstFtn; class JSPromiseAnyRejectElementFunction; class JSPromiseAllSettledElementFunction; class JSPromiseFinallyFunction; class JSPromiseValueThunkOrThrowerFunction; class PromiseReaction; class PromiseCapability; class PromiseIteratorRecord; class JSAsyncFuncObject; class JSAsyncFunction; class JSAsyncFromSyncIterUnwarpFunction; class PromiseRecord; class JSLocale; class ResolvingFunctionsRecord; class EcmaVM; class Heap; class ConstantPool; class Program; class LayoutInfo; class JSIntlBoundFunction; class FreeObject; class JSNativePointer; class TSModuleTable; class TSTypeTable; class TSObjLayoutInfo; class TSType; class TSObjectType; class TSClassType; class TSUnionType; class TSInterfaceType; class TSClassInstanceType; class TSFunctionType; class TSArrayType; class TSIteratorInstanceType; class TSNamespaceType; class JSAPIArrayList; class JSAPIArrayListIterator; class JSAPIDeque; class JSAPIDequeIterator; class TaggedHashArray; class LinkedNode; class RBTreeNode; class JSAPIHashMap; class JSAPIHashSet; class JSAPIHashMapIterator; class JSAPIHashSetIterator; class JSAPILightWeightMap; class JSAPILightWeightMapIterator; class JSAPILightWeightSet; class JSAPILightWeightSetIterator; class JSAPIQueue; class JSAPIQueueIterator; class JSAPIStack; class JSAPIStackIterator; class JSAPITreeSet; class JSAPITreeMap; class JSAPITreeSetIterator; class JSAPITreeMapIterator; class JSAPIVector; class JSAPIVectorIterator; class JSAPILinkedList; class JSAPIList; class JSAPILinkedListIterator; class JSAPIListIterator; class ModuleNamespace; class ImportEntry; class LocalExportEntry; class IndirectExportEntry; class StarExportEntry; class SourceTextModule; class CjsModule; class CjsRequire; class CjsExports; class ResolvedBinding; class ResolvedIndexBinding; class BigInt; class AsyncGeneratorRequest; class AsyncIteratorRecord; class JSAsyncGeneratorFunction; class JSAsyncGeneratorObject; class CellRecord; class ClassLiteral; namespace job { class MicroJobQueue; class PendingJob; } // namespace job class TransitionHandler; class PrototypeHandler; class TransWithProtoHandler; class StoreTSHandler; class PropertyBox; class ProtoChangeMarker; class ProtoChangeDetails; class ProfileTypeInfo; class MachineCode; class ClassInfoExtractor; class AOTLiteralInfo; class VTable; namespace kungfu { class TSHClassGenerator; } // namespace kungfu enum class CompletionRecordType : uint8_t; enum class PrimitiveType : uint8_t; enum class IterationKind : uint8_t; enum class MethodIndex : uint8_t; using ErrorType = base::ErrorType; using base::ErrorType; using DeleteEntryPoint = void (*)(void *, void *); enum class RemoveSlots { YES, NO }; enum class GrowMode { KEEP, GROW }; class ObjectFactory { public: ObjectFactory(JSThread *thread, Heap *heap); ~ObjectFactory() = default; JSHandle NewMethodForNativeFunction(const void *func, FunctionKind kind = FunctionKind::NORMAL_FUNCTION, kungfu::BuiltinsStubCSigns::ID builtinId = kungfu::BuiltinsStubCSigns::INVALID, MemSpaceType spaceType = OLD_SPACE); JSHandle NewProfileTypeInfo(uint32_t length); JSHandle NewConstantPool(uint32_t capacity); JSHandle NewProgram(); JSHandle GetJSError(const ErrorType &errorType, const char *data = nullptr, bool needCheckStack = true); JSHandle NewJSError(const ErrorType &errorType, const JSHandle &message, bool needCheckStack = true); JSHandle NewJSAggregateError(); JSHandle NewTransitionHandler(); JSHandle NewPrototypeHandler(); JSHandle NewTransWithProtoHandler(); JSHandle NewStoreTSHandler(); JSHandle NewEmptyJSObject(); // use for others create, prototype is Function.prototype // use for native function JSHandle NewJSFunction(const JSHandle &env, const void *nativeFunc = nullptr, FunctionKind kind = FunctionKind::NORMAL_FUNCTION, kungfu::BuiltinsStubCSigns::ID builtinId = kungfu::BuiltinsStubCSigns::INVALID, MemSpaceType spaceType = OLD_SPACE); // use for method JSHandle NewJSFunction(const JSHandle &env, const JSHandle &method); JSHandle NewJSFunction(const JSHandle &methodHandle); JSHandle NewJSFunction(const JSHandle &methodHandle, const JSHandle &homeObject); JSHandle NewJSFunction(const JSHandle &methodHandle, FunctionKind kind, bool isOptimized, bool canFastCall); JSHandle NewJSNativeErrorFunction(const JSHandle &env, const void *nativeFunc = nullptr); JSHandle NewSpecificTypedArrayFunction(const JSHandle &env, const void *nativeFunc = nullptr); JSHandle OrdinaryNewJSObjectCreate(const JSHandle &proto); JSHandle CreateNullJSObject(); JSHandle NewAotFunction(uint32_t numArgs, uintptr_t codeEntry); JSHandle NewJSBoundFunction(const JSHandle &target, const JSHandle &boundThis, const JSHandle &args); JSHandle NewJSIntlBoundFunction(MethodIndex idx, int functionLength = 1); JSHandle NewJSProxyRevocFunction(const JSHandle &proxy); JSHandle NewJSAsyncAwaitStatusFunction(MethodIndex idx); JSHandle NewJSGeneratorObject(JSHandle generatorFunction); JSHandle NewJSAsyncFuncObject(); JSHandle NewJSAsyncGeneratorObject(JSHandle generatorFunction); JSHandle NewJSPrimitiveRef(const JSHandle &function, const JSHandle &object); JSHandle NewJSPrimitiveRef(PrimitiveType type, const JSHandle &object); // get JSHClass for Ecma ClassLinker JSHandle NewGlobalEnv(JSHClass *globalEnvClass); // get JSHClass for Ecma ClassLinker JSHandle NewLexicalEnv(int numSlots); inline LexicalEnv *InlineNewLexicalEnv(int numSlots); JSHandle NewJSSymbol(); JSHandle NewPrivateSymbol(); JSHandle NewPrivateNameSymbol(const JSHandle &name); JSHandle NewWellKnownSymbol(const JSHandle &name); JSHandle NewPublicSymbol(const JSHandle &name); JSHandle NewSymbolWithTable(const JSHandle &name); JSHandle NewPrivateNameSymbolWithChar(const char *description); JSHandle NewWellKnownSymbolWithChar(const char *description); JSHandle NewPublicSymbolWithChar(const char *description); JSHandle NewSymbolWithTableWithChar(const char *description); JSHandle NewAccessorData(); JSHandle NewInternalAccessor(void *setter, void *getter); JSHandle NewPromiseCapability(); JSHandle NewPromiseReaction(); JSHandle NewPromiseRecord(); JSHandle NewAsyncGeneratorRequest(); JSHandle NewAsyncIteratorRecord(const JSHandle &itor, const JSHandle &next, bool done); JSHandle NewResolvingFunctionsRecord(); JSHandle NewPromiseIteratorRecord(const JSHandle &itor, bool done); JSHandle NewMicroJobQueue(); JSHandle NewPendingJob(const JSHandle &func, const JSHandle &argv); JSHandle NewJSArray(); JSHandle NewJSProxy(const JSHandle &target, const JSHandle &handler); JSHandle NewJSRealm(); JSHandle NewJSArguments(); JSHandle NewJSString(const JSHandle &str, const JSHandle &newTarget); template JSHandle ConvertListToArray(const JSThread *thread, const JSHandle &list, uint32_t numberOfNodes) { MemSpaceType spaceType = numberOfNodes < LENGTH_THRESHOLD ? MemSpaceType::SEMI_SPACE : MemSpaceType::OLD_SPACE; JSHandle dstElements = NewTaggedArrayWithoutInit(numberOfNodes, spaceType); if (numberOfNodes == 0) { return dstElements; } int dataIndex = Derived::ELEMENTS_START_INDEX; for (uint32_t i = 0; i < numberOfNodes; i++) { dataIndex = list->GetElement(dataIndex + Derived::NEXT_PTR_OFFSET).GetInt(); dstElements->Set(thread, i, list->GetElement(dataIndex)); } return dstElements; } JSHandle NewAndCopyTaggedArray(JSHandle &srcElements, uint32_t newLength, uint32_t oldLength); JSHandle NewTaggedArray(uint32_t length, JSTaggedValue initVal = JSTaggedValue::Hole()); JSHandle NewTaggedArray(uint32_t length, JSTaggedValue initVal, bool nonMovable); JSHandle NewTaggedArray(uint32_t length, JSTaggedValue initVal, MemSpaceType spaceType); // Copy on write array is allocated in nonmovable space by default. JSHandle NewCOWTaggedArray(uint32_t length, JSTaggedValue initVal = JSTaggedValue::Hole()); JSHandle NewDictionaryArray(uint32_t length); JSHandle NewJSForinIterator(const JSHandle &obj); JSHandle NewByteArray(uint32_t length, uint32_t size); JSHandle NewPropertyBox(const JSHandle &name); JSHandle NewProtoChangeMarker(); JSHandle NewProtoChangeDetails(); JSHandle NewBigInt(uint32_t length); // use for copy properties keys's array to another array JSHandle ExtendArray(const JSHandle &old, uint32_t length, JSTaggedValue initVal = JSTaggedValue::Hole(), MemSpaceType type = MemSpaceType::SEMI_SPACE); JSHandle CopyPartArray(const JSHandle &old, uint32_t start, uint32_t end); JSHandle CopyArray(const JSHandle &old, uint32_t oldLength, uint32_t newLength, JSTaggedValue initVal = JSTaggedValue::Hole(), MemSpaceType type = MemSpaceType::SEMI_SPACE); JSHandle CloneProperties(const JSHandle &old); JSHandle CloneProperties(const JSHandle &old, const JSHandle &env, const JSHandle &obj); JSHandle CreateLayoutInfo(int properties, MemSpaceType type = MemSpaceType::SEMI_SPACE, GrowMode mode = GrowMode::GROW); JSHandle ExtendLayoutInfo(const JSHandle &old, int properties); JSHandle CopyLayoutInfo(const JSHandle &old); JSHandle CopyAndReSort(const JSHandle &old, int end, int capacity); JSHandle GetEmptyString() const; JSHandle EmptyArray() const; FreeObject *FillFreeObject(uintptr_t address, size_t size, RemoveSlots removeSlots = RemoveSlots::NO, uintptr_t hugeObjectHead = 0); TaggedObject *NewObject(const JSHandle &hclass); TaggedObject *NewNonMovableObject(const JSHandle &hclass, uint32_t inobjPropCount = 0); void InitializeExtraProperties(const JSHandle &hclass, TaggedObject *obj, uint32_t inobjPropCount); JSHandle NewTaggedQueue(uint32_t length); JSHandle GetEmptyTaggedQueue() const; JSHandle NewJSSetIterator(const JSHandle &set, IterationKind kind); JSHandle NewJSRegExpIterator(const JSHandle &matcher, const JSHandle &inputStr, bool global, bool fullUnicode); JSHandle NewJSMapIterator(const JSHandle &map, IterationKind kind); JSHandle NewJSArrayIterator(const JSHandle &array, IterationKind kind); JSHandle NewCompletionRecord(CompletionRecordType type, JSHandle value); JSHandle NewGeneratorContext(); JSHandle CreateJSPromiseReactionsFunction(MethodIndex idx); JSHandle CreateJSPromiseExecutorFunction(); JSHandle NewJSPromiseAllResolveElementFunction(); JSHandle NewJSPromiseAnyRejectElementFunction(); JSHandle NewJSPromiseAllSettledResolveElementFunction(); JSHandle NewJSPromiseAllSettledRejectElementFunction(); JSHandle NewJSPromiseThenFinallyFunction(); JSHandle NewJSPromiseCatchFinallyFunction(); JSHandle NewJSPromiseValueThunkFunction(); JSHandle NewJSPromiseThrowerFunction(); JSHandle NewJSAsyGenResNextRetProRstFulfilledFtn(); JSHandle NewJSAsyGenResNextRetProRstRejectedFtn(); JSHandle NewJSAsyncFromSyncIterUnwarpFunction(); JSHandle CloneObjectLiteral(JSHandle object, const JSHandle &env, bool canShareHClass = true); JSHandle CloneObjectLiteral(JSHandle object); JSHandle CloneArrayLiteral(JSHandle object); JSHandle CloneJSFuction(JSHandle func); JSHandle CloneClassCtor(JSHandle ctor, const JSHandle &lexenv, bool canShareHClass); void NewJSArrayBufferData(const JSHandle &array, int32_t length); JSHandle NewJSArrayBuffer(int32_t length); JSHandle NewJSArrayBuffer(void *buffer, int32_t length, const DeleteEntryPoint &deleter, void *data, bool share = false); JSHandle NewJSDataView(JSHandle buffer, uint32_t offset, uint32_t length); void NewJSSharedArrayBufferData(const JSHandle &array, int32_t length); JSHandle NewJSSharedArrayBuffer(int32_t length); JSHandle NewJSSharedArrayBuffer(void *buffer, int32_t length); void NewJSRegExpByteCodeData(const JSHandle ®exp, void *buffer, size_t size); template inline void NewJSIntlIcuData(const JSHandle &obj, const S &icu, const DeleteEntryPoint &callback); EcmaString *InternString(const JSHandle &key); inline JSHandle NewJSNativePointer(void *externalPointer, const DeleteEntryPoint &callBack = nullptr, void *data = nullptr, bool nonMovable = false, size_t nativeBindingsize = 0); JSHandle NewOldSpaceObjLiteralByHClass(const JSHandle &properties, size_t length); JSHandle SetLayoutInObjHClass(const JSHandle &properties, size_t length, const JSHandle &objClass); JSHandle GetObjectLiteralHClass(const JSHandle &properties, size_t length); // only use for creating Function.prototype and Function JSHandle NewJSFunctionByHClass(const JSHandle &method, const JSHandle &clazz, MemSpaceType type = MemSpaceType::SEMI_SPACE); JSHandle NewJSFunctionByHClass(const void *func, const JSHandle &clazz, FunctionKind kind = FunctionKind::NORMAL_FUNCTION); JSHandle NewMethod(const MethodLiteral *methodLiteral, MemSpaceType spaceType = OLD_SPACE); JSHandle NewMethod(const JSPandaFile *jsPandaFile, MethodLiteral *methodLiteral, JSHandle constpool, uint32_t entryIndex, bool needSetAotFlag, bool *canFastCall = nullptr); // used for creating jsobject by constructor JSHandle NewJSObjectByConstructor(const JSHandle &constructor, const JSHandle &newTarget); JSHandle NewJSObjectByConstructor(const JSHandle &constructor); void InitializeJSObject(const JSHandle &obj, const JSHandle &jshclass); JSHandle NewJSObjectWithInit(const JSHandle &jshclass); uintptr_t NewSpaceBySnapshotAllocator(size_t size); JSHandle NewMachineCodeObject(size_t length, const uint8_t *data); JSHandle NewClassInfoExtractor(JSHandle method); JSHandle NewClassLiteral(); // ----------------------------------- new TSType ---------------------------------------- JSHandle CreateTSObjLayoutInfo(int propNum, JSTaggedValue initVal = JSTaggedValue::Hole()); JSHandle NewTSObjectType(uint32_t numOfKeys); JSHandle NewTSClassType(); JSHandle NewTSUnionType(uint32_t length); JSHandle NewTSInterfaceType(); JSHandle NewTSClassInstanceType(); JSHandle NewTSTypeTable(uint32_t length); JSHandle NewTSModuleTable(uint32_t length); JSHandle NewTSFunctionType(uint32_t length); JSHandle NewTSArrayType(); JSHandle NewTSIteratorInstanceType(); JSHandle NewTSNamespaceType(); // ----------------------------------- new string ---------------------------------------- JSHandle NewFromASCII(const CString &data); JSHandle NewFromUtf8(const CString &data); JSHandle NewFromUtf16(const CS16tring &data); JSHandle NewFromStdString(const std::string &data); JSHandle NewFromUtf8(const uint8_t *utf8Data, uint32_t utf8Len); JSHandle NewFromUtf16(const uint16_t *utf16Data, uint32_t utf16Len); JSHandle NewFromUtf16Compress(const uint16_t *utf16Data, uint32_t utf16Len); JSHandle NewFromUtf16NotCompress(const uint16_t *utf16Data, uint32_t utf16Len); JSHandle NewFromUtf8Literal(const uint8_t *utf8Data, uint32_t utf8Len); JSHandle NewFromUtf8LiteralCompress(const uint8_t *utf8Data, uint32_t utf8Len); JSHandle NewFromUtf16Literal(const uint16_t *utf16Data, uint32_t utf16Len); JSHandle NewFromUtf16LiteralCompress(const uint16_t *utf16Data, uint32_t utf16Len); JSHandle NewFromUtf16LiteralNotCompress(const uint16_t *utf16Data, uint32_t utf16Len); inline EcmaString *AllocLineStringObject(size_t size); inline EcmaString *AllocOldSpaceLineStringObject(size_t size); inline EcmaString *AllocNonMovableLineStringObject(size_t size); inline EcmaString *AllocConstantStringObject(MemSpaceType type); inline EcmaString *AllocTreeStringObject(); JSHandle ConcatFromString(const JSHandle &firstString, const JSHandle &secondString); // used for creating Function JSHandle NewJSObject(const JSHandle &jshclass); // used for creating jshclass in Builtins, Function, Class_Linker JSHandle NewEcmaHClass(uint32_t size, JSType type, const JSHandle &prototype, bool isOptimized = false, bool canFastCall = false); // It is used to provide iterators for non ECMA standard jsapi containers. JSHandle NewJSAPIPlainArray(uint32_t capacity); JSHandle NewJSAPIPlainArrayIterator(const JSHandle &plainarray, IterationKind kind); JSHandle NewJSAPIArrayList(uint32_t capacity); JSHandle NewJSAPILightWeightMapIterator(const JSHandle &obj, IterationKind kind); JSHandle NewJSAPILightWeightSetIterator(const JSHandle &obj, IterationKind kind); JSHandle CopyQueue(const JSHandle &old, uint32_t newLength, uint32_t front, uint32_t tail); JSHandle NewJSAPIQueueIterator(const JSHandle &queue); JSHandle CopyDeque(const JSHandle &old, uint32_t newLength, uint32_t oldLength, uint32_t first, uint32_t last); JSHandle NewJSAPIDequeIterator(const JSHandle &deque); JSHandle NewJSAPIArrayListIterator(const JSHandle &arrayList); JSHandle NewJSAPIList(); JSHandle NewJSAPILinkedList(); JSHandle NewJSAPILinkedListIterator(const JSHandle &linkedList); JSHandle NewJSAPIListIterator(const JSHandle &list); JSHandle NewJSAPITreeMapIterator(const JSHandle &map, IterationKind kind); JSHandle NewJSAPITreeSetIterator(const JSHandle &set, IterationKind kind); JSHandle NewJSAPIStackIterator(const JSHandle &stack); JSHandle NewJSAPIVector(uint32_t capacity); JSHandle NewJSAPIVectorIterator(const JSHandle &vector); JSHandle NewJSAPIHashMapIterator(const JSHandle &hashMap, IterationKind kind); JSHandle NewJSAPIHashSetIterator(const JSHandle &hashSet, IterationKind kind); JSHandle NewTaggedHashArray(uint32_t length); JSHandle NewLinkedNode(int hash, const JSHandle &key, const JSHandle &value, const JSHandle &next); JSHandle NewTreeNode(int hash, const JSHandle &key, const JSHandle &value); // --------------------------------------module-------------------------------------------- JSHandle NewModuleNamespace(); JSHandle NewImportEntry(); JSHandle NewImportEntry(const JSHandle &moduleRequest, const JSHandle &importName, const JSHandle &localName); JSHandle NewLocalExportEntry(); JSHandle NewLocalExportEntry( const JSHandle &exportName, const JSHandle &localName, const uint32_t index = 0); JSHandle NewIndirectExportEntry(); JSHandle NewIndirectExportEntry(const JSHandle &exportName, const JSHandle &moduleRequest, const JSHandle &importName); JSHandle NewStarExportEntry(); JSHandle NewStarExportEntry(const JSHandle &moduleRequest); JSHandle NewSourceTextModule(); JSHandle NewResolvedBindingRecord(); JSHandle NewResolvedBindingRecord(const JSHandle &module, const JSHandle &bindingName); JSHandle NewResolvedIndexBindingRecord(); JSHandle NewResolvedIndexBindingRecord(const JSHandle &module, int32_t index); JSHandle NewCellRecord(); JSHandle NewJSAsyncGeneratorFunction(const JSHandle &method); // --------------------------------------require-------------------------------------------- JSHandle NewCjsModule(); JSHandle NewCjsExports(); JSHandle NewCjsRequire(); JSHandle CreateIteratorResultInstanceClass(const JSHandle &env); // --------------------------------------old space object-------------------------------------------- JSHandle NewOldSpaceJSObject(const JSHandle &jshclass); TaggedObject *NewOldSpaceObject(const JSHandle &hclass); JSHandle NewOldSpaceTaggedArray(uint32_t length, JSTaggedValue initVal = JSTaggedValue::Hole()); // ---------------------------------New objects used internally-------------------------------------- JSHandle NewJSStableArrayWithElements(const JSHandle &elements); // ---------------------------------------Used by AOT------------------------------------------------ JSHandle NewAOTLiteralInfo(uint32_t length, JSTaggedValue initVal = JSTaggedValue::Hole()); JSHandle NewVTable(uint32_t length, JSTaggedValue initVal = JSTaggedValue::Hole()); JSHandle GetNonOptimizedHclass(JSHandle oldHClassHandle, FunctionKind kind); JSHandle NewEcmaHClass(JSHClass *hclass, uint32_t size, JSType type, uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); private: friend class GlobalEnv; friend class GlobalEnvConstants; friend class EcmaString; friend class SnapshotProcessor; friend class TSManager; void InitObjectFields(const TaggedObject *object); JSThread *thread_ {nullptr}; bool isTriggerGc_ {false}; bool triggerSemiGC_ {false}; EcmaVM *vm_ {nullptr}; Heap *heap_ {nullptr}; static constexpr uint32_t LENGTH_THRESHOLD = 50; NO_COPY_SEMANTIC(ObjectFactory); NO_MOVE_SEMANTIC(ObjectFactory); void NewObjectHook() const; // used for creating jshclass in Builtins, Function, Class_Linker JSHandle NewEcmaHClass(uint32_t size, JSType type, uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); // used for creating jshclass in GlobalEnv, EcmaVM JSHandle NewEcmaHClassClass(JSHClass *hclass, uint32_t size, JSType type); JSHandle NewEcmaReadOnlyHClass(JSHClass *hclass, uint32_t size, JSType type, uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); JSHandle InitClassClass(); // used to create nonmovable js_object JSHandle NewNonMovableJSObject(const JSHandle &jshclass); // used to create nonmovable utf8 string at global constants JSHandle NewFromASCIINonMovable(const CString &data); // used for creating Function JSHandle NewJSFunction(const JSHandle &env, const JSHandle &hclass); JSHandle CreateObjectClass(const JSHandle &keys, const JSHandle &values); JSHandle CreateObjectClass(const JSHandle &properties, size_t length); JSHandle CreateFunctionClass(FunctionKind kind, uint32_t size, JSType type, const JSHandle &prototype, bool isOptimized = false, bool canFastCall = false); JSHandle CreateDefaultClassPrototypeHClass(JSHClass *hclass); JSHandle CreateDefaultClassConstructorHClass(JSHClass *hclass); // used for creating ref.prototype in buildins, such as Number.prototype JSHandle NewJSPrimitiveRef(const JSHandle &hclass, const JSHandle &object); JSHandle GetStringFromStringTable(const uint8_t *utf8Data, uint32_t utf8Len, bool canBeCompress) const; JSHandle GetStringFromStringTableNonMovable(const uint8_t *utf8Data, uint32_t utf8Len) const; // For MUtf-8 string data EcmaString* PUBLIC_API GetRawStringFromStringTable(StringData sd, MemSpaceType type = MemSpaceType::SEMI_SPACE, bool isConstantString = false, uint32_t idOffset = 0) const; JSHandle GetStringFromStringTable(const uint16_t *utf16Data, uint32_t utf16Len, bool canBeCompress) const; JSHandle GetStringFromStringTable(EcmaString *string) const; JSHandle GetStringFromStringTable(const JSHandle &firstString, const JSHandle &secondString); JSHandle NewEmptyArray(); // only used for EcmaVM. JSHandle CreateJSArguments(const JSHandle &env); JSHandle CreateJSArrayInstanceClass(JSHandle proto); JSHandle CreateJSRegExpInstanceClass(JSHandle proto); inline TaggedObject *AllocObjectWithSpaceType(size_t size, JSHClass *cls, MemSpaceType type); JSHandle NewTaggedArrayWithoutInit(uint32_t length, MemSpaceType spaceType); friend class Builtins; // create builtins object need hclass friend class JSFunction; // create prototype_or_hclass need hclass friend class JSHClass; // HC transition need hclass friend class EcmaVM; // hold the factory instance friend class JsVerificationTest; friend class PandaFileTranslator; friend class LiteralDataExtractor; friend class RuntimeStubs; friend class ClassInfoExtractor; friend class ModuleDataExtractor; friend class ModuleDataAccessor; friend class ConstantPool; friend class EcmaContext; friend class kungfu::TSHClassGenerator; }; class ClassLinkerFactory { private: friend class GlobalEnv; // root class in class_linker need hclass friend class EcmaVM; // root class in class_linker need hclass }; } // namespace panda::ecmascript #endif // ECMASCRIPT_OBJECT_FACTORY_H