!762 share constpool, and fix some codestyle

Merge pull request !762 from changcheng/fix_codestyle
This commit is contained in:
openharmony_ci 2022-03-21 15:01:23 +00:00 committed by Gitee
commit 1f6c66ef1c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
30 changed files with 332 additions and 289 deletions

View File

@ -24,6 +24,7 @@
#include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/js_object-inl.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/jspandafile/js_pandafile_manager.h"
#include "ecmascript/object_factory.h"
#include "ecmascript/tooling/pt_js_extractor.h"
@ -191,7 +192,6 @@ JSHandle<EcmaString> ErrorHelper::BuildEcmaStackTrace(JSThread *thread)
CString ErrorHelper::BuildNativeEcmaStackTrace(JSThread *thread)
{
auto ecmaVm = thread->GetEcmaVM();
CString data;
auto sp = const_cast<JSTaggedType *>(thread->GetCurrentSPFrame());
InterpretedFrameHandler frameHandler(sp);
@ -205,7 +205,8 @@ CString ErrorHelper::BuildNativeEcmaStackTrace(JSThread *thread)
data += DecodeFunctionName(method->ParseFunctionName());
data.append(" (");
// source file
PtJSExtractor *debugExtractor = ecmaVm->GetDebugInfoExtractor(method->GetPandaFile());
PtJSExtractor *debugExtractor =
JSPandaFileManager::GetInstance()->GetPtJSExtractor(method->GetJSPandaFile());
const CString &sourceFile = debugExtractor->GetSourceFile(method->GetFileId());
if (sourceFile.empty()) {
data.push_back('?');

View File

@ -52,17 +52,16 @@ bool PassManager::CollectInfoOfPandaFile(const std::string &filename, BytecodeTr
return false;
}
const JSPandaFile *jsPandaFile =
vm_->GetJSPandaFileManager()->LoadAotInfoFromPf(filename, &(translateInfo->methodPcInfos));
JSPandaFileManager::GetCurrent()->LoadAotInfoFromPf(filename, &(translateInfo->methodPcInfos));
if (jsPandaFile == nullptr) {
return false;
}
translateInfo->jsPandaFile = jsPandaFile;
TSLoader *tsLoader = vm_->GetTSLoader();
tsLoader->DecodeTSTypes(*jsPandaFile->GetPandaFile());
tsLoader->DecodeTSTypes(jsPandaFile);
PandaFileTranslator translator(vm_, jsPandaFile);
auto program = translator.GenerateProgram();
auto program = PandaFileTranslator::GenerateProgram(vm_, jsPandaFile);
JSHandle<JSFunction> mainFunc(vm_->GetJSThread(), program->GetMainFunction());
JSHandle<JSTaggedValue> constPool(vm_->GetJSThread(), mainFunc->GetConstantPool());
translateInfo->constantPool = constPool;

View File

@ -14,12 +14,16 @@
*/
#include "ecmascript/dfx/cpu_profiler/cpu_profiler.h"
#include <atomic>
#include <chrono>
#include <climits>
#include <csignal>
#include <fstream>
#include "ecmascript/jspandafile/js_pandafile_manager.h"
#include "ecmascript/platform/platform.h"
namespace panda::ecmascript {
CMap<JSMethod *, struct StackInfo> CpuProfiler::staticStackInfo_ = CMap<JSMethod *, struct StackInfo>();
std::atomic<CpuProfiler*> CpuProfiler::singleton_ = nullptr;
@ -189,7 +193,6 @@ void CpuProfiler::GetFrameStack(JSThread *thread)
void CpuProfiler::ParseMethodInfo(JSMethod *method, JSThread *thread, InterpretedFrameHandler frameHandler)
{
struct StackInfo codeEntry;
auto ecmaVm = thread->GetEcmaVM();
if (method != nullptr && method->IsNative()) {
codeEntry.codeType = "other";
codeEntry.functionName = "native";
@ -203,7 +206,8 @@ void CpuProfiler::ParseMethodInfo(JSMethod *method, JSThread *thread, Interprete
codeEntry.functionName = functionName.c_str();
}
// source file
tooling::ecmascript::PtJSExtractor *debugExtractor = ecmaVm->GetDebugInfoExtractor(method->GetPandaFile());
tooling::ecmascript::PtJSExtractor *debugExtractor =
JSPandaFileManager::GetInstance()->GetPtJSExtractor(method->GetJSPandaFile());
const CString &sourceFile = debugExtractor->GetSourceFile(method->GetFileId());
if (sourceFile.empty()) {
codeEntry.url = "";

View File

@ -217,12 +217,6 @@ bool EcmaVM::Initialize()
return true;
}
JSPandaFileManager *EcmaVM::GetJSPandaFileManager()
{
static JSPandaFileManager jsFileManager;
return &jsFileManager;
}
void EcmaVM::InitializeEcmaScriptRunStat()
{
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
@ -341,12 +335,6 @@ EcmaVM::~EcmaVM()
}
}
tooling::ecmascript::PtJSExtractor *EcmaVM::GetDebugInfoExtractor(const panda_file::File *file)
{
tooling::ecmascript::PtJSExtractor *res = GetJSPandaFileManager()->GetOrCreatePtJSExtractor(file);
return res;
}
JSHandle<GlobalEnv> EcmaVM::GetGlobalEnv() const
{
return JSHandle<GlobalEnv>(reinterpret_cast<uintptr_t>(&globalEnv_));
@ -380,7 +368,7 @@ Expected<int, Runtime::Error> EcmaVM::InvokeEcmaEntrypoint(const JSPandaFile *js
JSHandle<Program> program;
if (snapshotSerializeEnable_) {
#if defined(ECMASCRIPT_SUPPORT_SNAPSHOT)
program = GetJSPandaFileManager()->GenerateProgram(this, jsPandaFile);
program = JSPandaFileManager::GetInstance()->GenerateProgram(this, jsPandaFile);
auto index = jsPandaFile->GetJSPandaFileDesc().find(frameworkAbcFileName_);
if (index != CString::npos) {
@ -393,7 +381,7 @@ Expected<int, Runtime::Error> EcmaVM::InvokeEcmaEntrypoint(const JSPandaFile *js
}
} else {
if (jsPandaFile != frameworkPandaFile_) {
program = GetJSPandaFileManager()->GenerateProgram(this, jsPandaFile);
program = JSPandaFileManager::GetInstance()->GenerateProgram(this, jsPandaFile);
} else {
program = JSHandle<Program>(thread_, frameworkProgram_);
frameworkProgram_ = JSTaggedValue::Hole();
@ -447,6 +435,23 @@ Expected<int, Runtime::Error> EcmaVM::InvokeEcmaEntrypoint(const JSPandaFile *js
return 0;
}
JSTaggedValue EcmaVM::FindConstpool(const JSPandaFile *jsPandaFile)
{
auto iter = cachedConstpools_.find(jsPandaFile);
if (iter == cachedConstpools_.end()) {
return JSTaggedValue::Hole();
}
return iter->second;
}
void EcmaVM::SetConstpool(const JSPandaFile *jsPandaFile, JSTaggedValue constpool)
{
ASSERT(constpool.IsTaggedArray());
ASSERT(cachedConstpools_.find(jsPandaFile) == cachedConstpools_.end());
cachedConstpools_[jsPandaFile] = constpool;
}
JSHandle<JSTaggedValue> EcmaVM::GetAndClearEcmaUncaughtException() const
{
JSHandle<JSTaggedValue> exceptionHandle = GetEcmaUncaughtException();
@ -535,6 +540,22 @@ void EcmaVM::ProcessReferences(const WeakRootVisitor &v0)
}
++iter;
}
// program maps
for (auto iter = cachedConstpools_.begin(); iter != cachedConstpools_.end();) {
auto object = iter->second;
if (object.IsObject()) {
TaggedObject *obj = object.GetTaggedObject();
auto fwd = v0(obj);
if (fwd == nullptr) {
iter = cachedConstpools_.erase(iter);
continue;
} else if (fwd != obj) {
iter->second = JSTaggedValue(fwd);
}
}
++iter;
}
}
void EcmaVM::PushToNativePointerList(JSNativePointer *array)
@ -554,7 +575,7 @@ void EcmaVM::RemoveFromNativePointerList(JSNativePointer *array)
}
// Do not support snapshot on windows
bool EcmaVM::VerifyFilePath(const CString &filePath) const
bool EcmaVM::VerifyFilePath(const std::string &filePath) const
{
#ifndef PANDA_TARGET_WINDOWS
if (filePath.size() > PATH_MAX) {
@ -583,6 +604,8 @@ void EcmaVM::ClearBufferData()
iter->Destroy();
}
nativePointerList_.clear();
cachedConstpools_.clear();
}
bool EcmaVM::ExecutePromisePendingJob() const

View File

@ -32,7 +32,6 @@
#include "ecmascript/mem/space.h"
#include "ecmascript/platform/task.h"
#include "ecmascript/snapshot/mem/snapshot_serialize.h"
#include "ecmascript/tooling/pt_js_extractor.h"
#include "include/panda_vm.h"
#include "libpandabase/macros.h"
#ifndef PANDA_TARGET_WINDOWS
@ -69,7 +68,6 @@ class JSArrayBuffer;
class JSFunction;
class Program;
class TSLoader;
struct BytecodeTranslationInfo;
class ModuleManager;
using HostPromiseRejectionTracker = void (*)(const EcmaVM* vm,
const JSHandle<JSPromise> promise,
@ -79,8 +77,6 @@ using HostPromiseRejectionTracker = void (*)(const EcmaVM* vm,
using PromiseRejectCallback = void (*)(void* info);
class EcmaVM : public PandaVM {
using PtJSExtractor = tooling::ecmascript::PtJSExtractor;
public:
static EcmaVM *Cast(PandaVM *object)
{
@ -99,8 +95,6 @@ public:
~EcmaVM() override;
PtJSExtractor *GetDebugInfoExtractor(const panda_file::File *file);
bool IsInitialized() const
{
return vmInitialized_;
@ -383,7 +377,9 @@ public:
}
}
static JSPandaFileManager* PUBLIC_API GetJSPandaFileManager();
void SetConstpool(const JSPandaFile *jsPandaFile, JSTaggedValue constpool);
JSTaggedValue FindConstpool(const JSPandaFile *jsPandaFile);
protected:
bool CheckEntrypointSignature([[maybe_unused]] Method *entrypoint) override
@ -412,7 +408,7 @@ private:
void InitializeEcmaScriptRunStat();
bool VerifyFilePath(const CString &filePath) const;
bool VerifyFilePath(const std::string &filePath) const;
void ClearBufferData();
@ -452,10 +448,11 @@ private:
EcmaRuntimeStat *runtimeStat_ {nullptr};
// For framewrok file snapshot.
CString snapshotFileName_;
CString frameworkAbcFileName_;
std::string snapshotFileName_;
std::string frameworkAbcFileName_;
JSTaggedValue frameworkProgram_ {JSTaggedValue::Hole()};
const JSPandaFile *frameworkPandaFile_ {nullptr};
CMap<const JSPandaFile *, JSTaggedValue> cachedConstpools_ {};
// VM resources.
ChunkVector<JSMethod *> nativeMethods_;

View File

@ -3553,28 +3553,21 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool
}
HANDLE_OPCODE(HANDLE_DEFINECLASSWITHBUFFER_PREF_ID16_IMM16_IMM16_V8_V8) {
uint16_t methodId = READ_INST_16_1();
uint16_t imm = READ_INST_16_3();
uint16_t length = READ_INST_16_5();
uint16_t v0 = READ_INST_8_7();
uint16_t v1 = READ_INST_8_8();
LOG_INST() << "intrinsics::defineclasswithbuffer"
<< " method id:" << methodId << " literal id:" << imm << " lexenv: v" << v0 << " parent: v" << v1;
<< " method id:" << methodId << " lexenv: v" << v0 << " parent: v" << v1;
JSFunction *classTemplate = JSFunction::Cast(constpool->GetObjectFromCache(methodId).GetTaggedObject());
ASSERT(classTemplate != nullptr);
TaggedArray *literalBuffer = TaggedArray::Cast(constpool->GetObjectFromCache(imm).GetTaggedObject());
JSTaggedValue lexenv = GET_VREG_VALUE(v0);
JSTaggedValue proto = GET_VREG_VALUE(v1);
JSTaggedValue res;
SAVE_PC();
if (LIKELY(!classTemplate->GetResolved())) {
res = SlowRuntimeStub::ResolveClass(thread, JSTaggedValue(classTemplate), literalBuffer,
proto, lexenv, constpool);
} else {
res = SlowRuntimeStub::CloneClassFromTemplate(thread, JSTaggedValue(classTemplate),
proto, lexenv, constpool);
}
res = SlowRuntimeStub::CloneClassFromTemplate(thread, JSTaggedValue(classTemplate),
proto, lexenv, constpool);
INTERPRETER_RETURN_IF_ABRUPT(res);
ASSERT(res.IsClassConstructor());

View File

@ -2071,10 +2071,6 @@ JSTaggedValue SlowRuntimeStub::CloneClassFromTemplate(JSThread *thread, JSTagged
JSHandle<JSObject> clsPrototype(thread, cls->GetFunctionPrototype());
bool canShareHClass = false;
if (cls->GetClass()->GetProto() == baseHandle.GetTaggedValue()) {
canShareHClass = true;
}
JSHandle<JSFunction> cloneClass = factory->CloneClassCtor(cls, lexenvHandle, canShareHClass);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<JSObject> cloneClassPrototype = factory->CloneObjectLiteral(JSHandle<JSObject>(clsPrototype), lexenvHandle,

View File

@ -13,10 +13,23 @@
* limitations under the License.
*/
#include "js_method.h"
#include "ecmascript/js_method.h"
#include "ecmascript/jspandafile/js_pandafile.h"
#include "libpandafile/method_data_accessor-inl.h"
namespace panda::ecmascript {
JSMethod::JSMethod(Class *klass, const JSPandaFile *jsPandaFile, panda_file::File::EntityId fileId,
panda_file::File::EntityId codeId, uint32_t accessFlags,
uint32_t numArgs, const uint16_t *shorty)
: Method(klass, jsPandaFile != nullptr ? jsPandaFile->GetPandaFile() : nullptr,
fileId, codeId, accessFlags, numArgs, shorty)
{
bytecodeArray_ = JSMethod::GetInstructions();
bytecodeArraySize_ = JSMethod::GetCodeSize();
jsPandaFile_ = jsPandaFile;
}
// It's not allowed '#' token appear in ECMA function(method) name, which discriminates same names in panda methods.
CString JSMethod::ParseFunctionName() const
{

View File

@ -49,6 +49,7 @@ JS_METHOD_OFFSET_LIST(JS_METHOD_OFFSET_MACRO)
#undef JS_METHOD_OFFSET_MACRO
namespace panda::ecmascript {
class JSPandaFile;
class JSMethod : public Method {
public:
static constexpr uint8_t MAX_SLOT_SIZE = 0xFF;
@ -59,14 +60,9 @@ public:
return static_cast<JSMethod *>(method);
}
explicit JSMethod(Class *klass, const panda_file::File *pf, panda_file::File::EntityId fileId,
panda_file::File::EntityId codeId, uint32_t accessFlags, uint32_t numArgs, const uint16_t *shorty)
: Method(klass, pf, fileId, codeId, accessFlags, numArgs, shorty)
{
bytecodeArray_ = JSMethod::GetInstructions();
bytecodeArraySize_ = JSMethod::GetCodeSize();
}
JSMethod(Class *klass, const JSPandaFile *jsPandaFile, panda_file::File::EntityId fileId,
panda_file::File::EntityId codeId, uint32_t accessFlags,
uint32_t numArgs, const uint16_t *shorty);
JSMethod() = delete;
~JSMethod() = default;
JSMethod(const JSMethod &) = delete;
@ -187,8 +183,14 @@ public:
return NumArgsBits::Decode(callField_);
}
const JSPandaFile *GetJSPandaFile() const
{
return jsPandaFile_;
}
private:
uint64_t callField_ {0};
const JSPandaFile *jsPandaFile_ {nullptr};
const uint8_t *bytecodeArray_ {nullptr};
uint32_t bytecodeArraySize_ {0};
uint8_t slotSize_ {0};

View File

@ -18,8 +18,9 @@
#include "ecmascript/jspandafile/program_object-inl.h"
namespace panda::ecmascript {
JSPandaFile::JSPandaFile(const panda_file::File *pf, const CString &descriptor) : pf_(pf), desc_(descriptor)
JSPandaFile::JSPandaFile(const panda_file::File *pf, const std::string &descriptor) : pf_(pf), desc_(descriptor)
{
ASSERT(pf_ != nullptr);
Initialize();
}
@ -77,7 +78,7 @@ void JSPandaFile::Initialize()
methods_ = static_cast<JSMethod *>(JSPandaFileManager::AllocateBuffer(sizeof(JSMethod) * numMethods_));
}
const JSMethod *JSPandaFile::FindMethods(uint32_t offset) const
JSMethod *JSPandaFile::FindMethods(uint32_t offset) const
{
return methodMap_.at(offset);
}

View File

@ -17,7 +17,7 @@
#define ECMASCRIPT_JSPANDAFILE_JS_PANDAFILE_H
#include "ecmascript/jspandafile/constpool_value.h"
#include "ecmascript/jspandafile/panda_file_translator.h"
#include "ecmascript/jspandafile/js_pandafile_manager.h"
#include "ecmascript/mem/c_containers.h"
#include "ecmascript/tooling/pt_js_extractor.h"
#include "libpandafile/file.h"
@ -35,12 +35,12 @@ namespace ecmascript {
class JSPandaFile {
public:
JSPandaFile(const panda_file::File *pf, const CString &descriptor);
JSPandaFile(const panda_file::File *pf, const std::string &descriptor);
~JSPandaFile();
tooling::ecmascript::PtJSExtractor *GetOrCreatePtJSExtractor();
CString GetJSPandaFileDesc() const
const std::string &GetJSPandaFileDesc() const
{
return desc_;
}
@ -89,7 +89,7 @@ public:
mainMethodIndex_ = mainMethodIndex;
}
const JSMethod *FindMethods(uint32_t offset) const;
JSMethod *FindMethods(uint32_t offset) const;
Span<const uint32_t> GetClasses() const
{
@ -106,10 +106,10 @@ private:
uint32_t numMethods_ {0};
uint32_t mainMethodIndex_ {0};
JSMethod *methods_ {nullptr};
CUnorderedMap<uint32_t, JSMethod *> methodMap_;
std::unordered_map<uint32_t, JSMethod *> methodMap_;
const panda_file::File *pf_ {nullptr};
std::unique_ptr<tooling::ecmascript::PtJSExtractor> ptJSExtractor_;
CString desc_;
std::string desc_;
bool isModule_ {false};
};
} // namespace ecmascript

View File

@ -25,7 +25,7 @@ namespace panda::ecmascript {
bool JSPandaFileExecutor::ExecuteFromFile(JSThread *thread, const std::string &filename, std::string_view entryPoint,
const std::vector<std::string> &args)
{
const JSPandaFile *jsPandaFile = EcmaVM::GetJSPandaFileManager()->LoadJSPandaFile(filename);
const JSPandaFile *jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(filename);
if (jsPandaFile == nullptr) {
return false;
}
@ -52,7 +52,7 @@ bool JSPandaFileExecutor::ExecuteFromBuffer(JSThread *thread, const void *buffer
std::string_view entryPoint, const std::vector<std::string> &args,
const std::string &filename)
{
const JSPandaFile *jsPandaFile = EcmaVM::GetJSPandaFileManager()->LoadJSPandaFile(filename, buffer, size);
const JSPandaFile *jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(filename, buffer, size);
if (jsPandaFile == nullptr) {
return false;
}

View File

@ -14,6 +14,7 @@
*/
#include "ecmascript/jspandafile/js_pandafile_manager.h"
#include "ecmascript/jspandafile/program_object-inl.h"
namespace panda::ecmascript {
@ -34,24 +35,20 @@ JSPandaFileManager::~JSPandaFileManager()
const JSPandaFile *JSPandaFileManager::LoadAotInfoFromPf(const std::string &filename,
std::vector<MethodPcInfo> *methodPcInfos)
{
CString desc = ConvertToString(filename);
auto pf = panda_file::OpenPandaFileOrZip(filename, panda_file::File::READ_WRITE);
if (pf == nullptr) {
JSPandaFile *jsPandaFile = OpenJSPandaFile(filename);
if (jsPandaFile == nullptr) {
LOG_ECMA(ERROR) << "open file " << filename << " error";
return nullptr;
}
JSPandaFile *jsPandaFile = NewJSPandaFile(pf.release(), desc);
PandaFileTranslator::TranslateClasses(jsPandaFile, ENTRY_FUNCTION_NAME, methodPcInfos);
return jsPandaFile;
}
const JSPandaFile *JSPandaFileManager::LoadJSPandaFile(const std::string &filename)
{
ECMA_BYTRACE_NAME(BYTRACE_TAG_ARK, "JSPandaFileManager::LoadJSPandaFile");
CString desc = ConvertToString(filename);
const JSPandaFile *jsPandaFile = FindJSPandaFile(desc);
const JSPandaFile *jsPandaFile = FindJSPandaFile(filename);
if (jsPandaFile != nullptr) {
IncreaseRefJSPandaFile(jsPandaFile);
return jsPandaFile;
@ -63,7 +60,7 @@ const JSPandaFile *JSPandaFileManager::LoadJSPandaFile(const std::string &filena
return nullptr;
}
jsPandaFile = GenerateJSPandaFile(pf.release(), desc);
jsPandaFile = GenerateJSPandaFile(pf.release(), filename);
return jsPandaFile;
}
@ -73,8 +70,7 @@ const JSPandaFile *JSPandaFileManager::LoadJSPandaFile(const std::string &filena
return nullptr;
}
CString desc = ConvertToString(filename);
const JSPandaFile *jsPandaFile = FindJSPandaFile(desc);
const JSPandaFile *jsPandaFile = FindJSPandaFile(filename);
if (jsPandaFile != nullptr) {
IncreaseRefJSPandaFile(jsPandaFile);
return jsPandaFile;
@ -85,7 +81,7 @@ const JSPandaFile *JSPandaFileManager::LoadJSPandaFile(const std::string &filena
LOG_ECMA(ERROR) << "open file " << filename << " error";
return nullptr;
}
jsPandaFile = GenerateJSPandaFile(pf.release(), desc);
jsPandaFile = GenerateJSPandaFile(pf.release(), filename);
return jsPandaFile;
}
@ -95,12 +91,11 @@ JSHandle<Program> JSPandaFileManager::GenerateProgram(EcmaVM *vm, const JSPandaF
LOG_ECMA(INFO) << "GenerateProgram " << jsPandaFile->GetPandaFile()->GetFilename();
ASSERT(GetJSPandaFile(jsPandaFile->GetPandaFile()) != nullptr);
PandaFileTranslator translator(vm, jsPandaFile);
auto result = translator.GenerateProgram();
return result;
JSHandle<Program> program = PandaFileTranslator::GenerateProgram(vm, jsPandaFile);
return program;
}
const JSPandaFile *JSPandaFileManager::FindJSPandaFile(const CString &filename)
const JSPandaFile *JSPandaFileManager::FindJSPandaFile(const std::string &filename)
{
if (filename.empty()) {
return nullptr;
@ -161,7 +156,19 @@ void JSPandaFileManager::DecreaseRefJSPandaFile(const JSPandaFile *jsPandaFile)
ReleaseJSPandaFile(jsPandaFile);
}
JSPandaFile *JSPandaFileManager::NewJSPandaFile(const panda_file::File *pf, const CString &desc)
JSPandaFile *JSPandaFileManager::OpenJSPandaFile(const std::string &filename)
{
auto pf = panda_file::OpenPandaFileOrZip(filename, panda_file::File::READ_WRITE);
if (pf == nullptr) {
LOG_ECMA(ERROR) << "open file " << filename << " error";
return nullptr;
}
JSPandaFile *jsPandaFile = NewJSPandaFile(pf.release(), filename);
return jsPandaFile;
}
JSPandaFile *JSPandaFileManager::NewJSPandaFile(const panda_file::File *pf, const std::string &desc)
{
return new JSPandaFile(pf, desc);
}
@ -175,18 +182,18 @@ void JSPandaFileManager::ReleaseJSPandaFile(const JSPandaFile *jsPandaFile)
delete jsPandaFile;
}
tooling::ecmascript::PtJSExtractor *JSPandaFileManager::GetOrCreatePtJSExtractor(const panda_file::File *pf)
tooling::ecmascript::PtJSExtractor *JSPandaFileManager::GetPtJSExtractor(const JSPandaFile *jsPandaFile)
{
os::memory::LockHolder lock(jsPandaFileLock_);
const JSPandaFile *existJSPandaFile = GetJSPandaFile(pf);
if (existJSPandaFile == nullptr) {
auto iter = loadedJSPandaFiles_.find(jsPandaFile);
if (iter == loadedJSPandaFiles_.end()) {
LOG_ECMA(FATAL) << "can not get PtJSExtrjsPandaFile from unknown jsPandaFile";
return nullptr;
}
return const_cast<JSPandaFile *>(existJSPandaFile)->GetOrCreatePtJSExtractor();
return const_cast<JSPandaFile *>(jsPandaFile)->GetOrCreatePtJSExtractor();
}
const JSPandaFile *JSPandaFileManager::GenerateJSPandaFile(const panda_file::File *pf, const CString &desc)
const JSPandaFile *JSPandaFileManager::GenerateJSPandaFile(const panda_file::File *pf, const std::string &desc)
{
ASSERT(GetJSPandaFile(pf) == nullptr);

View File

@ -34,9 +34,14 @@ class Program;
class JSPandaFileManager {
public:
JSPandaFileManager() = default;
~JSPandaFileManager();
static JSPandaFileManager *GetInstance()
{
static JSPandaFileManager jsFileManager;
return &jsFileManager;
}
JSHandle<Program> GenerateProgram(EcmaVM *vm, const JSPandaFile *jsPandaFile);
const JSPandaFile* PUBLIC_API LoadAotInfoFromPf(const std::string &filename,
@ -46,11 +51,11 @@ public:
const JSPandaFile *LoadJSPandaFile(const std::string &filename, const void *buffer, size_t size);
JSPandaFile *NewJSPandaFile(const panda_file::File *pf, const CString &desc);
JSPandaFile *OpenJSPandaFile(const std::string &filename);
const JSPandaFile *GenerateJSPandaFile(const panda_file::File *pf, const CString &desc);
JSPandaFile *NewJSPandaFile(const panda_file::File *pf, const std::string &desc);
tooling::ecmascript::PtJSExtractor *GetOrCreatePtJSExtractor(const panda_file::File *pf);
tooling::ecmascript::PtJSExtractor *GetPtJSExtractor(const JSPandaFile *jsPandaFile);
static void RemoveJSPandaFile(void *pointer, void *data);
@ -68,15 +73,18 @@ public:
}
private:
JSPandaFileManager() = default;
class JSPandaFileAllocator {
public:
static void *AllocateBuffer(size_t size);
static void FreeBuffer(void *mem);
};
const JSPandaFile *GenerateJSPandaFile(const panda_file::File *pf, const std::string &desc);
void ReleaseJSPandaFile(const JSPandaFile *jsPandaFile);
const JSPandaFile *GetJSPandaFile(const panda_file::File *pf);
const JSPandaFile *FindJSPandaFile(const CString &filename);
const JSPandaFile *FindJSPandaFile(const std::string &filename);
void InsertJSPandaFile(const JSPandaFile *jsPandaFile);
void IncreaseRefJSPandaFile(const JSPandaFile *jsPandaFile);
void DecreaseRefJSPandaFile(const JSPandaFile *jsPandaFile);

View File

@ -14,10 +14,12 @@
*/
#include "ecmascript/jspandafile/literal_data_extractor.h"
#include "ecmascript/base/string_helper.h"
#include "ecmascript/ecma_string.h"
#include "ecmascript/global_env.h"
#include "ecmascript/js_thread.h"
#include "ecmascript/jspandafile/js_pandafile.h"
#include "ecmascript/tagged_array-inl.h"
#include "libpandafile/literal_data_accessor-inl.h"
@ -26,13 +28,14 @@ using LiteralTag = panda_file::LiteralTag;
using StringData = panda_file::StringData;
using LiteralValue = panda_file::LiteralDataAccessor::LiteralValue;
void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const panda_file::File *pf, size_t index,
void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const JSPandaFile *jsPandaFile, size_t index,
JSMutableHandle<TaggedArray> elements,
JSMutableHandle<TaggedArray> properties, PandaFileTranslator *pft)
JSMutableHandle<TaggedArray> properties)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
LOG_ECMA(DEBUG) << "Panda File" << pf->GetFilename();
LOG_ECMA(DEBUG) << "Panda File" << jsPandaFile->GetJSPandaFileDesc();
const panda_file::File *pf = jsPandaFile->GetPandaFile();
panda_file::File::EntityId literalArraysId = pf->GetLiteralArraysId();
panda_file::LiteralDataAccessor lda(*pf, literalArraysId);
@ -45,7 +48,7 @@ void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const panda_file
uint32_t methodId;
FunctionKind kind;
lda.EnumerateLiteralVals(
index, [elements, properties, &epos, &ppos, factory, thread, pft, pf, &methodId, &kind]
index, [elements, properties, &epos, &ppos, factory, thread, jsPandaFile, pf, &methodId, &kind]
(const LiteralValue &value, const LiteralTag &tag) {
JSTaggedValue jt = JSTaggedValue::Null();
bool flag = false;
@ -73,21 +76,19 @@ void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const panda_file
break;
}
case LiteralTag::METHOD: {
ASSERT(pft != nullptr);
methodId = std::get<uint32_t>(value);
kind = FunctionKind::NORMAL_FUNCTION;
break;
}
case LiteralTag::GENERATORMETHOD: {
ASSERT(pft != nullptr);
methodId = std::get<uint32_t>(value);
kind = FunctionKind::GENERATOR_FUNCTION;
break;
}
case LiteralTag::METHODAFFILIATE: {
ASSERT(pft != nullptr);
uint16_t length = std::get<uint16_t>(value);
JSHandle<JSFunction> jsFunc = pft->DefineMethodInLiteral(thread, methodId, kind, length);
auto method = jsPandaFile->FindMethods(methodId);
JSHandle<JSFunction> jsFunc = DefineMethodInLiteral(thread, method, kind, length);
jt = jsFunc.GetTaggedValue();
break;
}
@ -114,12 +115,13 @@ void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const panda_file
});
}
JSHandle<TaggedArray> LiteralDataExtractor::GetDatasIgnoreType(JSThread *thread, const panda_file::File *pf,
size_t index, PandaFileTranslator *pft)
JSHandle<TaggedArray> LiteralDataExtractor::GetDatasIgnoreType(JSThread *thread, const JSPandaFile *jsPandaFile,
size_t index)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
LOG_ECMA(DEBUG) << "Panda File" << pf->GetFilename();
LOG_ECMA(DEBUG) << "Panda File" << jsPandaFile->GetJSPandaFileDesc();
const panda_file::File *pf = jsPandaFile->GetPandaFile();
panda_file::File::EntityId literalArraysId = pf->GetLiteralArraysId();
panda_file::LiteralDataAccessor lda(*pf, literalArraysId);
@ -129,7 +131,7 @@ JSHandle<TaggedArray> LiteralDataExtractor::GetDatasIgnoreType(JSThread *thread,
uint32_t methodId;
FunctionKind kind;
lda.EnumerateLiteralVals(
index, [literals, &pos, factory, thread, pft, pf, &methodId, &kind]
index, [literals, &pos, factory, thread, jsPandaFile, &methodId, &kind]
(const panda_file::LiteralDataAccessor::LiteralValue &value, const LiteralTag &tag) {
JSTaggedValue jt = JSTaggedValue::Null();
switch (tag) {
@ -146,27 +148,26 @@ JSHandle<TaggedArray> LiteralDataExtractor::GetDatasIgnoreType(JSThread *thread,
break;
}
case LiteralTag::STRING: {
const panda_file::File *pf = jsPandaFile->GetPandaFile();
StringData sd = pf->GetStringData(panda_file::File::EntityId(std::get<uint32_t>(value)));
EcmaString *str = factory->GetRawStringFromStringTable(sd.data, sd.utf16_length, sd.is_ascii);
jt = JSTaggedValue(str);
break;
}
case LiteralTag::METHOD: {
ASSERT(pft != nullptr);
methodId = std::get<uint32_t>(value);
kind = FunctionKind::NORMAL_FUNCTION;
break;
}
case LiteralTag::GENERATORMETHOD: {
ASSERT(pft != nullptr);
methodId = std::get<uint32_t>(value);
kind = FunctionKind::GENERATOR_FUNCTION;
break;
}
case LiteralTag::METHODAFFILIATE: {
ASSERT(pft != nullptr);
uint16_t length = std::get<uint16_t>(value);
JSHandle<JSFunction> jsFunc = pft->DefineMethodInLiteral(thread, methodId, kind, length);
auto method = jsPandaFile->FindMethods(methodId);
JSHandle<JSFunction> jsFunc = DefineMethodInLiteral(thread, method, kind, length);
jt = jsFunc.GetTaggedValue();
break;
}
@ -192,4 +193,30 @@ JSHandle<TaggedArray> LiteralDataExtractor::GetDatasIgnoreType(JSThread *thread,
});
return literals;
}
JSHandle<JSFunction> LiteralDataExtractor::DefineMethodInLiteral(JSThread *thread, JSMethod *method, FunctionKind kind,
uint16_t length)
{
ASSERT(method != nullptr);
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
JSHandle<JSHClass> functionClass;
if (kind == FunctionKind::NORMAL_FUNCTION) {
functionClass = JSHandle<JSHClass>::Cast(env->GetFunctionClassWithoutProto());
} else {
functionClass = JSHandle<JSHClass>::Cast(env->GetGeneratorFunctionClass());
}
JSHandle<JSFunction> jsFunc = factory->NewJSFunctionByDynClass(method, functionClass, kind);
if (kind == FunctionKind::GENERATOR_FUNCTION) {
JSHandle<JSTaggedValue> objFun = env->GetObjectFunction();
JSHandle<JSObject> initialGeneratorFuncPrototype =
factory->NewJSObjectByConstructor(JSHandle<JSFunction>(objFun), objFun);
JSObject::SetPrototype(thread, initialGeneratorFuncPrototype, env->GetGeneratorPrototype());
jsFunc->SetProtoOrDynClass(thread, initialGeneratorFuncPrototype);
}
jsFunc->SetPropertyInlinedProps(thread, JSFunction::LENGTH_INLINE_PROPERTY_INDEX, JSTaggedValue(length));
return jsFunc;
}
} // namespace panda::ecmascript

View File

@ -32,11 +32,11 @@ public:
DEFAULT_NOEXCEPT_MOVE_SEMANTIC(LiteralDataExtractor);
DEFAULT_COPY_SEMANTIC(LiteralDataExtractor);
static void ExtractObjectDatas(JSThread *thread, const panda_file::File *pf, size_t index,
JSMutableHandle<TaggedArray> elements, JSMutableHandle<TaggedArray> properties,
PandaFileTranslator *pft);
static JSHandle<TaggedArray> GetDatasIgnoreType(JSThread *thread, const panda_file::File *pf, size_t index,
PandaFileTranslator *pft = nullptr);
static void ExtractObjectDatas(JSThread *thread, const JSPandaFile *jsPandaFile, size_t index,
JSMutableHandle<TaggedArray> elements, JSMutableHandle<TaggedArray> properties);
static JSHandle<TaggedArray> GetDatasIgnoreType(JSThread *thread, const JSPandaFile *jsPandaFile, size_t index);
static JSHandle<JSFunction> DefineMethodInLiteral(JSThread *thread, JSMethod *method, FunctionKind kind,
uint16_t length);
};
} // namespace panda::ecmascript
#endif // ECMASCRIPT_JSPANDAFILE_LITERAL_DATA_EXTRACTOR_H

View File

@ -15,10 +15,6 @@
#include "panda_file_translator.h"
#include <string>
#include <string_view>
#include <vector>
#include "ecmascript/global_env.h"
#include "ecmascript/interpreter/interpreter.h"
#include "ecmascript/jspandafile/class_info_extractor.h"
@ -39,14 +35,6 @@
#include "libpandafile/class_data_accessor-inl.h"
namespace panda::ecmascript {
PandaFileTranslator::PandaFileTranslator(EcmaVM *vm, const JSPandaFile *jsPandaFile)
: ecmaVm_(vm),
factory_(vm->GetFactory()),
thread_(vm->GetJSThread()),
jsPandaFile_(jsPandaFile)
{
}
template<class T, class... Args>
static T *InitializeMemory(T *mem, Args... args)
{
@ -56,6 +44,7 @@ static T *InitializeMemory(T *mem, Args... args)
void PandaFileTranslator::TranslateClasses(JSPandaFile *jsPandaFile, const CString &methodName,
std::vector<MethodPcInfo> *methodPcInfos)
{
ASSERT(jsPandaFile != nullptr && jsPandaFile->GetMethods() != nullptr);
JSMethod *methods = jsPandaFile->GetMethods();
const panda_file::File *pf = jsPandaFile->GetPandaFile();
size_t methodIdx = 0;
@ -83,8 +72,7 @@ void PandaFileTranslator::TranslateClasses(JSPandaFile *jsPandaFile, const CStri
jsPandaFile->UpdateMainMethodIndex(mda.GetMethodId().GetOffset());
}
panda_file::ProtoDataAccessor pda(*pf, mda.GetProtoId());
InitializeMemory(method, nullptr, pf, mda.GetMethodId(), codeDataAccessor.GetCodeId(),
InitializeMemory(method, nullptr, jsPandaFile, mda.GetMethodId(), codeDataAccessor.GetCodeId(),
mda.GetAccessFlags(), codeDataAccessor.GetNumArgs(), nullptr);
method->SetHotnessCounter(EcmaInterpreter::METHOD_HOTNESS_THRESHOLD);
method->InitializeCallField();
@ -98,106 +86,134 @@ void PandaFileTranslator::TranslateClasses(JSPandaFile *jsPandaFile, const CStri
}
}
JSHandle<Program> PandaFileTranslator::GenerateProgram()
JSHandle<Program> PandaFileTranslator::GenerateProgram(EcmaVM *vm, const JSPandaFile *jsPandaFile)
{
EcmaHandleScope handleScope(thread_);
JSThread *thread = vm->GetJSThread();
EcmaHandleScope handleScope(thread);
JSHandle<Program> program = factory_->NewProgram();
uint32_t constpoolIndex = jsPandaFile_->GetConstpoolIndex();
JSHandle<ConstantPool> constpool = factory_->NewConstantPool(constpoolIndex + 1);
const panda_file::File *pf = jsPandaFile_->GetPandaFile();
JSHandle<GlobalEnv> env = vm->GetGlobalEnv();
ObjectFactory *factory = vm->GetFactory();
JSHandle<Program> program = factory->NewProgram();
uint32_t mainMethodIndex = jsPandaFile->GetMainMethodIndex();
auto method = jsPandaFile->FindMethods(mainMethodIndex);
ASSERT(method != nullptr);
JSHandle<JSHClass> dynclass = JSHandle<JSHClass>::Cast(env->GetFunctionClassWithProto());
JSHandle<JSFunction> mainFunc =
factory->NewJSFunctionByDynClass(method, dynclass, FunctionKind::BASE_CONSTRUCTOR);
program->SetMainFunction(thread, mainFunc.GetTaggedValue());
JSTaggedValue constpool = vm->FindConstpool(jsPandaFile);
if (constpool.IsHole()) {
constpool = ParseConstPool(vm, jsPandaFile);
vm->SetConstpool(jsPandaFile, constpool);
}
mainFunc->SetConstantPool(thread, constpool);
return program;
}
JSTaggedValue PandaFileTranslator::ParseConstPool(EcmaVM *vm, const JSPandaFile *jsPandaFile)
{
JSThread *thread = vm->GetJSThread();
JSHandle<GlobalEnv> env = vm->GetGlobalEnv();
ObjectFactory *factory = vm->GetFactory();
uint32_t constpoolIndex = jsPandaFile->GetConstpoolIndex();
JSHandle<ConstantPool> constpool = factory->NewConstantPool(constpoolIndex + 1);
const panda_file::File *pf = jsPandaFile->GetPandaFile();
JSHandle<GlobalEnv> env = ecmaVm_->GetGlobalEnv();
JSHandle<JSHClass> dynclass = JSHandle<JSHClass>::Cast(env->GetFunctionClassWithProto());
JSHandle<JSHClass> normalDynclass = JSHandle<JSHClass>::Cast(env->GetFunctionClassWithoutProto());
JSHandle<JSHClass> asyncDynclass = JSHandle<JSHClass>::Cast(env->GetAsyncFunctionClass());
JSHandle<JSHClass> generatorDynclass = JSHandle<JSHClass>::Cast(env->GetGeneratorFunctionClass());
const std::unordered_map<uint32_t, uint64_t> &constpoolMap = jsPandaFile_->GetConstpoolMap();
uint32_t mainMethodIndex = jsPandaFile_->GetMainMethodIndex();
const std::unordered_map<uint32_t, uint64_t> &constpoolMap = jsPandaFile->GetConstpoolMap();
[[maybe_unused]] uint32_t mainMethodIndex = jsPandaFile->GetMainMethodIndex();
for (const auto &it : constpoolMap) {
ConstPoolValue value(it.second);
if (value.GetConstpoolType() == ConstPoolType::STRING) {
panda_file::File::EntityId id(it.first);
auto foundStr = pf->GetStringData(id);
auto string = factory_->GetRawStringFromStringTable(foundStr.data,
foundStr.utf16_length, foundStr.is_ascii);
constpool->Set(thread_, value.GetConstpoolIndex(), JSTaggedValue(string));
auto string = factory->GetRawStringFromStringTable(foundStr.data,
foundStr.utf16_length, foundStr.is_ascii);
constpool->Set(thread, value.GetConstpoolIndex(), JSTaggedValue(string));
} else if (value.GetConstpoolType() == ConstPoolType::BASE_FUNCTION) {
ASSERT(mainMethodIndex != it.first);
panda_file::File::EntityId id(it.first);
auto method = const_cast<JSMethod *>(jsPandaFile_->FindMethods(it.first));
auto method = jsPandaFile->FindMethods(it.first);
ASSERT(method != nullptr);
JSHandle<JSFunction> jsFunc =
factory_->NewJSFunctionByDynClass(method, dynclass, FunctionKind::BASE_CONSTRUCTOR);
constpool->Set(thread_, value.GetConstpoolIndex(), jsFunc.GetTaggedValue());
jsFunc->SetConstantPool(thread_, constpool.GetTaggedValue());
factory->NewJSFunctionByDynClass(method, dynclass, FunctionKind::BASE_CONSTRUCTOR);
constpool->Set(thread, value.GetConstpoolIndex(), jsFunc.GetTaggedValue());
jsFunc->SetConstantPool(thread, constpool.GetTaggedValue());
} else if (value.GetConstpoolType() == ConstPoolType::NC_FUNCTION) {
ASSERT(mainMethodIndex != it.first);
panda_file::File::EntityId id(it.first);
auto method = const_cast<JSMethod *>(jsPandaFile_->FindMethods(it.first));
auto method = jsPandaFile->FindMethods(it.first);
ASSERT(method != nullptr);
JSHandle<JSFunction> jsFunc =
factory_->NewJSFunctionByDynClass(method, normalDynclass, FunctionKind::NORMAL_FUNCTION);
constpool->Set(thread_, value.GetConstpoolIndex(), jsFunc.GetTaggedValue());
jsFunc->SetConstantPool(thread_, constpool.GetTaggedValue());
factory->NewJSFunctionByDynClass(method, normalDynclass, FunctionKind::NORMAL_FUNCTION);
constpool->Set(thread, value.GetConstpoolIndex(), jsFunc.GetTaggedValue());
jsFunc->SetConstantPool(thread, constpool.GetTaggedValue());
} else if (value.GetConstpoolType() == ConstPoolType::GENERATOR_FUNCTION) {
ASSERT(mainMethodIndex != it.first);
panda_file::File::EntityId id(it.first);
auto method = const_cast<JSMethod *>(jsPandaFile_->FindMethods(it.first));
auto method = jsPandaFile->FindMethods(it.first);
ASSERT(method != nullptr);
JSHandle<JSFunction> jsFunc =
factory_->NewJSFunctionByDynClass(method, generatorDynclass, FunctionKind::GENERATOR_FUNCTION);
factory->NewJSFunctionByDynClass(method, generatorDynclass, FunctionKind::GENERATOR_FUNCTION);
// 26.3.4.3 prototype
// Whenever a GeneratorFunction instance is created another ordinary object is also created and
// is the initial value of the generator function's "prototype" property.
JSHandle<JSTaggedValue> objFun = env->GetObjectFunction();
JSHandle<JSObject> initialGeneratorFuncPrototype =
factory_->NewJSObjectByConstructor(JSHandle<JSFunction>(objFun), objFun);
JSObject::SetPrototype(thread_, initialGeneratorFuncPrototype, env->GetGeneratorPrototype());
jsFunc->SetProtoOrDynClass(thread_, initialGeneratorFuncPrototype);
factory->NewJSObjectByConstructor(JSHandle<JSFunction>(objFun), objFun);
JSObject::SetPrototype(thread, initialGeneratorFuncPrototype, env->GetGeneratorPrototype());
jsFunc->SetProtoOrDynClass(thread, initialGeneratorFuncPrototype);
constpool->Set(thread_, value.GetConstpoolIndex(), jsFunc.GetTaggedValue());
jsFunc->SetConstantPool(thread_, constpool.GetTaggedValue());
constpool->Set(thread, value.GetConstpoolIndex(), jsFunc.GetTaggedValue());
jsFunc->SetConstantPool(thread, constpool.GetTaggedValue());
} else if (value.GetConstpoolType() == ConstPoolType::ASYNC_FUNCTION) {
ASSERT(mainMethodIndex != it.first);
panda_file::File::EntityId id(it.first);
auto method = const_cast<JSMethod *>(jsPandaFile_->FindMethods(it.first));
auto method = jsPandaFile->FindMethods(it.first);
ASSERT(method != nullptr);
JSHandle<JSFunction> jsFunc =
factory_->NewJSFunctionByDynClass(method, asyncDynclass, FunctionKind::ASYNC_FUNCTION);
constpool->Set(thread_, value.GetConstpoolIndex(), jsFunc.GetTaggedValue());
jsFunc->SetConstantPool(thread_, constpool.GetTaggedValue());
factory->NewJSFunctionByDynClass(method, asyncDynclass, FunctionKind::ASYNC_FUNCTION);
constpool->Set(thread, value.GetConstpoolIndex(), jsFunc.GetTaggedValue());
jsFunc->SetConstantPool(thread, constpool.GetTaggedValue());
} else if (value.GetConstpoolType() == ConstPoolType::CLASS_FUNCTION) {
ASSERT(mainMethodIndex != it.first);
panda_file::File::EntityId id(it.first);
auto method = const_cast<JSMethod *>(jsPandaFile_->FindMethods(it.first));
auto method = jsPandaFile->FindMethods(it.first);
ASSERT(method != nullptr);
JSHandle<ClassInfoExtractor> classInfoExtractor = factory_->NewClassInfoExtractor(method);
constpool->Set(thread_, value.GetConstpoolIndex(), classInfoExtractor.GetTaggedValue());
JSHandle<ClassInfoExtractor> classInfoExtractor = factory->NewClassInfoExtractor(method);
constpool->Set(thread, value.GetConstpoolIndex(), classInfoExtractor.GetTaggedValue());
} else if (value.GetConstpoolType() == ConstPoolType::METHOD) {
ASSERT(mainMethodIndex != it.first);
panda_file::File::EntityId id(it.first);
auto method = const_cast<JSMethod *>(jsPandaFile_->FindMethods(it.first));
auto method = jsPandaFile->FindMethods(it.first);
ASSERT(method != nullptr);
JSHandle<JSFunction> jsFunc =
factory_->NewJSFunctionByDynClass(method, normalDynclass, FunctionKind::NORMAL_FUNCTION);
constpool->Set(thread_, value.GetConstpoolIndex(), jsFunc.GetTaggedValue());
jsFunc->SetConstantPool(thread_, constpool.GetTaggedValue());
factory->NewJSFunctionByDynClass(method, normalDynclass, FunctionKind::NORMAL_FUNCTION);
constpool->Set(thread, value.GetConstpoolIndex(), jsFunc.GetTaggedValue());
jsFunc->SetConstantPool(thread, constpool.GetTaggedValue());
} else if (value.GetConstpoolType() == ConstPoolType::OBJECT_LITERAL) {
size_t index = it.first;
JSMutableHandle<TaggedArray> elements(thread_, JSTaggedValue::Undefined());
JSMutableHandle<TaggedArray> properties(thread_, JSTaggedValue::Undefined());
LiteralDataExtractor::ExtractObjectDatas(thread_, pf, index, elements, properties, this);
JSHandle<JSObject> obj = JSObject::CreateObjectFromProperties(thread_, properties);
JSMutableHandle<TaggedArray> elements(thread, JSTaggedValue::Undefined());
JSMutableHandle<TaggedArray> properties(thread, JSTaggedValue::Undefined());
LiteralDataExtractor::ExtractObjectDatas(thread, jsPandaFile, index, elements, properties);
JSHandle<JSObject> obj = JSObject::CreateObjectFromProperties(thread, properties);
JSMutableHandle<JSTaggedValue> key(thread_, JSTaggedValue::Undefined());
JSMutableHandle<JSTaggedValue> valueHandle(thread_, JSTaggedValue::Undefined());
JSMutableHandle<JSTaggedValue> key(thread, JSTaggedValue::Undefined());
JSMutableHandle<JSTaggedValue> valueHandle(thread, JSTaggedValue::Undefined());
size_t elementsLen = elements->GetLength();
for (size_t i = 0; i < elementsLen; i += 2) { // 2: Each literal buffer contains a pair of key-value.
key.Update(elements->Get(i));
@ -205,41 +221,35 @@ JSHandle<Program> PandaFileTranslator::GenerateProgram()
break;
}
valueHandle.Update(elements->Get(i + 1));
JSObject::DefinePropertyByLiteral(thread_, obj, key, valueHandle);
JSObject::DefinePropertyByLiteral(thread, obj, key, valueHandle);
}
constpool->Set(thread_, value.GetConstpoolIndex(), obj.GetTaggedValue());
constpool->Set(thread, value.GetConstpoolIndex(), obj.GetTaggedValue());
} else if (value.GetConstpoolType() == ConstPoolType::ARRAY_LITERAL) {
size_t index = it.first;
JSHandle<TaggedArray> literal =
LiteralDataExtractor::GetDatasIgnoreType(thread_, pf, static_cast<size_t>(index));
LiteralDataExtractor::GetDatasIgnoreType(thread, jsPandaFile, static_cast<size_t>(index));
uint32_t length = literal->GetLength();
JSHandle<JSArray> arr(JSArray::ArrayCreate(thread_, JSTaggedNumber(length)));
arr->SetElements(thread_, literal);
constpool->Set(thread_, value.GetConstpoolIndex(), arr.GetTaggedValue());
JSHandle<JSArray> arr(JSArray::ArrayCreate(thread, JSTaggedNumber(length)));
arr->SetElements(thread, literal);
constpool->Set(thread, value.GetConstpoolIndex(), arr.GetTaggedValue());
} else if (value.GetConstpoolType() == ConstPoolType::CLASS_LITERAL) {
size_t index = it.first;
JSHandle<TaggedArray> literal =
LiteralDataExtractor::GetDatasIgnoreType(thread_, pf, static_cast<size_t>(index), this);
constpool->Set(thread_, value.GetConstpoolIndex(), literal.GetTaggedValue());
LiteralDataExtractor::GetDatasIgnoreType(thread, jsPandaFile, static_cast<size_t>(index));
constpool->Set(thread, value.GetConstpoolIndex(), literal.GetTaggedValue());
}
}
{
auto method = const_cast<JSMethod *>(jsPandaFile_->FindMethods(mainMethodIndex));
ASSERT(method != nullptr);
JSHandle<JSFunction> mainFunc =
factory_->NewJSFunctionByDynClass(method, dynclass, FunctionKind::BASE_CONSTRUCTOR);
mainFunc->SetConstantPool(thread_, constpool.GetTaggedValue());
program->SetMainFunction(thread_, mainFunc.GetTaggedValue());
// link JSPandaFile
JSHandle<JSNativePointer> jsPandaFilePointer = factory_->NewJSNativePointer(
const_cast<JSPandaFile *>(jsPandaFile_), JSPandaFileManager::RemoveJSPandaFile,
EcmaVM::GetJSPandaFileManager());
constpool->Set(thread_, constpoolIndex, jsPandaFilePointer.GetTaggedValue());
}
DefineClassInConstPool(constpool);
return program;
// link JSPandaFile
JSHandle<JSNativePointer> jsPandaFilePointer = factory->NewJSNativePointer(
const_cast<JSPandaFile *>(jsPandaFile), JSPandaFileManager::RemoveJSPandaFile,
JSPandaFileManager::GetInstance());
constpool->Set(thread, constpoolIndex, jsPandaFilePointer.GetTaggedValue());
DefineClassInConstPool(thread, constpool);
return constpool.GetTaggedValue();
}
void PandaFileTranslator::FixOpcode(uint8_t *pc)
@ -527,33 +537,7 @@ void PandaFileTranslator::TranslateBytecode(JSPandaFile *jsPandaFile, uint32_t i
}
}
JSHandle<JSFunction> PandaFileTranslator::DefineMethodInLiteral(JSThread *thread, uint32_t methodId, FunctionKind kind,
uint16_t length) const
{
auto method = const_cast<JSMethod *>(jsPandaFile_->FindMethods(methodId));
ASSERT(method != nullptr);
JSHandle<GlobalEnv> env = thread_->GetEcmaVM()->GetGlobalEnv();
JSHandle<JSHClass> functionClass;
if (kind == FunctionKind::NORMAL_FUNCTION) {
functionClass = JSHandle<JSHClass>::Cast(env->GetFunctionClassWithoutProto());
} else {
functionClass = JSHandle<JSHClass>::Cast(env->GetGeneratorFunctionClass());
}
JSHandle<JSFunction> jsFunc = factory_->NewJSFunctionByDynClass(method, functionClass, kind);
if (kind == FunctionKind::GENERATOR_FUNCTION) {
JSHandle<JSTaggedValue> objFun = env->GetObjectFunction();
JSHandle<JSObject> initialGeneratorFuncPrototype =
factory_->NewJSObjectByConstructor(JSHandle<JSFunction>(objFun), objFun);
JSObject::SetPrototype(thread_, initialGeneratorFuncPrototype, env->GetGeneratorPrototype());
jsFunc->SetProtoOrDynClass(thread_, initialGeneratorFuncPrototype);
}
jsFunc->SetPropertyInlinedProps(thread, JSFunction::LENGTH_INLINE_PROPERTY_INDEX, JSTaggedValue(length));
return jsFunc;
}
void PandaFileTranslator::DefineClassInConstPool(const JSHandle<ConstantPool> &constpool) const
void PandaFileTranslator::DefineClassInConstPool(JSThread *thread, JSHandle<ConstantPool> constpool)
{
uint32_t length = constpool->GetLength();
uint32_t index = 0;
@ -569,11 +553,11 @@ void PandaFileTranslator::DefineClassInConstPool(const JSHandle<ConstantPool> &c
JSTaggedValue nextValue = constpool->Get(index + 1);
ASSERT(nextValue.IsTaggedArray());
JSHandle<ClassInfoExtractor> extractor(thread_, value);
JSHandle<TaggedArray> literal(thread_, nextValue);
ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(thread_, extractor, literal);
JSHandle<JSFunction> cls = ClassHelper::DefineClassTemplate(thread_, extractor, constpool);
constpool->Set(thread_, index, cls);
JSHandle<ClassInfoExtractor> extractor(thread, value);
JSHandle<TaggedArray> literal(thread, nextValue);
ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(thread, extractor, literal);
JSHandle<JSFunction> cls = ClassHelper::DefineClassTemplate(thread, extractor, constpool);
constpool->Set(thread, index, cls);
index += 2; // 2: pair of extractor and literal
}
}

View File

@ -41,18 +41,15 @@ class Program;
class JSPandaFileManager;
class JSPandaFile;
class PandaFileTranslator {
class PUBLIC_API PandaFileTranslator {
public:
enum FixInstructionIndex : uint8_t { FIX_ONE = 1, FIX_TWO = 2, FIX_FOUR = 4 };
explicit PandaFileTranslator(const JSPandaFile *jsPandaFile);
PUBLIC_API PandaFileTranslator(EcmaVM *vm, const JSPandaFile *jsPandaFile);
PandaFileTranslator() = default;
~PandaFileTranslator() = default;
NO_COPY_SEMANTIC(PandaFileTranslator);
NO_MOVE_SEMANTIC(PandaFileTranslator);
JSHandle<JSFunction> DefineMethodInLiteral(JSThread *thread, uint32_t methodId, FunctionKind kind,
uint16_t length) const;
JSHandle<Program> PUBLIC_API GenerateProgram();
static JSHandle<Program> GenerateProgram(EcmaVM *vm, const JSPandaFile *jsPandaFile);
static void TranslateClasses(JSPandaFile *jsPandaFile, const CString &methodName,
std::vector<MethodPcInfo> *methodPcInfos = nullptr);
@ -62,12 +59,8 @@ private:
static void FixInstructionId32(const BytecodeInstruction &inst, uint32_t index, uint32_t fixOrder = 0);
static void FixOpcode(uint8_t *pc);
static void UpdateICOffset(JSMethod *method, uint8_t *pc);
void DefineClassInConstPool(const JSHandle<ConstantPool> &constpool) const;
EcmaVM *ecmaVm_;
ObjectFactory *factory_;
JSThread *thread_;
const JSPandaFile *jsPandaFile_;
static JSTaggedValue ParseConstPool(EcmaVM *vm, const JSPandaFile *jsPandaFile);
static void DefineClassInConstPool(JSThread *thread, JSHandle<ConstantPool> constpool);
};
} // namespace panda::ecmascript
#endif // ECMASCRIPT_JSPANDAFILE_PANDA_FILE_TRANSLATOR_H

View File

@ -24,8 +24,8 @@ JSTaggedValue ScopeInfoExtractor::GenerateScopeInfo(JSThread *thread, uint16_t s
EcmaVM *ecmaVm = thread->GetEcmaVM();
ObjectFactory *factory = ecmaVm->GetFactory();
JSMethod *method = InterpretedFrameHandler(thread).GetMethod();
const panda_file::File *pf = method->GetPandaFile();
JSHandle<TaggedArray> elementsLiteral = LiteralDataExtractor::GetDatasIgnoreType(thread, pf, scopeId);
const JSPandaFile *jsPandaFile = method->GetJSPandaFile();
JSHandle<TaggedArray> elementsLiteral = LiteralDataExtractor::GetDatasIgnoreType(thread, jsPandaFile, scopeId);
ASSERT(elementsLiteral->GetLength() > 0);
size_t length = elementsLiteral->GetLength();

View File

@ -80,11 +80,11 @@ void ModuleManager::StoreModuleValue(JSTaggedValue key, JSTaggedValue value)
currentModule->StoreModuleValue(thread, keyHandle, valueHandle);
}
JSHandle<SourceTextModule> ModuleManager::HostGetImportedModule(const CString &referencingModule)
JSHandle<SourceTextModule> ModuleManager::HostGetImportedModule(const std::string &referencingModule)
{
ObjectFactory *factory = vm_->GetFactory();
JSHandle<JSTaggedValue> referencingHandle =
JSHandle<JSTaggedValue>::Cast(factory->NewFromString(referencingModule));
JSHandle<JSTaggedValue>::Cast(factory->NewFromStdString(referencingModule));
int entry =
NameDictionary::Cast(resolvedModules_.GetTaggedObject())->FindEntry(referencingHandle.GetTaggedValue());
LOG_IF(entry == -1, FATAL, ECMASCRIPT) << "cannot get module: " << referencingModule;
@ -106,7 +106,7 @@ JSHandle<SourceTextModule> ModuleManager::HostResolveImportedModule(const std::s
thread, NameDictionary::Cast(resolvedModules_.GetTaggedObject())->GetValue(entry));
}
const JSPandaFile *jsPandaFile = EcmaVM::GetJSPandaFileManager()->LoadJSPandaFile(referencingModule);
const JSPandaFile *jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(referencingModule);
if (jsPandaFile == nullptr) {
LOG_ECMA(ERROR) << "open jsPandaFile " << referencingModule << " error";
UNREACHABLE();

View File

@ -28,7 +28,7 @@ public:
JSTaggedValue GetModuleValueInner(JSTaggedValue key);
JSTaggedValue GetModuleValueOutter(JSTaggedValue key);
void StoreModuleValue(JSTaggedValue key, JSTaggedValue value);
JSHandle<SourceTextModule> HostGetImportedModule(const CString &referencingModule);
JSHandle<SourceTextModule> HostGetImportedModule(const std::string &referencingModule);
JSHandle<SourceTextModule> HostResolveImportedModule(const std::string &referencingModule);
JSTaggedValue GetModuleNamespace(JSTaggedValue localName);
void AddResolveImportedModule(const JSPandaFile *jsPandaFile, const std::string &referencingModule);

View File

@ -658,7 +658,7 @@ void SourceTextModule::ModuleExecution(JSThread *thread, const JSHandle<SourceTe
JSTaggedValue moduleFileName = module->GetEcmaModuleFilename();
ASSERT(moduleFileName.IsString());
std::string moduleFilenameStr = base::StringHelper::ToStdString(EcmaString::Cast(moduleFileName.GetHeapObject()));
const JSPandaFile *jsPandaFile = EcmaVM::GetJSPandaFileManager()->LoadJSPandaFile(moduleFilenameStr);
const JSPandaFile *jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(moduleFilenameStr);
if (jsPandaFile == nullptr) {
LOG_ECMA(ERROR) << "open jsPandaFile " << moduleFilenameStr << " error";
UNREACHABLE();

View File

@ -36,10 +36,10 @@
namespace panda::ecmascript {
constexpr uint32_t PANDA_FILE_ALIGNMENT = 4096;
void SnapShot::MakeSnapShotProgramObject(Program *program, const panda_file::File *pf, const CString &fileName)
void SnapShot::MakeSnapShotProgramObject(Program *program, const panda_file::File *pf, const std::string &fileName)
{
std::fstream write;
std::pair<bool, CString> filePath = VerifyFilePath(fileName);
std::pair<bool, std::string> filePath = VerifyFilePath(fileName);
if (!filePath.first) {
LOG(ERROR, RUNTIME) << "snapshot file path error";
return;
@ -117,13 +117,13 @@ void SnapShot::MakeSnapShotProgramObject(Program *program, const panda_file::Fil
write.close();
}
const JSPandaFile *SnapShot::DeserializeGlobalEnvAndProgram(const CString &abcFile, const CString &snapshotFile)
const JSPandaFile *SnapShot::DeserializeGlobalEnvAndProgram(const std::string &abcFile, const std::string &snapshotFile)
{
SnapShotSerialize serialize(vm_, false);
serialize.GeneratedNativeMethod();
std::pair<bool, CString> filePath = VerifyFilePath(snapshotFile);
std::pair<bool, std::string> filePath = VerifyFilePath(snapshotFile);
if (!filePath.first) {
LOG(ERROR, RUNTIME) << "snapshot file path error";
return nullptr;
@ -188,7 +188,7 @@ const JSPandaFile *SnapShot::DeserializeGlobalEnvAndProgram(const CString &abcFi
abcFile);
close(fd);
// Snapshot file has translated
const JSPandaFile *jsPandaFile = EcmaVM::GetJSPandaFileManager()->NewJSPandaFile(pf.release(), abcFile);
const JSPandaFile *jsPandaFile = JSPandaFileManager::GetInstance()->NewJSPandaFile(pf.release(), abcFile);
// redirect object field
serialize.RedirectSlot(jsPandaFile);
return jsPandaFile;
@ -202,7 +202,7 @@ size_t SnapShot::AlignUpPageSize(size_t spaceSize)
return PAGE_SIZE_ALIGN_UP * (spaceSize / PAGE_SIZE_ALIGN_UP + 1);
}
std::pair<bool, CString> SnapShot::VerifyFilePath(const CString &filePath)
std::pair<bool, std::string> SnapShot::VerifyFilePath(const std::string &filePath)
{
if (filePath.size() > PATH_MAX) {
return std::make_pair(false, "");
@ -210,7 +210,7 @@ std::pair<bool, CString> SnapShot::VerifyFilePath(const CString &filePath)
CVector<char> resolvedPath(PATH_MAX);
auto result = realpath(filePath.c_str(), resolvedPath.data());
if (result == resolvedPath.data() || errno == ENOENT) {
return std::make_pair(true, CString(resolvedPath.data()));
return std::make_pair(true, std::string(resolvedPath.data()));
}
return std::make_pair(false, "");
}

View File

@ -33,9 +33,9 @@ public:
~SnapShot() = default;
void MakeSnapShotProgramObject(Program *program, const panda_file::File *pf,
const CString &fileName = "./snapshot");
const JSPandaFile *DeserializeGlobalEnvAndProgram(const CString &abcFile,
const CString &snapshotFile = "./snapshot");
const std::string &fileName = "./snapshot");
const JSPandaFile *DeserializeGlobalEnvAndProgram(const std::string &abcFile,
const std::string &snapshotFile = "./snapshot");
private:
struct Header {
@ -45,7 +45,7 @@ private:
private:
size_t AlignUpPageSize(size_t spaceSize);
std::pair<bool, CString> VerifyFilePath(const CString &filePath);
std::pair<bool, std::string> VerifyFilePath(const std::string &filePath);
NO_MOVE_SEMANTIC(SnapShot);
NO_COPY_SEMANTIC(SnapShot);

View File

@ -148,9 +148,9 @@ void DebuggerApi::ClearException(const EcmaVM *ecmaVm)
const panda_file::File *DebuggerApi::FindPandaFile(const EcmaVM *ecmaVm, const CString &fileName)
{
const panda_file::File *pfs = nullptr;
EcmaVM::GetJSPandaFileManager()->EnumerateJSPandaFiles([&pfs, fileName](
::panda::ecmascript::JSPandaFileManager::GetInstance()->EnumerateJSPandaFiles([&pfs, fileName](
const panda::ecmascript::JSPandaFile *jsPandaFile) {
if (jsPandaFile->GetJSPandaFileDesc() == fileName) {
if (ConvertToString(jsPandaFile->GetJSPandaFileDesc()) == fileName) {
pfs = jsPandaFile->GetPandaFile();
return false;
}

View File

@ -141,9 +141,9 @@ bool JSDebugger::RemoveBreakpoint(const JSMethod *method, uint32_t bcOffset)
JSMethod *JSDebugger::FindMethod(const PtLocation &location) const
{
JSMethod *method = nullptr;
EcmaVM::GetJSPandaFileManager()->EnumerateJSPandaFiles([&method, location](
::panda::ecmascript::JSPandaFileManager::GetInstance()->EnumerateJSPandaFiles([&method, location](
const panda::ecmascript::JSPandaFile *jsPandaFile) {
if (CString(location.GetPandaFile()) == jsPandaFile->GetJSPandaFileDesc()) {
if (location.GetPandaFile() == jsPandaFile->GetJSPandaFileDesc()) {
JSMethod *methodsData = jsPandaFile->GetMethods();
uint32_t numberMethods = jsPandaFile->GetNumMethods();
for (uint32_t i = 0; i < numberMethods; ++i) {

View File

@ -14,20 +14,22 @@
*/
#include "ecmascript/ts_types/ts_loader.h"
#include "ecmascript/jspandafile/js_pandafile.h"
#include "ecmascript/ts_types/ts_type_table.h"
namespace panda::ecmascript {
void TSLoader::DecodeTSTypes(const panda_file::File &pf)
void TSLoader::DecodeTSTypes(const JSPandaFile *jsPandaFile)
{
JSThread *thread = vm_->GetJSThread();
ObjectFactory *factory = vm_->GetFactory();
JSHandle<TSModuleTable> table = GetTSModuleTable();
JSHandle<EcmaString> queryFileName = factory->NewFromStdString(pf.GetFilename());
JSHandle<EcmaString> queryFileName = factory->NewFromStdString(jsPandaFile->GetJSPandaFileDesc());
int index = table->GetGlobalModuleID(thread, queryFileName);
if (index == TSModuleTable::NOT_FOUND) {
CVector<JSHandle<EcmaString>> recordImportModules {};
TSTypeTable::Initialize(thread, pf, recordImportModules);
TSTypeTable::Initialize(thread, jsPandaFile, recordImportModules);
Link();
}
}

View File

@ -158,7 +158,7 @@ public:
explicit TSLoader(EcmaVM *vm);
~TSLoader() = default;
void PUBLIC_API DecodeTSTypes(const panda_file::File &pf);
void PUBLIC_API DecodeTSTypes(const JSPandaFile *jsPandaFile);
void AddTypeTable(JSHandle<JSTaggedValue> typeTable, JSHandle<EcmaString> amiPath);

View File

@ -12,38 +12,41 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecmascript/js_handle.h"
#include "ecmascript/ts_types/ts_type_table.h"
#include "ecmascript/jspandafile/js_pandafile_manager.h"
#include "ecmascript/jspandafile/literal_data_extractor.h"
#include "ecmascript/jspandafile/program_object.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,
void TSTypeTable::Initialize(JSThread *thread, const JSPandaFile *jsPandaFile,
CVector<JSHandle<EcmaString>> &recordImportModules)
{
EcmaVM *vm = thread->GetEcmaVM();
TSLoader *tsLoader = vm->GetTSLoader();
ObjectFactory *factory = vm->GetFactory();
JSHandle<TSTypeTable> tsTypetable = GenerateTypeTable(thread, pf, recordImportModules);
JSHandle<TSTypeTable> tsTypetable = GenerateTypeTable(thread, jsPandaFile, recordImportModules);
// Set TStypeTable -> GlobleModuleTable
JSHandle<EcmaString> fileName = factory->NewFromStdString(pf.GetFilename());
JSHandle<EcmaString> fileName = factory->NewFromStdString(jsPandaFile->GetJSPandaFileDesc());
tsLoader->AddTypeTable(JSHandle<JSTaggedValue>(tsTypetable), fileName);
// management dependency module
while (recordImportModules.size() > 0) {
const panda_file::File *moduleFile = GetPandaFile(recordImportModules.back());
CString filename = ConvertToString(recordImportModules.back().GetTaggedValue());
recordImportModules.pop_back();
const JSPandaFile *moduleFile = JSPandaFileManager::GetInstance()->OpenJSPandaFile(filename.c_str());
ASSERT(moduleFile != nullptr);
TSTypeTable::Initialize(thread, *moduleFile, recordImportModules);
TSTypeTable::Initialize(thread, moduleFile, recordImportModules);
}
}
JSHandle<TSTypeTable> TSTypeTable::GenerateTypeTable(JSThread *thread, const panda_file::File &pf,
JSHandle<TSTypeTable> TSTypeTable::GenerateTypeTable(JSThread *thread, const JSPandaFile *jsPandaFile,
CVector<JSHandle<EcmaString>> &recordImportModules)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
@ -52,7 +55,7 @@ JSHandle<TSTypeTable> TSTypeTable::GenerateTypeTable(JSThread *thread, const pan
int typeKind = 0;
uint32_t idx = 0;
JSHandle<TaggedArray> summaryLiteral = LiteralDataExtractor::GetDatasIgnoreType(thread, &pf, idx++);
JSHandle<TaggedArray> summaryLiteral = LiteralDataExtractor::GetDatasIgnoreType(thread, jsPandaFile, idx++);
ASSERT_PRINT(summaryLiteral->Get(TYPE_KIND_OFFSET).GetInt() == static_cast<int32_t>(TypeLiteralFlag::COUNTER),
"summary type literal flag is not counter");
@ -60,9 +63,9 @@ JSHandle<TSTypeTable> TSTypeTable::GenerateTypeTable(JSThread *thread, const pan
JSHandle<TSTypeTable> table = factory->NewTSTypeTable(length);
JSMutableHandle<TaggedArray> typeLiteral(thread, JSTaggedValue::Undefined());
JSHandle<EcmaString> fileName = factory->NewFromStdString(jsPandaFile->GetJSPandaFileDesc());
for (; idx <= length; ++idx) {
typeLiteral.Update(LiteralDataExtractor::GetDatasIgnoreType(thread, &pf, idx).GetTaggedValue());
JSHandle<EcmaString> fileName = factory->NewFromStdString(pf.GetFilename());
typeLiteral.Update(LiteralDataExtractor::GetDatasIgnoreType(thread, jsPandaFile, idx).GetTaggedValue());
JSHandle<JSTaggedValue> type = ParseType(thread, table, typeLiteral, fileName, recordImportModules);
if (!type->IsNull()) {
// Set every object type GT
@ -76,7 +79,7 @@ JSHandle<TSTypeTable> TSTypeTable::GenerateTypeTable(JSThread *thread, const pan
}
table->SetTypeTableLength(thread, length); // record the object type number
table->SetExportValueTable(thread, pf);
table->SetExportValueTable(thread, *jsPandaFile->GetPandaFile());
return table;
}
@ -175,14 +178,6 @@ panda_file::File::EntityId TSTypeTable::GetFileId(const panda_file::File &pf)
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();

View File

@ -51,7 +51,7 @@ public:
return static_cast<TSTypeTable *>(object);
}
static void Initialize(JSThread *thread, const panda_file::File &pf,
static void Initialize(JSThread *thread, const JSPandaFile *jsPandaFile,
CVector<JSHandle<EcmaString>> &recordImportModules);
static GlobalTSTypeRef GetPropertyTypeGT(JSThread *thread, JSHandle<TSTypeTable> &table, TSTypeKind typeKind,
@ -78,15 +78,13 @@ public:
private:
static JSHandle<TSTypeTable> GenerateTypeTable(JSThread *thread, const panda_file::File &pf,
static JSHandle<TSTypeTable> GenerateTypeTable(JSThread *thread, const JSPandaFile *jsPandaFile,
CVector<JSHandle<EcmaString>> &recordImportModules);
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);