mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 08:03:29 +00:00
issue:#I4P7EY
Reason: To support AOT compilation, add ts type system to provide some interfaces and struct to wrap ts type and help type infer Description: create the global class TSLoader to expose the external interfaces, create the TSType and it's derived class, TSClassType, TSClassInstanceType, TSImportType and so on to wrap ts type in runtime. Add TDD unitest. Signed-off-by: lifansheng <lifansheng1@huawei.com>
This commit is contained in:
parent
cf3ee3ab96
commit
9efea35541
6
BUILD.gn
6
BUILD.gn
@ -53,6 +53,7 @@ group("ark_js_unittest") {
|
||||
"//ark/js_runtime/ecmascript/snapshot/tests:unittest",
|
||||
"//ark/js_runtime/ecmascript/tests:unittest",
|
||||
"//ark/js_runtime/ecmascript/tooling/test:unittest",
|
||||
"//ark/js_runtime/ecmascript/ts_types/tests:unittest",
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -73,6 +74,7 @@ group("ark_js_host_unittest") {
|
||||
"//ark/js_runtime/ecmascript/snapshot/tests:host_unittest",
|
||||
"//ark/js_runtime/ecmascript/tests:host_unittest",
|
||||
"//ark/js_runtime/ecmascript/tooling/test:host_unittest",
|
||||
"//ark/js_runtime/ecmascript/ts_types/tests:host_unittest",
|
||||
]
|
||||
if (is_standard_system) {
|
||||
deps += [ "//ark/js_runtime/ecmascript/compiler/tests:host_unittest" ]
|
||||
@ -421,6 +423,10 @@ ecma_source = [
|
||||
"ecmascript/weak_vector.cpp",
|
||||
"ecmascript/compiler/llvm/llvm_stackmap_parser.cpp",
|
||||
"ecmascript/class_info_extractor.cpp",
|
||||
"ecmascript/ts_types/ts_type.cpp",
|
||||
"ecmascript/ts_types/ts_type_table.cpp",
|
||||
"ecmascript/ts_types/ts_loader.cpp",
|
||||
"ecmascript/ts_types/ts_obj_layout_info.cpp",
|
||||
]
|
||||
|
||||
ecma_source += [
|
||||
|
@ -29,6 +29,8 @@
|
||||
#include "ecmascript/literal_data_extractor.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/tagged_array.h"
|
||||
#include "ecmascript/ts_types/ts_type_table.h"
|
||||
#include "ecmascript/ts_types/ts_loader.h"
|
||||
#include "libpandabase/mem/mem.h"
|
||||
#include "libpandabase/utils/logger.h"
|
||||
#include "libpandabase/utils/utf.h"
|
||||
@ -55,6 +57,10 @@ void PandaFileTranslator::TranslateAndCollectPandaFile(EcmaVM *vm, const panda_f
|
||||
const CString &methodName,
|
||||
std::vector<BytecodeTranslationInfo> &infoList)
|
||||
{
|
||||
if (vm->GetJSOptions().IsEnableTsAot()) {
|
||||
TSLoader *tsLoader = vm->GetTSLoader();
|
||||
tsLoader->DecodeTSTypes(pf);
|
||||
}
|
||||
PandaFileTranslator translator(vm);
|
||||
translator.TranslateClasses(pf, methodName, infoList);
|
||||
}
|
||||
|
@ -81,6 +81,7 @@
|
||||
#include "ecmascript/tagged_tree-inl.h"
|
||||
#include "ecmascript/template_map.h"
|
||||
#include "ecmascript/transitions_dictionary.h"
|
||||
#include "ecmascript/ts_types/ts_type.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using MicroJobQueue = panda::ecmascript::job::MicroJobQueue;
|
||||
@ -259,6 +260,18 @@ CString JSHClass::DumpJSType(JSType type)
|
||||
return "ClassInfoExtractor";
|
||||
case JSType::JS_API_ARRAY_LIST:
|
||||
return "ArrayList";
|
||||
case JSType::TS_OBJECT_TYPE:
|
||||
return "TSObjectType";
|
||||
case JSType::TS_CLASS_TYPE:
|
||||
return "TSClassType";
|
||||
case JSType::TS_INTERFACE_TYPE:
|
||||
return "TSInterfaceType";
|
||||
case JSType::TS_IMPORT_TYPE:
|
||||
return "TSImportType";
|
||||
case JSType::TS_CLASS_INSTANCE_TYPE:
|
||||
return "TSClassInstanceType";
|
||||
case JSType::TS_UNION_TYPE:
|
||||
return "TSUnionType";
|
||||
case JSType::JS_API_ARRAYLIST_ITERATOR:
|
||||
return "JSArraylistIterator";
|
||||
case JSType::JS_API_TREE_MAP:
|
||||
@ -612,6 +625,24 @@ static void DumpObject(JSThread *thread, TaggedObject *obj, std::ostream &os)
|
||||
case JSType::JS_API_ARRAYLIST_ITERATOR:
|
||||
JSAPIArrayListIterator::Cast(obj)->Dump(thread, os);
|
||||
break;
|
||||
case JSType::TS_OBJECT_TYPE:
|
||||
TSObjectType::Cast(obj)->Dump(thread, os);
|
||||
break;
|
||||
case JSType::TS_CLASS_TYPE:
|
||||
TSClassType::Cast(obj)->Dump(thread, os);
|
||||
break;
|
||||
case JSType::TS_INTERFACE_TYPE:
|
||||
TSInterfaceType::Cast(obj)->Dump(thread, os);
|
||||
break;
|
||||
case JSType::TS_IMPORT_TYPE:
|
||||
TSImportType::Cast(obj)->Dump(thread, os);
|
||||
break;
|
||||
case JSType::TS_CLASS_INSTANCE_TYPE:
|
||||
TSClassInstanceType::Cast(obj)->Dump(thread, os);
|
||||
break;
|
||||
case JSType::TS_UNION_TYPE:
|
||||
TSUnionType::Cast(obj)->Dump(thread, os);
|
||||
break;
|
||||
case JSType::JS_API_TREE_MAP:
|
||||
JSAPITreeMap::Cast(obj)->Dump(thread, os);
|
||||
break;
|
||||
@ -2086,6 +2117,221 @@ void ClassInfoExtractor::Dump(JSThread *thread, std::ostream &os) const
|
||||
os << "\n";
|
||||
}
|
||||
|
||||
void TSObjectType::Dump(JSThread *thread, std::ostream &os) const
|
||||
{
|
||||
os << " - TSObjectType globalTSTypeRef: ";
|
||||
GlobalTSTypeRef gt = GetGTRef();
|
||||
uint64_t globalTSTypeRef = gt.GetGlobalTSTypeRef();
|
||||
os << globalTSTypeRef;
|
||||
os << "\n";
|
||||
os << " - TSObjectType moduleId: ";
|
||||
uint32_t moduleId = gt.GetModuleId();
|
||||
os << moduleId;
|
||||
os << "\n";
|
||||
os << " - TSObjectType localTypeId: ";
|
||||
uint32_t localTypeId = gt.GetLocalId();
|
||||
os << localTypeId;
|
||||
os << "\n";
|
||||
os << " - TSObjectType typeKind: ";
|
||||
uint32_t typeKind = gt.GetUserDefineTypeKind();
|
||||
os << typeKind;
|
||||
os << "\n";
|
||||
os << " - ObjLayoutInfo: ";
|
||||
DumpArrayClass(thread, TaggedArray::Cast(GetObjLayoutInfo().GetTaggedObject()), os);
|
||||
os << " - HClass: ";
|
||||
GetHClass().D();
|
||||
}
|
||||
|
||||
void TSClassType::Dump(JSThread *thread, std::ostream &os) const
|
||||
{
|
||||
os << " - Dump Class Type - " << "\n";
|
||||
os << " - TSClassType globalTSTypeRef: ";
|
||||
GlobalTSTypeRef gt = GetGTRef();
|
||||
uint64_t globalTSTypeRef = gt.GetGlobalTSTypeRef();
|
||||
os << globalTSTypeRef;
|
||||
os << "\n";
|
||||
os << " - TSClassType moduleId: ";
|
||||
uint32_t moduleId = gt.GetModuleId();
|
||||
os << moduleId;
|
||||
os << "\n";
|
||||
os << " - TSClassType localTypeId: ";
|
||||
uint32_t localTypeId = gt.GetLocalId();
|
||||
os << localTypeId;
|
||||
os << "\n";
|
||||
os << " - TSClassType typeKind: ";
|
||||
uint32_t typeKind = gt.GetUserDefineTypeKind();
|
||||
os << typeKind;
|
||||
os << "\n";
|
||||
os << " - ExtensionTypeGT: ";
|
||||
JSTaggedValue extensionType = GetExtensionType();
|
||||
if (extensionType.IsUndefined()) {
|
||||
os << " (base class type) ";
|
||||
} else {
|
||||
uint64_t extensionTypeGT = TSType::Cast(extensionType.GetTaggedObject())->GetGTRef().GetGlobalTSTypeRef();
|
||||
os << extensionTypeGT;
|
||||
}
|
||||
os << "\n";
|
||||
|
||||
os << " - InstanceType: " << "\n";
|
||||
if (GetInstanceType().IsTSObjectType()) {
|
||||
TSObjectType *instanceType = TSObjectType::Cast(GetInstanceType().GetTaggedObject());
|
||||
instanceType->Dump(thread, os);
|
||||
os << "\n";
|
||||
}
|
||||
|
||||
os << " - ConstructorType: " << "\n";
|
||||
if (GetConstructorType().IsTSObjectType()) {
|
||||
TSObjectType *constructorType = TSObjectType::Cast(GetConstructorType().GetTaggedObject());
|
||||
constructorType->Dump(thread, os);
|
||||
os << "\n";
|
||||
}
|
||||
|
||||
os << " - PrototypeType: " << "\n";
|
||||
if (GetPrototypeType().IsTSObjectType()) {
|
||||
TSObjectType *prototypeType = TSObjectType::Cast(GetPrototypeType().GetTaggedObject());
|
||||
prototypeType->Dump(thread, os);
|
||||
os << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void TSInterfaceType::Dump(JSThread *thread, std::ostream &os) const
|
||||
{
|
||||
os << " - Dump Interface Type - " << "\n";
|
||||
os << " - TSInterfaceType globalTSTypeRef: ";
|
||||
GlobalTSTypeRef gt = GetGTRef();
|
||||
uint64_t globalTSTypeRef = gt.GetGlobalTSTypeRef();
|
||||
os << globalTSTypeRef;
|
||||
os << "\n";
|
||||
os << " - TSClassType moduleId: ";
|
||||
uint32_t moduleId = gt.GetModuleId();
|
||||
os << moduleId;
|
||||
os << "\n";
|
||||
os << " - TSClassType localTypeId: ";
|
||||
uint32_t localTypeId = gt.GetLocalId();
|
||||
os << localTypeId;
|
||||
os << "\n";
|
||||
os << " - TSClassType typeKind: ";
|
||||
uint32_t typeKind = gt.GetUserDefineTypeKind();
|
||||
os << typeKind;
|
||||
os << "\n";
|
||||
os << " - Extends TypeId: " << "\n";
|
||||
JSHandle<TaggedArray> extendsId(thread, GetExtends());
|
||||
if (extendsId->GetLength() == 0) {
|
||||
os << " (base interface type) "<< "\n";
|
||||
}
|
||||
DumpArrayClass(thread, TaggedArray::Cast(GetExtends().GetTaggedObject()), os);
|
||||
|
||||
os << " - Fields: " << "\n";
|
||||
if (GetFields().IsTSObjectType()) {
|
||||
TSObjectType *fieldsType = TSObjectType::Cast(GetFields().GetTaggedObject());
|
||||
fieldsType->Dump(thread, os);
|
||||
os << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void TSImportType::Dump(JSThread *thread, std::ostream &os) const
|
||||
{
|
||||
os << " - Dump Import Type - " << "\n";
|
||||
os << " - TSImportType globalTSTypeRef: ";
|
||||
GlobalTSTypeRef gt = GetGTRef();
|
||||
uint64_t globalTSTypeRef = gt.GetGlobalTSTypeRef();
|
||||
os << globalTSTypeRef;
|
||||
os << "\n";
|
||||
os << " - TSClassType moduleId: ";
|
||||
uint32_t moduleId = gt.GetModuleId();
|
||||
os << moduleId;
|
||||
os << "\n";
|
||||
os << " - TSClassType localTypeId: ";
|
||||
uint32_t localTypeId = gt.GetLocalId();
|
||||
os << localTypeId;
|
||||
os << "\n";
|
||||
os << " - TSClassType typeKind: ";
|
||||
uint32_t typeKind = gt.GetUserDefineTypeKind();
|
||||
os << typeKind;
|
||||
os << "\n";
|
||||
os << " - Target Type: ";
|
||||
if (GetTargetType().IsTSInterfaceType()) {
|
||||
TSInterfaceType *targetType = TSInterfaceType::Cast(GetTargetType().GetTaggedObject());
|
||||
targetType->Dump(thread, os);
|
||||
os << "\n";
|
||||
} else if (GetTargetType().IsTSClassType()) {
|
||||
TSClassType *targetType = TSClassType::Cast(GetTargetType().GetTaggedObject());
|
||||
targetType->Dump(thread, os);
|
||||
os << "\n";
|
||||
} else if (GetTargetType().IsTSClassInstanceType()) {
|
||||
TSClassInstanceType *targetType = TSClassInstanceType::Cast(GetTargetType().GetTaggedObject());
|
||||
targetType->Dump(thread, os);
|
||||
os << "\n";
|
||||
} else if (GetTargetType().IsTSUnionType()) {
|
||||
TSUnionType *targetType = TSUnionType::Cast(GetTargetType().GetTaggedObject());
|
||||
targetType->Dump(thread, os);
|
||||
os << "\n";
|
||||
} else {
|
||||
os << " - no link Target Type: ";
|
||||
os << "\n";
|
||||
}
|
||||
os << " - Taget Type Path: ";
|
||||
JSTaggedValue importPath = GetImportPath();
|
||||
importPath.DumpTaggedValue(thread, os);
|
||||
os << "\n";
|
||||
}
|
||||
|
||||
void TSClassInstanceType::Dump(JSThread *thread, std::ostream &os) const
|
||||
{
|
||||
os << " - Dump ClassInstance Type - " << "\n";
|
||||
os << " - TSClassInstanceType globalTSTypeRef: ";
|
||||
GlobalTSTypeRef gt = GetGTRef();
|
||||
uint64_t globalTSTypeRef = gt.GetGlobalTSTypeRef();
|
||||
os << globalTSTypeRef;
|
||||
os << "\n";
|
||||
os << " - TSClassType moduleId: ";
|
||||
uint32_t moduleId = gt.GetModuleId();
|
||||
os << moduleId;
|
||||
os << "\n";
|
||||
os << " - TSClassType localTypeId: ";
|
||||
uint32_t localTypeId = gt.GetLocalId();
|
||||
os << localTypeId;
|
||||
os << "\n";
|
||||
os << " - TSClassType typeKind: ";
|
||||
uint32_t typeKind = gt.GetUserDefineTypeKind();
|
||||
os << typeKind;
|
||||
os << "\n";
|
||||
|
||||
JSTaggedValue createClassType = GetCreateClassType();
|
||||
if (!createClassType.IsUndefined()) {
|
||||
os << " - CreateClassType GT: ";
|
||||
uint64_t createClassTypeGT = TSClassType::Cast(createClassType
|
||||
.GetTaggedObject())->GetGTRef().GetGlobalTSTypeRef();
|
||||
os << createClassTypeGT;
|
||||
os << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void TSUnionType::Dump(JSThread *thread, std::ostream &os) const
|
||||
{
|
||||
os << " - Dump UnionType Type - " << "\n";
|
||||
os << " - TSUnionType globalTSTypeRef: ";
|
||||
GlobalTSTypeRef gt = GetGTRef();
|
||||
uint64_t globalTSTypeRef = gt.GetGlobalTSTypeRef();
|
||||
os << globalTSTypeRef;
|
||||
os << "\n";
|
||||
os << " - TSClassType moduleId: ";
|
||||
uint32_t moduleId = gt.GetModuleId();
|
||||
os << moduleId;
|
||||
os << "\n";
|
||||
os << " - TSClassType localTypeId: ";
|
||||
uint32_t localTypeId = gt.GetLocalId();
|
||||
os << localTypeId;
|
||||
os << "\n";
|
||||
os << " - TSClassType typeKind: ";
|
||||
uint32_t typeKind = gt.GetUserDefineTypeKind();
|
||||
os << typeKind;
|
||||
os << "\n";
|
||||
os << " - TSUnionType TypeId: " << "\n";
|
||||
JSHandle<TaggedArray> componentTypes(thread, GetComponentTypes());
|
||||
|
||||
DumpArrayClass(thread, TaggedArray::Cast(GetComponentTypes().GetTaggedObject()), os);
|
||||
}
|
||||
// ########################################################################################
|
||||
// Dump for Snapshot
|
||||
// ########################################################################################
|
||||
@ -2351,6 +2597,24 @@ static void DumpObject(JSThread *thread, TaggedObject *obj,
|
||||
case JSType::CLASS_INFO_EXTRACTOR:
|
||||
ClassInfoExtractor::Cast(obj)->DumpForSnapshot(thread, vec);
|
||||
return;
|
||||
case JSType::TS_OBJECT_TYPE:
|
||||
TSObjectType::Cast(obj)->DumpForSnapshot(thread, vec);
|
||||
return;
|
||||
case JSType::TS_CLASS_TYPE:
|
||||
TSClassType::Cast(obj)->DumpForSnapshot(thread, vec);
|
||||
return;
|
||||
case JSType::TS_INTERFACE_TYPE:
|
||||
TSInterfaceType::Cast(obj)->DumpForSnapshot(thread, vec);
|
||||
return;
|
||||
case JSType::TS_IMPORT_TYPE:
|
||||
TSImportType::Cast(obj)->DumpForSnapshot(thread, vec);
|
||||
return;
|
||||
case JSType::TS_CLASS_INSTANCE_TYPE:
|
||||
TSClassInstanceType::Cast(obj)->DumpForSnapshot(thread, vec);
|
||||
return;
|
||||
case JSType::TS_UNION_TYPE:
|
||||
TSUnionType::Cast(obj)->DumpForSnapshot(thread, vec);
|
||||
return;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
@ -3219,4 +3483,40 @@ void ClassInfoExtractor::DumpForSnapshot(JSThread *thread, std::vector<std::pair
|
||||
vec.push_back(std::make_pair(CString("StaticProperties"), GetStaticProperties()));
|
||||
vec.push_back(std::make_pair(CString("StaticElements"), GetStaticElements()));
|
||||
}
|
||||
|
||||
void TSObjectType::DumpForSnapshot(JSThread *thread, std::vector<std::pair<CString, JSTaggedValue>> &vec) const
|
||||
{
|
||||
vec.push_back(std::make_pair(CString("ObjLayoutInfo"), GetObjLayoutInfo()));
|
||||
vec.push_back(std::make_pair(CString("HClass"), GetHClass()));
|
||||
}
|
||||
|
||||
void TSClassType::DumpForSnapshot(JSThread *thread, std::vector<std::pair<CString, JSTaggedValue>> &vec) const
|
||||
{
|
||||
vec.push_back(std::make_pair(CString("InstanceType"), GetInstanceType()));
|
||||
vec.push_back(std::make_pair(CString("ConstructorType"), GetConstructorType()));
|
||||
vec.push_back(std::make_pair(CString("PrototypeType"), GetPrototypeType()));
|
||||
vec.push_back(std::make_pair(CString("ExtensionType"), GetExtensionType()));
|
||||
}
|
||||
|
||||
void TSInterfaceType::DumpForSnapshot(JSThread *thread, std::vector<std::pair<CString, JSTaggedValue>> &vec) const
|
||||
{
|
||||
vec.push_back(std::make_pair(CString("Fields"), GetFields()));
|
||||
vec.push_back(std::make_pair(CString("Extends"), GetExtends()));
|
||||
}
|
||||
|
||||
void TSClassInstanceType::DumpForSnapshot(JSThread *thread, std::vector<std::pair<CString, JSTaggedValue>> &vec) const
|
||||
{
|
||||
vec.push_back(std::make_pair(CString("classTypeIndex"), GetCreateClassType()));
|
||||
}
|
||||
|
||||
void TSImportType::DumpForSnapshot(JSThread *thread, std::vector<std::pair<CString, JSTaggedValue>> &vec) const
|
||||
{
|
||||
vec.push_back(std::make_pair(CString("TargetType"), GetTargetType()));
|
||||
vec.push_back(std::make_pair(CString("ImportTypePath"), GetImportPath()));
|
||||
}
|
||||
|
||||
void TSUnionType::DumpForSnapshot(JSThread *thread, std::vector<std::pair<CString, JSTaggedValue>> &vec) const
|
||||
{
|
||||
vec.push_back(std::make_pair(CString("ComponentTypes"), GetComponentTypes()));
|
||||
}
|
||||
} // namespace panda::ecmascript
|
||||
|
@ -140,7 +140,7 @@ JSHandle<JSTaggedValue> ModuleManager::GetModule(const JSThread *thread,
|
||||
return thread->GlobalConstants()->GetHandledUndefined();
|
||||
}
|
||||
|
||||
CString ModuleManager::GenerateModuleFullPath(const std::string ¤tPathFile, const CString &relativeFile)
|
||||
CString ModuleManager::GenerateAmiPath(const std::string ¤tPathFile, const CString &relativeFile)
|
||||
{
|
||||
if (relativeFile.find("./") != 0 && relativeFile.find("../") != 0) { // not start with "./" or "../"
|
||||
return relativeFile; // not relative
|
||||
|
@ -66,7 +66,7 @@ public:
|
||||
|
||||
JSHandle<JSTaggedValue> GetModule(const JSThread *thread, JSHandle<JSTaggedValue> moduleName);
|
||||
|
||||
CString GenerateModuleFullPath(const std::string ¤tPathFile, const CString &relativeFile);
|
||||
CString GenerateAmiPath(const std::string ¤tPathFile, const CString &relativeFile);
|
||||
|
||||
const CString &GetCurrentExportModuleName();
|
||||
|
||||
@ -85,6 +85,11 @@ public:
|
||||
|
||||
void DebugPrint(const JSThread *thread, const CString &caller);
|
||||
|
||||
void Iterate(const RootVisitor &v)
|
||||
{
|
||||
v(Root::ROOT_VM, ObjectSlot(reinterpret_cast<uintptr_t>(&ecmaModules_)));
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr uint32_t DEAULT_DICTIONART_CAPACITY = 4;
|
||||
|
||||
|
@ -50,6 +50,8 @@
|
||||
#include "ecmascript/tagged_queue-inl.h"
|
||||
#include "ecmascript/tagged_queue.h"
|
||||
#include "ecmascript/template_map.h"
|
||||
#include "ecmascript/ts_types/ts_loader.h"
|
||||
#include "ecmascript/vmstat/runtime_stat.h"
|
||||
#include "include/runtime_notification.h"
|
||||
#include "libpandafile/file.h"
|
||||
|
||||
@ -190,6 +192,7 @@ bool EcmaVM::Initialize()
|
||||
}
|
||||
|
||||
moduleManager_ = new ModuleManager(this);
|
||||
tsLoader_ = new TSLoader(this);
|
||||
InitializeFinish();
|
||||
notificationManager_->VmStartEvent();
|
||||
notificationManager_->VmInitializationEvent(thread_->GetThreadId());
|
||||
@ -300,6 +303,11 @@ EcmaVM::~EcmaVM()
|
||||
moduleManager_ = nullptr;
|
||||
}
|
||||
|
||||
if (tsLoader_ != nullptr) {
|
||||
delete tsLoader_;
|
||||
tsLoader_ = nullptr;
|
||||
}
|
||||
|
||||
if (thread_ != nullptr) {
|
||||
delete thread_;
|
||||
thread_ = nullptr;
|
||||
@ -711,8 +719,9 @@ void EcmaVM::Iterate(const RootVisitor &v)
|
||||
{
|
||||
v(Root::ROOT_VM, ObjectSlot(reinterpret_cast<uintptr_t>(&globalEnv_)));
|
||||
v(Root::ROOT_VM, ObjectSlot(reinterpret_cast<uintptr_t>(µJobQueue_)));
|
||||
v(Root::ROOT_VM, ObjectSlot(reinterpret_cast<uintptr_t>(&moduleManager_->ecmaModules_)));
|
||||
v(Root::ROOT_VM, ObjectSlot(reinterpret_cast<uintptr_t>(®expCache_)));
|
||||
moduleManager_->Iterate(v);
|
||||
tsLoader_->Iterate(v);
|
||||
}
|
||||
|
||||
void EcmaVM::SetGlobalEnv(GlobalEnv *global)
|
||||
@ -735,7 +744,7 @@ JSHandle<JSTaggedValue> EcmaVM::GetModuleByName(JSHandle<JSTaggedValue> moduleNa
|
||||
CString relativeFile = ConvertToString(EcmaString::Cast(moduleName->GetTaggedObject()));
|
||||
|
||||
// generate full path
|
||||
CString abcPath = moduleManager_->GenerateModuleFullPath(currentPathFile, relativeFile);
|
||||
CString abcPath = moduleManager_->GenerateAmiPath(currentPathFile, relativeFile);
|
||||
|
||||
// Uniform module name
|
||||
JSHandle<EcmaString> abcModuleName = factory_->NewFromString(abcPath);
|
||||
|
@ -68,6 +68,7 @@ class JSFunction;
|
||||
class Program;
|
||||
class ModuleManager;
|
||||
class EcmaModule;
|
||||
class TSLoader;
|
||||
struct BytecodeTranslationInfo;
|
||||
using HostPromiseRejectionTracker = void (*)(const EcmaVM* vm,
|
||||
const JSHandle<JSPromise> promise,
|
||||
@ -356,6 +357,10 @@ public:
|
||||
return moduleManager_;
|
||||
}
|
||||
|
||||
TSLoader *GetTSLoader() const
|
||||
{
|
||||
return tsLoader_;
|
||||
}
|
||||
void SetupRegExpResultCache();
|
||||
|
||||
JSHandle<JSTaggedValue> GetRegExpCache() const
|
||||
@ -487,6 +492,7 @@ private:
|
||||
CString snapshotFileName_;
|
||||
ChunkVector<JSMethod *> nativeMethods_;
|
||||
ModuleManager *moduleManager_ {nullptr};
|
||||
TSLoader *tsLoader_ {nullptr};
|
||||
bool optionalLogEnabled_ {false};
|
||||
ChunkVector<std::tuple<Program *, const panda_file::File *, bool>> pandaFileWithProgram_;
|
||||
|
||||
|
@ -87,7 +87,7 @@ class JSThread;
|
||||
V(JSTaggedValue, AsyncFunctionPrototype, ASYNC_FUNCTION_PROTOTYPE_INDEX) \
|
||||
V(JSTaggedValue, JSGlobalObject, JS_GLOBAL_OBJECT_INDEX) \
|
||||
V(JSTaggedValue, EmptyArray, EMPTY_ARRAY_OBJECT_INDEX) \
|
||||
V(JSTaggedValue, EmptyLayoutInfo, EMPTY_LAYOUT_INFO_OBJECT_INDEX) \
|
||||
V(JSTaggedValue, EmptyLayoutInfo, EMPTY_LAYOUT_INFO_OBJECT_INDEX) \
|
||||
V(JSTaggedValue, EmptyTaggedQueue, EMPTY_TAGGED_QUEUE_OBJECT_INDEX) \
|
||||
V(JSTaggedValue, HasInstanceSymbol, HASINSTANCE_SYMBOL_INDEX) \
|
||||
V(JSTaggedValue, IsConcatSpreadableSymbol, ISCONCAT_SYMBOL_INDEX) \
|
||||
|
@ -37,6 +37,14 @@ inline void GlobalEnvConstants::SetConstant(ConstantIndex index, JSTaggedValue v
|
||||
constants_[static_cast<int>(index)] = value;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void GlobalEnvConstants::SetConstant(ConstantIndex index, JSHandle<T> value)
|
||||
{
|
||||
DASSERT_PRINT(index >= ConstantIndex::CONSTATNT_BEGIN && index < ConstantIndex::CONSTATNT_END,
|
||||
"Root Index out of bound");
|
||||
constants_[static_cast<int>(index)] = value.GetTaggedValue();
|
||||
}
|
||||
|
||||
inline uintptr_t GlobalEnvConstants::GetGlobalConstantAddr(ConstantIndex index) const
|
||||
{
|
||||
return ToUintPtr(this) + sizeof(JSTaggedValue) * static_cast<int>(index);
|
||||
|
@ -51,6 +51,7 @@
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/js_thread.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/ts_types/ts_type.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
void GlobalEnvConstants::InitRootsClass([[maybe_unused]] JSThread *thread, JSHClass *dynClassClass)
|
||||
@ -59,79 +60,60 @@ void GlobalEnvConstants::InitRootsClass([[maybe_unused]] JSThread *thread, JSHCl
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
|
||||
SetConstant(ConstantIndex::HCLASS_CLASS_INDEX, JSTaggedValue(dynClassClass));
|
||||
SetConstant(ConstantIndex::STRING_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, 0, JSType::STRING).GetTaggedValue());
|
||||
SetConstant(ConstantIndex::ARRAY_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, 0, JSType::TAGGED_ARRAY).GetTaggedValue());
|
||||
SetConstant(ConstantIndex::STRING_CLASS_INDEX, factory->NewEcmaDynClass(dynClassClass, 0, JSType::STRING));
|
||||
SetConstant(ConstantIndex::ARRAY_CLASS_INDEX, factory->NewEcmaDynClass(dynClassClass, 0, JSType::TAGGED_ARRAY));
|
||||
SetConstant(ConstantIndex::DICTIONARY_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, 0, JSType::TAGGED_DICTIONARY).GetTaggedValue());
|
||||
SetConstant(
|
||||
ConstantIndex::JS_NATIVE_POINTER_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, JSNativePointer::SIZE, JSType::JS_NATIVE_POINTER).GetTaggedValue());
|
||||
SetConstant(ConstantIndex::ENV_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, 0, JSType::TAGGED_ARRAY).GetTaggedValue());
|
||||
factory->NewEcmaDynClass(dynClassClass, 0, JSType::TAGGED_DICTIONARY));
|
||||
SetConstant(ConstantIndex::JS_NATIVE_POINTER_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, JSNativePointer::SIZE, JSType::JS_NATIVE_POINTER));
|
||||
SetConstant(ConstantIndex::ENV_CLASS_INDEX, factory->NewEcmaDynClass(dynClassClass, 0, JSType::TAGGED_ARRAY));
|
||||
SetConstant(ConstantIndex::FREE_OBJECT_WITH_NONE_FIELD_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, FreeObject::NEXT_OFFSET, JSType::FREE_OBJECT_WITH_NONE_FIELD)
|
||||
.GetTaggedValue());
|
||||
factory->NewEcmaDynClass(dynClassClass, FreeObject::NEXT_OFFSET, JSType::FREE_OBJECT_WITH_NONE_FIELD));
|
||||
SetConstant(ConstantIndex::FREE_OBJECT_WITH_ONE_FIELD_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, FreeObject::SIZE_OFFSET, JSType::FREE_OBJECT_WITH_ONE_FIELD)
|
||||
.GetTaggedValue());
|
||||
SetConstant(
|
||||
ConstantIndex::FREE_OBJECT_WITH_TWO_FIELD_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, FreeObject::SIZE, JSType::FREE_OBJECT_WITH_TWO_FIELD).GetTaggedValue());
|
||||
factory->NewEcmaDynClass(dynClassClass, FreeObject::SIZE_OFFSET, JSType::FREE_OBJECT_WITH_ONE_FIELD));
|
||||
SetConstant(ConstantIndex::FREE_OBJECT_WITH_TWO_FIELD_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, FreeObject::SIZE, JSType::FREE_OBJECT_WITH_TWO_FIELD));
|
||||
SetConstant(ConstantIndex::SYMBOL_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, JSSymbol::SIZE, JSType::SYMBOL).GetTaggedValue());
|
||||
factory->NewEcmaDynClass(dynClassClass, JSSymbol::SIZE, JSType::SYMBOL));
|
||||
SetConstant(ConstantIndex::ACCESSOE_DATA_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, AccessorData::SIZE, JSType::ACCESSOR_DATA).GetTaggedValue());
|
||||
SetConstant(
|
||||
ConstantIndex::INTERNAL_ACCESSOR_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, AccessorData::SIZE, JSType::INTERNAL_ACCESSOR).GetTaggedValue());
|
||||
factory->NewEcmaDynClass(dynClassClass, AccessorData::SIZE, JSType::ACCESSOR_DATA));
|
||||
SetConstant(ConstantIndex::INTERNAL_ACCESSOR_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, AccessorData::SIZE, JSType::INTERNAL_ACCESSOR));
|
||||
SetConstant(ConstantIndex::JS_PROXY_ORDINARY_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, JSProxy::SIZE, JSType::JS_PROXY).GetTaggedValue());
|
||||
SetConstant(
|
||||
ConstantIndex::COMPLETION_RECORD_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, CompletionRecord::SIZE, JSType::COMPLETION_RECORD).GetTaggedValue());
|
||||
SetConstant(
|
||||
ConstantIndex::GENERATOR_CONTEST_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, GeneratorContext::SIZE, JSType::JS_GENERATOR_CONTEXT).GetTaggedValue());
|
||||
SetConstant(
|
||||
ConstantIndex::CAPABILITY_RECORD_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, PromiseCapability::SIZE, JSType::PROMISE_CAPABILITY).GetTaggedValue());
|
||||
SetConstant(
|
||||
ConstantIndex::REACTIONS_RECORD_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, PromiseReaction::SIZE, JSType::PROMISE_REACTIONS).GetTaggedValue());
|
||||
factory->NewEcmaDynClass(dynClassClass, JSProxy::SIZE, JSType::JS_PROXY));
|
||||
SetConstant(ConstantIndex::COMPLETION_RECORD_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, CompletionRecord::SIZE, JSType::COMPLETION_RECORD));
|
||||
SetConstant(ConstantIndex::GENERATOR_CONTEST_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, GeneratorContext::SIZE, JSType::JS_GENERATOR_CONTEXT));
|
||||
SetConstant(ConstantIndex::CAPABILITY_RECORD_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, PromiseCapability::SIZE, JSType::PROMISE_CAPABILITY));
|
||||
SetConstant(ConstantIndex::REACTIONS_RECORD_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, PromiseReaction::SIZE, JSType::PROMISE_REACTIONS));
|
||||
SetConstant(ConstantIndex::PROMISE_ITERATOR_RECORD_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, PromiseIteratorRecord::SIZE, JSType::PROMISE_ITERATOR_RECORD)
|
||||
.GetTaggedValue());
|
||||
factory->NewEcmaDynClass(dynClassClass, PromiseIteratorRecord::SIZE, JSType::PROMISE_ITERATOR_RECORD));
|
||||
SetConstant(ConstantIndex::PROMISE_RECORD_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, PromiseRecord::SIZE, JSType::PROMISE_RECORD).GetTaggedValue());
|
||||
SetConstant(
|
||||
ConstantIndex::PROMISE_RESOLVING_FUNCTIONS_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, ResolvingFunctionsRecord::SIZE, JSType::RESOLVING_FUNCTIONS_RECORD)
|
||||
.GetTaggedValue());
|
||||
SetConstant(
|
||||
ConstantIndex::MICRO_JOB_QUEUE_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, job::MicroJobQueue::SIZE, JSType::MICRO_JOB_QUEUE).GetTaggedValue());
|
||||
factory->NewEcmaDynClass(dynClassClass, PromiseRecord::SIZE, JSType::PROMISE_RECORD));
|
||||
SetConstant(ConstantIndex::PROMISE_RESOLVING_FUNCTIONS_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, ResolvingFunctionsRecord::SIZE,
|
||||
JSType::RESOLVING_FUNCTIONS_RECORD));
|
||||
SetConstant(ConstantIndex::MICRO_JOB_QUEUE_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, job::MicroJobQueue::SIZE, JSType::MICRO_JOB_QUEUE));
|
||||
SetConstant(ConstantIndex::PENDING_JOB_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, job::PendingJob::SIZE, JSType::PENDING_JOB).GetTaggedValue());
|
||||
SetConstant(
|
||||
ConstantIndex::PROTO_CHANGE_MARKER_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, ProtoChangeMarker::SIZE, JSType::PROTO_CHANGE_MARKER).GetTaggedValue());
|
||||
SetConstant(
|
||||
ConstantIndex::PROTO_CHANGE_DETAILS_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, ProtoChangeDetails::SIZE, JSType::PROTOTYPE_INFO).GetTaggedValue());
|
||||
SetConstant(
|
||||
ConstantIndex::PROTOTYPE_HANDLER_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, PrototypeHandler::SIZE, JSType::PROTOTYPE_HANDLER).GetTaggedValue());
|
||||
SetConstant(
|
||||
ConstantIndex::TRANSITION_HANDLER_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, TransitionHandler::SIZE, JSType::TRANSITION_HANDLER).GetTaggedValue());
|
||||
factory->NewEcmaDynClass(dynClassClass, job::PendingJob::SIZE, JSType::PENDING_JOB));
|
||||
SetConstant(ConstantIndex::PROTO_CHANGE_MARKER_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, ProtoChangeMarker::SIZE, JSType::PROTO_CHANGE_MARKER));
|
||||
SetConstant(ConstantIndex::PROTO_CHANGE_DETAILS_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, ProtoChangeDetails::SIZE, JSType::PROTOTYPE_INFO));
|
||||
SetConstant(ConstantIndex::PROTOTYPE_HANDLER_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, PrototypeHandler::SIZE, JSType::PROTOTYPE_HANDLER));
|
||||
SetConstant(ConstantIndex::TRANSITION_HANDLER_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, TransitionHandler::SIZE, JSType::TRANSITION_HANDLER));
|
||||
SetConstant(ConstantIndex::PROPERTY_BOX_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, PropertyBox::SIZE, JSType::PROPERTY_BOX).GetTaggedValue());
|
||||
factory->NewEcmaDynClass(dynClassClass, PropertyBox::SIZE, JSType::PROPERTY_BOX));
|
||||
SetConstant(ConstantIndex::PROGRAM_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, Program::SIZE, JSType::PROGRAM).GetTaggedValue());
|
||||
factory->NewEcmaDynClass(dynClassClass, Program::SIZE, JSType::PROGRAM));
|
||||
SetConstant(ConstantIndex::ECMA_MODULE_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, EcmaModule::SIZE, JSType::ECMA_MODULE).GetTaggedValue());
|
||||
factory->NewEcmaDynClass(dynClassClass, EcmaModule::SIZE, JSType::ECMA_MODULE));
|
||||
|
||||
JSHClass *jsProxyCallableClass = *factory->NewEcmaDynClass(dynClassClass, JSProxy::SIZE, JSType::JS_PROXY);
|
||||
|
||||
@ -145,12 +127,23 @@ void GlobalEnvConstants::InitRootsClass([[maybe_unused]] JSThread *thread, JSHCl
|
||||
SetConstant(ConstantIndex::JS_PROXY_CONSTRUCT_CLASS_INDEX, JSTaggedValue(jsProxyConstructClass));
|
||||
|
||||
SetConstant(ConstantIndex::JS_REALM_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, JSRealm::SIZE, JSType::JS_REALM).GetTaggedValue());
|
||||
factory->NewEcmaDynClass(dynClassClass, JSRealm::SIZE, JSType::JS_REALM));
|
||||
SetConstant(ConstantIndex::MACHINE_CODE_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, 0, JSType::MACHINE_CODE_OBJECT).GetTaggedValue());
|
||||
factory->NewEcmaDynClass(dynClassClass, 0, JSType::MACHINE_CODE_OBJECT));
|
||||
SetConstant(ConstantIndex::CLASS_INFO_EXTRACTOR_HCLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, ClassInfoExtractor::SIZE, JSType::CLASS_INFO_EXTRACTOR)
|
||||
.GetTaggedValue());
|
||||
factory->NewEcmaDynClass(dynClassClass, ClassInfoExtractor::SIZE, JSType::CLASS_INFO_EXTRACTOR));
|
||||
SetConstant(ConstantIndex::TS_OBJECT_TYPE_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, TSObjectType::SIZE, JSType::TS_OBJECT_TYPE));
|
||||
SetConstant(ConstantIndex::TS_CLASS_TYPE_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, TSClassType::SIZE, JSType::TS_CLASS_TYPE));
|
||||
SetConstant(ConstantIndex::TS_UNION_TYPE_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, TSClassType::SIZE, JSType::TS_UNION_TYPE));
|
||||
SetConstant(ConstantIndex::TS_INTERFACE_TYPE_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, TSInterfaceType::SIZE, JSType::TS_INTERFACE_TYPE));
|
||||
SetConstant(ConstantIndex::TS_CLASS_INSTANCE_TYPE_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, TSClassInstanceType::SIZE, JSType::TS_CLASS_INSTANCE_TYPE));
|
||||
SetConstant(ConstantIndex::TS_IMPORT_TYPE_CLASS_INDEX,
|
||||
factory->NewEcmaDynClass(dynClassClass, TSImportType::SIZE, JSType::TS_IMPORT_TYPE));
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(readability-function-size)
|
||||
@ -163,308 +156,240 @@ void GlobalEnvConstants::InitGlobalConstant(JSThread *thread)
|
||||
auto vm = thread->GetEcmaVM();
|
||||
SetConstant(ConstantIndex::EMPTY_STRING_OBJECT_INDEX, JSTaggedValue(EcmaString::CreateEmptyString(vm)));
|
||||
[[maybe_unused]] auto test = EcmaString::Cast(GetHandledEmptyString().GetObject<EcmaString>());
|
||||
SetConstant(ConstantIndex::CONSTRUCTOR_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("constructor").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::PROTOTYPE_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("prototype").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::LENGTH_STRING_INDEX, factory->NewFromCanBeCompressString("length").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::VALUE_STRING_INDEX, factory->NewFromCanBeCompressString("value").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::SET_STRING_INDEX, factory->NewFromCanBeCompressString("set").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::GET_STRING_INDEX, factory->NewFromCanBeCompressString("get").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::WRITABLE_STRING_INDEX, factory->NewFromCanBeCompressString("writable").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::ENUMERABLE_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("enumerable").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::CONFIGURABLE_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("configurable").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::CONSTRUCTOR_STRING_INDEX, factory->NewFromCanBeCompressString("constructor"));
|
||||
SetConstant(ConstantIndex::PROTOTYPE_STRING_INDEX, factory->NewFromCanBeCompressString("prototype"));
|
||||
SetConstant(ConstantIndex::LENGTH_STRING_INDEX, factory->NewFromCanBeCompressString("length"));
|
||||
SetConstant(ConstantIndex::VALUE_STRING_INDEX, factory->NewFromCanBeCompressString("value"));
|
||||
SetConstant(ConstantIndex::SET_STRING_INDEX, factory->NewFromCanBeCompressString("set"));
|
||||
SetConstant(ConstantIndex::GET_STRING_INDEX, factory->NewFromCanBeCompressString("get"));
|
||||
SetConstant(ConstantIndex::WRITABLE_STRING_INDEX, factory->NewFromCanBeCompressString("writable"));
|
||||
SetConstant(ConstantIndex::ENUMERABLE_STRING_INDEX, factory->NewFromCanBeCompressString("enumerable"));
|
||||
SetConstant(ConstantIndex::CONFIGURABLE_STRING_INDEX, factory->NewFromCanBeCompressString("configurable"));
|
||||
/* SymbolTable *RegisterSymbols */
|
||||
SetConstant(ConstantIndex::NAME_STRING_INDEX, factory->NewFromCanBeCompressString("name").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::GETPROTOTYPEOF_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("getPrototypeOf").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::SETPROTOTYPEOF_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("setPrototypeOf").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::ISEXTENSIBLE_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("isExtensible").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::NAME_STRING_INDEX, factory->NewFromCanBeCompressString("name"));
|
||||
SetConstant(ConstantIndex::GETPROTOTYPEOF_STRING_INDEX, factory->NewFromCanBeCompressString("getPrototypeOf"));
|
||||
SetConstant(ConstantIndex::SETPROTOTYPEOF_STRING_INDEX, factory->NewFromCanBeCompressString("setPrototypeOf"));
|
||||
SetConstant(ConstantIndex::ISEXTENSIBLE_STRING_INDEX, factory->NewFromCanBeCompressString("isExtensible"));
|
||||
SetConstant(ConstantIndex::PREVENTEXTENSIONS_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("preventExtensions").GetTaggedValue());
|
||||
factory->NewFromCanBeCompressString("preventExtensions"));
|
||||
SetConstant(ConstantIndex::GETOWNPROPERTYDESCRIPTOR_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("getOwnPropertyDescriptor").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::DEFINEPROPERTY_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("defineProperty").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::HAS_STRING_INDEX, factory->NewFromCanBeCompressString("has").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::DELETEPROPERTY_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("deleteProperty").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::ENUMERATE_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("enumerate").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::OWNKEYS_STRING_INDEX, factory->NewFromCanBeCompressString("ownKeys").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::APPLY_STRING_INDEX, factory->NewFromCanBeCompressString("apply").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::NEGATIVE_ZERO_STRING_INDEX, factory->NewFromCanBeCompressString("-0").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::DONE_STRING_INDEX, factory->NewFromCanBeCompressString("done").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::PROXY_STRING_INDEX, factory->NewFromCanBeCompressString("proxy").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::REVOKE_STRING_INDEX, factory->NewFromCanBeCompressString("revoke").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::NEXT_STRING_INDEX, factory->NewFromCanBeCompressString("next").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::TO_STRING_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("toString").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::TO_LOCALE_STRING_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("toLocaleString").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::VALUE_OF_STRING_INDEX, factory->NewFromCanBeCompressString("valueOf").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::UNDEFINED_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("undefined").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::NULL_STRING_INDEX, factory->NewFromCanBeCompressString("null").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::BOOLEAN_STRING_INDEX, factory->NewFromCanBeCompressString("boolean").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::NUMBER_STRING_INDEX, factory->NewFromCanBeCompressString("number").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::FUNCTION_STRING_INDEX, factory->NewFromCanBeCompressString("function").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::STRING_STRING_INDEX, factory->NewFromCanBeCompressString("string").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::SYMBOL_STRING_INDEX, factory->NewFromCanBeCompressString("symbol").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::OBJECT_STRING_INDEX, factory->NewFromCanBeCompressString("object").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::TRUE_STRING_INDEX, factory->NewFromCanBeCompressString("true").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::FALSE_STRING_INDEX, factory->NewFromCanBeCompressString("false").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::RETURN_STRING_INDEX, factory->NewFromCanBeCompressString("return").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::PROXY_CONSTRUCT_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("construct").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::PROXY_CALL_STRING_INDEX, factory->NewFromCanBeCompressString("call").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::PROMISE_THEN_STRING_INDEX, factory->NewFromCanBeCompressString("then").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::PROMISE_CATCH_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("catch").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::SCRIPT_JOB_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("ScriptJobs").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::PROMISE_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("PrimiseJobs").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::THROWER_STRING_INDEX, factory->NewFromCanBeCompressString("Thrower").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::IDENTITY_STRING_INDEX, factory->NewFromCanBeCompressString("Identity").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::CALLER_STRING_INDEX, factory->NewFromCanBeCompressString("caller").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::CALLEE_STRING_INDEX, factory->NewFromCanBeCompressString("callee").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::INT8_ARRAY_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("Int8Array").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::UINT8_ARRAY_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("Uint8Array").GetTaggedValue());
|
||||
factory->NewFromCanBeCompressString("getOwnPropertyDescriptor"));
|
||||
SetConstant(ConstantIndex::DEFINEPROPERTY_STRING_INDEX, factory->NewFromCanBeCompressString("defineProperty"));
|
||||
SetConstant(ConstantIndex::HAS_STRING_INDEX, factory->NewFromCanBeCompressString("has"));
|
||||
SetConstant(ConstantIndex::DELETEPROPERTY_STRING_INDEX, factory->NewFromCanBeCompressString("deleteProperty"));
|
||||
SetConstant(ConstantIndex::ENUMERATE_STRING_INDEX, factory->NewFromCanBeCompressString("enumerate"));
|
||||
SetConstant(ConstantIndex::OWNKEYS_STRING_INDEX, factory->NewFromCanBeCompressString("ownKeys"));
|
||||
SetConstant(ConstantIndex::APPLY_STRING_INDEX, factory->NewFromCanBeCompressString("apply"));
|
||||
SetConstant(ConstantIndex::NEGATIVE_ZERO_STRING_INDEX, factory->NewFromCanBeCompressString("-0"));
|
||||
SetConstant(ConstantIndex::DONE_STRING_INDEX, factory->NewFromCanBeCompressString("done"));
|
||||
SetConstant(ConstantIndex::PROXY_STRING_INDEX, factory->NewFromCanBeCompressString("proxy"));
|
||||
SetConstant(ConstantIndex::REVOKE_STRING_INDEX, factory->NewFromCanBeCompressString("revoke"));
|
||||
SetConstant(ConstantIndex::NEXT_STRING_INDEX, factory->NewFromCanBeCompressString("next"));
|
||||
SetConstant(ConstantIndex::TO_STRING_STRING_INDEX, factory->NewFromCanBeCompressString("toString"));
|
||||
SetConstant(ConstantIndex::TO_LOCALE_STRING_STRING_INDEX, factory->NewFromCanBeCompressString("toLocaleString"));
|
||||
SetConstant(ConstantIndex::VALUE_OF_STRING_INDEX, factory->NewFromCanBeCompressString("valueOf"));
|
||||
SetConstant(ConstantIndex::UNDEFINED_STRING_INDEX, factory->NewFromCanBeCompressString("undefined"));
|
||||
SetConstant(ConstantIndex::NULL_STRING_INDEX, factory->NewFromCanBeCompressString("null"));
|
||||
SetConstant(ConstantIndex::BOOLEAN_STRING_INDEX, factory->NewFromCanBeCompressString("boolean"));
|
||||
SetConstant(ConstantIndex::NUMBER_STRING_INDEX, factory->NewFromCanBeCompressString("number"));
|
||||
SetConstant(ConstantIndex::FUNCTION_STRING_INDEX, factory->NewFromCanBeCompressString("function"));
|
||||
SetConstant(ConstantIndex::STRING_STRING_INDEX, factory->NewFromCanBeCompressString("string"));
|
||||
SetConstant(ConstantIndex::SYMBOL_STRING_INDEX, factory->NewFromCanBeCompressString("symbol"));
|
||||
SetConstant(ConstantIndex::OBJECT_STRING_INDEX, factory->NewFromCanBeCompressString("object"));
|
||||
SetConstant(ConstantIndex::TRUE_STRING_INDEX, factory->NewFromCanBeCompressString("true"));
|
||||
SetConstant(ConstantIndex::FALSE_STRING_INDEX, factory->NewFromCanBeCompressString("false"));
|
||||
SetConstant(ConstantIndex::RETURN_STRING_INDEX, factory->NewFromCanBeCompressString("return"));
|
||||
SetConstant(ConstantIndex::PROXY_CONSTRUCT_STRING_INDEX, factory->NewFromCanBeCompressString("construct"));
|
||||
SetConstant(ConstantIndex::PROXY_CALL_STRING_INDEX, factory->NewFromCanBeCompressString("call"));
|
||||
SetConstant(ConstantIndex::PROMISE_THEN_STRING_INDEX, factory->NewFromCanBeCompressString("then"));
|
||||
SetConstant(ConstantIndex::PROMISE_CATCH_STRING_INDEX, factory->NewFromCanBeCompressString("catch"));
|
||||
SetConstant(ConstantIndex::SCRIPT_JOB_STRING_INDEX, factory->NewFromCanBeCompressString("ScriptJobs"));
|
||||
SetConstant(ConstantIndex::PROMISE_STRING_INDEX, factory->NewFromCanBeCompressString("PrimiseJobs"));
|
||||
SetConstant(ConstantIndex::THROWER_STRING_INDEX, factory->NewFromCanBeCompressString("Thrower"));
|
||||
SetConstant(ConstantIndex::IDENTITY_STRING_INDEX, factory->NewFromCanBeCompressString("Identity"));
|
||||
SetConstant(ConstantIndex::CALLER_STRING_INDEX, factory->NewFromCanBeCompressString("caller"));
|
||||
SetConstant(ConstantIndex::CALLEE_STRING_INDEX, factory->NewFromCanBeCompressString("callee"));
|
||||
SetConstant(ConstantIndex::INT8_ARRAY_STRING_INDEX, factory->NewFromCanBeCompressString("Int8Array"));
|
||||
SetConstant(ConstantIndex::UINT8_ARRAY_STRING_INDEX, factory->NewFromCanBeCompressString("Uint8Array"));
|
||||
SetConstant(ConstantIndex::UINT8_CLAMPED_ARRAY_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("Uint8ClampedArray").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::INT16_ARRAY_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("Int16Array").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::UINT16_ARRAY_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("Uint16Array").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::INT32_ARRAY_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("Int32Array").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::UINT32_ARRAY_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("Uint32Array").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::FLOAT32_ARRAY_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("Float32Array").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::FLOAT64_ARRAY_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("Float64Array").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::ASYNC_FUNCTION_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("AsyncFunction").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::PROMISE_RESOLVE_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("resolve").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::ID_STRING_INDEX, factory->NewFromCanBeCompressString("id").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::METHOD_STRING_INDEX, factory->NewFromCanBeCompressString("method").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::PARAMS_STRING_INDEX, factory->NewFromCanBeCompressString("params").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::RESULT_STRING_INDEX, factory->NewFromCanBeCompressString("result").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::TO_JSON_STRING_INDEX, factory->NewFromCanBeCompressString("toJSON").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::GLOBAL_STRING_INDEX, factory->NewFromCanBeCompressString("global").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::MESSAGE_STRING_INDEX, factory->NewFromCanBeCompressString("message").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::ERROR_STRING_INDEX, factory->NewFromCanBeCompressString("Error").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::RANGE_ERROR_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("RangeError").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::REFERENCE_ERROR_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("ReferenceError").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::TYPE_ERROR_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("TypeError").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::URI_ERROR_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("URIError").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::SYNTAX_ERROR_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("SyntaxError").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::EVAL_ERROR_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("EvalError").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::STACK_STRING_INDEX, factory->NewFromCanBeCompressString("stack").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::STACK_EMPTY_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("stackisempty").GetTaggedValue());
|
||||
factory->NewFromCanBeCompressString("Uint8ClampedArray"));
|
||||
SetConstant(ConstantIndex::INT16_ARRAY_STRING_INDEX, factory->NewFromCanBeCompressString("Int16Array"));
|
||||
SetConstant(ConstantIndex::UINT16_ARRAY_STRING_INDEX, factory->NewFromCanBeCompressString("Uint16Array"));
|
||||
SetConstant(ConstantIndex::INT32_ARRAY_STRING_INDEX, factory->NewFromCanBeCompressString("Int32Array"));
|
||||
SetConstant(ConstantIndex::UINT32_ARRAY_STRING_INDEX, factory->NewFromCanBeCompressString("Uint32Array"));
|
||||
SetConstant(ConstantIndex::FLOAT32_ARRAY_STRING_INDEX, factory->NewFromCanBeCompressString("Float32Array"));
|
||||
SetConstant(ConstantIndex::FLOAT64_ARRAY_STRING_INDEX, factory->NewFromCanBeCompressString("Float64Array"));
|
||||
SetConstant(ConstantIndex::ASYNC_FUNCTION_STRING_INDEX, factory->NewFromCanBeCompressString("AsyncFunction"));
|
||||
SetConstant(ConstantIndex::PROMISE_RESOLVE_STRING_INDEX, factory->NewFromCanBeCompressString("resolve"));
|
||||
SetConstant(ConstantIndex::ID_STRING_INDEX, factory->NewFromCanBeCompressString("id"));
|
||||
SetConstant(ConstantIndex::METHOD_STRING_INDEX, factory->NewFromCanBeCompressString("method"));
|
||||
SetConstant(ConstantIndex::PARAMS_STRING_INDEX, factory->NewFromCanBeCompressString("params"));
|
||||
SetConstant(ConstantIndex::RESULT_STRING_INDEX, factory->NewFromCanBeCompressString("result"));
|
||||
SetConstant(ConstantIndex::TO_JSON_STRING_INDEX, factory->NewFromCanBeCompressString("toJSON"));
|
||||
SetConstant(ConstantIndex::GLOBAL_STRING_INDEX, factory->NewFromCanBeCompressString("global"));
|
||||
SetConstant(ConstantIndex::MESSAGE_STRING_INDEX, factory->NewFromCanBeCompressString("message"));
|
||||
SetConstant(ConstantIndex::ERROR_STRING_INDEX, factory->NewFromCanBeCompressString("Error"));
|
||||
SetConstant(ConstantIndex::RANGE_ERROR_STRING_INDEX, factory->NewFromCanBeCompressString("RangeError"));
|
||||
SetConstant(ConstantIndex::REFERENCE_ERROR_STRING_INDEX, factory->NewFromCanBeCompressString("ReferenceError"));
|
||||
SetConstant(ConstantIndex::TYPE_ERROR_STRING_INDEX, factory->NewFromCanBeCompressString("TypeError"));
|
||||
SetConstant(ConstantIndex::URI_ERROR_STRING_INDEX, factory->NewFromCanBeCompressString("URIError"));
|
||||
SetConstant(ConstantIndex::SYNTAX_ERROR_STRING_INDEX, factory->NewFromCanBeCompressString("SyntaxError"));
|
||||
SetConstant(ConstantIndex::EVAL_ERROR_STRING_INDEX, factory->NewFromCanBeCompressString("EvalError"));
|
||||
SetConstant(ConstantIndex::STACK_STRING_INDEX, factory->NewFromCanBeCompressString("stack"));
|
||||
SetConstant(ConstantIndex::STACK_EMPTY_STRING_INDEX, factory->NewFromCanBeCompressString("stackisempty"));
|
||||
SetConstant(ConstantIndex::OBJ_NOT_COERCIBLE_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("objectnotcoercible").GetTaggedValue());
|
||||
factory->NewFromCanBeCompressString("objectnotcoercible"));
|
||||
/* for Intl. */
|
||||
SetConstant(ConstantIndex::LANGUAGE_STRING_CLASS_INDEX,
|
||||
factory->NewFromCanBeCompressString("language").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::SCRIPT_STRING_CLASS_INDEX,
|
||||
factory->NewFromCanBeCompressString("script").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::REGION_STRING_CLASS_INDEX,
|
||||
factory->NewFromCanBeCompressString("region").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::BASE_NAME_STRING_CLASS_INDEX,
|
||||
factory->NewFromCanBeCompressString("baseName").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::CALENDAR_STRING_CLASS_INDEX,
|
||||
factory->NewFromCanBeCompressString("calendar").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::COLLATION_STRING_CLASS_INDEX,
|
||||
factory->NewFromCanBeCompressString("collation").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::HOUR_CYCLE_STRING_CLASS_INDEX,
|
||||
factory->NewFromCanBeCompressString("hourCycle").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::CASE_FIRST_STRING_CLASS_INDEX,
|
||||
factory->NewFromCanBeCompressString("caseFirst").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::NUMERIC_STRING_CLASS_INDEX,
|
||||
factory->NewFromCanBeCompressString("numeric").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::LANGUAGE_STRING_CLASS_INDEX, factory->NewFromCanBeCompressString("language"));
|
||||
SetConstant(ConstantIndex::SCRIPT_STRING_CLASS_INDEX, factory->NewFromCanBeCompressString("script"));
|
||||
SetConstant(ConstantIndex::REGION_STRING_CLASS_INDEX, factory->NewFromCanBeCompressString("region"));
|
||||
SetConstant(ConstantIndex::BASE_NAME_STRING_CLASS_INDEX, factory->NewFromCanBeCompressString("baseName"));
|
||||
SetConstant(ConstantIndex::CALENDAR_STRING_CLASS_INDEX, factory->NewFromCanBeCompressString("calendar"));
|
||||
SetConstant(ConstantIndex::COLLATION_STRING_CLASS_INDEX, factory->NewFromCanBeCompressString("collation"));
|
||||
SetConstant(ConstantIndex::HOUR_CYCLE_STRING_CLASS_INDEX, factory->NewFromCanBeCompressString("hourCycle"));
|
||||
SetConstant(ConstantIndex::CASE_FIRST_STRING_CLASS_INDEX, factory->NewFromCanBeCompressString("caseFirst"));
|
||||
SetConstant(ConstantIndex::NUMERIC_STRING_CLASS_INDEX, factory->NewFromCanBeCompressString("numeric"));
|
||||
SetConstant(ConstantIndex::NUMBERING_SYSTEM_STRING_CLASS_INDEX,
|
||||
factory->NewFromCanBeCompressString("numberingSystem").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::TYPE_STRING_INDEX, factory->NewFromCanBeCompressString("type").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::LOCALE_MATCHER_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("localeMatcher").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::FORMAT_MATCHER_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("formatMatcher").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::HOUR12_STRING_INDEX, factory->NewFromCanBeCompressString("hour12").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::H11_STRING_INDEX, factory->NewFromCanBeCompressString("h11").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::H12_STRING_INDEX, factory->NewFromCanBeCompressString("h12").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::H23_STRING_INDEX, factory->NewFromCanBeCompressString("h23").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::H24_STRING_INDEX, factory->NewFromCanBeCompressString("h24").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::WEEK_DAY_STRING_INDEX, factory->NewFromCanBeCompressString("weekday").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::ERA_STRING_INDEX, factory->NewFromCanBeCompressString("era").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::YEAR_STRING_INDEX, factory->NewFromCanBeCompressString("year").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::QUARTER_STRING_INDEX, factory->NewFromCanBeCompressString("quarter").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::MONTH_STRING_INDEX, factory->NewFromCanBeCompressString("month").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::DAY_STRING_INDEX, factory->NewFromCanBeCompressString("day").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::HOUR_STRING_INDEX, factory->NewFromCanBeCompressString("hour").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::MINUTE_STRING_INDEX, factory->NewFromCanBeCompressString("minute").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::SECOND_STRING_INDEX, factory->NewFromCanBeCompressString("second").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::YEARS_STRING_INDEX, factory->NewFromCanBeCompressString("years").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::QUARTERS_STRING_INDEX, factory->NewFromCanBeCompressString("quarters").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::MONTHS_STRING_INDEX, factory->NewFromCanBeCompressString("months").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::DAYS_STRING_INDEX, factory->NewFromCanBeCompressString("days").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::HOURS_STRING_INDEX, factory->NewFromCanBeCompressString("hours").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::MINUTES_STRING_INDEX, factory->NewFromCanBeCompressString("minutes").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::SECONDS_STRING_INDEX, factory->NewFromCanBeCompressString("seconds").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::TIME_ZONE_NAME_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("timeZoneName").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::LOCALE_STRING_INDEX, factory->NewFromCanBeCompressString("locale").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::TIME_ZONE_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("timeZone").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::LITERAL_STRING_INDEX, factory->NewFromCanBeCompressString("literal").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::YEAR_NAME_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("yearName").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::DAY_PERIOD_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("dayPeriod").GetTaggedValue());
|
||||
factory->NewFromCanBeCompressString("numberingSystem"));
|
||||
SetConstant(ConstantIndex::TYPE_STRING_INDEX, factory->NewFromCanBeCompressString("type"));
|
||||
SetConstant(ConstantIndex::LOCALE_MATCHER_STRING_INDEX, factory->NewFromCanBeCompressString("localeMatcher"));
|
||||
SetConstant(ConstantIndex::FORMAT_MATCHER_STRING_INDEX, factory->NewFromCanBeCompressString("formatMatcher"));
|
||||
SetConstant(ConstantIndex::HOUR12_STRING_INDEX, factory->NewFromCanBeCompressString("hour12"));
|
||||
SetConstant(ConstantIndex::H11_STRING_INDEX, factory->NewFromCanBeCompressString("h11"));
|
||||
SetConstant(ConstantIndex::H12_STRING_INDEX, factory->NewFromCanBeCompressString("h12"));
|
||||
SetConstant(ConstantIndex::H23_STRING_INDEX, factory->NewFromCanBeCompressString("h23"));
|
||||
SetConstant(ConstantIndex::H24_STRING_INDEX, factory->NewFromCanBeCompressString("h24"));
|
||||
SetConstant(ConstantIndex::WEEK_DAY_STRING_INDEX, factory->NewFromCanBeCompressString("weekday"));
|
||||
SetConstant(ConstantIndex::ERA_STRING_INDEX, factory->NewFromCanBeCompressString("era"));
|
||||
SetConstant(ConstantIndex::YEAR_STRING_INDEX, factory->NewFromCanBeCompressString("year"));
|
||||
SetConstant(ConstantIndex::QUARTER_STRING_INDEX, factory->NewFromCanBeCompressString("quarter"));
|
||||
SetConstant(ConstantIndex::MONTH_STRING_INDEX, factory->NewFromCanBeCompressString("month"));
|
||||
SetConstant(ConstantIndex::DAY_STRING_INDEX, factory->NewFromCanBeCompressString("day"));
|
||||
SetConstant(ConstantIndex::HOUR_STRING_INDEX, factory->NewFromCanBeCompressString("hour"));
|
||||
SetConstant(ConstantIndex::MINUTE_STRING_INDEX, factory->NewFromCanBeCompressString("minute"));
|
||||
SetConstant(ConstantIndex::SECOND_STRING_INDEX, factory->NewFromCanBeCompressString("second"));
|
||||
SetConstant(ConstantIndex::YEARS_STRING_INDEX, factory->NewFromCanBeCompressString("years"));
|
||||
SetConstant(ConstantIndex::QUARTERS_STRING_INDEX, factory->NewFromCanBeCompressString("quarters"));
|
||||
SetConstant(ConstantIndex::MONTHS_STRING_INDEX, factory->NewFromCanBeCompressString("months"));
|
||||
SetConstant(ConstantIndex::DAYS_STRING_INDEX, factory->NewFromCanBeCompressString("days"));
|
||||
SetConstant(ConstantIndex::HOURS_STRING_INDEX, factory->NewFromCanBeCompressString("hours"));
|
||||
SetConstant(ConstantIndex::MINUTES_STRING_INDEX, factory->NewFromCanBeCompressString("minutes"));
|
||||
SetConstant(ConstantIndex::SECONDS_STRING_INDEX, factory->NewFromCanBeCompressString("seconds"));
|
||||
SetConstant(ConstantIndex::TIME_ZONE_NAME_STRING_INDEX, factory->NewFromCanBeCompressString("timeZoneName"));
|
||||
SetConstant(ConstantIndex::LOCALE_STRING_INDEX, factory->NewFromCanBeCompressString("locale"));
|
||||
SetConstant(ConstantIndex::TIME_ZONE_STRING_INDEX, factory->NewFromCanBeCompressString("timeZone"));
|
||||
SetConstant(ConstantIndex::LITERAL_STRING_INDEX, factory->NewFromCanBeCompressString("literal"));
|
||||
SetConstant(ConstantIndex::YEAR_NAME_STRING_INDEX, factory->NewFromCanBeCompressString("yearName"));
|
||||
SetConstant(ConstantIndex::DAY_PERIOD_STRING_INDEX, factory->NewFromCanBeCompressString("dayPeriod"));
|
||||
SetConstant(ConstantIndex::FRACTIONAL_SECOND_DIGITS_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("fractionalSecondDigits").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::FRACTIONAL_SECOND_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("fractionalSecond").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::RELATED_YEAR_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("relatedYear").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::LOOK_UP_STRING_INDEX, factory->NewFromCanBeCompressString("lookup").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::BEST_FIT_STRING_INDEX, factory->NewFromCanBeCompressString("bestfit").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::DATE_STYLE_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("dateStyle").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::TIME_STYLE_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("timeStyle").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::UTC_STRING_INDEX, factory->NewFromCanBeCompressString("UTC").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::INITIALIZED_RELATIVE_INDEX,
|
||||
factory->NewFromCanBeCompressString("true").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::WEEK_STRING_INDEX, factory->NewFromCanBeCompressString("week").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::WEEKS_STRING_INDEX, factory->NewFromCanBeCompressString("weeks").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::SOURCE_STRING_INDEX, factory->NewFromCanBeCompressString("source").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::FORMAT_STRING_INDEX, factory->NewFromCanBeCompressString("format").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::EN_US_STRING_INDEX, factory->NewFromCanBeCompressString("en-US").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::UND_STRING_INDEX, factory->NewFromCanBeCompressString("und").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::LATN_STRING_INDEX, factory->NewFromCanBeCompressString("latn").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::STYLE_STRING_INDEX, factory->NewFromCanBeCompressString("style").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::UNIT_STRING_INDEX, factory->NewFromCanBeCompressString("unit").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::INTEGER_STRING_INDEX, factory->NewFromCanBeCompressString("integer").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::NAN_STRING_INDEX, factory->NewFromCanBeCompressString("nan").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::INFINITY_STRING_INDEX, factory->NewFromCanBeCompressString("infinity").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::FRACTION_STRING_INDEX, factory->NewFromCanBeCompressString("fraction").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::DECIMAL_STRING_INDEX, factory->NewFromCanBeCompressString("decimal").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::GROUP_STRING_INDEX, factory->NewFromCanBeCompressString("group").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::CURRENCY_STRING_INDEX, factory->NewFromCanBeCompressString("currency").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::CURRENCY_SIGN_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("currencySign").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::CURRENCY_DISPLAY_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("currencyDisplay").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::PERCENT_SIGN_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("percentSign").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::PERCENT_STRING_INDEX, factory->NewFromCanBeCompressString("percent").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::MINUS_SIGN_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("minusSign").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::PLUS_SIGN_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("plusSign").GetTaggedValue());
|
||||
factory->NewFromCanBeCompressString("fractionalSecondDigits"));
|
||||
SetConstant(ConstantIndex::FRACTIONAL_SECOND_STRING_INDEX, factory->NewFromCanBeCompressString("fractionalSecond"));
|
||||
SetConstant(ConstantIndex::RELATED_YEAR_STRING_INDEX, factory->NewFromCanBeCompressString("relatedYear"));
|
||||
SetConstant(ConstantIndex::LOOK_UP_STRING_INDEX, factory->NewFromCanBeCompressString("lookup"));
|
||||
SetConstant(ConstantIndex::BEST_FIT_STRING_INDEX, factory->NewFromCanBeCompressString("bestfit"));
|
||||
SetConstant(ConstantIndex::DATE_STYLE_STRING_INDEX, factory->NewFromCanBeCompressString("dateStyle"));
|
||||
SetConstant(ConstantIndex::TIME_STYLE_STRING_INDEX, factory->NewFromCanBeCompressString("timeStyle"));
|
||||
SetConstant(ConstantIndex::UTC_STRING_INDEX, factory->NewFromCanBeCompressString("UTC"));
|
||||
SetConstant(ConstantIndex::INITIALIZED_RELATIVE_INDEX, factory->NewFromCanBeCompressString("true"));
|
||||
SetConstant(ConstantIndex::WEEK_STRING_INDEX, factory->NewFromCanBeCompressString("week"));
|
||||
SetConstant(ConstantIndex::WEEKS_STRING_INDEX, factory->NewFromCanBeCompressString("weeks"));
|
||||
SetConstant(ConstantIndex::SOURCE_STRING_INDEX, factory->NewFromCanBeCompressString("source"));
|
||||
SetConstant(ConstantIndex::FORMAT_STRING_INDEX, factory->NewFromCanBeCompressString("format"));
|
||||
SetConstant(ConstantIndex::EN_US_STRING_INDEX, factory->NewFromCanBeCompressString("en-US"));
|
||||
SetConstant(ConstantIndex::UND_STRING_INDEX, factory->NewFromCanBeCompressString("und"));
|
||||
SetConstant(ConstantIndex::LATN_STRING_INDEX, factory->NewFromCanBeCompressString("latn"));
|
||||
SetConstant(ConstantIndex::STYLE_STRING_INDEX, factory->NewFromCanBeCompressString("style"));
|
||||
SetConstant(ConstantIndex::UNIT_STRING_INDEX, factory->NewFromCanBeCompressString("unit"));
|
||||
SetConstant(ConstantIndex::INTEGER_STRING_INDEX, factory->NewFromCanBeCompressString("integer"));
|
||||
SetConstant(ConstantIndex::NAN_STRING_INDEX, factory->NewFromCanBeCompressString("nan"));
|
||||
SetConstant(ConstantIndex::INFINITY_STRING_INDEX, factory->NewFromCanBeCompressString("infinity"));
|
||||
SetConstant(ConstantIndex::FRACTION_STRING_INDEX, factory->NewFromCanBeCompressString("fraction"));
|
||||
SetConstant(ConstantIndex::DECIMAL_STRING_INDEX, factory->NewFromCanBeCompressString("decimal"));
|
||||
SetConstant(ConstantIndex::GROUP_STRING_INDEX, factory->NewFromCanBeCompressString("group"));
|
||||
SetConstant(ConstantIndex::CURRENCY_STRING_INDEX, factory->NewFromCanBeCompressString("currency"));
|
||||
SetConstant(ConstantIndex::CURRENCY_SIGN_STRING_INDEX, factory->NewFromCanBeCompressString("currencySign"));
|
||||
SetConstant(ConstantIndex::CURRENCY_DISPLAY_STRING_INDEX, factory->NewFromCanBeCompressString("currencyDisplay"));
|
||||
SetConstant(ConstantIndex::PERCENT_SIGN_STRING_INDEX, factory->NewFromCanBeCompressString("percentSign"));
|
||||
SetConstant(ConstantIndex::PERCENT_STRING_INDEX, factory->NewFromCanBeCompressString("percent"));
|
||||
SetConstant(ConstantIndex::MINUS_SIGN_STRING_INDEX, factory->NewFromCanBeCompressString("minusSign"));
|
||||
SetConstant(ConstantIndex::PLUS_SIGN_STRING_INDEX, factory->NewFromCanBeCompressString("plusSign"));
|
||||
SetConstant(ConstantIndex::EXPONENT_SEPARATOR_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("exponentSeparator").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::EXPONENT_MINUS_SIGN_INDEX,
|
||||
factory->NewFromCanBeCompressString("exponentMinusSign").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::EXPONENT_INTEGER_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("exponentInteger").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::LONG_STRING_INDEX, factory->NewFromCanBeCompressString("long").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::SHORT_STRING_INDEX, factory->NewFromCanBeCompressString("short").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::FULL_STRING_INDEX, factory->NewFromCanBeCompressString("full").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::MEDIUM_STRING_INDEX, factory->NewFromCanBeCompressString("medium").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::NARROW_STRING_INDEX, factory->NewFromCanBeCompressString("narrow").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::ALWAYS_STRING_INDEX, factory->NewFromCanBeCompressString("always").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::AUTO_STRING_INDEX, factory->NewFromCanBeCompressString("auto").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::UNIT_DISPLAY_INDEX, factory->NewFromCanBeCompressString("unitDisplay").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::NOTATION_INDEX, factory->NewFromCanBeCompressString("notation").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::COMPACT_DISPALY_INDEX,
|
||||
factory->NewFromCanBeCompressString("compactDisplay").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::USER_GROUPING_INDEX,
|
||||
factory->NewFromCanBeCompressString("useGrouping").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::SIGN_DISPLAY_INDEX, factory->NewFromCanBeCompressString("signDisplay").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::CODE_INDEX, factory->NewFromCanBeCompressString("code").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::NARROW_SYMBOL_INDEX,
|
||||
factory->NewFromCanBeCompressString("narrowSymbol").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::STANDARD_INDEX, factory->NewFromCanBeCompressString("standard").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::ACCOUNTING_INDEX, factory->NewFromCanBeCompressString("accounting").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::SCIENTIFIC_INDEX, factory->NewFromCanBeCompressString("scientific").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::ENGINEERING_INDEX, factory->NewFromCanBeCompressString("engineering").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::COMPACT_STRING_INDEX, factory->NewFromCanBeCompressString("compact").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::NEVER_INDEX, factory->NewFromCanBeCompressString("never").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::EXPECT_ZERO_INDEX, factory->NewFromCanBeCompressString("exceptZero").GetTaggedValue());
|
||||
factory->NewFromCanBeCompressString("exponentSeparator"));
|
||||
SetConstant(ConstantIndex::EXPONENT_MINUS_SIGN_INDEX, factory->NewFromCanBeCompressString("exponentMinusSign"));
|
||||
SetConstant(ConstantIndex::EXPONENT_INTEGER_STRING_INDEX, factory->NewFromCanBeCompressString("exponentInteger"));
|
||||
SetConstant(ConstantIndex::LONG_STRING_INDEX, factory->NewFromCanBeCompressString("long"));
|
||||
SetConstant(ConstantIndex::SHORT_STRING_INDEX, factory->NewFromCanBeCompressString("short"));
|
||||
SetConstant(ConstantIndex::FULL_STRING_INDEX, factory->NewFromCanBeCompressString("full"));
|
||||
SetConstant(ConstantIndex::MEDIUM_STRING_INDEX, factory->NewFromCanBeCompressString("medium"));
|
||||
SetConstant(ConstantIndex::NARROW_STRING_INDEX, factory->NewFromCanBeCompressString("narrow"));
|
||||
SetConstant(ConstantIndex::ALWAYS_STRING_INDEX, factory->NewFromCanBeCompressString("always"));
|
||||
SetConstant(ConstantIndex::AUTO_STRING_INDEX, factory->NewFromCanBeCompressString("auto"));
|
||||
SetConstant(ConstantIndex::UNIT_DISPLAY_INDEX, factory->NewFromCanBeCompressString("unitDisplay"));
|
||||
SetConstant(ConstantIndex::NOTATION_INDEX, factory->NewFromCanBeCompressString("notation"));
|
||||
SetConstant(ConstantIndex::COMPACT_DISPALY_INDEX, factory->NewFromCanBeCompressString("compactDisplay"));
|
||||
SetConstant(ConstantIndex::USER_GROUPING_INDEX, factory->NewFromCanBeCompressString("useGrouping"));
|
||||
SetConstant(ConstantIndex::SIGN_DISPLAY_INDEX, factory->NewFromCanBeCompressString("signDisplay"));
|
||||
SetConstant(ConstantIndex::CODE_INDEX, factory->NewFromCanBeCompressString("code"));
|
||||
SetConstant(ConstantIndex::NARROW_SYMBOL_INDEX, factory->NewFromCanBeCompressString("narrowSymbol"));
|
||||
SetConstant(ConstantIndex::STANDARD_INDEX, factory->NewFromCanBeCompressString("standard"));
|
||||
SetConstant(ConstantIndex::ACCOUNTING_INDEX, factory->NewFromCanBeCompressString("accounting"));
|
||||
SetConstant(ConstantIndex::SCIENTIFIC_INDEX, factory->NewFromCanBeCompressString("scientific"));
|
||||
SetConstant(ConstantIndex::ENGINEERING_INDEX, factory->NewFromCanBeCompressString("engineering"));
|
||||
SetConstant(ConstantIndex::COMPACT_STRING_INDEX, factory->NewFromCanBeCompressString("compact"));
|
||||
SetConstant(ConstantIndex::NEVER_INDEX, factory->NewFromCanBeCompressString("never"));
|
||||
SetConstant(ConstantIndex::EXPECT_ZERO_INDEX, factory->NewFromCanBeCompressString("exceptZero"));
|
||||
SetConstant(ConstantIndex::MINIMUM_INTEGER_DIGITS_INDEX,
|
||||
factory->NewFromCanBeCompressString("minimumIntegerDigits").GetTaggedValue());
|
||||
factory->NewFromCanBeCompressString("minimumIntegerDigits"));
|
||||
SetConstant(ConstantIndex::MINIMUM_FRACTIONDIGITS_INDEX,
|
||||
factory->NewFromCanBeCompressString("minimumFractionDigits").GetTaggedValue());
|
||||
factory->NewFromCanBeCompressString("minimumFractionDigits"));
|
||||
SetConstant(ConstantIndex::MAXIMUM_FRACTIONDIGITS_INDEX,
|
||||
factory->NewFromCanBeCompressString("maximumFractionDigits").GetTaggedValue());
|
||||
factory->NewFromCanBeCompressString("maximumFractionDigits"));
|
||||
SetConstant(ConstantIndex::MINIMUM_SIGNIFICANTDIGITS_INDEX,
|
||||
factory->NewFromCanBeCompressString("minimumSignificantDigits").GetTaggedValue());
|
||||
factory->NewFromCanBeCompressString("minimumSignificantDigits"));
|
||||
SetConstant(ConstantIndex::MAXIMUM_SIGNIFICANTDIGITS_INDEX,
|
||||
factory->NewFromCanBeCompressString("maximumSignificantDigits").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::INVALID_DATE_INDEX,
|
||||
factory->NewFromCanBeCompressString("Invalid Date").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::USAGE_INDEX, factory->NewFromCanBeCompressString("usage").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::COMPARE_INDEX, factory->NewFromCanBeCompressString("compare").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::SENSITIVITY_INDEX, factory->NewFromCanBeCompressString("sensitivity").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::IGNORE_PUNCTUATION_INDEX,
|
||||
factory->NewFromCanBeCompressString("ignorePunctuation").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::CARDINAL_INDEX, factory->NewFromCanBeCompressString("cardinal").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::ORDINAL_INDEX, factory->NewFromCanBeCompressString("ordinal").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::EXEC_INDEX, factory->NewFromCanBeCompressString("exec").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::LAST_INDEX_INDEX, factory->NewFromCanBeCompressString("lastIndex").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::PLURAL_CATEGORIES_INDEX,
|
||||
factory->NewFromCanBeCompressString("pluralCategories").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::SORT_INDEX, factory->NewFromCanBeCompressString("sort").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::SEARCH_INDEX, factory->NewFromCanBeCompressString("search").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::BASE_INDEX, factory->NewFromCanBeCompressString("base").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::ACCENT_INDEX, factory->NewFromCanBeCompressString("accent").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::CASE_INDEX, factory->NewFromCanBeCompressString("case").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::VARIANT_INDEX, factory->NewFromCanBeCompressString("variant").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::EN_US_POSIX_STRING_INDEX,
|
||||
factory->NewFromCanBeCompressString("en-US-POSIX").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::UPPER_INDEX, factory->NewFromCanBeCompressString("upper").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::LOWER_INDEX, factory->NewFromCanBeCompressString("lower").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::DEFAULT_INDEX, factory->NewFromCanBeCompressString("default").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::SHARED_INDEX, factory->NewFromCanBeCompressString("shared").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::START_RANGE_INDEX, factory->NewFromCanBeCompressString("startRange").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::END_RANGE_INDEX, factory->NewFromCanBeCompressString("endRange").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::ISO8601_INDEX, factory->NewFromCanBeCompressString("iso8601").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::GREGORY_INDEX, factory->NewFromCanBeCompressString("gregory").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::ETHIOAA_INDEX, factory->NewFromCanBeCompressString("ethioaa").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::STICKY_INDEX, factory->NewFromCanBeCompressString("sticky").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::U_INDEX, factory->NewFromCanBeCompressString("u").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::INDEX_INDEX, factory->NewFromCanBeCompressString("index").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::INPUT_INDEX, factory->NewFromCanBeCompressString("input").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::UNICODE_INDEX, factory->NewFromCanBeCompressString("unicode").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::ZERO_INDEX, factory->NewFromCanBeCompressString("0").GetTaggedValue());
|
||||
SetConstant(ConstantIndex::VALUES_INDEX, factory->NewFromCanBeCompressString("values").GetTaggedValue());
|
||||
factory->NewFromCanBeCompressString("maximumSignificantDigits"));
|
||||
SetConstant(ConstantIndex::INVALID_DATE_INDEX, factory->NewFromCanBeCompressString("Invalid Date"));
|
||||
SetConstant(ConstantIndex::USAGE_INDEX, factory->NewFromCanBeCompressString("usage"));
|
||||
SetConstant(ConstantIndex::COMPARE_INDEX, factory->NewFromCanBeCompressString("compare"));
|
||||
SetConstant(ConstantIndex::SENSITIVITY_INDEX, factory->NewFromCanBeCompressString("sensitivity"));
|
||||
SetConstant(ConstantIndex::IGNORE_PUNCTUATION_INDEX, factory->NewFromCanBeCompressString("ignorePunctuation"));
|
||||
SetConstant(ConstantIndex::CARDINAL_INDEX, factory->NewFromCanBeCompressString("cardinal"));
|
||||
SetConstant(ConstantIndex::ORDINAL_INDEX, factory->NewFromCanBeCompressString("ordinal"));
|
||||
SetConstant(ConstantIndex::EXEC_INDEX, factory->NewFromCanBeCompressString("exec"));
|
||||
SetConstant(ConstantIndex::LAST_INDEX_INDEX, factory->NewFromCanBeCompressString("lastIndex"));
|
||||
SetConstant(ConstantIndex::PLURAL_CATEGORIES_INDEX, factory->NewFromCanBeCompressString("pluralCategories"));
|
||||
SetConstant(ConstantIndex::SORT_INDEX, factory->NewFromCanBeCompressString("sort"));
|
||||
SetConstant(ConstantIndex::SEARCH_INDEX, factory->NewFromCanBeCompressString("search"));
|
||||
SetConstant(ConstantIndex::BASE_INDEX, factory->NewFromCanBeCompressString("base"));
|
||||
SetConstant(ConstantIndex::ACCENT_INDEX, factory->NewFromCanBeCompressString("accent"));
|
||||
SetConstant(ConstantIndex::CASE_INDEX, factory->NewFromCanBeCompressString("case"));
|
||||
SetConstant(ConstantIndex::VARIANT_INDEX, factory->NewFromCanBeCompressString("variant"));
|
||||
SetConstant(ConstantIndex::EN_US_POSIX_STRING_INDEX, factory->NewFromCanBeCompressString("en-US-POSIX"));
|
||||
SetConstant(ConstantIndex::UPPER_INDEX, factory->NewFromCanBeCompressString("upper"));
|
||||
SetConstant(ConstantIndex::LOWER_INDEX, factory->NewFromCanBeCompressString("lower"));
|
||||
SetConstant(ConstantIndex::DEFAULT_INDEX, factory->NewFromCanBeCompressString("default"));
|
||||
SetConstant(ConstantIndex::SHARED_INDEX, factory->NewFromCanBeCompressString("shared"));
|
||||
SetConstant(ConstantIndex::START_RANGE_INDEX, factory->NewFromCanBeCompressString("startRange"));
|
||||
SetConstant(ConstantIndex::END_RANGE_INDEX, factory->NewFromCanBeCompressString("endRange"));
|
||||
SetConstant(ConstantIndex::ISO8601_INDEX, factory->NewFromCanBeCompressString("iso8601"));
|
||||
SetConstant(ConstantIndex::GREGORY_INDEX, factory->NewFromCanBeCompressString("gregory"));
|
||||
SetConstant(ConstantIndex::ETHIOAA_INDEX, factory->NewFromCanBeCompressString("ethioaa"));
|
||||
SetConstant(ConstantIndex::STICKY_INDEX, factory->NewFromCanBeCompressString("sticky"));
|
||||
SetConstant(ConstantIndex::U_INDEX, factory->NewFromCanBeCompressString("u"));
|
||||
SetConstant(ConstantIndex::INDEX_INDEX, factory->NewFromCanBeCompressString("index"));
|
||||
SetConstant(ConstantIndex::INPUT_INDEX, factory->NewFromCanBeCompressString("input"));
|
||||
SetConstant(ConstantIndex::UNICODE_INDEX, factory->NewFromCanBeCompressString("unicode"));
|
||||
SetConstant(ConstantIndex::ZERO_INDEX, factory->NewFromCanBeCompressString("0"));
|
||||
SetConstant(ConstantIndex::VALUES_INDEX, factory->NewFromCanBeCompressString("values"));
|
||||
|
||||
auto accessor = factory->NewInternalAccessor(reinterpret_cast<void *>(JSFunction::PrototypeSetter),
|
||||
reinterpret_cast<void *>(JSFunction::PrototypeGetter));
|
||||
SetConstant(ConstantIndex::FUNCTION_PROTOTYPE_ACCESSOR, accessor.GetTaggedValue());
|
||||
SetConstant(ConstantIndex::FUNCTION_PROTOTYPE_ACCESSOR, accessor);
|
||||
accessor = factory->NewInternalAccessor(nullptr, reinterpret_cast<void *>(JSFunction::NameGetter));
|
||||
SetConstant(ConstantIndex::FUNCTION_NAME_ACCESSOR, accessor.GetTaggedValue());
|
||||
SetConstant(ConstantIndex::FUNCTION_NAME_ACCESSOR, accessor);
|
||||
accessor = factory->NewInternalAccessor(reinterpret_cast<void *>(JSArray::LengthSetter),
|
||||
reinterpret_cast<void *>(JSArray::LengthGetter));
|
||||
SetConstant(ConstantIndex::ARRAY_LENGTH_ACCESSOR, accessor.GetTaggedValue());
|
||||
SetConstant(ConstantIndex::ARRAY_LENGTH_ACCESSOR, accessor);
|
||||
}
|
||||
|
||||
void GlobalEnvConstants::InitGlobalUndefined()
|
||||
|
@ -66,8 +66,13 @@ class JSThread;
|
||||
V(JSTaggedValue, JSRealmClass, JS_REALM_CLASS_INDEX, ecma_roots_class) \
|
||||
V(JSTaggedValue, JSRegExpClass, JS_REGEXP_CLASS_INDEX, ecma_roots_class) \
|
||||
V(JSTaggedValue, MachineCodeClass, MACHINE_CODE_CLASS_INDEX, ecma_roots_class) \
|
||||
V(JSTaggedValue, ClassInfoExtractorHClass, CLASS_INFO_EXTRACTOR_HCLASS_INDEX, ecma_roots_class)
|
||||
|
||||
V(JSTaggedValue, ClassInfoExtractorHClass, CLASS_INFO_EXTRACTOR_HCLASS_INDEX, ecma_roots_class) \
|
||||
V(JSTaggedValue, TSObjectTypeClass, TS_OBJECT_TYPE_CLASS_INDEX, ecma_roots_class) \
|
||||
V(JSTaggedValue, TSClassTypeClass, TS_CLASS_TYPE_CLASS_INDEX, ecma_roots_class) \
|
||||
V(JSTaggedValue, TSUnionTypeClass, TS_UNION_TYPE_CLASS_INDEX, ecma_roots_class) \
|
||||
V(JSTaggedValue, TSInterfaceTypeClass, TS_INTERFACE_TYPE_CLASS_INDEX, ecma_roots_class) \
|
||||
V(JSTaggedValue, TSClassInstanceTypeClass, TS_CLASS_INSTANCE_TYPE_CLASS_INDEX, ecma_roots_class) \
|
||||
V(JSTaggedValue, TSImportTypeClass, TS_IMPORT_TYPE_CLASS_INDEX, ecma_roots_class)
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
||||
#define GLOBAL_ENV_CONSTANT_SPECIAL(V) \
|
||||
V(JSTaggedValue, Undefined, UNDEFINED_INDEX, ecma_roots_special) \
|
||||
@ -343,6 +348,9 @@ public:
|
||||
|
||||
void SetConstant(ConstantIndex index, JSTaggedValue value);
|
||||
|
||||
template<typename T>
|
||||
void SetConstant(ConstantIndex index, JSHandle<T> value);
|
||||
|
||||
uintptr_t GetGlobalConstantAddr(ConstantIndex index) const;
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
||||
|
@ -358,6 +358,20 @@ CString *HeapSnapShot::GenerateNodeName(JSThread *thread, TaggedObject *entry)
|
||||
return GetString("Program");
|
||||
case JSType::MACHINE_CODE_OBJECT:
|
||||
return GetString("MachineCode");
|
||||
case JSType::CLASS_INFO_EXTRACTOR:
|
||||
return GetString("ClassInfoExtractor");
|
||||
case JSType::TS_OBJECT_TYPE:
|
||||
return GetString("TSObjectType");
|
||||
case JSType::TS_INTERFACE_TYPE:
|
||||
return GetString("TSInterfaceType");
|
||||
case JSType::TS_CLASS_TYPE:
|
||||
return GetString("TSClassType");
|
||||
case JSType::TS_UNION_TYPE:
|
||||
return GetString("TSUnionType");
|
||||
case JSType::TS_IMPORT_TYPE:
|
||||
return GetString("TSImportType");
|
||||
case JSType::TS_CLASS_INSTANCE_TYPE:
|
||||
return GetString("TSClassInstanceType");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -166,7 +166,13 @@ class ProtoChangeDetails;
|
||||
MACHINE_CODE_OBJECT, \
|
||||
ECMA_MODULE, /* ///////////////////////////////////////////////////////////////////////////////////-PADDING */ \
|
||||
CLASS_INFO_EXTRACTOR, /* //////////////////////////////////////////////////////////////////////////-PADDING */ \
|
||||
JS_TYPE_LAST = CLASS_INFO_EXTRACTOR, /* ///////////////////////////////////////////////////////////-PADDING */ \
|
||||
TS_UNION_TYPE, /* ////////////////////////////////////////////////////////////////////////////////-PADDING */ \
|
||||
TS_OBJECT_TYPE, /* ///////////////////////////////////////////////////////////////////////////////-PADDING */ \
|
||||
TS_IMPORT_TYPE, /* ///////////////////////////////////////////////////////////////////////////////-PADDING */ \
|
||||
TS_CLASS_TYPE, /* //////////////////////////////////////////////////////////////////////////////-PADDING */ \
|
||||
TS_CLASS_INSTANCE_TYPE, /* ///////////////////////////////////////////////////////////////////////-PADDING */ \
|
||||
TS_INTERFACE_TYPE, /* //////////////////////////////////////////////////////////////////////////-PADDING */ \
|
||||
TYPE_LAST = TS_INTERFACE_TYPE, /* /////////////////////////////////////////////////////////////////-PADDING */ \
|
||||
\
|
||||
JS_FUNCTION_BEGIN = JS_FUNCTION, /* ///////////////////////////////////////////////////////////////-PADDING */ \
|
||||
JS_FUNCTION_END = JS_ASYNC_AWAIT_STATUS_FUNCTION, /* //////////////////////////////////////////////-PADDING */ \
|
||||
@ -897,6 +903,36 @@ public:
|
||||
return GetObjectType() == JSType::MACHINE_CODE_OBJECT;
|
||||
}
|
||||
|
||||
inline bool IsTSObjectType() const
|
||||
{
|
||||
return GetObjectType() == JSType::TS_OBJECT_TYPE;
|
||||
}
|
||||
|
||||
inline bool IsTSClassType() const
|
||||
{
|
||||
return GetObjectType() == JSType::TS_CLASS_TYPE;
|
||||
}
|
||||
|
||||
inline bool IsTSInterfaceType() const
|
||||
{
|
||||
return GetObjectType() == JSType::TS_INTERFACE_TYPE;
|
||||
}
|
||||
|
||||
inline bool IsTSUnionType() const
|
||||
{
|
||||
return GetObjectType() == JSType::TS_UNION_TYPE;
|
||||
}
|
||||
|
||||
inline bool IsTSClassInstanceType() const
|
||||
{
|
||||
return GetObjectType() == JSType::TS_CLASS_INSTANCE_TYPE;
|
||||
}
|
||||
|
||||
inline bool IsTSImportType() const
|
||||
{
|
||||
return GetObjectType() == JSType::TS_IMPORT_TYPE;
|
||||
}
|
||||
|
||||
inline void SetElementRepresentation(Representation representation)
|
||||
{
|
||||
uint32_t bits = GetBitField();
|
||||
|
@ -870,6 +870,36 @@ inline bool JSTaggedValue::IsClassInfoExtractor() const
|
||||
return IsHeapObject() && GetTaggedObject()->GetClass()->IsClassInfoExtractor();
|
||||
}
|
||||
|
||||
inline bool JSTaggedValue::IsTSObjectType() const
|
||||
{
|
||||
return IsHeapObject() && GetTaggedObject()->GetClass()->IsTSObjectType();
|
||||
}
|
||||
|
||||
inline bool JSTaggedValue::IsTSClassType() const
|
||||
{
|
||||
return IsHeapObject() && GetTaggedObject()->GetClass()->IsTSClassType();
|
||||
}
|
||||
|
||||
inline bool JSTaggedValue::IsTSInterfaceType() const
|
||||
{
|
||||
return IsHeapObject() && GetTaggedObject()->GetClass()->IsTSInterfaceType();
|
||||
}
|
||||
|
||||
inline bool JSTaggedValue::IsTSUnionType() const
|
||||
{
|
||||
return IsHeapObject() && GetTaggedObject()->GetClass()->IsTSUnionType();
|
||||
}
|
||||
|
||||
inline bool JSTaggedValue::IsTSImportType() const
|
||||
{
|
||||
return IsHeapObject() && GetTaggedObject()->GetClass()->IsTSImportType();
|
||||
}
|
||||
|
||||
inline bool JSTaggedValue::IsTSClassInstanceType() const
|
||||
{
|
||||
return IsHeapObject() && GetTaggedObject()->GetClass()->IsTSClassInstanceType();
|
||||
}
|
||||
|
||||
inline double JSTaggedValue::ExtractNumber() const
|
||||
{
|
||||
ASSERT(IsNumber());
|
||||
|
@ -332,6 +332,12 @@ public:
|
||||
bool IsProtoChangeDetails() const;
|
||||
bool IsMachineCodeObject() const;
|
||||
bool IsClassInfoExtractor() const;
|
||||
bool IsTSObjectType() const;
|
||||
bool IsTSClassType() const;
|
||||
bool IsTSUnionType() const;
|
||||
bool IsTSInterfaceType() const;
|
||||
bool IsTSClassInstanceType() const;
|
||||
bool IsTSImportType() const;
|
||||
static bool IsSameTypeOrHClass(JSTaggedValue x, JSTaggedValue y);
|
||||
|
||||
static ComparisonResult Compare(JSThread *thread, const JSHandle<JSTaggedValue> &x,
|
||||
|
@ -65,6 +65,8 @@
|
||||
#include "ecmascript/mem/object_xray.h"
|
||||
#include "ecmascript/mem/machine_code.h"
|
||||
#include "ecmascript/mem/mem.h"
|
||||
#include "ecmascript/ts_types/ts_type.h"
|
||||
#include "ecmascript/ts_types/ts_type_table.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
void ObjectXRay::VisitVMRoots(const RootVisitor &visitor, const RootRangeVisitor &rangeVisitor) const
|
||||
@ -307,6 +309,23 @@ void ObjectXRay::VisitObjectBody(TaggedObject *object, JSHClass *klass, const Ec
|
||||
case JSType::JS_API_ARRAYLIST_ITERATOR:
|
||||
JSAPIArrayListIterator::Cast(object)->VisitRangeSlot(visitor);
|
||||
break;
|
||||
case JSType::TS_OBJECT_TYPE:
|
||||
TSObjectType::Cast(object)->VisitRangeSlot(visitor);
|
||||
break;
|
||||
case JSType::TS_CLASS_TYPE:
|
||||
TSClassType::Cast(object)->VisitRangeSlot(visitor);
|
||||
break;
|
||||
case JSType::TS_UNION_TYPE:
|
||||
TSUnionType::Cast(object)->VisitRangeSlot(visitor);
|
||||
break;
|
||||
case JSType::TS_INTERFACE_TYPE:
|
||||
TSInterfaceType::Cast(object)->VisitRangeSlot(visitor);
|
||||
break;
|
||||
case JSType::TS_IMPORT_TYPE:
|
||||
TSImportType::Cast(object)->VisitRangeSlot(visitor);
|
||||
break;
|
||||
case JSType::TS_CLASS_INSTANCE_TYPE:
|
||||
TSClassInstanceType::Cast(object)->VisitRangeSlot(visitor);
|
||||
case JSType::JS_API_TREE_MAP:
|
||||
JSAPITreeMap::Cast(object)->VisitRangeSlot(visitor);
|
||||
break;
|
||||
|
@ -79,6 +79,11 @@
|
||||
#include "ecmascript/symbol_table-inl.h"
|
||||
#include "ecmascript/tagged_tree-inl.h"
|
||||
#include "ecmascript/template_map.h"
|
||||
#include "ecmascript/template_map.h"
|
||||
#include "ecmascript/ts_types/ts_obj_layout_info-inl.h"
|
||||
#include "ecmascript/ts_types/ts_type.h"
|
||||
#include "ecmascript/ts_types/ts_type_table.h"
|
||||
|
||||
|
||||
namespace panda::ecmascript {
|
||||
using Error = builtins::BuiltinsError;
|
||||
@ -2062,6 +2067,141 @@ JSHandle<ClassInfoExtractor> ObjectFactory::NewClassInfoExtractor(JSMethod *ctor
|
||||
return obj;
|
||||
}
|
||||
|
||||
// ----------------------------------- new TSType ----------------------------------------
|
||||
JSHandle<TSObjLayoutInfo> ObjectFactory::CreateTSObjLayoutInfo(int propNum, JSTaggedValue initVal)
|
||||
{
|
||||
int arrayLength = TSObjLayoutInfo::ComputeArrayLength(propNum);
|
||||
JSHandle<TSObjLayoutInfo> tsPropInfoHandle = JSHandle<TSObjLayoutInfo>::Cast(NewTaggedArray(arrayLength, initVal));
|
||||
tsPropInfoHandle->SetNumberOfElements(thread_, 0);
|
||||
return tsPropInfoHandle;
|
||||
}
|
||||
|
||||
JSHandle<TSObjectType> ObjectFactory::NewTSObjectType(uint32_t numOfKeys)
|
||||
{
|
||||
NewObjectHook();
|
||||
|
||||
TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(
|
||||
JSHClass::Cast(thread_->GlobalConstants()->GetTSObjectTypeClass().GetTaggedObject()));
|
||||
JSHandle<TSObjectType> objectType(thread_, header);
|
||||
|
||||
objectType->SetGTRef(GlobalTSTypeRef::Default());
|
||||
|
||||
JSHandle<TSObjLayoutInfo> tsPropInfo = CreateTSObjLayoutInfo(numOfKeys);
|
||||
objectType->SetObjLayoutInfo(thread_, tsPropInfo);
|
||||
|
||||
objectType->SetHClass(thread_, JSTaggedValue::Undefined());
|
||||
|
||||
return objectType;
|
||||
}
|
||||
|
||||
JSHandle<TSClassType> ObjectFactory::NewTSClassType()
|
||||
{
|
||||
NewObjectHook();
|
||||
|
||||
TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(
|
||||
JSHClass::Cast(thread_->GlobalConstants()->GetTSClassTypeClass().GetTaggedObject()));
|
||||
JSHandle<TSClassType> classType(thread_, header);
|
||||
|
||||
classType->SetGTRef(GlobalTSTypeRef::Default());
|
||||
classType->SetInstanceType(thread_, JSTaggedValue::Undefined());
|
||||
classType->SetConstructorType(thread_, JSTaggedValue::Undefined());
|
||||
classType->SetPrototypeType(thread_, JSTaggedValue::Undefined());
|
||||
classType->SetExtensionType(thread_, JSTaggedValue::Undefined());
|
||||
|
||||
return classType;
|
||||
}
|
||||
|
||||
JSHandle<TSInterfaceType> ObjectFactory::NewTSInterfaceType()
|
||||
{
|
||||
NewObjectHook();
|
||||
|
||||
TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(
|
||||
JSHClass::Cast(thread_->GlobalConstants()->GetTSInterfaceTypeClass().GetTaggedObject()));
|
||||
JSHandle<TSInterfaceType> interfaceType(thread_, header);
|
||||
|
||||
JSHandle<TaggedArray> extends = EmptyArray();
|
||||
interfaceType->SetGTRef(GlobalTSTypeRef::Default());
|
||||
interfaceType->SetExtends(thread_, extends);
|
||||
interfaceType->SetFields(thread_, JSTaggedValue::Undefined());
|
||||
|
||||
return interfaceType;
|
||||
}
|
||||
|
||||
|
||||
JSHandle<TSUnionType> ObjectFactory::NewTSUnionType(uint32_t length)
|
||||
{
|
||||
NewObjectHook();
|
||||
ASSERT(length > 0);
|
||||
|
||||
TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(
|
||||
JSHClass::Cast(thread_->GlobalConstants()->GetTSUnionTypeClass().GetTaggedObject()));
|
||||
JSHandle<TSUnionType> unionType(thread_, header);
|
||||
|
||||
unionType->SetGTRef(GlobalTSTypeRef::Default());
|
||||
JSHandle<TaggedArray> componentTypes = NewTaggedArray(length, JSTaggedValue::Undefined());
|
||||
unionType->SetComponentTypes(thread_, componentTypes);
|
||||
|
||||
return unionType;
|
||||
}
|
||||
|
||||
JSHandle<TSClassInstanceType> ObjectFactory::NewTSClassInstanceType()
|
||||
{
|
||||
NewObjectHook();
|
||||
|
||||
TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(
|
||||
JSHClass::Cast(thread_->GlobalConstants()->GetTSClassInstanceTypeClass().GetTaggedObject()));
|
||||
JSHandle<TSClassInstanceType> classInstanceType(thread_, header);
|
||||
|
||||
classInstanceType->SetGTRef(GlobalTSTypeRef::Default());
|
||||
classInstanceType->SetCreateClassType(JSTaggedValue::Undefined());
|
||||
|
||||
return classInstanceType;
|
||||
}
|
||||
|
||||
JSHandle<TSImportType> ObjectFactory::NewTSImportType()
|
||||
{
|
||||
NewObjectHook();
|
||||
|
||||
TaggedObject *header = heapHelper_.AllocateYoungGenerationOrHugeObject(
|
||||
JSHClass::Cast(thread_->GlobalConstants()->GetTSImportTypeClass().GetTaggedObject()));
|
||||
JSHandle<TSImportType> importType(thread_, header);
|
||||
|
||||
importType->SetGTRef(GlobalTSTypeRef::Default());
|
||||
importType->SetTargetType(thread_, JSTaggedValue::Undefined());
|
||||
importType->SetImportPath(thread_, JSTaggedValue::Undefined());
|
||||
|
||||
return importType;
|
||||
}
|
||||
|
||||
JSHandle<TSTypeTable> ObjectFactory::NewTSTypeTable(uint32_t length)
|
||||
{
|
||||
NewObjectHook();
|
||||
ASSERT(length > 0);
|
||||
|
||||
size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), length + TSTypeTable::RESERVE_TABLE_LENGTH);
|
||||
JSHClass *arrayClass = JSHClass::Cast(thread_->GlobalConstants()->GetArrayClass().GetTaggedObject());
|
||||
auto header = heapHelper_.AllocateOldGenerationOrHugeObject(arrayClass, size);
|
||||
|
||||
JSHandle<TSTypeTable> table(thread_, header);
|
||||
table->InitializeWithSpecialValue(JSTaggedValue::Undefined(), length);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
JSHandle<TSModuleTable> ObjectFactory::NewTSModuleTable(uint32_t length)
|
||||
{
|
||||
NewObjectHook();
|
||||
ASSERT(length > 0);
|
||||
|
||||
size_t size = TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), length);
|
||||
JSHClass *arrayClass = JSHClass::Cast(thread_->GlobalConstants()->GetArrayClass().GetTaggedObject());
|
||||
auto header = heapHelper_.AllocateYoungGenerationOrHugeObject(arrayClass, size);
|
||||
JSHandle<TSModuleTable> array(thread_, header);
|
||||
array->InitializeWithSpecialValue(JSTaggedValue::Undefined(), length);
|
||||
array->InitializeNumberOfTSTypeTable(thread_);
|
||||
|
||||
return array;
|
||||
}
|
||||
// ----------------------------------- new string ----------------------------------------
|
||||
JSHandle<EcmaString> ObjectFactory::NewFromString(const CString &data)
|
||||
{
|
||||
|
@ -83,6 +83,15 @@ class LayoutInfo;
|
||||
class JSIntlBoundFunction;
|
||||
class FreeObject;
|
||||
class JSNativePointer;
|
||||
class TSObjectType;
|
||||
class TSClassType;
|
||||
class TSUnionType;
|
||||
class TSInterfaceType;
|
||||
class TSTypeTable;
|
||||
class TSClassInstanceType;
|
||||
class TSImportType;
|
||||
class TSObjLayoutInfo;
|
||||
class TSModuleTable;
|
||||
class JSAPIArrayList;
|
||||
class JSAPIArrayListIterator;
|
||||
class JSAPITreeSet;
|
||||
@ -334,6 +343,17 @@ public:
|
||||
JSHandle<MachineCode> NewMachineCodeObject(size_t length, const uint8_t *data);
|
||||
JSHandle<ClassInfoExtractor> NewClassInfoExtractor(JSMethod *ctorMethod);
|
||||
|
||||
// ----------------------------------- 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);
|
||||
|
||||
~ObjectFactory() = default;
|
||||
|
||||
// ----------------------------------- new string ----------------------------------------
|
||||
@ -442,6 +462,11 @@ private:
|
||||
friend class LiteralDataExtractor;
|
||||
friend class RuntimeTrampolines;
|
||||
friend class ClassInfoExtractor;
|
||||
friend class TSObjectType;
|
||||
friend class TSClassType;
|
||||
friend class TSUnionType;
|
||||
friend class TSClassInstanceType;
|
||||
friend class TSImportType;
|
||||
};
|
||||
|
||||
class ClassLinkerFactory {
|
||||
|
@ -83,6 +83,7 @@
|
||||
#include "ecmascript/template_map.h"
|
||||
#include "ecmascript/tests/test_helper.h"
|
||||
#include "ecmascript/transitions_dictionary.h"
|
||||
#include "ecmascript/ts_types/ts_type.h"
|
||||
|
||||
using namespace panda::ecmascript;
|
||||
using namespace panda::ecmascript::base;
|
||||
@ -211,7 +212,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump)
|
||||
object##ClassName.GetTaggedValue().D(); \
|
||||
object##ClassName.GetTaggedValue().DumpForSnapshot(thread, snapshotVector);
|
||||
|
||||
for (JSType type = JSType::JS_OBJECT; type <= JSType::JS_TYPE_LAST; type = JSType(static_cast<int>(type) + 1)) {
|
||||
for (JSType type = JSType::JS_OBJECT; type <= JSType::TYPE_LAST; type = JSType(static_cast<int>(type) + 1)) {
|
||||
switch (type) {
|
||||
case JSType::JS_ERROR:
|
||||
case JSType::JS_EVAL_ERROR:
|
||||
@ -670,6 +671,42 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump)
|
||||
DUMP_FOR_HANDLE(jsArrayListIter)
|
||||
break;
|
||||
}
|
||||
case JSType::TS_OBJECT_TYPE: {
|
||||
CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), TSObjectType::SIZE, 3)
|
||||
JSHandle<TSObjectType> objectType = factory->NewTSObjectType(0);
|
||||
DUMP_FOR_HANDLE(objectType)
|
||||
break;
|
||||
}
|
||||
case JSType::TS_CLASS_TYPE: {
|
||||
CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), TSClassType::SIZE, 5)
|
||||
JSHandle<TSClassType> classType = factory->NewTSClassType();
|
||||
DUMP_FOR_HANDLE(classType)
|
||||
break;
|
||||
}
|
||||
case JSType::TS_INTERFACE_TYPE: {
|
||||
CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), TSInterfaceType::SIZE, 3)
|
||||
JSHandle<TSInterfaceType> interfaceType = factory->NewTSInterfaceType();
|
||||
DUMP_FOR_HANDLE(interfaceType)
|
||||
break;
|
||||
}
|
||||
case JSType::TS_IMPORT_TYPE: {
|
||||
CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), TSImportType::SIZE, 3)
|
||||
JSHandle<TSImportType> importType = factory->NewTSImportType();
|
||||
DUMP_FOR_HANDLE(importType)
|
||||
break;
|
||||
}
|
||||
case JSType::TS_CLASS_INSTANCE_TYPE: {
|
||||
CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), TSClassInstanceType::SIZE, 2)
|
||||
JSHandle<TSClassInstanceType> classInstanceType = factory->NewTSClassInstanceType();
|
||||
DUMP_FOR_HANDLE(classInstanceType)
|
||||
break;
|
||||
}
|
||||
case JSType::TS_UNION_TYPE: {
|
||||
CHECK_DUMP_FILEDS(TaggedObject::TaggedObjectSize(), TSUnionType::SIZE, 2)
|
||||
JSHandle<TSUnionType> unionType = factory->NewTSUnionType(1);
|
||||
DUMP_FOR_HANDLE(unionType)
|
||||
break;
|
||||
}
|
||||
case JSType::JS_API_TREE_MAP: {
|
||||
CHECK_DUMP_FILEDS(JSObject::SIZE, JSAPITreeMap::SIZE, 1)
|
||||
JSHandle<JSAPITreeMap> jsTreeMap = NewJSAPITreeMap(thread, factory);
|
||||
|
59
ecmascript/ts_types/tests/BUILD.gn
Normal file
59
ecmascript/ts_types/tests/BUILD.gn
Normal file
@ -0,0 +1,59 @@
|
||||
# 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.
|
||||
|
||||
import("//ark/js_runtime/js_runtime_config.gni")
|
||||
import("//ark/js_runtime/test/test_helper.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
module_output_path = "ark/js_runtime"
|
||||
|
||||
host_unittest_action("TSTypeTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
# test file
|
||||
"ts_type_test.cpp",
|
||||
]
|
||||
|
||||
configs = [
|
||||
"//ark/js_runtime:ecma_test_config",
|
||||
"//ark/js_runtime:ark_jsruntime_public_config", # should add before
|
||||
# arkruntime_public_config
|
||||
"//ark/js_runtime:ark_jsruntime_common_config",
|
||||
"$ark_root/runtime:arkruntime_public_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"$ark_root/libpandabase:libarkbase",
|
||||
"//ark/js_runtime:libark_jsruntime_test",
|
||||
sdk_libc_secshared_dep,
|
||||
]
|
||||
|
||||
if (!is_standard_system) {
|
||||
deps += [ "$ark_root/runtime:libarkruntime" ]
|
||||
}
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
# deps file
|
||||
deps = [ ":TSTypeTest" ]
|
||||
}
|
||||
|
||||
group("host_unittest") {
|
||||
testonly = true
|
||||
|
||||
# deps file
|
||||
deps = [ ":TSTypeTestAction" ]
|
||||
}
|
312
ecmascript/ts_types/tests/ts_type_test.cpp
Normal file
312
ecmascript/ts_types/tests/ts_type_test.cpp
Normal file
@ -0,0 +1,312 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <thread>
|
||||
|
||||
#include "ecmascript/ecma_vm.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/tests/test_helper.h"
|
||||
#include "ecmascript/ts_types/ts_type_table.h"
|
||||
#include "ecmascript/ts_types/ts_obj_layout_info-inl.h"
|
||||
|
||||
using namespace panda::ecmascript;
|
||||
namespace panda::test {
|
||||
class TSTypeTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
GTEST_LOG_(INFO) << "SetUpTestCase";
|
||||
}
|
||||
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
GTEST_LOG_(INFO) << "TearDownCase";
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
TestHelper::CreateEcmaVMWithScope(instance, thread, scope);
|
||||
ecmaVm = EcmaVM::Cast(instance);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
TestHelper::DestroyEcmaVMWithScope(instance, scope);
|
||||
}
|
||||
|
||||
PandaVM *instance {nullptr};
|
||||
EcmaVM *ecmaVm = nullptr;
|
||||
EcmaHandleScope *scope {nullptr};
|
||||
JSThread *thread {nullptr};
|
||||
};
|
||||
|
||||
HWTEST_F_L0(TSTypeTest, UnionType)
|
||||
{
|
||||
auto factory = ecmaVm->GetFactory();
|
||||
JSHandle<TSTypeTable> table = factory->NewTSTypeTable(2);
|
||||
|
||||
const int literalLength = 4;
|
||||
const int unionLength = 2;
|
||||
JSHandle<TaggedArray> literal = factory->NewTaggedArray(literalLength);
|
||||
literal->Set(thread, 0, JSTaggedValue(static_cast<int>(TSTypeTable::TypeLiteralFlag::UNION)));
|
||||
literal->Set(thread, 1, JSTaggedValue(unionLength));
|
||||
literal->Set(thread, 2, JSTaggedValue(51));
|
||||
literal->Set(thread, 3, JSTaggedValue(57));
|
||||
|
||||
CVector<JSHandle<EcmaString>> recordImportMdoules {};
|
||||
JSHandle<JSTaggedValue> type = TSTypeTable::ParseType(thread, table, literal,
|
||||
factory->NewFromString(CString("test")),
|
||||
recordImportMdoules);
|
||||
ASSERT_TRUE(type->IsTSUnionType());
|
||||
|
||||
JSHandle<TSUnionType> unionType = JSHandle<TSUnionType>(type);
|
||||
ASSERT_TRUE(unionType->GetComponentTypes().IsTaggedArray());
|
||||
|
||||
JSHandle<TaggedArray> unionArray(thread, unionType->GetComponentTypes());
|
||||
ASSERT_EQ(unionArray->GetLength(), unionLength);
|
||||
ASSERT_EQ(unionArray->Get(0).GetInt(), 51);
|
||||
ASSERT_EQ(unionArray->Get(1).GetInt(), 57);
|
||||
}
|
||||
|
||||
HWTEST_F_L0(TSTypeTest, ImportType)
|
||||
{
|
||||
auto factory = ecmaVm->GetFactory();
|
||||
TSLoader *tsLoader = ecmaVm->GetTSLoader();
|
||||
|
||||
JSHandle<TSTypeTable> exportTable = factory->NewTSTypeTable(3);
|
||||
JSHandle<TSTypeTable> importTable = factory->NewTSTypeTable(2);
|
||||
JSHandle<TSTypeTable> redirectImportTable = factory->NewTSTypeTable(3);
|
||||
GlobalTSTypeRef gt(0);
|
||||
|
||||
const int ImportLiteralLength = 2;
|
||||
CString importFile = "test_import.abc";
|
||||
JSHandle<EcmaString> importFileHandle = factory->NewFromString(importFile);
|
||||
CString importVarAndPath = "#A#test_redirect_import";
|
||||
JSHandle<EcmaString> importString = factory->NewFromString(importVarAndPath);
|
||||
JSHandle<TaggedArray> importLiteral = factory->NewTaggedArray(ImportLiteralLength);
|
||||
importLiteral->Set(thread, 0, JSTaggedValue(static_cast<int>(TSTypeTable::TypeLiteralFlag::IMPORT)));
|
||||
importLiteral->Set(thread, 1, importString);
|
||||
|
||||
CVector<JSHandle<EcmaString>> recordImportMdoules {};
|
||||
JSHandle<JSTaggedValue> importValueType = TSTypeTable::ParseType(thread, importTable,
|
||||
importLiteral, importFileHandle,
|
||||
recordImportMdoules);
|
||||
CString importMdoule = ConvertToString(recordImportMdoules.back().GetTaggedValue());
|
||||
recordImportMdoules.pop_back();
|
||||
ASSERT_EQ(importMdoule, "test_redirect_import.abc");
|
||||
|
||||
ASSERT_TRUE(importValueType->IsTSImportType());
|
||||
JSHandle<TSImportType> importType = JSHandle<TSImportType>(importValueType);
|
||||
|
||||
gt.SetUserDefineTypeKind(importLiteral->Get(0).GetInt() + GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT);
|
||||
gt.SetModuleId(tsLoader->GetNextModuleId());
|
||||
gt.SetLocalId(1 + GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT);
|
||||
importType->SetGTRef(gt);
|
||||
importTable->Set(thread, 0, JSTaggedValue(1));
|
||||
importTable->Set(thread, 1, JSHandle<JSTaggedValue>(importType));
|
||||
|
||||
GlobalTSTypeRef importGT = importType->GetGTRef();
|
||||
ASSERT_EQ(importType->GetTargetType(), JSTaggedValue::Undefined());
|
||||
|
||||
tsLoader->AddTypeTable(JSHandle<JSTaggedValue>(importTable), factory->NewFromString(importFile));
|
||||
|
||||
const int redirectImportLiteralLength = 2;
|
||||
CString redirectImportFile = "test_redirect_import.abc";
|
||||
JSHandle<EcmaString> redirectImportFileHandle = factory->NewFromString(redirectImportFile);
|
||||
CString redirectImportVarAndPath = "#A#test";
|
||||
|
||||
JSHandle<TaggedArray> redirectExportTableHandle = factory->NewTaggedArray(2);
|
||||
JSHandle<EcmaString> exportVal = factory->NewFromString("A");
|
||||
JSHandle<EcmaString> exportIndex = factory->NewFromString("51");
|
||||
redirectExportTableHandle->Set(thread, 0, exportVal);
|
||||
redirectExportTableHandle->Set(thread, 1, exportIndex);
|
||||
|
||||
JSHandle<EcmaString> redirectImportString = factory->NewFromString(redirectImportVarAndPath);
|
||||
JSHandle<TaggedArray> redirectImportLiteral = factory->NewTaggedArray(redirectImportLiteralLength);
|
||||
redirectImportLiteral->Set(thread, 0, JSTaggedValue(static_cast<int>(TSTypeTable::TypeLiteralFlag::IMPORT)));
|
||||
redirectImportLiteral->Set(thread, 1, redirectImportString);
|
||||
|
||||
JSHandle<JSTaggedValue> redirectImportValueType = TSTypeTable::ParseType(thread, redirectImportTable,
|
||||
redirectImportLiteral,
|
||||
redirectImportFileHandle,
|
||||
recordImportMdoules);
|
||||
importMdoule = ConvertToString(recordImportMdoules.back().GetTaggedValue());
|
||||
recordImportMdoules.pop_back();
|
||||
ASSERT_EQ(importMdoule, "test.abc");
|
||||
|
||||
ASSERT_TRUE(redirectImportValueType->IsTSImportType());
|
||||
JSHandle<TSImportType> redirectImportType = JSHandle<TSImportType>(redirectImportValueType);
|
||||
gt.Clear();
|
||||
gt.SetUserDefineTypeKind(redirectImportLiteral->Get(0).GetInt() + GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT);
|
||||
gt.SetModuleId(tsLoader->GetNextModuleId());
|
||||
gt.SetLocalId(1 + GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT);
|
||||
redirectImportType->SetGTRef(gt);
|
||||
redirectImportTable->Set(thread, 0, JSTaggedValue(1));
|
||||
redirectImportTable->Set(thread, 1, JSHandle<JSTaggedValue>(redirectImportType));
|
||||
redirectImportTable->Set(thread, 2, redirectExportTableHandle);
|
||||
|
||||
GlobalTSTypeRef redirectImportGT = redirectImportType->GetGTRef();
|
||||
ASSERT_EQ(redirectImportType->GetTargetType(), JSTaggedValue::Undefined());
|
||||
|
||||
tsLoader->AddTypeTable(JSHandle<JSTaggedValue>(redirectImportTable), factory->NewFromString(redirectImportFile));
|
||||
|
||||
const int literalLength = 4;
|
||||
const int unionLength = 2;
|
||||
CString fileName = "test.abc";
|
||||
JSHandle<EcmaString> fileNameHandle = factory->NewFromString(fileName);
|
||||
|
||||
JSHandle<TaggedArray> exportValueTableHandle = factory->NewTaggedArray(2);
|
||||
exportValueTableHandle->Set(thread, 0, exportVal);
|
||||
exportValueTableHandle->Set(thread, 1, exportIndex);
|
||||
JSHandle<TaggedArray> literal = factory->NewTaggedArray(literalLength);
|
||||
literal->Set(thread, 0, JSTaggedValue(static_cast<int>(TSTypeTable::TypeLiteralFlag::UNION)));
|
||||
literal->Set(thread, 1, JSTaggedValue(unionLength));
|
||||
literal->Set(thread, 2, JSTaggedValue(51));
|
||||
literal->Set(thread, 3, JSTaggedValue(57));
|
||||
|
||||
JSHandle<JSTaggedValue> type = TSTypeTable::ParseType(thread, exportTable, literal,
|
||||
fileNameHandle, recordImportMdoules);
|
||||
ASSERT_TRUE(type->IsTSUnionType());
|
||||
JSHandle<TSUnionType> unionType = JSHandle<TSUnionType>(type);
|
||||
|
||||
gt.Clear();
|
||||
gt.SetUserDefineTypeKind(literal->Get(0).GetInt() + GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT);
|
||||
gt.SetModuleId(tsLoader->GetNextModuleId());
|
||||
gt.SetLocalId(1 + GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT);
|
||||
unionType->SetGTRef(gt);
|
||||
exportTable->Set(thread, 0, JSTaggedValue(1));
|
||||
exportTable->Set(thread, 1, JSHandle<JSTaggedValue>(unionType));
|
||||
exportTable->Set(thread, 2, exportValueTableHandle);
|
||||
GlobalTSTypeRef unionTypeGT = unionType->GetGTRef();
|
||||
|
||||
tsLoader->AddTypeTable(JSHandle<JSTaggedValue>(exportTable), factory->NewFromString(fileName));
|
||||
|
||||
tsLoader->Link();
|
||||
GlobalTSTypeRef linkimportGT = tsLoader->GetImportTypeTargetGT(importGT);
|
||||
GlobalTSTypeRef linkredirectImportGT = tsLoader->GetImportTypeTargetGT(redirectImportGT);
|
||||
ASSERT_EQ(linkimportGT.GetGlobalTSTypeRef(), unionTypeGT.GetGlobalTSTypeRef());
|
||||
ASSERT_EQ(linkredirectImportGT.GetGlobalTSTypeRef(), unionTypeGT.GetGlobalTSTypeRef());
|
||||
|
||||
int length = tsLoader->GetUnionTypeLength(unionTypeGT);
|
||||
ASSERT_EQ(length, unionLength);
|
||||
}
|
||||
|
||||
HWTEST_F_L0(TSTypeTest, InterfaceType)
|
||||
{
|
||||
auto factory = ecmaVm->GetFactory();
|
||||
JSHandle<TSTypeTable> table = factory->NewTSTypeTable(2);
|
||||
|
||||
const int literalLength = 12;
|
||||
const int propsNum = 2;
|
||||
JSHandle<TaggedArray> literal = factory->NewTaggedArray(literalLength);
|
||||
JSHandle<EcmaString> propsNameA = factory->NewFromCanBeCompressString("propsA");
|
||||
JSHandle<EcmaString> propsNameB = factory->NewFromCanBeCompressString("propsB");
|
||||
literal->Set(thread, 0, JSTaggedValue(static_cast<int>(TSTypeTable::TypeLiteralFlag::INTERFACE)));
|
||||
literal->Set(thread, 1, JSTaggedValue(0));
|
||||
literal->Set(thread, 2, JSTaggedValue(propsNum));
|
||||
literal->Set(thread, 3, propsNameA.GetTaggedValue());
|
||||
literal->Set(thread, 4, JSTaggedValue(static_cast<int>(TSTypeKind::TS_STRING)));
|
||||
literal->Set(thread, 5, JSTaggedValue(0));
|
||||
literal->Set(thread, 6, JSTaggedValue(0));
|
||||
literal->Set(thread, 7, propsNameB.GetTaggedValue());
|
||||
literal->Set(thread, 8, JSTaggedValue(static_cast<int>(TSTypeKind::TS_NUMBER)));
|
||||
literal->Set(thread, 9, JSTaggedValue(0));
|
||||
literal->Set(thread, 10, JSTaggedValue(0));
|
||||
literal->Set(thread, 11, JSTaggedValue(0));
|
||||
|
||||
CVector<JSHandle<EcmaString>> recordImportMdoules {};
|
||||
JSHandle<JSTaggedValue> type = TSTypeTable::ParseType(thread, table, literal,
|
||||
factory->NewFromString(CString("test")),
|
||||
recordImportMdoules);
|
||||
ASSERT_TRUE(type->IsTSInterfaceType());
|
||||
JSHandle<TSInterfaceType> interfaceType = JSHandle<TSInterfaceType>(type);
|
||||
JSHandle<TSObjectType> fields = JSHandle<TSObjectType>(thread, interfaceType->GetFields());
|
||||
TSObjLayoutInfo *fieldsTypeInfo = TSObjLayoutInfo::Cast(fields->GetObjLayoutInfo().GetTaggedObject());
|
||||
|
||||
ASSERT_EQ(fieldsTypeInfo->GetPropertiesCapacity(), propsNum);
|
||||
ASSERT_EQ(fieldsTypeInfo->GetKey(0), propsNameA.GetTaggedValue());
|
||||
ASSERT_EQ(fieldsTypeInfo->GetTypeId(0).GetInt(), static_cast<int>(TSTypeKind::TS_STRING));
|
||||
ASSERT_EQ(fieldsTypeInfo->GetKey(1), propsNameB.GetTaggedValue());
|
||||
ASSERT_EQ(fieldsTypeInfo->GetTypeId(1).GetInt(), static_cast<int>(TSTypeKind::TS_NUMBER));
|
||||
}
|
||||
|
||||
HWTEST_F_L0(TSTypeTest, ClassType)
|
||||
{
|
||||
auto factory = ecmaVm->GetFactory();
|
||||
JSHandle<TSTypeTable> table = factory->NewTSTypeTable(2);
|
||||
|
||||
const int literalLength = 18;
|
||||
const int propsNum = 2;
|
||||
JSHandle<TaggedArray> literal = factory->NewTaggedArray(literalLength);
|
||||
JSHandle<EcmaString> propsNameA = factory->NewFromCanBeCompressString("propsA");
|
||||
JSHandle<EcmaString> propsNameB = factory->NewFromCanBeCompressString("propsB");
|
||||
JSHandle<EcmaString> funcName = factory->NewFromCanBeCompressString("constructor");
|
||||
literal->Set(thread, 0, JSTaggedValue(static_cast<int>(TSTypeTable::TypeLiteralFlag::CLASS)));
|
||||
literal->Set(thread, 1, JSTaggedValue(0));
|
||||
literal->Set(thread, 2, JSTaggedValue(0));
|
||||
literal->Set(thread, 3, JSTaggedValue(0));
|
||||
literal->Set(thread, 4, JSTaggedValue(propsNum));
|
||||
literal->Set(thread, 5, propsNameA.GetTaggedValue());
|
||||
literal->Set(thread, 6, JSTaggedValue(static_cast<int>(TSTypeKind::TS_STRING)));
|
||||
literal->Set(thread, 7, JSTaggedValue(0));
|
||||
literal->Set(thread, 8, JSTaggedValue(0));
|
||||
literal->Set(thread, 9, propsNameB.GetTaggedValue());
|
||||
literal->Set(thread, 10, JSTaggedValue(static_cast<int>(TSTypeKind::TS_NUMBER)));
|
||||
literal->Set(thread, 11, JSTaggedValue(0));
|
||||
literal->Set(thread, 12, JSTaggedValue(0));
|
||||
literal->Set(thread, 13, JSTaggedValue(1));
|
||||
literal->Set(thread, 14, funcName.GetTaggedValue());
|
||||
literal->Set(thread, 15, JSTaggedValue(static_cast<int>(TSTypeTable::TypeLiteralFlag::FUNCTION)));
|
||||
literal->Set(thread, 16, JSTaggedValue(0));
|
||||
literal->Set(thread, 17, JSTaggedValue(0));
|
||||
|
||||
CVector<JSHandle<EcmaString>> recordImportMdoules {};
|
||||
JSHandle<JSTaggedValue> type = TSTypeTable::ParseType(thread, table, literal,
|
||||
factory->NewFromString(CString("test")),
|
||||
recordImportMdoules);
|
||||
ASSERT_TRUE(type->IsTSClassType());
|
||||
JSHandle<TSClassType> classType = JSHandle<TSClassType>(type);
|
||||
JSHandle<TSObjectType> fields = JSHandle<TSObjectType>(thread, classType->GetInstanceType());
|
||||
TSObjLayoutInfo *fieldsTypeInfo = TSObjLayoutInfo::Cast(fields->GetObjLayoutInfo().GetTaggedObject());
|
||||
|
||||
ASSERT_EQ(fieldsTypeInfo->GetPropertiesCapacity(), propsNum);
|
||||
ASSERT_EQ(fieldsTypeInfo->GetKey(0), propsNameA.GetTaggedValue());
|
||||
ASSERT_EQ(fieldsTypeInfo->GetTypeId(0).GetInt(), static_cast<int>(TSTypeKind::TS_STRING));
|
||||
ASSERT_EQ(fieldsTypeInfo->GetKey(1), propsNameB.GetTaggedValue());
|
||||
ASSERT_EQ(fieldsTypeInfo->GetTypeId(1).GetInt(), static_cast<int>(TSTypeKind::TS_NUMBER));
|
||||
}
|
||||
|
||||
HWTEST_F_L0(TSTypeTest, ClassInstanceType)
|
||||
{
|
||||
auto factory = ecmaVm->GetFactory();
|
||||
JSHandle<TSTypeTable> table = factory->NewTSTypeTable(3);
|
||||
JSHandle<TSClassType> extendClass = factory->NewTSClassType();
|
||||
const int literalLength = 2;
|
||||
table->Set(thread, 0, extendClass);
|
||||
JSHandle<TaggedArray> literal = factory->NewTaggedArray(literalLength);
|
||||
|
||||
literal->Set(thread, 0, JSTaggedValue(static_cast<int>(TSTypeTable::TypeLiteralFlag::CLASS_INSTANCE)));
|
||||
literal->Set(thread, 1, JSTaggedValue(50));
|
||||
|
||||
CVector<JSHandle<EcmaString>> recordImportMdoules {};
|
||||
JSHandle<JSTaggedValue> type = TSTypeTable::ParseType(thread, table, literal,
|
||||
factory->NewFromString(CString("test")),
|
||||
recordImportMdoules);
|
||||
ASSERT_TRUE(type->IsTSClassInstanceType());
|
||||
JSHandle<TSClassInstanceType> classInstanceType = JSHandle<TSClassInstanceType>(type);
|
||||
|
||||
ASSERT_EQ(classInstanceType->GetCreateClassType(), extendClass.GetTaggedValue());
|
||||
}
|
||||
}
|
461
ecmascript/ts_types/ts_loader.cpp
Executable file
461
ecmascript/ts_types/ts_loader.cpp
Executable file
@ -0,0 +1,461 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "ecmascript/ts_types/ts_loader.h"
|
||||
#include "ecmascript/ts_types/ts_type_table.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
void TSLoader::DecodeTSTypes(const panda_file::File &pf)
|
||||
{
|
||||
JSThread *thread = vm_->GetJSThread();
|
||||
ObjectFactory *factory = vm_->GetFactory();
|
||||
JSHandle<TSModuleTable> table = GetTSModuleTable();
|
||||
|
||||
JSHandle<EcmaString> queryFileName = factory->NewFromStdString(pf.GetFilename());
|
||||
int index = table->GetGlobalModuleID(thread, queryFileName);
|
||||
if (index == TSModuleTable::NOT_FOUND) {
|
||||
CVector<JSHandle<EcmaString>> recordImportMdoules {};
|
||||
TSTypeTable::Initialize(thread, pf, recordImportMdoules);
|
||||
Link();
|
||||
}
|
||||
}
|
||||
|
||||
TSLoader::TSLoader(EcmaVM *vm) : vm_(vm)
|
||||
{
|
||||
JSHandle<TSModuleTable> table = vm_->GetFactory()->NewTSModuleTable(TSModuleTable::DEAULT_TABLE_CAPACITY);
|
||||
SetTSModuleTable(table);
|
||||
}
|
||||
|
||||
void TSLoader::AddTypeTable(JSHandle<JSTaggedValue> typeTable, JSHandle<EcmaString> amiPath)
|
||||
{
|
||||
JSThread *thread = vm_->GetJSThread();
|
||||
JSHandle<TSModuleTable> table = GetTSModuleTable();
|
||||
JSHandle<TSModuleTable> largeTable = TSModuleTable::AddTypeTable(thread, table, typeTable, amiPath);
|
||||
SetTSModuleTable(largeTable);
|
||||
}
|
||||
|
||||
void TSLoader::Link()
|
||||
{
|
||||
JSThread *thread = vm_->GetJSThread();
|
||||
JSHandle<TSModuleTable> table = GetTSModuleTable();
|
||||
|
||||
int length = table->GetNumberOfTSTypeTable();
|
||||
for (int i = 0; i < length; i++) {
|
||||
JSHandle<TSTypeTable> typeTable = table->GetTSTypeTable(thread, i);
|
||||
LinkTSTypeTable(typeTable);
|
||||
}
|
||||
}
|
||||
|
||||
void TSLoader::LinkTSTypeTable(JSHandle<TSTypeTable> table)
|
||||
{
|
||||
int length = table->GetLength();
|
||||
JSThread *thread = vm_->GetJSThread();
|
||||
ObjectFactory *factory = vm_->GetFactory();
|
||||
JSMutableHandle<TSImportType> importType = JSMutableHandle<TSImportType>(thread, factory->NewTSImportType()
|
||||
.GetTaggedValue());
|
||||
int i = 1;
|
||||
while (i < length && table->Get(i).IsTSImportType()) {
|
||||
importType.Update(table->Get(i));
|
||||
RecursivelyResolveTargetType(importType);
|
||||
table->Set(thread, i, importType);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
int TSLoader::GetUserdefinedTypeId(int localId)
|
||||
{
|
||||
return localId - GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT;
|
||||
}
|
||||
|
||||
bool TSLoader::IsPrimtiveBuiltinTypes(int localId) const
|
||||
{
|
||||
return localId < GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT ? 1 : 0;
|
||||
}
|
||||
|
||||
void TSLoader::RecursivelyResolveTargetType(JSMutableHandle<TSImportType>& importType)
|
||||
{
|
||||
if (!importType->GetTargetType().IsUndefined()) {
|
||||
return;
|
||||
}
|
||||
JSThread *thread = vm_->GetJSThread();
|
||||
JSHandle<TSModuleTable> table = GetTSModuleTable();
|
||||
|
||||
JSHandle<EcmaString> importVarAndPath(thread, importType->GetImportPath());
|
||||
JSHandle<EcmaString> target = GenerateImportVar(importVarAndPath);
|
||||
JSHandle<EcmaString> amiPath = GenerateImportRelativePath(importVarAndPath);
|
||||
int index = table->GetGlobalModuleID(thread, amiPath);
|
||||
ASSERT(index != TSModuleTable::NOT_FOUND);
|
||||
JSHandle<TSTypeTable> typeTable = table->GetTSTypeTable(thread, index);
|
||||
JSHandle<TaggedArray> moduleExportTable = TSTypeTable::GetExportValueTable(thread, typeTable);
|
||||
|
||||
int localId = GetTypeIndexFromExportTable(target, moduleExportTable);
|
||||
if (IsPrimtiveBuiltinTypes(localId)) {
|
||||
importType->SetTargetType(JSTaggedValue(localId));
|
||||
return;
|
||||
}
|
||||
int userDefId = GetUserdefinedTypeId(localId);
|
||||
|
||||
JSHandle<TSType> bindType = JSHandle<TSType>(thread, typeTable->Get(userDefId));
|
||||
if (bindType.GetTaggedValue().IsTSImportType()) {
|
||||
JSMutableHandle<TSImportType> redirectImportType(bindType);
|
||||
RecursivelyResolveTargetType(redirectImportType);
|
||||
typeTable->Set(thread, userDefId , redirectImportType);
|
||||
importType->SetTargetType(thread, redirectImportType->GetTargetType());
|
||||
} else {
|
||||
importType->SetTargetType(thread, bindType);
|
||||
}
|
||||
}
|
||||
|
||||
int TSLoader::GetTypeIndexFromExportTable(JSHandle<EcmaString> target, JSHandle<TaggedArray> &exportTable) const
|
||||
{
|
||||
int capcity = exportTable->GetLength();
|
||||
// capcity/2 -> ["A", "B", 51, 52] -> if target is "A", return 51, index = 0 + 4/2 = 2
|
||||
int length = capcity / 2 ;
|
||||
for (int i = 0; i < length; i++) {
|
||||
EcmaString *valueString = EcmaString::Cast(exportTable->Get(i).GetTaggedObject());
|
||||
if (EcmaString::StringsAreEqual(*target, valueString)) {
|
||||
EcmaString *localIdString = EcmaString::Cast(exportTable->Get(i + 1).GetTaggedObject());
|
||||
return CStringToULL(ConvertToString(localIdString));
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
GlobalTSTypeRef TSLoader::GetPropType(GlobalTSTypeRef gt, JSHandle<EcmaString> propertyName) const
|
||||
{
|
||||
JSThread *thread = vm_->GetJSThread();
|
||||
JSHandle<TSModuleTable> table = GetTSModuleTable();
|
||||
|
||||
int moduleId = gt.GetModuleId();
|
||||
int localTSTypeTableId = gt.GetLocalId();
|
||||
int userDefId = GetUserdefinedTypeId(localTSTypeTableId);
|
||||
TSTypeKind typeKind = GetTypeKind(gt);
|
||||
|
||||
JSHandle<TSTypeTable> typeTable = table->GetTSTypeTable(thread, moduleId);
|
||||
GlobalTSTypeRef propTypeRef = TSTypeTable::GetPropertyType(thread, typeTable, typeKind, userDefId,
|
||||
propertyName);
|
||||
return propTypeRef;
|
||||
}
|
||||
|
||||
int TSLoader::GetUnionTypeLength(GlobalTSTypeRef gt) const
|
||||
{
|
||||
JSThread *thread = vm_->GetJSThread();
|
||||
JSHandle<TSModuleTable> table = GetTSModuleTable();
|
||||
|
||||
int moduleId = gt.GetModuleId();
|
||||
int localTSTypetableId = gt.GetLocalId();
|
||||
int userDefId = GetUserdefinedTypeId(localTSTypetableId);
|
||||
[[maybe_unused]] TSTypeKind typeKind = GetTypeKind(gt);
|
||||
ASSERT(typeKind == TSTypeKind::TS_UNION);
|
||||
|
||||
JSHandle<TSTypeTable> typeTable = table->GetTSTypeTable(thread, moduleId);
|
||||
JSHandle<TSUnionType> unionType(thread, typeTable->Get(userDefId));
|
||||
JSHandle<TaggedArray> unionTypeArray(thread, unionType->GetComponentTypes());
|
||||
|
||||
return unionTypeArray->GetLength();
|
||||
}
|
||||
|
||||
int TSLoader::GetUTableIndex(GlobalTSTypeRef gt, int index) const
|
||||
{
|
||||
JSThread *thread = vm_->GetJSThread();
|
||||
int localTSTypetableId = gt.GetLocalId();
|
||||
int userDefId = GetUserdefinedTypeId(localTSTypetableId);
|
||||
|
||||
JSHandle<TaggedArray> typeTable = GetGlobalUTable();
|
||||
JSHandle<TSUnionType> unionType(thread, typeTable->Get(userDefId));
|
||||
JSHandle<TaggedArray> unionTypeArray(thread, unionType->GetComponentTypes());
|
||||
ASSERT(index < unionTypeArray->GetLength());
|
||||
int localUnionId = unionTypeArray->Get(index).GetNumber();
|
||||
return localUnionId;
|
||||
}
|
||||
|
||||
GlobalTSTypeRef TSLoader::GetUnionTypeByIndex(GlobalTSTypeRef gt, int index) const
|
||||
{
|
||||
JSThread *thread = vm_->GetJSThread();
|
||||
[[maybe_unused]] TSTypeKind typeKind = GetTypeKind(gt);
|
||||
ASSERT(typeKind == TSTypeKind::TS_UNION);
|
||||
|
||||
JSHandle<TaggedArray> typeTable = GetGlobalUTable();
|
||||
int localUnionId = GetUTableIndex(gt, index);
|
||||
if (IsPrimtiveBuiltinTypes(localUnionId)) {
|
||||
return GlobalTSTypeRef(localUnionId);
|
||||
}
|
||||
int unionTableIndex = GetUserdefinedTypeId(localUnionId);
|
||||
JSHandle<TSType> resulteType(thread, typeTable->Get(unionTableIndex));
|
||||
if (resulteType.GetTaggedValue().IsTSImportType()) {
|
||||
JSHandle<TSImportType> ImportType(thread, typeTable->Get(unionTableIndex));
|
||||
return JSHandle<TSType>(thread, ImportType->GetTargetType())->GetGTRef();
|
||||
}
|
||||
return resulteType->GetGTRef();
|
||||
}
|
||||
|
||||
GlobalTSTypeRef TSLoader::GetGTFromPandFile(const panda_file::File &pf, int localId) const
|
||||
{
|
||||
if (IsPrimtiveBuiltinTypes(localId)) {
|
||||
return GlobalTSTypeRef(localId);
|
||||
}
|
||||
|
||||
JSThread *thread = vm_->GetJSThread();
|
||||
ObjectFactory *factory = vm_->GetFactory();
|
||||
JSHandle<TSModuleTable> table = GetTSModuleTable();
|
||||
|
||||
CString moduleName = CString(pf.GetFilename());
|
||||
int moduleId = table->GetGlobalModuleID(thread, factory->NewFromString(moduleName));
|
||||
int userDefId = GetUserdefinedTypeId(localId);
|
||||
|
||||
JSHandle<TSTypeTable> typeTable = table->GetTSTypeTable(thread, moduleId);
|
||||
JSHandle<TSType> bindType = JSHandle<TSType>(thread, typeTable->Get(userDefId));
|
||||
|
||||
return bindType->GetGTRef();
|
||||
}
|
||||
|
||||
void TSLoader::Dump()
|
||||
{
|
||||
std::cout << "TSTypeTables:";
|
||||
JSThread *thread = vm_->GetJSThread();
|
||||
JSHandle<TSModuleTable> table = GetTSModuleTable();
|
||||
int GTLength = table->GetLength();
|
||||
for (int i = 0; i < GTLength; i++) {
|
||||
JSHandle<JSTaggedValue>(thread, table->Get(i))->Dump(thread, std::cout);
|
||||
}
|
||||
}
|
||||
|
||||
JSHandle<EcmaString> TSLoader::GenerateAmiPath(JSHandle<EcmaString> cur, JSHandle<EcmaString> rel) const
|
||||
{
|
||||
ObjectFactory *factory = vm_->GetFactory();
|
||||
CString currentAbcFile = ConvertToString(cur.GetTaggedValue());
|
||||
CString relativeAbcFile = ConvertToString(rel.GetTaggedValue());
|
||||
CString fullPath;
|
||||
|
||||
if (relativeAbcFile.find("./") != 0 && relativeAbcFile.find("../") != 0) { // not start with "./" or "../"
|
||||
fullPath = relativeAbcFile + ".abc";
|
||||
return factory->NewFromString(fullPath); // not relative
|
||||
}
|
||||
auto slashPos = currentAbcFile.find_last_of('/');
|
||||
if (slashPos == std::string::npos) {
|
||||
fullPath.append(relativeAbcFile.substr(2, relativeAbcFile.size() - 2)); // 2: remove "./"
|
||||
fullPath.append(".abc"); // ".js" -> ".abc"
|
||||
return factory->NewFromString(fullPath);
|
||||
}
|
||||
|
||||
fullPath.append(currentAbcFile.substr(0, slashPos + 1)); // 1: with "/"
|
||||
fullPath.append(relativeAbcFile.substr(2, relativeAbcFile.size() - 2)); // 2: remove "./"
|
||||
fullPath.append(".abc"); // ".js" -> ".abc"
|
||||
|
||||
return factory->NewFromString(fullPath);
|
||||
}
|
||||
|
||||
JSHandle<EcmaString> TSLoader::GenerateImportVar(JSHandle<EcmaString> import) const
|
||||
{
|
||||
ObjectFactory *factory = vm_->GetFactory();
|
||||
// importNamePath #A#./A
|
||||
CString importVarNamePath = ConvertToString(import.GetTaggedValue());
|
||||
auto firstPos = importVarNamePath.find_first_of('#');
|
||||
auto lastPos = importVarNamePath.find_last_of('#');
|
||||
CString target = importVarNamePath.substr(firstPos + 1, lastPos - firstPos - 1);
|
||||
return factory->NewFromString(target); // #A#./A -> A
|
||||
}
|
||||
|
||||
JSHandle<EcmaString> TSLoader::GenerateImportRelativePath(JSHandle<EcmaString> importRel) const
|
||||
{
|
||||
ObjectFactory *factory = vm_->GetFactory();
|
||||
CString importNamePath = ConvertToString(importRel.GetTaggedValue());
|
||||
auto lastPos = importNamePath.find_last_of('#');
|
||||
CString path = importNamePath.substr(lastPos + 1, importNamePath.size() - lastPos - 1);
|
||||
return factory->NewFromString(path); // #A#./A -> ./A
|
||||
}
|
||||
|
||||
JSHandle<JSTaggedValue> TSLoader::InitUnionTypeTable()
|
||||
{
|
||||
ObjectFactory *factory = vm_->GetFactory();
|
||||
|
||||
JSHandle<JSTaggedValue> initUnionTypeTable = JSHandle<JSTaggedValue>::Cast(factory->EmptyArray());
|
||||
return initUnionTypeTable;
|
||||
}
|
||||
|
||||
GlobalTSTypeRef TSLoader::AddUinonTypeToGlobalUnionTable(JSHandle<TSUnionType> unionType)
|
||||
{
|
||||
JSThread *thread = vm_->GetJSThread();
|
||||
JSHandle<TSModuleTable> table = GetTSModuleTable();
|
||||
|
||||
int unionTableId = table->GetNumberOfTSTypeTable();
|
||||
JSHandle<EcmaString> finalNameString = table->GetAmiPathByModuleId(thread, (unionTableId));
|
||||
[[maybe_unused]] CString finalModuleName = ConvertToString(finalNameString.GetTaggedValue());
|
||||
ASSERT(finalModuleName == "UnionTypeTable");
|
||||
|
||||
JSHandle<TaggedArray> unionTypeTable = GetGlobalUTable();
|
||||
JSHandle<TaggedArray> utWithNewUnion = TaggedArray::SetCapacity(thread, unionTypeTable,
|
||||
unionTypeTable->GetLength() + 1);
|
||||
int unionIndex = utWithNewUnion->GetLength() - 1;
|
||||
utWithNewUnion->Set(thread, unionIndex, unionType.GetTaggedValue());
|
||||
|
||||
int unionTypeTableOffset = TSModuleTable::GetTSTypeTableOffset(unionTableId);
|
||||
table->Set(thread, unionTypeTableOffset, utWithNewUnion.GetTaggedValue());
|
||||
SetTSModuleTable(table);
|
||||
GlobalTSTypeRef addUnionRef = CreateGT(unionTableId, unionIndex, static_cast<int>(TSTypeKind::TS_UNION));
|
||||
return addUnionRef;
|
||||
}
|
||||
|
||||
GlobalTSTypeRef TSLoader::CreateGT(int moduleId, int localId, int typeKind) const
|
||||
{
|
||||
return GlobalTSTypeRef(moduleId, localId, typeKind);
|
||||
}
|
||||
|
||||
GlobalTSTypeRef TSLoader::FindInGlobalUTable(JSHandle<TSUnionType> unionType) const
|
||||
{
|
||||
JSThread *thread = vm_->GetJSThread();
|
||||
JSHandle<TSModuleTable> table = GetTSModuleTable();
|
||||
int unionTableId = table->GetNumberOfTSTypeTable();
|
||||
|
||||
JSHandle<EcmaString> finalNameString = table->GetAmiPathByModuleId(thread, unionTableId);
|
||||
[[maybe_unused]] CString finalModuleName = ConvertToString(finalNameString.GetTaggedValue());
|
||||
ASSERT(finalModuleName == "UnionTypeTable");
|
||||
|
||||
JSHandle<TaggedArray> unionTypeTable = GetGlobalUTable();
|
||||
int tableLength = unionTypeTable->GetLength();
|
||||
GlobalTSTypeRef foundUnionRef = GlobalTSTypeRef::Default();
|
||||
for (int unionIndex = 0; unionIndex < tableLength; unionIndex++) {
|
||||
JSHandle<TSUnionType> unionTemp = JSHandle<TSUnionType>(thread, unionTypeTable->Get(unionIndex));
|
||||
ASSERT(unionTemp.GetTaggedValue().IsTSUnionType() && unionType.GetTaggedValue().IsTSUnionType());
|
||||
bool foundTag = unionTemp->IsEqual(thread, unionType);
|
||||
if (foundTag) {
|
||||
foundUnionRef = CreateGT(unionTableId, unionIndex,
|
||||
static_cast<int>(TSTypeKind::TS_UNION));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return foundUnionRef;
|
||||
}
|
||||
|
||||
GlobalTSTypeRef TSLoader::GetOrCreateUnionType(CVector<GlobalTSTypeRef> unionTypeRef, int size)
|
||||
{
|
||||
JSThread *thread = vm_->GetJSThread();
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
JSHandle<TSModuleTable> table = GetTSModuleTable();
|
||||
int finalTableId = table->GetNumberOfTSTypeTable();
|
||||
|
||||
JSHandle<EcmaString> finalNameString = table->GetAmiPathByModuleId(thread, finalTableId);
|
||||
[[maybe_unused]] CString finalModuleName = ConvertToString(finalNameString.GetTaggedValue());
|
||||
if (finalModuleName != "UnionTypeTable") {
|
||||
// Set UnionTypeTable -> GlobleModuleTable
|
||||
JSHandle<JSTaggedValue> initUnionTypeTable = InitUnionTypeTable();
|
||||
JSHandle<EcmaString> unionTableName = factory->NewFromString(CString("UnionTypeTable"));
|
||||
AddTypeTable(initUnionTypeTable, unionTableName);
|
||||
}
|
||||
|
||||
JSHandle<TSUnionType> unionType = factory->NewTSUnionType(size);
|
||||
JSHandle<TaggedArray> unionTypeArray(thread, unionType->GetComponentTypes());
|
||||
|
||||
for (int unionArgIndex = 0; unionArgIndex < size; unionArgIndex++) {
|
||||
unionTypeArray->Set(thread, unionArgIndex, JSTaggedValue(unionTypeRef[unionArgIndex].GetGlobalTSTypeRef()));
|
||||
}
|
||||
unionType->SetComponentTypes(thread, unionTypeArray);
|
||||
|
||||
GlobalTSTypeRef foundUnionRef = FindInGlobalUTable(unionType);
|
||||
int unionModuleId = table->GetNumberOfTSTypeTable();
|
||||
|
||||
int foundUnionModuleId = foundUnionRef.GetModuleId();
|
||||
if (foundUnionModuleId != unionModuleId) {
|
||||
foundUnionRef = AddUinonTypeToGlobalUnionTable(unionType);
|
||||
}
|
||||
return foundUnionRef;
|
||||
}
|
||||
|
||||
void TSLoader::Iterate(const RootVisitor &v)
|
||||
{
|
||||
v(Root::ROOT_VM, ObjectSlot(reinterpret_cast<uintptr_t>(&globalModuleTable_)));
|
||||
}
|
||||
|
||||
GlobalTSTypeRef TSLoader::GetPrmitiveGT(TSTypeKind kind) const
|
||||
{
|
||||
return GlobalTSTypeRef(static_cast<uint64_t>(kind));
|
||||
}
|
||||
|
||||
GlobalTSTypeRef TSLoader::GetImportTypeTargetGT(GlobalTSTypeRef gt) const
|
||||
{
|
||||
JSThread *thread = vm_->GetJSThread();
|
||||
JSHandle<TSModuleTable> table = GetTSModuleTable();
|
||||
|
||||
int moduleId = gt.GetModuleId();
|
||||
int localTSTypetableId = gt.GetLocalId();
|
||||
int LocalTableIndex = GetUserdefinedTypeId(localTSTypetableId);
|
||||
[[maybe_unused]] TSTypeKind typeKind = GetTypeKind(gt);
|
||||
ASSERT(typeKind == TSTypeKind::TS_IMPORT);
|
||||
|
||||
JSHandle<TSTypeTable> typeTable = table->GetTSTypeTable(thread, moduleId);
|
||||
JSHandle<TSImportType> importType(thread, typeTable->Get(LocalTableIndex));
|
||||
|
||||
if (importType->GetTargetType().IsInt()) {
|
||||
return GlobalTSTypeRef(importType->GetTargetType().GetInt());
|
||||
}
|
||||
return JSHandle<TSType>(thread, importType->GetTargetType())->GetGTRef();
|
||||
}
|
||||
|
||||
JSHandle<TaggedArray> TSLoader::GetGlobalUTable() const
|
||||
{
|
||||
JSThread *thread = vm_->GetJSThread();
|
||||
JSHandle<TSModuleTable> table = GetTSModuleTable();
|
||||
int moduleId = table->GetNumberOfTSTypeTable();
|
||||
|
||||
int globalUTableOffset = TSModuleTable::GetTSTypeTableOffset(moduleId);
|
||||
JSHandle<TaggedArray> globalUTable(thread, table->Get(globalUTableOffset));
|
||||
|
||||
return globalUTable;
|
||||
}
|
||||
|
||||
JSHandle<EcmaString> TSModuleTable::GetAmiPathByModuleId(JSThread *thread, int entry) const
|
||||
{
|
||||
int amiOffset = GetAmiPathOffset(entry);
|
||||
JSHandle<EcmaString> amiPath = JSHandle<EcmaString>(thread, Get(amiOffset));
|
||||
return amiPath;
|
||||
}
|
||||
|
||||
JSHandle<TSTypeTable> TSModuleTable::GetTSTypeTable(JSThread *thread, int entry) const
|
||||
{
|
||||
int typeTableOffset = GetTSTypeTableOffset(entry);
|
||||
JSHandle<TSTypeTable> typeTable = JSHandle<TSTypeTable>(thread, Get(typeTableOffset));
|
||||
|
||||
return typeTable;
|
||||
}
|
||||
|
||||
int TSModuleTable::GetGlobalModuleID(JSThread *thread, JSHandle<EcmaString> amiPath) const
|
||||
{
|
||||
int length = GetNumberOfTSTypeTable();
|
||||
for (int i = 0; i < length; i ++) {
|
||||
JSHandle<EcmaString> valueString = GetAmiPathByModuleId(thread, i);
|
||||
if (EcmaString::StringsAreEqual(*amiPath, *valueString)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
JSHandle<TSModuleTable> TSModuleTable::AddTypeTable(JSThread *thread, JSHandle<TSModuleTable> table,
|
||||
JSHandle<JSTaggedValue> typeTable, JSHandle<EcmaString> amiPath)
|
||||
{
|
||||
int numberOfTSTypeTable = table->GetNumberOfTSTypeTable();
|
||||
if (GetTSTypeTableOffset(numberOfTSTypeTable) > table->GetLength()) {
|
||||
table = JSHandle<TSModuleTable>(TaggedArray::SetCapacity(thread, JSHandle<TaggedArray>(table),
|
||||
table->GetLength()*INCREASE_CAPACITY_RATE));
|
||||
}
|
||||
|
||||
// increase 1 tstypeTable
|
||||
table->Set(thread, NUMBER_ELEMENTS_OFFSET, JSTaggedValue(numberOfTSTypeTable + 1));
|
||||
table->Set(thread, GetAmiPathOffset(numberOfTSTypeTable), amiPath);
|
||||
table->Set(thread, GetSortIdOffset(numberOfTSTypeTable), JSTaggedValue(GetSortIdOffset(numberOfTSTypeTable)));
|
||||
table->Set(thread, GetTSTypeTableOffset(numberOfTSTypeTable), typeTable);
|
||||
return table;
|
||||
}
|
||||
}
|
235
ecmascript/ts_types/ts_loader.h
Executable file
235
ecmascript/ts_types/ts_loader.h
Executable file
@ -0,0 +1,235 @@
|
||||
/*
|
||||
* 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_TS_TYPES_TS_LOADER_H
|
||||
#define ECMASCRIPT_TS_TYPES_TS_LOADER_H
|
||||
|
||||
#include "ecmascript/mem/c_string.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
#include "ecmascript/js_tagged_value-inl.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
class GlobalTSTypeRef {
|
||||
public:
|
||||
GlobalTSTypeRef(uint64_t num = 0) : ref_(num) {};
|
||||
GlobalTSTypeRef(int moduleId, int localId, int typeKind)
|
||||
{
|
||||
ref_ = 0;
|
||||
SetUserDefineTypeKind(typeKind);
|
||||
SetLocalId(localId);
|
||||
SetModuleId(moduleId);
|
||||
}
|
||||
~GlobalTSTypeRef() = default;
|
||||
|
||||
static constexpr int TS_TYPE_RESERVED_COUNT = 50;
|
||||
static constexpr int GLOBAL_TSTYPE_REF_SIZE = 64;
|
||||
static constexpr int USER_DEFINE_TYPE_KIND_FIELD_NUM = 6;
|
||||
static constexpr int GC_TYPE_FIELD_NUM = 3;
|
||||
static constexpr int LOCAL_TSTYPETABLE_INDEX_FIELD_NUM = 32;
|
||||
static constexpr int GLOBAL_MODULE_ID_FIELD_NUM = 23;
|
||||
FIRST_BIT_FIELD(GlobalTSTypeRef, UserDefineTypeKind, uint8_t, USER_DEFINE_TYPE_KIND_FIELD_NUM);
|
||||
NEXT_BIT_FIELD(GlobalTSTypeRef, GCType, uint32_t, GC_TYPE_FIELD_NUM, UserDefineTypeKind);
|
||||
NEXT_BIT_FIELD(GlobalTSTypeRef, LocalId, uint32_t, LOCAL_TSTYPETABLE_INDEX_FIELD_NUM, GCType);
|
||||
NEXT_BIT_FIELD(GlobalTSTypeRef, ModuleId, uint32_t, GLOBAL_MODULE_ID_FIELD_NUM, LocalId);
|
||||
|
||||
static GlobalTSTypeRef Default()
|
||||
{
|
||||
return GlobalTSTypeRef(0u);
|
||||
}
|
||||
|
||||
uint64_t GetGlobalTSTypeRef() const
|
||||
{
|
||||
return ref_;
|
||||
}
|
||||
|
||||
void SetGlobalTSTypeRef(uint64_t gt)
|
||||
{
|
||||
ref_ = gt;
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
ref_ = 0;
|
||||
}
|
||||
private:
|
||||
uint64_t ref_;
|
||||
};
|
||||
|
||||
enum class TSTypeKind : int {
|
||||
TS_ANY = 0,
|
||||
TS_NUMBER,
|
||||
TS_BOOLEAN,
|
||||
TS_VOID,
|
||||
TS_STRING,
|
||||
TS_SYMBOL,
|
||||
TS_NULL,
|
||||
TS_UNDEFINED,
|
||||
TS_INT,
|
||||
TS_TYPE_RESERVED_LENGTH = GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT, // include builtins type and MR type
|
||||
TS_CLASS,
|
||||
TS_CLASS_INSTANCE,
|
||||
TS_FUNCTION,
|
||||
TS_UNION,
|
||||
TS_ARRAY,
|
||||
TS_OBJECT,
|
||||
TS_IMPORT,
|
||||
TS_INTERFACE
|
||||
};
|
||||
|
||||
class TSModuleTable : public TaggedArray {
|
||||
public:
|
||||
|
||||
static constexpr int AMI_PATH_OFFSET = 1;
|
||||
static constexpr int SORT_ID_OFFSET = 2;
|
||||
static constexpr int TYPE_TABLE_OFFSET = 3;
|
||||
static constexpr int ELEMENT_OFFSET = 3;
|
||||
static constexpr int NUMBER_ELEMENTS_OFFSET = 0;
|
||||
static constexpr int INCREASE_CAPACITY_RATE = 2;
|
||||
static constexpr int DEAULT_TABLE_CAPACITY = 4;
|
||||
static constexpr int INITIA_TSTYPE_TABLE_NUMBER = 0;
|
||||
static constexpr int NOT_FOUND = -1;
|
||||
|
||||
static TSModuleTable *Cast(TaggedObject *object)
|
||||
{
|
||||
ASSERT(JSTaggedValue(object).IsTaggedArray());
|
||||
return static_cast<TSModuleTable *>(object);
|
||||
}
|
||||
|
||||
static JSHandle<TSModuleTable> AddTypeTable(JSThread *thread, JSHandle<TSModuleTable> table,
|
||||
JSHandle<JSTaggedValue> typeTable, JSHandle<EcmaString> amiPath);
|
||||
|
||||
JSHandle<EcmaString> GetAmiPathByModuleId(JSThread *thread, int entry) const;
|
||||
|
||||
JSHandle<TSTypeTable> GetTSTypeTable(JSThread *thread, int entry) const;
|
||||
|
||||
int GetGlobalModuleID(JSThread *thread, JSHandle<EcmaString> amiPath) const;
|
||||
|
||||
inline int GetNumberOfTSTypeTable() const
|
||||
{
|
||||
return Get(NUMBER_ELEMENTS_OFFSET).GetInt();;
|
||||
}
|
||||
|
||||
static int GetTSTypeTableOffset(int entry)
|
||||
{
|
||||
return entry * ELEMENT_OFFSET + TYPE_TABLE_OFFSET;
|
||||
}
|
||||
|
||||
void InitializeNumberOfTSTypeTable(JSThread *thread)
|
||||
{
|
||||
Set(thread, NUMBER_ELEMENTS_OFFSET, JSTaggedValue(INITIA_TSTYPE_TABLE_NUMBER));
|
||||
}
|
||||
private:
|
||||
|
||||
static int GetAmiPathOffset(int entry)
|
||||
{
|
||||
return entry * ELEMENT_OFFSET + AMI_PATH_OFFSET;
|
||||
}
|
||||
|
||||
static int GetSortIdOffset(int entry)
|
||||
{
|
||||
return entry * ELEMENT_OFFSET + SORT_ID_OFFSET;
|
||||
}
|
||||
};
|
||||
|
||||
class TSLoader {
|
||||
public:
|
||||
explicit TSLoader(EcmaVM *vm);
|
||||
~TSLoader() = default;
|
||||
|
||||
void DecodeTSTypes(const panda_file::File &pf);
|
||||
|
||||
void AddTypeTable(JSHandle<JSTaggedValue> typeTable, JSHandle<EcmaString> amiPath);
|
||||
|
||||
GlobalTSTypeRef GetGTFromPandFile(const panda_file::File &pf, int localId) const;
|
||||
|
||||
void Link();
|
||||
|
||||
void Dump();
|
||||
|
||||
inline static TSTypeKind GetTypeKind(GlobalTSTypeRef gt)
|
||||
{
|
||||
return static_cast<TSTypeKind>(gt.GetUserDefineTypeKind());
|
||||
}
|
||||
|
||||
GlobalTSTypeRef GetPropType(GlobalTSTypeRef gt, JSHandle<EcmaString> propertyName) const;
|
||||
|
||||
int GetUnionTypeLength(GlobalTSTypeRef gt) const;
|
||||
|
||||
static int GetUserdefinedTypeId(int LocalId);
|
||||
|
||||
bool IsPrimtiveBuiltinTypes(int localId) const;
|
||||
|
||||
int GetUTableIndex(GlobalTSTypeRef gt, int index) const;
|
||||
|
||||
GlobalTSTypeRef GetUnionTypeByIndex(GlobalTSTypeRef gt, int index) const;
|
||||
|
||||
GlobalTSTypeRef GetOrCreateUnionType(CVector<GlobalTSTypeRef> unionTypeRef, int size);
|
||||
|
||||
void Iterate(const RootVisitor &v);
|
||||
|
||||
GlobalTSTypeRef GetPrmitiveGT(TSTypeKind kind) const;
|
||||
|
||||
GlobalTSTypeRef GetImportTypeTargetGT(GlobalTSTypeRef gt) const;
|
||||
|
||||
JSHandle<TSModuleTable> GetTSModuleTable() const
|
||||
{
|
||||
return JSHandle<TSModuleTable>(reinterpret_cast<uintptr_t>(&globalModuleTable_));
|
||||
}
|
||||
|
||||
void SetTSModuleTable(JSHandle<TSModuleTable> table)
|
||||
{
|
||||
globalModuleTable_ = table.GetTaggedValue();
|
||||
}
|
||||
|
||||
int GetNextModuleId() const
|
||||
{
|
||||
JSHandle<TSModuleTable> table = GetTSModuleTable();
|
||||
return table->GetNumberOfTSTypeTable();
|
||||
}
|
||||
|
||||
JSHandle<EcmaString> GenerateAmiPath(JSHandle<EcmaString> cur, JSHandle<EcmaString> rel) const;
|
||||
|
||||
JSHandle<EcmaString> GenerateImportVar(JSHandle<EcmaString> import) const;
|
||||
|
||||
JSHandle<EcmaString> GenerateImportRelativePath(JSHandle<EcmaString> importRel) const;
|
||||
|
||||
private:
|
||||
|
||||
NO_COPY_SEMANTIC(TSLoader);
|
||||
NO_MOVE_SEMANTIC(TSLoader);
|
||||
|
||||
void LinkTSTypeTable(JSHandle<TSTypeTable> table);
|
||||
|
||||
void RecursivelyResolveTargetType(JSMutableHandle<TSImportType>& importType);
|
||||
|
||||
int GetTypeIndexFromExportTable(JSHandle<EcmaString> target, JSHandle<TaggedArray> &exportTable) const;
|
||||
|
||||
JSHandle<JSTaggedValue> InitUnionTypeTable();
|
||||
|
||||
GlobalTSTypeRef CreateGT(int moduleId, int localId, int typeKind) const;
|
||||
|
||||
GlobalTSTypeRef AddUinonTypeToGlobalUnionTable(JSHandle<TSUnionType> unionType);
|
||||
|
||||
GlobalTSTypeRef FindInGlobalUTable(JSHandle<TSUnionType> unionType) const;
|
||||
|
||||
JSHandle<TaggedArray> GetGlobalUTable() const;
|
||||
|
||||
EcmaVM *vm_ {nullptr};
|
||||
JSTaggedValue globalModuleTable_ {JSTaggedValue::Hole()};
|
||||
friend class EcmaVM;
|
||||
};
|
||||
} // namespace panda::ecmascript
|
||||
|
||||
#endif // ECMASCRIPT_TS_TYPES_TS_LOADER_H
|
68
ecmascript/ts_types/ts_obj_layout_info-inl.h
Normal file
68
ecmascript/ts_types/ts_obj_layout_info-inl.h
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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_TS_TYPES_TS_OBJ_LAYOUT_INFO_INL_H_
|
||||
#define ECMASCRIPT_TS_TYPES_TS_OBJ_LAYOUT_INFO_INL_H_
|
||||
|
||||
#include "ts_obj_layout_info.h"
|
||||
#include "ecmascript/tagged_array-inl.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
inline int TSObjLayoutInfo::GetPropertiesCapacity() const
|
||||
{
|
||||
return static_cast<int>((GetLength() - ELEMENTS_START_INDEX) / ENTRY_SIZE);
|
||||
}
|
||||
|
||||
inline void TSObjLayoutInfo::SetNumberOfElements(const JSThread *thread, int propertiesNum)
|
||||
{
|
||||
return TaggedArray::Set(thread, ELEMENTS_COUNT_INDEX, JSTaggedValue(propertiesNum));
|
||||
}
|
||||
|
||||
inline int TSObjLayoutInfo::NumberOfElements() const
|
||||
{
|
||||
return TaggedArray::Get(ELEMENTS_COUNT_INDEX).GetInt();
|
||||
}
|
||||
|
||||
inline uint32_t TSObjLayoutInfo::GetKeyIndex(int index) const
|
||||
{
|
||||
return ELEMENTS_START_INDEX + (static_cast<uint32_t>(index) * ENTRY_SIZE + ENTRY_KEY_OFFSET);
|
||||
}
|
||||
|
||||
inline uint32_t TSObjLayoutInfo::GetTypeIdIndex(int index) const
|
||||
{
|
||||
return ELEMENTS_START_INDEX + (static_cast<uint32_t>(index) * ENTRY_SIZE) + ENTRY_TYPE_OFFSET;
|
||||
}
|
||||
|
||||
inline void TSObjLayoutInfo::SetPropertyInit(const JSThread *thread, int index, const JSTaggedValue &key,
|
||||
const JSTaggedValue &tsTypeId)
|
||||
{
|
||||
uint32_t idxInArray = GetKeyIndex(index);
|
||||
TaggedArray::Set(thread, idxInArray + ENTRY_KEY_OFFSET, key);
|
||||
TaggedArray::Set(thread, idxInArray + ENTRY_TYPE_OFFSET, tsTypeId);
|
||||
}
|
||||
|
||||
inline JSTaggedValue TSObjLayoutInfo::GetKey(int index) const
|
||||
{
|
||||
uint32_t idxInArray = GetKeyIndex(index);
|
||||
return TaggedArray::Get(idxInArray);
|
||||
}
|
||||
|
||||
inline JSTaggedValue TSObjLayoutInfo::GetTypeId(int index) const
|
||||
{
|
||||
uint32_t idxInArray = GetTypeIdIndex(index);
|
||||
return TaggedArray::Get(idxInArray);
|
||||
}
|
||||
} // namespace panda::ecmascript
|
||||
#endif // ECMASCRIPT_TS_TYPES_TS_OBJ_LAYOUT_INFO_INL_H_
|
28
ecmascript/ts_types/ts_obj_layout_info.cpp
Normal file
28
ecmascript/ts_types/ts_obj_layout_info.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#include "ts_obj_layout_info-inl.h"
|
||||
#include "ecmascript/mem/assert_scope-inl.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
void TSObjLayoutInfo::SetKey(const JSThread *thread, [[maybe_unused]] int index, const JSTaggedValue &key,
|
||||
const JSTaggedValue &typeIdVal)
|
||||
{
|
||||
DISALLOW_GARBAGE_COLLECTION;
|
||||
int number = NumberOfElements();
|
||||
ASSERT(number == index);
|
||||
SetNumberOfElements(thread, number + 1);
|
||||
SetPropertyInit(thread, number, key, typeIdVal);
|
||||
}
|
||||
} // namespace panda::ecmascript
|
73
ecmascript/ts_types/ts_obj_layout_info.h
Normal file
73
ecmascript/ts_types/ts_obj_layout_info.h
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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_TS_TYPES_TS_OBJ_LAYOUT_INFO_H
|
||||
#define ECMASCRIPT_TS_TYPES_TS_OBJ_LAYOUT_INFO_H
|
||||
|
||||
#include "ecmascript/js_object.h"
|
||||
#include "ecmascript/tagged_array.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
// TSObjLayoutInfo contains keys and TsTypeId of Properties.
|
||||
class TSObjLayoutInfo : private TaggedArray {
|
||||
public:
|
||||
static constexpr int MIN_PROPERTIES_LENGTH = JSObject::MIN_PROPERTIES_LENGTH;
|
||||
static constexpr int MAX_PROPERTIES_LENGTH = PropertyAttributes::MAX_CAPACITY_OF_PROPERTIES;
|
||||
static constexpr int NUMBER_OF_PROPERTIES_INDEX = 0;
|
||||
static constexpr int ELEMENTS_START_INDEX = 1;
|
||||
static constexpr int ENTRY_SIZE = 2;
|
||||
static constexpr int ELEMENTS_COUNT_INDEX = ELEMENTS_START_INDEX - 1;
|
||||
static constexpr int ENTRY_TYPE_OFFSET = 1;
|
||||
static constexpr int ENTRY_KEY_OFFSET = 0;
|
||||
|
||||
inline static TSObjLayoutInfo *Cast(ObjectHeader *obj)
|
||||
{
|
||||
ASSERT(JSTaggedValue(obj).IsTaggedArray());
|
||||
return reinterpret_cast<TSObjLayoutInfo*>(obj);
|
||||
}
|
||||
|
||||
int GetPropertiesCapacity() const;
|
||||
void SetNumberOfElements(const JSThread *thread, int propertiesNum);
|
||||
int NumberOfElements() const;
|
||||
void SetPropertyInit(const JSThread *thread, int index, const JSTaggedValue &key, const JSTaggedValue &tsTypeId);
|
||||
JSTaggedValue GetKey(int index) const;
|
||||
JSTaggedValue GetTypeId(int index) const;
|
||||
void SetKey(const JSThread *thread, int index, const JSTaggedValue &key, const JSTaggedValue &typeId);
|
||||
|
||||
inline uint32_t GetLength() const
|
||||
{
|
||||
return TaggedArray::GetLength();
|
||||
}
|
||||
|
||||
static inline uint32_t ComputeArrayLength(uint32_t properties_number)
|
||||
{
|
||||
return (properties_number * ENTRY_SIZE) + ELEMENTS_START_INDEX;
|
||||
}
|
||||
|
||||
int FindElement(JSTaggedValue key, int propertiesNumber);
|
||||
|
||||
private:
|
||||
uint32_t GetKeyIndex(int index) const;
|
||||
uint32_t GetTypeIdIndex(int index) const;
|
||||
|
||||
static inline uint32_t ComputeGrowCapacity(uint32_t old_capacity)
|
||||
{
|
||||
uint32_t new_capacity = old_capacity * ENTRY_SIZE + ELEMENTS_START_INDEX;
|
||||
return new_capacity > MAX_PROPERTIES_LENGTH ? MAX_PROPERTIES_LENGTH : new_capacity;
|
||||
}
|
||||
};
|
||||
} // namespace panda::ecmascript
|
||||
|
||||
#endif // ECMASCRIPT_TS_TYPES_TS_OBJ_LAYOUT_INFO_H
|
175
ecmascript/ts_types/ts_type.cpp
Normal file
175
ecmascript/ts_types/ts_type.cpp
Normal file
@ -0,0 +1,175 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#include "ts_type.h"
|
||||
|
||||
#include "ecmascript/ic/ic_handler.h"
|
||||
#include "ecmascript/global_env.h"
|
||||
#include "ecmascript/layout_info.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
#include "ecmascript/js_hclass.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/ts_types/ts_obj_layout_info-inl.h"
|
||||
#include "ecmascript/ts_types/ts_type_table.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
JSHClass *TSObjectType::GetOrCreateHClass(JSThread *thread)
|
||||
{
|
||||
JSTaggedValue mayBeHClass = GetHClass();
|
||||
if (mayBeHClass.IsJSHClass()) {
|
||||
return JSHClass::Cast(mayBeHClass.GetTaggedObject());
|
||||
}
|
||||
JSHandle<TSObjLayoutInfo> propTypeInfo(thread, GetObjLayoutInfo().GetTaggedObject());
|
||||
JSHClass *hclass = CreateHClassByProps(thread, propTypeInfo);
|
||||
SetHClass(thread, JSTaggedValue(hclass));
|
||||
|
||||
return hclass;
|
||||
}
|
||||
|
||||
JSHClass *TSObjectType::CreateHClassByProps(JSThread *thread, JSHandle<TSObjLayoutInfo> propType) const
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
|
||||
int length = propType->GetLength();
|
||||
if (length > PropertyAttributes::MAX_CAPACITY_OF_PROPERTIES) {
|
||||
LOG(ERROR, RUNTIME) << "TSobject type has too many keys and cannot create hclass";
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
JSMutableHandle<JSTaggedValue> key(thread, JSTaggedValue::Undefined());
|
||||
JSHandle<LayoutInfo> layout = factory->CreateLayoutInfo(length);
|
||||
for (int index = 0; index < length; ++index) {
|
||||
JSTaggedValue tsPropKey = propType->GetKey(index);
|
||||
key.Update(tsPropKey);
|
||||
ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key");
|
||||
PropertyAttributes attributes = PropertyAttributes::Default();
|
||||
attributes.SetIsInlinedProps(true);
|
||||
attributes.SetRepresentation(Representation::MIXED);
|
||||
attributes.SetOffset(index);
|
||||
layout->AddKey(thread, index, key.GetTaggedValue(), attributes);
|
||||
}
|
||||
JSHandle<JSHClass> hclass = factory->NewEcmaDynClass(JSObject::SIZE, JSType::JS_OBJECT, length);
|
||||
hclass->SetLayout(thread, layout);
|
||||
hclass->SetNumberOfProps(length);
|
||||
|
||||
return *hclass;
|
||||
}
|
||||
|
||||
bool TSUnionType::IsEqual(JSThread *thread, JSHandle<TSUnionType> unionB)
|
||||
{
|
||||
DISALLOW_GARBAGE_COLLECTION;
|
||||
ASSERT(unionB->GetComponentTypes().IsTaggedArray());
|
||||
bool findUnionTag = 0;
|
||||
|
||||
TaggedArray *unionArrayA = TaggedArray::Cast(TSUnionType::GetComponentTypes().GetTaggedObject());
|
||||
TaggedArray *unionArrayB = TaggedArray::Cast(unionB->GetComponentTypes().GetTaggedObject());
|
||||
int unionALength = unionArrayA->GetLength();
|
||||
int unionBLength = unionArrayB->GetLength();
|
||||
if (unionALength != unionBLength) {
|
||||
return false;
|
||||
}
|
||||
for (int unionAIndex = 0; unionAIndex < unionALength; unionAIndex++) {
|
||||
int argUnionA = unionArrayA->Get(unionAIndex).GetNumber();
|
||||
bool findArgTag = 0;
|
||||
for (int unionBIndex = 0; unionBIndex < unionBLength; unionBIndex++) {
|
||||
int argUnionB = unionArrayB->Get(unionBIndex).GetNumber();
|
||||
if (argUnionA == argUnionB) {
|
||||
findArgTag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!findArgTag) {
|
||||
return findUnionTag;
|
||||
}
|
||||
}
|
||||
findUnionTag = 1;
|
||||
return findUnionTag;
|
||||
}
|
||||
|
||||
GlobalTSTypeRef TSClassType::SearchProperty(JSThread *thread, JSHandle<TSTypeTable> &table, TSTypeKind typeKind,
|
||||
int localtypeId, JSHandle<EcmaString> propName)
|
||||
{
|
||||
DISALLOW_GARBAGE_COLLECTION;
|
||||
CString propertyName = ConvertToString(propName.GetTaggedValue());
|
||||
|
||||
TSClassType *classType = TSClassType::Cast(table->Get(localtypeId).GetTaggedObject());
|
||||
TSObjectType *constructorType = TSObjectType::Cast(classType->GetConstructorType().GetTaggedObject());
|
||||
TSObjLayoutInfo *propTypeInfo = TSObjLayoutInfo::Cast(constructorType->GetObjLayoutInfo().GetTaggedObject());
|
||||
|
||||
// search static propType in constructorType
|
||||
for (int index = 0; index < propTypeInfo->NumberOfElements(); ++index) {
|
||||
JSTaggedValue tsPropKey = propTypeInfo->GetKey(index);
|
||||
if (ConvertToString(tsPropKey) == propertyName) {
|
||||
int localId = propTypeInfo->GetTypeId(index).GetNumber();
|
||||
if (localId < GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT) {
|
||||
return GlobalTSTypeRef(localId);
|
||||
}
|
||||
int localIdNonOffset = TSLoader::GetUserdefinedTypeId(localId);
|
||||
TSType *propertyType = TSType::Cast(table->Get(localIdNonOffset).GetTaggedObject());
|
||||
if (JSTaggedValue(propertyType).IsTSImportType()) {
|
||||
TSImportType *importType = TSImportType::Cast(table->Get(localIdNonOffset).GetTaggedObject());
|
||||
return importType->GetGTRef();
|
||||
}
|
||||
return propertyType->GetGTRef();
|
||||
}
|
||||
}
|
||||
return GlobalTSTypeRef::Default();
|
||||
}
|
||||
|
||||
GlobalTSTypeRef TSClassInstanceType::SearchProperty(JSThread *thread, JSHandle<TSTypeTable> &table, TSTypeKind typeKind,
|
||||
int localtypeId, JSHandle<EcmaString> propName)
|
||||
{
|
||||
DISALLOW_GARBAGE_COLLECTION;
|
||||
CString propertyName = ConvertToString(propName.GetTaggedValue());
|
||||
|
||||
TSClassInstanceType *classInstanceType = TSClassInstanceType::Cast(table->Get(localtypeId).GetTaggedObject());
|
||||
int localId = 0;
|
||||
TSClassType *createClassType = TSClassType::Cast(classInstanceType->GetCreateClassType().GetTaggedObject());
|
||||
TSObjectType *instanceType = TSObjectType::Cast(createClassType->GetInstanceType().GetTaggedObject());
|
||||
TSObjectType *prototype = TSObjectType::Cast(createClassType->GetPrototypeType().GetTaggedObject());
|
||||
TSObjLayoutInfo *instanceTypeInfo = TSObjLayoutInfo::Cast(instanceType->GetObjLayoutInfo().GetTaggedObject());
|
||||
TSObjLayoutInfo *prototypeTypeInfo = TSObjLayoutInfo::Cast(prototype->GetObjLayoutInfo().GetTaggedObject());
|
||||
|
||||
// search non-static propType in instanceType
|
||||
for (int index = 0; index < instanceTypeInfo->NumberOfElements(); ++index) {
|
||||
JSTaggedValue instancePropKey = instanceTypeInfo->GetKey(index);
|
||||
if (ConvertToString(instancePropKey) == propertyName) {
|
||||
localId = instanceTypeInfo->GetTypeId(index).GetNumber();
|
||||
if (localId < GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT) {
|
||||
return GlobalTSTypeRef(localId);
|
||||
}
|
||||
int localIdNonOffset = TSLoader::GetUserdefinedTypeId(localId);
|
||||
TSType *propertyType = TSType::Cast(table->Get(localIdNonOffset).GetTaggedObject());
|
||||
if (propertyType->GetGTRef().GetUserDefineTypeKind() ==
|
||||
static_cast<int>(TSTypeKind::TS_IMPORT)) {
|
||||
TSImportType *importType = TSImportType::Cast(table->Get(localIdNonOffset).GetTaggedObject());
|
||||
return importType->GetGTRef();
|
||||
}
|
||||
return propertyType->GetGTRef();
|
||||
}
|
||||
}
|
||||
// search functionType in prototype
|
||||
for (int index = 0; index < prototypeTypeInfo->NumberOfElements(); ++index) {
|
||||
JSTaggedValue prototypePropKey = prototypeTypeInfo->GetKey(index);
|
||||
if (ConvertToString(prototypePropKey) == propertyName) {
|
||||
localId = prototypeTypeInfo->GetTypeId(index).GetNumber();
|
||||
ASSERT(localId > GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT);
|
||||
int localIdNonOffset = TSLoader::GetUserdefinedTypeId(localId);
|
||||
TSType *propertyType = TSType::Cast(table->Get(localIdNonOffset).GetTaggedObject());
|
||||
return propertyType->GetGTRef();
|
||||
}
|
||||
}
|
||||
return GlobalTSTypeRef::Default();
|
||||
}
|
||||
}
|
145
ecmascript/ts_types/ts_type.h
Normal file
145
ecmascript/ts_types/ts_type.h
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* 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_TS_TYPES_TS_TYPE_H
|
||||
#define ECMASCRIPT_TS_TYPES_TS_TYPE_H
|
||||
|
||||
#include "ecmascript/ecma_macros.h"
|
||||
#include "ecmascript/js_tagged_value.h"
|
||||
#include "ecmascript/mem/tagged_object.h"
|
||||
#include "ecmascript/property_attributes.h"
|
||||
#include "ecmascript/ts_types/ts_loader.h"
|
||||
#include "include/hclass.h"
|
||||
#include "utils/bit_field.h"
|
||||
#include "ecmascript/ts_types/ts_obj_layout_info.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
|
||||
class TSType : public TaggedObject {
|
||||
public:
|
||||
static constexpr size_t BIT_FIELD_OFFSET = TaggedObjectSize();
|
||||
|
||||
inline static TSType *Cast(const TaggedObject *object)
|
||||
{
|
||||
return static_cast<TSType *>(const_cast<TaggedObject *>(object));
|
||||
}
|
||||
|
||||
ACCESSORS_PRIMITIVE_FIELD(Uint64, uint64_t, BIT_FIELD_OFFSET, SIZE);
|
||||
|
||||
GlobalTSTypeRef GetGTRef() const
|
||||
{
|
||||
return GlobalTSTypeRef(GetUint64());
|
||||
}
|
||||
|
||||
void SetGTRef(GlobalTSTypeRef r)
|
||||
{
|
||||
SetUint64(r.GetGlobalTSTypeRef());
|
||||
}
|
||||
};
|
||||
|
||||
class TSObjectType : public TSType {
|
||||
public:
|
||||
CAST_CHECK(TSObjectType, IsTSObjectType);
|
||||
|
||||
JSHClass *GetOrCreateHClass(JSThread *thread);
|
||||
|
||||
uint64_t GetTypeIdOfKey(JSTaggedValue key);
|
||||
|
||||
static constexpr size_t PROPERTIES_OFFSET = TSType::SIZE;
|
||||
ACCESSORS(ObjLayoutInfo, PROPERTIES_OFFSET, HCLASS_OFFSET);
|
||||
ACCESSORS(HClass, HCLASS_OFFSET, SIZE);
|
||||
|
||||
DECL_VISIT_OBJECT(PROPERTIES_OFFSET, SIZE)
|
||||
DECL_DUMP()
|
||||
|
||||
private:
|
||||
JSHClass* CreateHClassByProps(JSThread *thread, JSHandle<TSObjLayoutInfo> propType) const;
|
||||
};
|
||||
|
||||
class TSClassType : public TSType {
|
||||
public:
|
||||
CAST_CHECK(TSClassType, IsTSClassType);
|
||||
|
||||
static constexpr uint8_t FIELD_LENGTH = 4; // every field record name, typeIndex, accessFlag, readonly
|
||||
static constexpr size_t INSTANCE_TYPE_OFFSET = TSType::SIZE;
|
||||
|
||||
static GlobalTSTypeRef SearchProperty(JSThread *thread, JSHandle<TSTypeTable> &table, TSTypeKind typeKind,
|
||||
int localtypeId, JSHandle<EcmaString> propName);
|
||||
|
||||
ACCESSORS(InstanceType, INSTANCE_TYPE_OFFSET, CONSTRUCTOR_TYPE_OFFSET);
|
||||
ACCESSORS(ConstructorType, CONSTRUCTOR_TYPE_OFFSET, PROTOTYPE_TYPE_OFFSET);
|
||||
ACCESSORS(PrototypeType, PROTOTYPE_TYPE_OFFSET, EXTENSION_TYPE_OFFSET);
|
||||
ACCESSORS(ExtensionType, EXTENSION_TYPE_OFFSET, LAST_OFFSET);
|
||||
DEFINE_ALIGN_SIZE(LAST_OFFSET);
|
||||
|
||||
DECL_VISIT_OBJECT(INSTANCE_TYPE_OFFSET, LAST_OFFSET)
|
||||
DECL_DUMP()
|
||||
};
|
||||
|
||||
class TSClassInstanceType : public TSType {
|
||||
public:
|
||||
CAST_CHECK(TSClassInstanceType, IsTSClassInstanceType);
|
||||
|
||||
static GlobalTSTypeRef SearchProperty(JSThread *thread, JSHandle<TSTypeTable> &table, TSTypeKind typeKind,
|
||||
int localtypeId, JSHandle<EcmaString> propName);
|
||||
|
||||
static constexpr size_t CREATE_CLASS_TYPE_OFFSET = TSType::SIZE;
|
||||
ACCESSORS(CreateClassType, CREATE_CLASS_TYPE_OFFSET, SIZE);
|
||||
|
||||
DECL_VISIT_OBJECT(CREATE_CLASS_TYPE_OFFSET, SIZE)
|
||||
DECL_DUMP()
|
||||
};
|
||||
|
||||
class TSImportType : public TSType {
|
||||
public:
|
||||
CAST_CHECK(TSImportType, IsTSImportType);
|
||||
|
||||
static constexpr size_t IMPORT_TYPE_ID_OFFSET = TSType::SIZE;
|
||||
|
||||
ACCESSORS(ImportPath, IMPORT_TYPE_ID_OFFSET, IMPORT_PATH);
|
||||
ACCESSORS(TargetType, IMPORT_PATH, LAST_OFFSET);
|
||||
DEFINE_ALIGN_SIZE(LAST_OFFSET);
|
||||
|
||||
DECL_VISIT_OBJECT(IMPORT_TYPE_ID_OFFSET, IMPORT_PATH)
|
||||
DECL_DUMP()
|
||||
};
|
||||
|
||||
class TSUnionType : public TSType {
|
||||
public:
|
||||
CAST_CHECK(TSUnionType, IsTSUnionType);
|
||||
|
||||
bool IsEqual(JSThread *thread, JSHandle<TSUnionType> unionB);
|
||||
|
||||
static constexpr size_t KEYS_OFFSET = TSType::SIZE;
|
||||
ACCESSORS(ComponentTypes, KEYS_OFFSET, SIZE);
|
||||
|
||||
DECL_VISIT_OBJECT(KEYS_OFFSET, SIZE)
|
||||
DECL_DUMP()
|
||||
};
|
||||
|
||||
class TSInterfaceType : public TSType {
|
||||
public:
|
||||
CAST_CHECK(TSInterfaceType, IsTSInterfaceType);
|
||||
|
||||
static constexpr size_t EXTENDS_TYPE_ID_OFFSET = TSType::SIZE;
|
||||
ACCESSORS(Extends, EXTENDS_TYPE_ID_OFFSET, KEYS_OFFSET);
|
||||
ACCESSORS(Fields, KEYS_OFFSET, SIZE);
|
||||
|
||||
DECL_VISIT_OBJECT(KEYS_OFFSET, SIZE)
|
||||
DECL_DUMP()
|
||||
};
|
||||
} // namespace panda::ecmascript
|
||||
|
||||
#endif // ECMASCRIPT_TS_TYPES_TS_TYPE_H
|
450
ecmascript/ts_types/ts_type_table.cpp
Normal file
450
ecmascript/ts_types/ts_type_table.cpp
Normal file
@ -0,0 +1,450 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#include "ecmascript/class_linker/program_object.h"
|
||||
#include "ecmascript/js_handle.h"
|
||||
#include "ecmascript/literal_data_extractor.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/ts_types/ts_loader.h"
|
||||
#include "ecmascript/ts_types/ts_obj_layout_info-inl.h"
|
||||
#include "ecmascript/ts_types/ts_type_table.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
void TSTypeTable::Initialize(JSThread *thread, const panda_file::File &pf,
|
||||
CVector<JSHandle<EcmaString>> &recordImportMdoules)
|
||||
{
|
||||
EcmaVM *vm = thread->GetEcmaVM();
|
||||
TSLoader *tsLoader = vm->GetTSLoader();
|
||||
ObjectFactory *factory = vm->GetFactory();
|
||||
|
||||
JSHandle<TSTypeTable> tsTypetable = GenerateTypeTable(thread, pf, recordImportMdoules);
|
||||
LOG(DEBUG, DEBUGGER) << "dump TStypeTable";
|
||||
|
||||
// Set TStypeTable -> GlobleModuleTable
|
||||
JSHandle<EcmaString> fileName = factory->NewFromStdString(pf.GetFilename());
|
||||
tsLoader->AddTypeTable(JSHandle<JSTaggedValue>(tsTypetable), fileName);
|
||||
|
||||
// management dependency module
|
||||
while (recordImportMdoules.size() > 0) {
|
||||
const panda_file::File *moduleFile = GetPandaFile(recordImportMdoules.back());
|
||||
recordImportMdoules.pop_back();
|
||||
ASSERT(moduleFile != nullptr);
|
||||
TSTypeTable::Initialize(thread, *moduleFile, recordImportMdoules);
|
||||
}
|
||||
}
|
||||
|
||||
JSHandle<TSTypeTable> TSTypeTable::GenerateTypeTable(JSThread *thread, const panda_file::File &pf,
|
||||
CVector<JSHandle<EcmaString>> &recordImportMdoules)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
TSLoader *tsLoader = thread->GetEcmaVM()->GetTSLoader();
|
||||
GlobalTSTypeRef ref = GlobalTSTypeRef::Default();
|
||||
int typeKind = 0;
|
||||
|
||||
JSHandle<TaggedArray> summaryLiteral = LiteralDataExtractor::GetDatasIgnoreType(thread, &pf, 0);
|
||||
ASSERT_PRINT(summaryLiteral->Get(TYPE_KIND_OFFSET).GetInt() == static_cast<int32_t>(TypeLiteralFlag::COUNTER),
|
||||
"summary type literal flag is not counter");
|
||||
|
||||
uint32_t length = summaryLiteral->Get(TABLE_LENGTH_OFFSET_IN_LITREAL).GetInt();
|
||||
JSHandle<TSTypeTable> table = factory->NewTSTypeTable(length);
|
||||
|
||||
table->SetTypeTableLength(thread, length); // just for corresponding index between type literal and type table
|
||||
|
||||
JSMutableHandle<TaggedArray> typeLiteral(thread, JSTaggedValue::Undefined());
|
||||
for (uint32_t idx = 1; idx <= length; ++idx) {
|
||||
typeLiteral.Update(LiteralDataExtractor::GetDatasIgnoreType(thread, &pf, idx).GetTaggedValue());
|
||||
JSHandle<EcmaString> fileName = factory->NewFromStdString(pf.GetFilename());
|
||||
JSHandle<JSTaggedValue> type = ParseType(thread, table, typeLiteral, fileName, recordImportMdoules);
|
||||
if (!type->IsNull()) {
|
||||
typeKind = typeLiteral->Get(TYPE_KIND_OFFSET).GetInt();
|
||||
ref.SetUserDefineTypeKind(typeKind + GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT);
|
||||
ref.SetModuleId(tsLoader->GetNextModuleId());
|
||||
ref.SetLocalId(idx + GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT);
|
||||
JSHandle<TSType>(type)->SetGTRef(ref);
|
||||
}
|
||||
|
||||
table->Set(thread, idx, type);
|
||||
}
|
||||
|
||||
JSHandle<TaggedArray> exportValueTable = GetExportTableFromPandFile(thread, pf);
|
||||
if (exportValueTable->GetLength() != 0) { //add exprotValueTable to tSTypeTable if isn't empty
|
||||
table->Set(thread, table->GetLength() - 1, exportValueTable);
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
JSHandle<JSTaggedValue> TSTypeTable::ParseType(JSThread *thread, JSHandle<TSTypeTable> &table,
|
||||
JSHandle<TaggedArray> &literal, JSHandle<EcmaString> fileName,
|
||||
CVector<JSHandle<EcmaString>> &recordImportMdoules)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
TypeLiteralFlag flag = static_cast<TypeLiteralFlag>(literal->Get(TYPE_KIND_OFFSET).GetInt());
|
||||
switch (flag) {
|
||||
case TypeLiteralFlag::CLASS: {
|
||||
JSHandle<TSClassType> classType = ParseClassType(thread, table, literal);
|
||||
return JSHandle<JSTaggedValue>(thread, classType.GetTaggedValue());
|
||||
}
|
||||
case TypeLiteralFlag::CLASS_INSTANCE: {
|
||||
uint32_t bindIndex = literal->Get(1).GetInt() - GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT;
|
||||
JSHandle<TSClassType> createClassType(thread, table->Get(bindIndex));
|
||||
ASSERT(createClassType.GetTaggedValue().IsTSClassType());
|
||||
JSHandle<TSClassInstanceType> classInstance = factory->NewTSClassInstanceType();
|
||||
classInstance->SetCreateClassType(thread, createClassType);
|
||||
return JSHandle<JSTaggedValue>(thread, classInstance.GetTaggedValue());
|
||||
}
|
||||
case TypeLiteralFlag::INTERFACE: {
|
||||
JSHandle<TSInterfaceType> interfaceType = ParseInterfaceType(thread, table, literal);
|
||||
return JSHandle<JSTaggedValue>(thread, interfaceType.GetTaggedValue());
|
||||
}
|
||||
case TypeLiteralFlag::IMPORT: {
|
||||
JSHandle<TSImportType> importType = ParseImportType(thread, literal, fileName, recordImportMdoules);
|
||||
return JSHandle<JSTaggedValue>(thread, importType.GetTaggedValue());
|
||||
}
|
||||
case TypeLiteralFlag::UNION: {
|
||||
JSHandle<TSUnionType> unionType = ParseUnionType(thread, table, literal);
|
||||
return JSHandle<JSTaggedValue>(thread, unionType.GetTaggedValue());
|
||||
}
|
||||
case TypeLiteralFlag::FUNCTION:
|
||||
break;
|
||||
case TypeLiteralFlag::OBJECT:
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
// not support type yet
|
||||
return JSHandle<JSTaggedValue>(thread, JSTaggedValue::Null());
|
||||
}
|
||||
|
||||
GlobalTSTypeRef TSTypeTable::GetPropertyType(JSThread *thread, JSHandle<TSTypeTable> &table,
|
||||
TSTypeKind typeKind, uint32_t localtypeId, JSHandle<EcmaString> propName)
|
||||
{
|
||||
DISALLOW_GARBAGE_COLLECTION;
|
||||
CString propertyName = ConvertToString(propName.GetTaggedValue());
|
||||
switch (typeKind) {
|
||||
case TSTypeKind::TS_CLASS: {
|
||||
return TSClassType::SearchProperty(thread, table, typeKind, localtypeId, propName);
|
||||
break;
|
||||
}
|
||||
case TSTypeKind::TS_CLASS_INSTANCE: {
|
||||
return TSClassInstanceType::SearchProperty(thread, table, typeKind, localtypeId, propName);
|
||||
break;
|
||||
}
|
||||
case TSTypeKind::TS_OBJECT:
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
return GlobalTSTypeRef::Default();
|
||||
}
|
||||
|
||||
panda_file::File::EntityId TSTypeTable::GetFileId(const panda_file::File &pf)
|
||||
{
|
||||
Span<const uint32_t> classIndexes = pf.GetClasses();
|
||||
panda_file::File::EntityId fileId {0};
|
||||
panda_file::File::StringData sd = {static_cast<uint32_t>(ENTRY_FUNC_NAME.size()),
|
||||
reinterpret_cast<const uint8_t *>(CString(ENTRY_FUNC_NAME).c_str())};
|
||||
|
||||
for (const uint32_t index : classIndexes) {
|
||||
panda_file::File::EntityId classId(index);
|
||||
if (pf.IsExternal(classId)) {
|
||||
continue;
|
||||
}
|
||||
panda_file::ClassDataAccessor cda(pf, classId);
|
||||
cda.EnumerateMethods([&fileId, &pf, &sd](panda_file::MethodDataAccessor &mda) {
|
||||
if (pf.GetStringData(mda.GetNameId()) == sd) {
|
||||
fileId = mda.GetMethodId();
|
||||
}
|
||||
});
|
||||
}
|
||||
return fileId;
|
||||
}
|
||||
|
||||
const panda_file::File* TSTypeTable::GetPandaFile(JSHandle<EcmaString> modulePath)
|
||||
{
|
||||
CString modulePathString = ConvertToString(modulePath.GetTaggedValue());
|
||||
auto pandfile = panda_file::OpenPandaFileOrZip(modulePathString, panda_file::File::READ_WRITE);
|
||||
ASSERT(pandfile != nullptr);
|
||||
return pandfile.release();
|
||||
}
|
||||
|
||||
JSHandle<TaggedArray> TSTypeTable::GetExportTableFromPandFile(JSThread *thread, const panda_file::File &pf)
|
||||
{
|
||||
EcmaVM *ecmaVm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = ecmaVm->GetFactory();
|
||||
|
||||
panda_file::File::EntityId fileId = GetFileId(pf);
|
||||
panda_file::MethodDataAccessor mda(pf, fileId);
|
||||
|
||||
CVector<CString> exportTable;
|
||||
const char *exportSymbols;
|
||||
const char *exportSymbolTypes;
|
||||
auto *fileName = pf.GetFilename().c_str();
|
||||
if (::strcmp("ohos.lib.d.ts", fileName) == 0) {
|
||||
exportSymbols = "declaredSymbols";
|
||||
exportSymbolTypes = "declaredSymbols";
|
||||
} else {
|
||||
exportSymbols = "exportedSymbols";
|
||||
exportSymbolTypes = "exportedSymbolTypes";
|
||||
}
|
||||
|
||||
mda.EnumerateAnnotations([&](panda_file::File::EntityId annotation_id) {
|
||||
panda_file::AnnotationDataAccessor ada(pf, annotation_id);
|
||||
auto *annotationName = reinterpret_cast<const char *>(pf.GetStringData(ada.GetClassId()).data);
|
||||
ASSERT(annotationName != nullptr);
|
||||
if (::strcmp("L_ESTypeAnnotation;", annotationName) == 0) {
|
||||
uint32_t length = ada.GetCount();
|
||||
for (uint32_t i = 0; i < length; i++) {
|
||||
panda_file::AnnotationDataAccessor::Elem adae = ada.GetElement(i);
|
||||
auto *elem_name = reinterpret_cast<const char *>(pf.GetStringData(adae.GetNameId()).data);
|
||||
uint32_t elem_count = adae.GetArrayValue().GetCount();
|
||||
ASSERT(elem_name != nullptr);
|
||||
if (::strcmp(exportSymbols, elem_name) == 0) { // exportedSymbols -> ["A", "B", "c"]
|
||||
for (uint32_t j = 0; j < elem_count; ++j) {
|
||||
auto valueEntityId = adae.GetArrayValue().Get<panda_file::File::EntityId>(j);
|
||||
auto *valueStringData = reinterpret_cast<const char *>(pf.GetStringData(valueEntityId).data);
|
||||
CString target = ConvertToString(std::string(valueStringData));
|
||||
exportTable.push_back(target);
|
||||
}
|
||||
}
|
||||
if (::strcmp(exportSymbolTypes, elem_name) == 0) { // exportedSymbolTypes -> [51, 52, 53]
|
||||
for (uint32_t k = 0; k < elem_count; ++k) {
|
||||
auto value = adae.GetArrayValue().Get<panda_file::File::EntityId>(k).GetOffset();
|
||||
CString typeId = ToCString(value);
|
||||
exportTable.push_back(typeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
array_size_t length = exportTable.size();
|
||||
JSHandle<TaggedArray> exportArray = factory->NewTaggedArray(length);
|
||||
for (array_size_t i = 0; i < length; i ++) {
|
||||
JSHandle<EcmaString> typeIdString = factory->NewFromString(exportTable[i]);
|
||||
exportArray->Set(thread, i, JSHandle<JSTaggedValue>::Cast(typeIdString));
|
||||
}
|
||||
return exportArray;
|
||||
}
|
||||
|
||||
JSHandle<TSImportType> TSTypeTable::ParseImportType(JSThread *thread, const JSHandle<TaggedArray> &literal,
|
||||
JSHandle<EcmaString> fileName,
|
||||
CVector<JSHandle<EcmaString>> &recordImportMdoules)
|
||||
{
|
||||
EcmaVM *ecmaVm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = ecmaVm->GetFactory();
|
||||
TSLoader *tsLoader = ecmaVm->GetTSLoader();
|
||||
|
||||
JSHandle<TSImportType> importType = factory->NewTSImportType();
|
||||
JSHandle<EcmaString> importVarNamePath = JSHandle<EcmaString>(thread, literal->Get(1)); // #A#./A
|
||||
JSHandle<EcmaString> targetVar = tsLoader->GenerateImportVar(importVarNamePath); // #A#./A -> A
|
||||
JSHandle<EcmaString> relativePath = tsLoader->GenerateImportRelativePath(importVarNamePath); // #A#./A -> ./A
|
||||
JSHandle<EcmaString> fullPathHandle = tsLoader->GenerateAmiPath(fileName, relativePath); // ./A -> XXX/XXX/A
|
||||
CString fullPath = ConvertToString(fullPathHandle.GetTaggedValue());
|
||||
CString target = ConvertToString(targetVar.GetTaggedValue());
|
||||
|
||||
CString indexAndPath = "#" + target + "#" + fullPath; // #A#XXX/XXX/A
|
||||
|
||||
int32_t entry = tsLoader->GetTSModuleTable()->GetGlobalModuleID(thread, fullPathHandle);
|
||||
if (entry == -1) {
|
||||
bool flag = false;
|
||||
for (auto it : recordImportMdoules) {
|
||||
if (ConvertToString(it.GetTaggedValue()) == fullPath) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag) {
|
||||
recordImportMdoules.push_back(fullPathHandle);
|
||||
}
|
||||
}
|
||||
|
||||
JSHandle<EcmaString> indexAndPathString = factory->NewFromString(indexAndPath);
|
||||
importType->SetImportPath(thread, indexAndPathString.GetTaggedValue());
|
||||
return importType;
|
||||
}
|
||||
|
||||
JSHandle<TSClassType> TSTypeTable::ParseClassType(JSThread *thread, JSHandle<TSTypeTable> &typeTable,
|
||||
const JSHandle<TaggedArray> &literal)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
JSHandle<TSClassType> classType = factory->NewTSClassType();
|
||||
ASSERT(static_cast<TypeLiteralFlag>(literal->Get(0).GetInt()) == TypeLiteralFlag::CLASS);
|
||||
|
||||
uint32_t index = 1;
|
||||
index++; // ignore class modifier
|
||||
|
||||
uint32_t extendsTypeId = literal->Get(index++).GetInt();
|
||||
|
||||
// ignore implement
|
||||
uint32_t numImplement = literal->Get(index++).GetInt();
|
||||
index += numImplement;
|
||||
|
||||
JSMutableHandle<JSTaggedValue> key(thread, JSTaggedValue::Undefined());
|
||||
JSMutableHandle<JSTaggedValue> typeId(thread, JSTaggedValue::Undefined());
|
||||
|
||||
// resolve instance type
|
||||
uint32_t numBaseFields = 0;
|
||||
uint32_t numFields = literal->Get(index++).GetInt();
|
||||
|
||||
JSHandle<TSObjectType> instanceType;
|
||||
if (extendsTypeId) { // base class is 0
|
||||
uint32_t realExtendsTypeId = extendsTypeId - GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT;
|
||||
JSHandle<TSClassType> extensionType(thread, typeTable->Get(realExtendsTypeId));
|
||||
ASSERT(extensionType.GetTaggedValue().IsTSClassType());
|
||||
classType->SetExtensionType(thread, extensionType);
|
||||
instanceType = LinkSuper(thread, extensionType, &numBaseFields, numFields);
|
||||
} else {
|
||||
instanceType = factory->NewTSObjectType(numFields);
|
||||
}
|
||||
|
||||
JSHandle<TSObjLayoutInfo> instanceTypeInfo(thread, instanceType->GetObjLayoutInfo());
|
||||
ASSERT(instanceTypeInfo->GetPropertiesCapacity() == numBaseFields + numFields);
|
||||
for (uint32_t fieldIndex = 0; fieldIndex < numFields; ++fieldIndex) {
|
||||
key.Update(literal->Get(index++));
|
||||
typeId.Update(literal->Get(index++));
|
||||
index += 2; // 2: ignore accessFlag and readonly
|
||||
instanceTypeInfo->SetKey(thread, numBaseFields + fieldIndex, key.GetTaggedValue(), typeId.GetTaggedValue());
|
||||
}
|
||||
classType->SetInstanceType(thread, instanceType);
|
||||
|
||||
// resolve prototype type
|
||||
uint32_t numNonStatic = literal->Get(index++).GetInt();
|
||||
JSHandle<TSObjectType> prototypeType = factory->NewTSObjectType(numNonStatic);
|
||||
|
||||
JSHandle<TSObjLayoutInfo> nonStaticTypeInfo(thread, prototypeType->GetObjLayoutInfo());
|
||||
ASSERT(nonStaticTypeInfo->GetPropertiesCapacity() == numNonStatic);
|
||||
for (uint32_t nonStaticIndex = 0; nonStaticIndex < numNonStatic; ++nonStaticIndex) {
|
||||
key.Update(literal->Get(index++));
|
||||
typeId.Update(literal->Get(index++));
|
||||
nonStaticTypeInfo->SetKey(thread, nonStaticIndex, key.GetTaggedValue(), typeId.GetTaggedValue());
|
||||
}
|
||||
classType->SetPrototypeType(thread, prototypeType);
|
||||
|
||||
// resolve constructor type
|
||||
// stitic include fields and methods, which the former takes up 4 spaces and the latter takes up 2 spaces.
|
||||
uint32_t numStaticFields = literal->Get(index++).GetInt();
|
||||
uint32_t numStaticMethods = literal->Get(index + numStaticFields * TSClassType::FIELD_LENGTH).GetInt();
|
||||
uint32_t numStatic = numStaticFields + numStaticMethods;
|
||||
// new function type when support it
|
||||
JSHandle<TSObjectType> constructorType = factory->NewTSObjectType(numStatic);
|
||||
|
||||
JSHandle<TSObjLayoutInfo> staticTypeInfo(thread, constructorType->GetObjLayoutInfo());
|
||||
ASSERT(staticTypeInfo->GetPropertiesCapacity() == numStatic);
|
||||
for (uint32_t staticIndex = 0; staticIndex < numStaticFields; ++staticIndex) {
|
||||
key.Update(literal->Get(index++));
|
||||
typeId.Update(literal->Get(index++));
|
||||
index += 2; // 2: ignore accessFlag and readonly
|
||||
staticTypeInfo->SetKey(thread, staticIndex, key.GetTaggedValue(), typeId.GetTaggedValue());
|
||||
}
|
||||
index++; // jmp over numStaticMethods
|
||||
|
||||
// static methods
|
||||
for (uint32_t staticIndex = numStaticFields; staticIndex < numStatic; ++staticIndex) {
|
||||
key.Update(literal->Get(index++));
|
||||
typeId.Update(literal->Get(index++));
|
||||
staticTypeInfo->SetKey(thread, staticIndex, key.GetTaggedValue(), typeId.GetTaggedValue());
|
||||
}
|
||||
classType->SetConstructorType(thread, constructorType);
|
||||
return classType;
|
||||
}
|
||||
|
||||
JSHandle<TSInterfaceType> TSTypeTable::ParseInterfaceType(JSThread *thread, JSHandle<TSTypeTable> &typeTable,
|
||||
const JSHandle<TaggedArray> &literal)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
|
||||
uint32_t index = 0;
|
||||
JSHandle<TSInterfaceType> interfaceType = factory->NewTSInterfaceType();
|
||||
ASSERT(static_cast<TypeLiteralFlag>(literal->Get(index).GetInt()) == TypeLiteralFlag::INTERFACE);
|
||||
|
||||
index++;
|
||||
// resolve extends of interface
|
||||
uint32_t numExtends = literal->Get(index++).GetInt();
|
||||
JSHandle<TaggedArray> extendsId(factory->NewTaggedArray(numExtends));
|
||||
JSMutableHandle<JSTaggedValue> extendsType(thread, JSTaggedValue::Undefined());
|
||||
for (uint32_t extendsIndex = 0; extendsIndex < numExtends; extendsIndex++) {
|
||||
extendsType.Update(literal->Get(index++));
|
||||
extendsId->Set(thread, extendsIndex, extendsType);
|
||||
}
|
||||
interfaceType->SetExtends(extendsId.GetTaggedValue());
|
||||
|
||||
// resolve fields of interface
|
||||
uint32_t numFields = literal->Get(index++).GetInt();
|
||||
JSMutableHandle<JSTaggedValue> key(thread, JSTaggedValue::Undefined());
|
||||
JSMutableHandle<JSTaggedValue> typeId(thread, JSTaggedValue::Undefined());
|
||||
|
||||
JSHandle<TSObjectType> fieldsType = factory->NewTSObjectType(numFields);
|
||||
|
||||
JSHandle<TSObjLayoutInfo> fieldsTypeInfo(thread, fieldsType->GetObjLayoutInfo());
|
||||
ASSERT(fieldsTypeInfo->GetPropertiesCapacity() == numFields);
|
||||
for (uint32_t fieldsIndex = 0; fieldsIndex < numFields; ++fieldsIndex) {
|
||||
key.Update(literal->Get(index++));
|
||||
typeId.Update(literal->Get(index++));
|
||||
index += 2; // 2: ignore accessFlag and readonly
|
||||
fieldsTypeInfo->SetKey(thread, fieldsIndex, key.GetTaggedValue(), typeId.GetTaggedValue());
|
||||
}
|
||||
interfaceType->SetFields(thread, fieldsType);
|
||||
|
||||
return interfaceType;
|
||||
}
|
||||
|
||||
JSHandle<TSObjectType> TSTypeTable::LinkSuper(JSThread *thread, JSHandle<TSClassType> &baseClassType,
|
||||
uint32_t *numBaseFields, uint32_t numDerivedFields)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
|
||||
JSHandle<TSObjectType> baseInstanceType(thread, baseClassType->GetInstanceType());
|
||||
TSObjLayoutInfo *baseInstanceTypeInfo = TSObjLayoutInfo::Cast(baseInstanceType->GetObjLayoutInfo()
|
||||
.GetTaggedObject());
|
||||
*numBaseFields = baseInstanceTypeInfo->GetLength();
|
||||
|
||||
JSHandle<TSObjectType> derivedInstanceType = factory->NewTSObjectType(*numBaseFields + numDerivedFields);
|
||||
JSHandle<TSObjLayoutInfo> derivedInstanceTypeInfo(thread, derivedInstanceType->GetObjLayoutInfo());
|
||||
|
||||
for (uint32_t index = 0; index < baseInstanceTypeInfo->GetLength(); ++index) {
|
||||
JSTaggedValue baseInstanceKey = baseInstanceTypeInfo->GetKey(index);
|
||||
JSTaggedValue baseInstanceTypeId = baseInstanceTypeInfo->GetTypeId(index);
|
||||
derivedInstanceTypeInfo->SetKey(thread, index, baseInstanceKey, baseInstanceTypeId);
|
||||
}
|
||||
return derivedInstanceType;
|
||||
}
|
||||
|
||||
JSHandle<TSUnionType> TSTypeTable::ParseUnionType(JSThread *thread, JSHandle<TSTypeTable> &typeTable,
|
||||
const JSHandle<TaggedArray> &literal)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
uint32_t index = 0;
|
||||
ASSERT(static_cast<TypeLiteralFlag>(literal->Get(index).GetInt()) == TypeLiteralFlag::UNION);
|
||||
index++;
|
||||
uint32_t unionTypeLength = literal->Get(index++).GetInt();
|
||||
|
||||
JSHandle<TSUnionType> unionType = factory->NewTSUnionType(unionTypeLength);
|
||||
JSHandle<TaggedArray> unionTypeArray(thread, unionType->GetComponentTypes());
|
||||
JSMutableHandle<JSTaggedValue> localTypeIdHandle(thread, JSTaggedValue::Undefined());
|
||||
for (uint32_t unionTypeId = 0; unionTypeId < unionTypeLength; ++unionTypeId) {
|
||||
localTypeIdHandle.Update(literal->Get(index++));
|
||||
unionTypeArray->Set(thread, unionTypeId, localTypeIdHandle);
|
||||
}
|
||||
unionType->SetComponentTypes(thread, unionTypeArray);
|
||||
return unionType;
|
||||
}
|
||||
|
||||
JSHandle<TaggedArray> TSTypeTable::GetExportValueTable(JSThread *thread, JSHandle<TSTypeTable> typeTable)
|
||||
{
|
||||
int index = typeTable->GetLength() - 1;
|
||||
JSHandle<TaggedArray> exportValueTable = JSHandle<TaggedArray>(thread, typeTable->Get(index));
|
||||
return exportValueTable;
|
||||
}
|
||||
}
|
97
ecmascript/ts_types/ts_type_table.h
Normal file
97
ecmascript/ts_types/ts_type_table.h
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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_TS_TYPES_TS_TYPE_TABLE_H
|
||||
#define ECMASCRIPT_TS_TYPES_TS_TYPE_TABLE_H
|
||||
|
||||
#include "ecmascript/tagged_array.h"
|
||||
#include "ecmascript/ts_types/ts_type.h"
|
||||
|
||||
namespace panda::ecmascript {
|
||||
class TSTypeTable : public TaggedArray {
|
||||
public:
|
||||
enum class TypeLiteralFlag : uint8_t {
|
||||
COUNTER = 0, // just used for the first type literal
|
||||
CLASS,
|
||||
CLASS_INSTANCE,
|
||||
FUNCTION,
|
||||
UNION,
|
||||
ARRAY,
|
||||
OBJECT, // object literal
|
||||
IMPORT,
|
||||
INTERFACE
|
||||
};
|
||||
|
||||
static constexpr std::string_view ENTRY_FUNC_NAME = "func_main_0";
|
||||
static constexpr size_t RESERVE_TABLE_LENGTH = 2; // for reserve length and reserve exportTable
|
||||
static constexpr size_t TABLE_LENGTH_OFFSET_IN_LITREAL = 1;
|
||||
static constexpr size_t TYPE_KIND_OFFSET = 0;
|
||||
static constexpr size_t LENGTH_OFFSET = 0;
|
||||
|
||||
inline static TSTypeTable *Cast(TaggedObject *object)
|
||||
{
|
||||
ASSERT(JSTaggedValue(object).IsTaggedArray());
|
||||
return static_cast<TSTypeTable *>(object);
|
||||
}
|
||||
|
||||
static void Initialize(JSThread *thread, const panda_file::File &pf,
|
||||
CVector<JSHandle<EcmaString>> &recordImportMdoules);
|
||||
|
||||
static GlobalTSTypeRef GetPropertyType(JSThread *thread, JSHandle<TSTypeTable> &table, TSTypeKind typeKind,
|
||||
uint32_t index, JSHandle<EcmaString> propName);
|
||||
|
||||
static JSHandle<JSTaggedValue> ParseType(JSThread *thread, JSHandle<TSTypeTable> &table,
|
||||
JSHandle<TaggedArray> &literal,
|
||||
JSHandle<EcmaString> fileName,
|
||||
CVector<JSHandle<EcmaString>> &recordImportMdoules);
|
||||
|
||||
static JSHandle<TaggedArray> GetExportValueTable(JSThread *thread, JSHandle<TSTypeTable> typeTable);
|
||||
|
||||
void SetTypeTableLength(const JSThread *thread, uint32_t length)
|
||||
{
|
||||
TaggedArray::Set(thread, LENGTH_OFFSET, JSTaggedValue(length));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static JSHandle<TSTypeTable> GenerateTypeTable(JSThread *thread, const panda_file::File &pf,
|
||||
CVector<JSHandle<EcmaString>> &recordImportMdoules);
|
||||
|
||||
static JSHandle<TaggedArray> GetExportTableFromPandFile(JSThread *thread, const panda_file::File &pf);
|
||||
|
||||
static panda_file::File::EntityId GetFileId(const panda_file::File &pf);
|
||||
|
||||
static const panda_file::File* GetPandaFile(JSHandle<EcmaString> modulePath);
|
||||
|
||||
static JSHandle<TSClassType> ParseClassType(JSThread *thread, JSHandle<TSTypeTable> &typeTable,
|
||||
const JSHandle<TaggedArray> &literal);
|
||||
|
||||
static JSHandle<TSInterfaceType> ParseInterfaceType(JSThread *thread, JSHandle<TSTypeTable> &typeTable,
|
||||
const JSHandle<TaggedArray> &literal);
|
||||
|
||||
static JSHandle<TSImportType> ParseImportType(JSThread *thread,
|
||||
const JSHandle<TaggedArray> &literal,
|
||||
JSHandle<EcmaString> fileName,
|
||||
CVector<JSHandle<EcmaString>> &recordImportMdoules);
|
||||
|
||||
static JSHandle<TSUnionType> ParseUnionType(JSThread *thread, JSHandle<TSTypeTable> &typeTable,
|
||||
const JSHandle<TaggedArray> &literal);
|
||||
|
||||
static JSHandle<TSObjectType> LinkSuper(JSThread *thread, JSHandle<TSClassType> &baseClassType,
|
||||
uint32_t *numBaseFields, uint32_t numDerivedFields);
|
||||
};
|
||||
} // namespace panda::ecmascript
|
||||
|
||||
#endif // ECMASCRIPT_TS_TYPES_TS_TYPE_TABLE_H
|
@ -452,4 +452,9 @@
|
||||
<option name="push" value="test/test/libark_jsruntime_test.so -> /data/test" src="out"/>
|
||||
</preparer>
|
||||
</target>
|
||||
<target name="TSTypeTest">
|
||||
<preparer>
|
||||
<option name="push" value="test/test/libark_jsruntime_test.so -> /data/test" src="out"/>
|
||||
</preparer>
|
||||
</target>
|
||||
</configuration>
|
||||
|
Loading…
Reference in New Issue
Block a user