2021-09-04 08:06:49 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2021-09-07 14:24:16 +00:00
|
|
|
#ifndef ECMASCRIPT_OBJECT_FACTORY_H
|
|
|
|
#define ECMASCRIPT_OBJECT_FACTORY_H
|
2021-09-04 08:06:49 +00:00
|
|
|
|
|
|
|
#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"
|
2022-02-17 07:11:23 +00:00
|
|
|
#include "ecmascript/mem/heap_region_allocator.h"
|
2021-09-07 14:24:16 +00:00
|
|
|
#include "ecmascript/mem/machine_code.h"
|
2022-02-17 07:11:23 +00:00
|
|
|
#include "ecmascript/mem/native_area_allocator.h"
|
2022-03-16 10:12:15 +00:00
|
|
|
#include "ecmascript/mem/space.h"
|
2021-09-04 08:06:49 +00:00
|
|
|
#include "ecmascript/tagged_array.h"
|
|
|
|
|
|
|
|
namespace panda::ecmascript {
|
2022-04-21 09:17:00 +00:00
|
|
|
struct JSMethod;
|
2021-09-04 08:06:49 +00:00
|
|
|
class JSObject;
|
|
|
|
class JSArray;
|
2022-04-12 01:39:08 +00:00
|
|
|
class JSAPIPlainArray;
|
2021-09-04 08:06:49 +00:00
|
|
|
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;
|
2022-05-16 04:21:50 +00:00
|
|
|
class JSRegExpIterator;
|
2021-09-04 08:06:49 +00:00
|
|
|
class JSMapIterator;
|
|
|
|
class JSArrayIterator;
|
2022-04-12 01:39:08 +00:00
|
|
|
class JSAPIPlainArrayIterator;
|
2021-09-04 08:06:49 +00:00
|
|
|
class JSStringIterator;
|
|
|
|
class JSGeneratorObject;
|
|
|
|
class CompletionRecord;
|
|
|
|
class GeneratorContext;
|
|
|
|
class JSArrayBuffer;
|
|
|
|
class JSDataView;
|
|
|
|
class JSPromise;
|
|
|
|
class JSPromiseReactionsFunction;
|
|
|
|
class JSPromiseExecutorFunction;
|
|
|
|
class JSPromiseAllResolveElementFunction;
|
|
|
|
class PromiseReaction;
|
|
|
|
class PromiseCapability;
|
|
|
|
class PromiseIteratorRecord;
|
|
|
|
class JSAsyncFuncObject;
|
|
|
|
class JSAsyncFunction;
|
|
|
|
class PromiseRecord;
|
|
|
|
class JSLocale;
|
|
|
|
class ResolvingFunctionsRecord;
|
|
|
|
class EcmaVM;
|
|
|
|
class Heap;
|
|
|
|
class ConstantPool;
|
|
|
|
class Program;
|
|
|
|
class LayoutInfo;
|
2021-09-07 14:24:16 +00:00
|
|
|
class JSIntlBoundFunction;
|
2021-09-04 08:06:49 +00:00
|
|
|
class FreeObject;
|
|
|
|
class JSNativePointer;
|
2022-02-22 08:50:20 +00:00
|
|
|
class TSObjectType;
|
|
|
|
class TSClassType;
|
|
|
|
class TSUnionType;
|
|
|
|
class TSInterfaceType;
|
|
|
|
class TSTypeTable;
|
|
|
|
class TSClassInstanceType;
|
2022-03-08 01:26:23 +00:00
|
|
|
class TSFunctionType;
|
|
|
|
class TSArrayType;
|
2022-02-22 08:50:20 +00:00
|
|
|
class TSImportType;
|
|
|
|
class TSObjLayoutInfo;
|
|
|
|
class TSModuleTable;
|
2022-03-08 01:26:23 +00:00
|
|
|
class TSFunctionType;
|
|
|
|
class TSArrayType;
|
2022-02-17 09:00:31 +00:00
|
|
|
class JSAPIArrayList;
|
|
|
|
class JSAPIArrayListIterator;
|
2022-03-28 03:12:46 +00:00
|
|
|
class JSAPIDeque;
|
|
|
|
class JSAPIDequeIterator;
|
2022-03-05 02:35:02 +00:00
|
|
|
class JSAPIQueue;
|
|
|
|
class JSAPIQueueIterator;
|
2022-03-28 03:12:46 +00:00
|
|
|
class JSAPIStack;
|
|
|
|
class JSAPIStackIterator;
|
2022-02-10 03:02:38 +00:00
|
|
|
class JSAPITreeSet;
|
|
|
|
class JSAPITreeMap;
|
|
|
|
class JSAPITreeSetIterator;
|
|
|
|
class JSAPITreeMapIterator;
|
2022-01-30 08:01:33 +00:00
|
|
|
class ModuleNamespace;
|
|
|
|
class ImportEntry;
|
|
|
|
class ExportEntry;
|
|
|
|
class SourceTextModule;
|
|
|
|
class ResolvedBinding;
|
2022-03-10 13:25:06 +00:00
|
|
|
class BigInt;
|
2021-09-04 08:06:49 +00:00
|
|
|
namespace job {
|
|
|
|
class MicroJobQueue;
|
|
|
|
class PendingJob;
|
|
|
|
} // namespace job
|
|
|
|
class TransitionHandler;
|
|
|
|
class PrototypeHandler;
|
|
|
|
class PropertyBox;
|
|
|
|
class ProtoChangeMarker;
|
|
|
|
class ProtoChangeDetails;
|
|
|
|
class ProfileTypeInfo;
|
2021-09-07 14:24:16 +00:00
|
|
|
class MachineCode;
|
2021-12-25 01:51:43 +00:00
|
|
|
class ClassInfoExtractor;
|
2021-09-04 08:06:49 +00:00
|
|
|
|
2022-01-25 10:05:12 +00:00
|
|
|
enum class CompletionRecordType : uint8_t;
|
2021-09-04 08:06:49 +00:00
|
|
|
enum class PrimitiveType : uint8_t;
|
2022-01-25 10:05:12 +00:00
|
|
|
enum class IterationKind : uint8_t;
|
2021-09-04 08:06:49 +00:00
|
|
|
|
|
|
|
using ErrorType = base::ErrorType;
|
|
|
|
using base::ErrorType;
|
|
|
|
using DeleteEntryPoint = void (*)(void *, void *);
|
|
|
|
|
|
|
|
enum class RemoveSlots { YES, NO };
|
|
|
|
class ObjectFactory {
|
|
|
|
public:
|
|
|
|
explicit ObjectFactory(JSThread *thread, Heap *heap);
|
|
|
|
|
|
|
|
JSHandle<ProfileTypeInfo> NewProfileTypeInfo(uint32_t length);
|
|
|
|
JSHandle<ConstantPool> NewConstantPool(uint32_t capacity);
|
|
|
|
JSHandle<Program> NewProgram();
|
|
|
|
|
|
|
|
JSHandle<JSObject> GetJSError(const ErrorType &errorType, const char *data = nullptr);
|
|
|
|
|
|
|
|
JSHandle<JSObject> NewJSError(const ErrorType &errorType, const JSHandle<EcmaString> &message);
|
|
|
|
|
2021-09-07 14:24:16 +00:00
|
|
|
JSHandle<TransitionHandler> NewTransitionHandler();
|
2021-09-04 08:06:49 +00:00
|
|
|
|
2021-09-07 14:24:16 +00:00
|
|
|
JSHandle<PrototypeHandler> NewPrototypeHandler();
|
2021-09-04 08:06:49 +00:00
|
|
|
|
|
|
|
JSHandle<JSObject> NewEmptyJSObject();
|
|
|
|
|
|
|
|
// use for others create, prototype is Function.prototype
|
|
|
|
// use for native function
|
|
|
|
JSHandle<JSFunction> NewJSFunction(const JSHandle<GlobalEnv> &env, const void *nativeFunc = nullptr,
|
|
|
|
FunctionKind kind = FunctionKind::NORMAL_FUNCTION);
|
|
|
|
// use for method
|
|
|
|
JSHandle<JSFunction> NewJSFunction(const JSHandle<GlobalEnv> &env, JSMethod *method,
|
|
|
|
FunctionKind kind = FunctionKind::NORMAL_FUNCTION);
|
|
|
|
|
|
|
|
JSHandle<JSFunction> NewJSNativeErrorFunction(const JSHandle<GlobalEnv> &env, const void *nativeFunc = nullptr);
|
|
|
|
|
|
|
|
JSHandle<JSFunction> NewSpecificTypedArrayFunction(const JSHandle<GlobalEnv> &env,
|
|
|
|
const void *nativeFunc = nullptr);
|
|
|
|
|
|
|
|
JSHandle<JSObject> OrdinaryNewJSObjectCreate(const JSHandle<JSTaggedValue> &proto);
|
|
|
|
|
2022-04-16 09:32:42 +00:00
|
|
|
JSHandle<JSFunction> NewAotFunction(uint32_t numArgs, uintptr_t codeEntry);
|
|
|
|
|
2021-09-04 08:06:49 +00:00
|
|
|
JSHandle<JSBoundFunction> NewJSBoundFunction(const JSHandle<JSFunctionBase> &target,
|
|
|
|
const JSHandle<JSTaggedValue> &boundThis,
|
|
|
|
const JSHandle<TaggedArray> &args);
|
|
|
|
|
2021-09-07 14:24:16 +00:00
|
|
|
JSHandle<JSIntlBoundFunction> NewJSIntlBoundFunction(const void *nativeFunc = nullptr, int functionLength = 1);
|
|
|
|
|
2021-09-04 08:06:49 +00:00
|
|
|
JSHandle<JSProxyRevocFunction> NewJSProxyRevocFunction(const JSHandle<JSProxy> &proxy,
|
|
|
|
const void *nativeFunc = nullptr);
|
|
|
|
|
|
|
|
JSHandle<JSAsyncAwaitStatusFunction> NewJSAsyncAwaitStatusFunction(const void *nativeFunc = nullptr);
|
|
|
|
JSHandle<JSFunction> NewJSGeneratorFunction(JSMethod *method);
|
|
|
|
|
|
|
|
JSHandle<JSAsyncFunction> NewAsyncFunction(JSMethod *method);
|
|
|
|
|
|
|
|
JSHandle<JSGeneratorObject> NewJSGeneratorObject(JSHandle<JSTaggedValue> generatorFunction);
|
|
|
|
|
|
|
|
JSHandle<JSAsyncFuncObject> NewJSAsyncFuncObject();
|
|
|
|
|
|
|
|
JSHandle<JSPrimitiveRef> NewJSPrimitiveRef(const JSHandle<JSFunction> &function,
|
|
|
|
const JSHandle<JSTaggedValue> &object);
|
|
|
|
JSHandle<JSPrimitiveRef> NewJSPrimitiveRef(PrimitiveType type, const JSHandle<JSTaggedValue> &object);
|
|
|
|
|
|
|
|
// get JSHClass for Ecma ClassLinker
|
|
|
|
JSHandle<GlobalEnv> NewGlobalEnv(JSHClass *globalEnvClass);
|
|
|
|
|
|
|
|
// get JSHClass for Ecma ClassLinker
|
|
|
|
JSHandle<LexicalEnv> NewLexicalEnv(int numSlots);
|
|
|
|
|
|
|
|
inline LexicalEnv *InlineNewLexicalEnv(int numSlots);
|
|
|
|
|
|
|
|
JSHandle<JSSymbol> NewJSSymbol();
|
|
|
|
|
|
|
|
JSHandle<JSSymbol> NewPrivateSymbol();
|
|
|
|
|
|
|
|
JSHandle<JSSymbol> NewPrivateNameSymbol(const JSHandle<JSTaggedValue> &name);
|
|
|
|
|
|
|
|
JSHandle<JSSymbol> NewWellKnownSymbol(const JSHandle<JSTaggedValue> &name);
|
|
|
|
|
|
|
|
JSHandle<JSSymbol> NewPublicSymbol(const JSHandle<JSTaggedValue> &name);
|
|
|
|
|
|
|
|
JSHandle<JSSymbol> NewSymbolWithTable(const JSHandle<JSTaggedValue> &name);
|
|
|
|
|
|
|
|
JSHandle<JSSymbol> NewPrivateNameSymbolWithChar(const char *description);
|
|
|
|
|
|
|
|
JSHandle<JSSymbol> NewWellKnownSymbolWithChar(const char *description);
|
|
|
|
|
|
|
|
JSHandle<JSSymbol> NewPublicSymbolWithChar(const char *description);
|
|
|
|
|
|
|
|
JSHandle<JSSymbol> NewSymbolWithTableWithChar(const char *description);
|
|
|
|
|
|
|
|
JSHandle<AccessorData> NewAccessorData();
|
|
|
|
JSHandle<AccessorData> NewInternalAccessor(void *setter, void *getter);
|
|
|
|
|
|
|
|
JSHandle<PromiseCapability> NewPromiseCapability();
|
|
|
|
|
|
|
|
JSHandle<PromiseReaction> NewPromiseReaction();
|
|
|
|
|
|
|
|
JSHandle<PromiseRecord> NewPromiseRecord();
|
|
|
|
|
|
|
|
JSHandle<ResolvingFunctionsRecord> NewResolvingFunctionsRecord();
|
|
|
|
|
2022-01-25 10:05:12 +00:00
|
|
|
JSHandle<PromiseIteratorRecord> NewPromiseIteratorRecord(const JSHandle<JSTaggedValue> &itor, bool done);
|
2021-09-04 08:06:49 +00:00
|
|
|
|
|
|
|
JSHandle<job::MicroJobQueue> NewMicroJobQueue();
|
|
|
|
|
|
|
|
JSHandle<job::PendingJob> NewPendingJob(const JSHandle<JSFunction> &func, const JSHandle<TaggedArray> &argv);
|
|
|
|
|
|
|
|
JSHandle<JSArray> NewJSArray();
|
|
|
|
|
|
|
|
JSHandle<JSProxy> NewJSProxy(const JSHandle<JSTaggedValue> &target, const JSHandle<JSTaggedValue> &handler);
|
|
|
|
JSHandle<JSRealm> NewJSRealm();
|
|
|
|
|
|
|
|
JSHandle<JSArguments> NewJSArguments();
|
|
|
|
|
|
|
|
JSHandle<JSPrimitiveRef> NewJSString(const JSHandle<JSTaggedValue> &str);
|
|
|
|
|
2022-01-14 13:50:26 +00:00
|
|
|
JSHandle<TaggedArray> NewTaggedArray(uint32_t length, JSTaggedValue initVal = JSTaggedValue::Hole());
|
|
|
|
JSHandle<TaggedArray> NewTaggedArray(uint32_t length, JSTaggedValue initVal, bool nonMovable);
|
|
|
|
JSHandle<TaggedArray> NewTaggedArray(uint32_t length, JSTaggedValue initVal, MemSpaceType spaceType);
|
|
|
|
JSHandle<TaggedArray> NewDictionaryArray(uint32_t length);
|
2021-09-04 08:06:49 +00:00
|
|
|
JSHandle<JSForInIterator> NewJSForinIterator(const JSHandle<JSTaggedValue> &obj);
|
|
|
|
|
|
|
|
JSHandle<PropertyBox> NewPropertyBox(const JSHandle<JSTaggedValue> &name);
|
|
|
|
|
|
|
|
JSHandle<ProtoChangeMarker> NewProtoChangeMarker();
|
|
|
|
|
|
|
|
JSHandle<ProtoChangeDetails> NewProtoChangeDetails();
|
2022-03-10 13:25:06 +00:00
|
|
|
JSHandle<BigInt> NewBigInt();
|
2021-09-04 08:06:49 +00:00
|
|
|
// use for copy properties keys's array to another array
|
2022-01-14 13:50:26 +00:00
|
|
|
JSHandle<TaggedArray> ExtendArray(const JSHandle<TaggedArray> &old, uint32_t length,
|
2021-09-04 08:06:49 +00:00
|
|
|
JSTaggedValue initVal = JSTaggedValue::Hole());
|
2022-01-14 13:50:26 +00:00
|
|
|
JSHandle<TaggedArray> CopyPartArray(const JSHandle<TaggedArray> &old, uint32_t start, uint32_t end);
|
|
|
|
JSHandle<TaggedArray> CopyArray(const JSHandle<TaggedArray> &old, uint32_t oldLength, uint32_t newLength,
|
2021-09-04 08:06:49 +00:00
|
|
|
JSTaggedValue initVal = JSTaggedValue::Hole());
|
|
|
|
JSHandle<TaggedArray> CloneProperties(const JSHandle<TaggedArray> &old);
|
|
|
|
JSHandle<TaggedArray> CloneProperties(const JSHandle<TaggedArray> &old, const JSHandle<JSTaggedValue> &env,
|
|
|
|
const JSHandle<JSObject> &obj, const JSHandle<JSTaggedValue> &constpool);
|
|
|
|
|
|
|
|
JSHandle<LayoutInfo> CreateLayoutInfo(int properties, JSTaggedValue initVal = JSTaggedValue::Hole());
|
|
|
|
|
|
|
|
JSHandle<LayoutInfo> ExtendLayoutInfo(const JSHandle<LayoutInfo> &old, int properties,
|
|
|
|
JSTaggedValue initVal = JSTaggedValue::Hole());
|
|
|
|
|
|
|
|
JSHandle<LayoutInfo> CopyLayoutInfo(const JSHandle<LayoutInfo> &old);
|
|
|
|
|
|
|
|
JSHandle<LayoutInfo> CopyAndReSort(const JSHandle<LayoutInfo> &old, int end, int capacity);
|
|
|
|
|
|
|
|
JSHandle<EcmaString> GetEmptyString() const;
|
|
|
|
|
|
|
|
JSHandle<TaggedArray> EmptyArray() const;
|
|
|
|
|
|
|
|
FreeObject *FillFreeObject(uintptr_t address, size_t size, RemoveSlots removeSlots = RemoveSlots::NO);
|
|
|
|
|
2021-12-17 09:18:10 +00:00
|
|
|
TaggedObject *NewDynObject(const JSHandle<JSHClass> &dynclass);
|
2021-09-04 08:06:49 +00:00
|
|
|
|
|
|
|
TaggedObject *NewNonMovableDynObject(const JSHandle<JSHClass> &dynclass, int inobjPropCount = 0);
|
|
|
|
|
|
|
|
void InitializeExtraProperties(const JSHandle<JSHClass> &dynclass, TaggedObject *obj, int inobjPropCount);
|
|
|
|
|
2022-01-14 13:50:26 +00:00
|
|
|
JSHandle<TaggedQueue> NewTaggedQueue(uint32_t length);
|
2021-09-04 08:06:49 +00:00
|
|
|
|
|
|
|
JSHandle<TaggedQueue> GetEmptyTaggedQueue() const;
|
|
|
|
|
|
|
|
JSHandle<JSSetIterator> NewJSSetIterator(const JSHandle<JSSet> &set, IterationKind kind);
|
|
|
|
|
2022-05-16 04:21:50 +00:00
|
|
|
JSHandle<JSRegExpIterator> NewJSRegExpIterator(const JSHandle<JSTaggedValue> &matcher,
|
|
|
|
const JSHandle<EcmaString> &inputStr, bool global,
|
|
|
|
bool fullUnicode);
|
|
|
|
|
2021-09-04 08:06:49 +00:00
|
|
|
JSHandle<JSMapIterator> NewJSMapIterator(const JSHandle<JSMap> &map, IterationKind kind);
|
|
|
|
|
|
|
|
JSHandle<JSArrayIterator> NewJSArrayIterator(const JSHandle<JSObject> &array, IterationKind kind);
|
|
|
|
|
2022-01-25 10:05:12 +00:00
|
|
|
JSHandle<CompletionRecord> NewCompletionRecord(CompletionRecordType type, JSHandle<JSTaggedValue> value);
|
2021-09-04 08:06:49 +00:00
|
|
|
|
|
|
|
JSHandle<GeneratorContext> NewGeneratorContext();
|
|
|
|
|
|
|
|
JSHandle<JSPromiseReactionsFunction> CreateJSPromiseReactionsFunction(const void *nativeFunc);
|
|
|
|
|
|
|
|
JSHandle<JSPromiseExecutorFunction> CreateJSPromiseExecutorFunction(const void *nativeFunc);
|
|
|
|
|
|
|
|
JSHandle<JSPromiseAllResolveElementFunction> NewJSPromiseAllResolveElementFunction(const void *nativeFunc);
|
|
|
|
|
|
|
|
JSHandle<JSObject> CloneObjectLiteral(JSHandle<JSObject> object, const JSHandle<JSTaggedValue> &env,
|
2021-12-25 01:51:43 +00:00
|
|
|
const JSHandle<JSTaggedValue> &constpool, bool canShareHClass = true);
|
2021-09-04 08:06:49 +00:00
|
|
|
JSHandle<JSObject> CloneObjectLiteral(JSHandle<JSObject> object);
|
|
|
|
JSHandle<JSArray> CloneArrayLiteral(JSHandle<JSArray> object);
|
|
|
|
JSHandle<JSFunction> CloneJSFuction(JSHandle<JSFunction> obj, FunctionKind kind);
|
2021-12-25 01:51:43 +00:00
|
|
|
JSHandle<JSFunction> CloneClassCtor(JSHandle<JSFunction> ctor, const JSHandle<JSTaggedValue> &lexenv,
|
|
|
|
bool canShareHClass);
|
2021-09-04 08:06:49 +00:00
|
|
|
|
|
|
|
void NewJSArrayBufferData(const JSHandle<JSArrayBuffer> &array, int32_t length);
|
|
|
|
|
|
|
|
JSHandle<JSArrayBuffer> NewJSArrayBuffer(int32_t length);
|
|
|
|
|
|
|
|
JSHandle<JSArrayBuffer> NewJSArrayBuffer(void *buffer, int32_t length, const DeleteEntryPoint &deleter, void *data,
|
|
|
|
bool share = false);
|
|
|
|
|
2022-01-25 10:05:12 +00:00
|
|
|
JSHandle<JSDataView> NewJSDataView(JSHandle<JSArrayBuffer> buffer, uint32_t offset, uint32_t length);
|
2021-09-04 08:06:49 +00:00
|
|
|
|
2022-03-30 03:35:52 +00:00
|
|
|
void NewJSSharedArrayBufferData(const JSHandle<JSArrayBuffer> &array, int32_t length);
|
|
|
|
|
|
|
|
JSHandle<JSArrayBuffer> NewJSSharedArrayBuffer(int32_t length);
|
|
|
|
|
|
|
|
JSHandle<JSArrayBuffer> NewJSSharedArrayBuffer(void *buffer, int32_t length);
|
|
|
|
|
2021-09-04 08:06:49 +00:00
|
|
|
void NewJSRegExpByteCodeData(const JSHandle<JSRegExp> ®exp, void *buffer, size_t size);
|
|
|
|
|
2021-09-07 14:24:16 +00:00
|
|
|
template<typename T, typename S>
|
2021-09-04 08:06:49 +00:00
|
|
|
inline void NewJSIntlIcuData(const JSHandle<T> &obj, const S &icu, const DeleteEntryPoint &callback);
|
|
|
|
|
|
|
|
EcmaString *InternString(const JSHandle<JSTaggedValue> &key);
|
|
|
|
|
2021-09-29 12:46:00 +00:00
|
|
|
inline JSHandle<JSNativePointer> NewJSNativePointer(void *externalPointer,
|
|
|
|
const DeleteEntryPoint &callBack = nullptr,
|
|
|
|
void *data = nullptr,
|
|
|
|
bool nonMovable = false);
|
2021-09-04 08:06:49 +00:00
|
|
|
|
2022-04-11 12:01:28 +00:00
|
|
|
JSHandle<JSObject> GetObjectLiteralByHClass(const JSHandle<TaggedArray> &properties, size_t length);
|
|
|
|
JSHandle<JSHClass> SetLayoutInObjHClass(const JSHandle<TaggedArray> &properties, size_t length,
|
|
|
|
const JSHandle<JSHClass> &objClass);
|
|
|
|
JSHandle<JSHClass> GetObjectLiteralHClass(const JSHandle<TaggedArray> &properties, size_t length);
|
2021-09-04 08:06:49 +00:00
|
|
|
// only use for creating Function.prototype and Function
|
|
|
|
JSHandle<JSFunction> NewJSFunctionByDynClass(JSMethod *method, const JSHandle<JSHClass> &clazz,
|
|
|
|
FunctionKind kind = FunctionKind::NORMAL_FUNCTION);
|
|
|
|
|
|
|
|
// used for creating jsobject by constructor
|
|
|
|
JSHandle<JSObject> NewJSObjectByConstructor(const JSHandle<JSFunction> &constructor,
|
|
|
|
const JSHandle<JSTaggedValue> &newTarget);
|
2022-05-20 09:32:34 +00:00
|
|
|
void InitializeJSObject(const JSHandle<JSObject> &obj, const JSHandle<JSHClass> &jshclass);
|
|
|
|
JSHandle<JSObject> NewJSObjectWithInit(const JSHandle<JSHClass> &jshclass);
|
2022-04-28 13:21:03 +00:00
|
|
|
uintptr_t NewSpaceBySnapshotAllocator(size_t size);
|
2021-09-07 14:24:16 +00:00
|
|
|
JSHandle<MachineCode> NewMachineCodeObject(size_t length, const uint8_t *data);
|
2021-12-25 01:51:43 +00:00
|
|
|
JSHandle<ClassInfoExtractor> NewClassInfoExtractor(JSMethod *ctorMethod);
|
2021-09-04 08:06:49 +00:00
|
|
|
|
2022-02-22 08:50:20 +00:00
|
|
|
// ----------------------------------- new TSType ----------------------------------------
|
|
|
|
JSHandle<TSObjLayoutInfo> CreateTSObjLayoutInfo(int propNum, JSTaggedValue initVal = JSTaggedValue::Hole());
|
|
|
|
JSHandle<TSObjectType> NewTSObjectType(uint32_t numOfKeys);
|
|
|
|
JSHandle<TSClassType> NewTSClassType();
|
|
|
|
JSHandle<TSUnionType> NewTSUnionType(uint32_t length);
|
|
|
|
JSHandle<TSInterfaceType> NewTSInterfaceType();
|
|
|
|
JSHandle<TSImportType> NewTSImportType();
|
|
|
|
JSHandle<TSClassInstanceType> NewTSClassInstanceType();
|
|
|
|
JSHandle<TSTypeTable> NewTSTypeTable(uint32_t length);
|
|
|
|
JSHandle<TSModuleTable> NewTSModuleTable(uint32_t length);
|
2022-03-08 01:26:23 +00:00
|
|
|
JSHandle<TSFunctionType> NewTSFunctionType(uint32_t length);
|
|
|
|
JSHandle<TSArrayType> NewTSArrayType();
|
2022-02-22 08:50:20 +00:00
|
|
|
|
2021-09-04 08:06:49 +00:00
|
|
|
~ObjectFactory() = default;
|
|
|
|
|
2021-09-07 14:24:16 +00:00
|
|
|
// ----------------------------------- new string ----------------------------------------
|
2022-04-09 02:34:11 +00:00
|
|
|
JSHandle<EcmaString> NewFromASCII(const CString &data);
|
|
|
|
JSHandle<EcmaString> NewFromUtf8(const CString &data);
|
2021-09-07 14:24:16 +00:00
|
|
|
|
|
|
|
JSHandle<EcmaString> NewFromStdString(const std::string &data);
|
|
|
|
|
|
|
|
JSHandle<EcmaString> NewFromUtf8(const uint8_t *utf8Data, uint32_t utf8Len);
|
|
|
|
|
|
|
|
JSHandle<EcmaString> NewFromUtf16(const uint16_t *utf16Data, uint32_t utf16Len);
|
2022-04-09 02:34:11 +00:00
|
|
|
JSHandle<EcmaString> NewFromUtf16Compress(const uint16_t *utf16Data, uint32_t utf16Len);
|
|
|
|
JSHandle<EcmaString> NewFromUtf16NotCompress(const uint16_t *utf16Data, uint32_t utf16Len);
|
2021-09-07 14:24:16 +00:00
|
|
|
|
|
|
|
JSHandle<EcmaString> NewFromUtf8Literal(const uint8_t *utf8Data, uint32_t utf8Len);
|
2022-04-09 02:34:11 +00:00
|
|
|
JSHandle<EcmaString> NewFromUtf8LiteralCompress(const uint8_t *utf8Data, uint32_t utf8Len);
|
2021-09-07 14:24:16 +00:00
|
|
|
|
|
|
|
JSHandle<EcmaString> NewFromUtf16Literal(const uint16_t *utf16Data, uint32_t utf16Len);
|
2022-04-09 02:34:11 +00:00
|
|
|
JSHandle<EcmaString> NewFromUtf16LiteralCompress(const uint16_t *utf16Data, uint32_t utf16Len);
|
|
|
|
JSHandle<EcmaString> NewFromUtf16LiteralNotCompress(const uint16_t *utf16Data, uint32_t utf16Len);
|
2021-09-07 14:24:16 +00:00
|
|
|
|
2022-02-10 13:57:57 +00:00
|
|
|
JSHandle<EcmaString> ConcatFromString(const JSHandle<EcmaString> &firstString,
|
|
|
|
const JSHandle<EcmaString> &secondString);
|
2021-09-07 14:24:16 +00:00
|
|
|
|
2021-10-18 06:11:40 +00:00
|
|
|
// used for creating Function
|
|
|
|
JSHandle<JSObject> NewJSObject(const JSHandle<JSHClass> &jshclass);
|
2021-12-17 09:18:10 +00:00
|
|
|
|
2021-10-18 06:11:40 +00:00
|
|
|
// used for creating jshclass in Builtins, Function, Class_Linker
|
|
|
|
JSHandle<JSHClass> NewEcmaDynClass(uint32_t size, JSType type, const JSHandle<JSTaggedValue> &prototype);
|
|
|
|
|
2022-02-10 03:02:38 +00:00
|
|
|
// It is used to provide iterators for non ECMA standard jsapi containers.
|
2022-04-12 01:39:08 +00:00
|
|
|
JSHandle<JSAPIPlainArray> NewJSAPIPlainArray(array_size_t capacity);
|
|
|
|
JSHandle<JSAPIPlainArrayIterator> NewJSAPIPlainArrayIterator(const JSHandle<JSAPIPlainArray> &plainarray,
|
|
|
|
IterationKind kind);
|
2022-02-17 09:00:31 +00:00
|
|
|
JSHandle<JSAPIArrayList> NewJSAPIArrayList(uint32_t capacity);
|
2022-03-05 02:35:02 +00:00
|
|
|
JSHandle<TaggedArray> CopyQueue(const JSHandle<TaggedArray> &old, uint32_t oldLength,
|
|
|
|
uint32_t newLength, uint32_t front, uint32_t tail);
|
|
|
|
JSHandle<JSAPIQueueIterator> NewJSAPIQueueIterator(const JSHandle<JSAPIQueue> &queue);
|
2022-03-28 03:12:46 +00:00
|
|
|
JSHandle<TaggedArray> CopyDeque(const JSHandle<TaggedArray> &old, uint32_t newLength, uint32_t oldLength,
|
|
|
|
uint32_t first, uint32_t last);
|
|
|
|
JSHandle<JSAPIDequeIterator> NewJSAPIDequeIterator(const JSHandle<JSAPIDeque> &deque);
|
2022-02-17 09:00:31 +00:00
|
|
|
JSHandle<JSAPIArrayListIterator> NewJSAPIArrayListIterator(const JSHandle<JSAPIArrayList> &arrayList);
|
2022-02-10 03:02:38 +00:00
|
|
|
JSHandle<JSAPITreeMapIterator> NewJSAPITreeMapIterator(const JSHandle<JSAPITreeMap> &map, IterationKind kind);
|
|
|
|
JSHandle<JSAPITreeSetIterator> NewJSAPITreeSetIterator(const JSHandle<JSAPITreeSet> &set, IterationKind kind);
|
2022-03-28 03:12:46 +00:00
|
|
|
JSHandle<JSAPIStackIterator> NewJSAPIStackIterator(const JSHandle<JSAPIStack> &stack);
|
2022-01-30 08:01:33 +00:00
|
|
|
// --------------------------------------module--------------------------------------------
|
|
|
|
JSHandle<ModuleNamespace> NewModuleNamespace();
|
|
|
|
JSHandle<ImportEntry> NewImportEntry();
|
|
|
|
JSHandle<ImportEntry> NewImportEntry(const JSHandle<JSTaggedValue> &moduleRequest,
|
|
|
|
const JSHandle<JSTaggedValue> &importName,
|
|
|
|
const JSHandle<JSTaggedValue> &localName);
|
|
|
|
JSHandle<ExportEntry> NewExportEntry();
|
|
|
|
JSHandle<ExportEntry> NewExportEntry(const JSHandle<JSTaggedValue> &exportName,
|
|
|
|
const JSHandle<JSTaggedValue> &moduleRequest,
|
|
|
|
const JSHandle<JSTaggedValue> &importName,
|
|
|
|
const JSHandle<JSTaggedValue> &localName);
|
|
|
|
JSHandle<SourceTextModule> NewSourceTextModule();
|
|
|
|
JSHandle<ResolvedBinding> NewResolvedBindingRecord();
|
|
|
|
JSHandle<ResolvedBinding> NewResolvedBindingRecord(const JSHandle<SourceTextModule> &module,
|
|
|
|
const JSHandle<JSTaggedValue> &bindingName);
|
2022-02-10 03:02:38 +00:00
|
|
|
|
2021-09-04 08:06:49 +00:00
|
|
|
private:
|
|
|
|
friend class GlobalEnv;
|
|
|
|
friend class GlobalEnvConstants;
|
|
|
|
friend class EcmaString;
|
|
|
|
JSHandle<JSFunction> NewJSFunctionImpl(JSMethod *method);
|
|
|
|
|
|
|
|
void InitObjectFields(const TaggedObject *object);
|
|
|
|
|
2021-09-07 14:24:16 +00:00
|
|
|
JSThread *thread_ {nullptr};
|
|
|
|
bool isTriggerGc_ {false};
|
|
|
|
bool triggerSemiGC_ {false};
|
2021-09-04 08:06:49 +00:00
|
|
|
|
2021-09-07 14:24:16 +00:00
|
|
|
EcmaVM *vm_ {nullptr};
|
|
|
|
Heap *heap_ {nullptr};
|
2021-09-04 08:06:49 +00:00
|
|
|
|
|
|
|
NO_COPY_SEMANTIC(ObjectFactory);
|
|
|
|
NO_MOVE_SEMANTIC(ObjectFactory);
|
|
|
|
|
2021-12-17 09:18:10 +00:00
|
|
|
void NewObjectHook() const;
|
2021-09-04 08:06:49 +00:00
|
|
|
|
|
|
|
// used for creating jshclass in Builtins, Function, Class_Linker
|
2021-12-17 09:18:10 +00:00
|
|
|
JSHandle<JSHClass> NewEcmaDynClass(uint32_t size, JSType type,
|
|
|
|
uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS);
|
2021-09-04 08:06:49 +00:00
|
|
|
// used for creating jshclass in GlobalEnv, EcmaVM
|
2021-12-17 09:18:10 +00:00
|
|
|
JSHandle<JSHClass> NewEcmaDynClassClass(JSHClass *hclass, uint32_t size, JSType type);
|
|
|
|
JSHandle<JSHClass> NewEcmaDynClass(JSHClass *hclass, uint32_t size, JSType type,
|
|
|
|
uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS);
|
2022-03-26 09:00:26 +00:00
|
|
|
JSHandle<JSHClass> InitClassClass();
|
2021-09-04 08:06:49 +00:00
|
|
|
|
|
|
|
// used to create nonmovable js_object
|
|
|
|
JSHandle<JSObject> NewNonMovableJSObject(const JSHandle<JSHClass> &jshclass);
|
|
|
|
|
|
|
|
// used for creating Function
|
|
|
|
JSHandle<JSFunction> NewJSFunction(const JSHandle<GlobalEnv> &env, const JSHandle<JSHClass> &dynKlass);
|
|
|
|
JSHandle<JSHClass> CreateObjectClass(const JSHandle<TaggedArray> &properties, size_t length);
|
|
|
|
JSHandle<JSHClass> CreateFunctionClass(FunctionKind kind, uint32_t size, JSType type,
|
|
|
|
const JSHandle<JSTaggedValue> &prototype);
|
|
|
|
|
|
|
|
// used for creating ref.prototype in buildins, such as Number.prototype
|
|
|
|
JSHandle<JSPrimitiveRef> NewJSPrimitiveRef(const JSHandle<JSHClass> &dynKlass,
|
|
|
|
const JSHandle<JSTaggedValue> &object);
|
|
|
|
|
2021-09-07 14:24:16 +00:00
|
|
|
JSHandle<EcmaString> GetStringFromStringTable(const uint8_t *utf8Data, uint32_t utf8Len, bool canBeCompress) const;
|
2021-09-04 08:06:49 +00:00
|
|
|
// For MUtf-8 string data
|
2021-09-24 02:25:00 +00:00
|
|
|
EcmaString *GetRawStringFromStringTable(const uint8_t *mutf8Data, uint32_t utf16Len, bool canBeCompressed) const;
|
2021-09-04 08:06:49 +00:00
|
|
|
|
2021-09-07 14:24:16 +00:00
|
|
|
JSHandle<EcmaString> GetStringFromStringTable(const uint16_t *utf16Data, uint32_t utf16Len,
|
|
|
|
bool canBeCompress) const;
|
2021-09-04 08:06:49 +00:00
|
|
|
|
|
|
|
JSHandle<EcmaString> GetStringFromStringTable(EcmaString *string) const;
|
|
|
|
|
2022-02-10 13:57:57 +00:00
|
|
|
JSHandle<EcmaString> GetStringFromStringTable(const JSHandle<EcmaString> &firstString,
|
|
|
|
const JSHandle<EcmaString> &secondString);
|
|
|
|
|
2021-09-04 08:06:49 +00:00
|
|
|
inline EcmaString *AllocStringObject(size_t size);
|
|
|
|
inline EcmaString *AllocNonMovableStringObject(size_t size);
|
|
|
|
JSHandle<TaggedArray> NewEmptyArray(); // only used for EcmaVM.
|
|
|
|
|
|
|
|
JSHandle<JSHClass> CreateJSArguments();
|
|
|
|
JSHandle<JSHClass> CreateJSArrayInstanceClass(JSHandle<JSTaggedValue> proto);
|
|
|
|
JSHandle<JSHClass> CreateJSRegExpInstanceClass(JSHandle<JSTaggedValue> proto);
|
|
|
|
|
2021-09-07 14:24:16 +00:00
|
|
|
friend class Builtins; // create builtins object need dynclass
|
|
|
|
friend class JSFunction; // create prototype_or_dynclass need dynclass
|
|
|
|
friend class JSHClass; // HC transition need dynclass
|
|
|
|
friend class EcmaVM; // hold the factory instance
|
2021-09-04 08:06:49 +00:00
|
|
|
friend class JsVerificationTest;
|
|
|
|
friend class PandaFileTranslator;
|
|
|
|
friend class LiteralDataExtractor;
|
2022-03-16 10:12:15 +00:00
|
|
|
friend class RuntimeStubs;
|
2021-12-25 01:51:43 +00:00
|
|
|
friend class ClassInfoExtractor;
|
2022-02-22 08:50:20 +00:00
|
|
|
friend class TSObjectType;
|
2022-01-30 08:01:33 +00:00
|
|
|
friend class ModuleDataExtractor;
|
2021-09-04 08:06:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ClassLinkerFactory {
|
|
|
|
private:
|
2021-09-07 14:24:16 +00:00
|
|
|
friend class GlobalEnv; // root class in class_linker need dynclass
|
|
|
|
friend class EcmaVM; // root class in class_linker need dynclass
|
2021-09-04 08:06:49 +00:00
|
|
|
};
|
|
|
|
} // namespace panda::ecmascript
|
2021-09-07 14:24:16 +00:00
|
|
|
#endif // ECMASCRIPT_OBJECT_FACTORY_H
|