From cdfab120f02d090be0c271b3b056b99b0a07df4b Mon Sep 17 00:00:00 2001 From: wengchangcheng Date: Thu, 31 Mar 2022 23:38:07 +0800 Subject: [PATCH] refactor stl container 1. using runtime container instead of stl container 2. change debugger line amd column type to int32_t issue: https://gitee.com/openharmony/ark_js_runtime/issues/I50NHW Signed-off-by: wengchangcheng Change-Id: I0eb4651f17c6f6894f11de1ba904bcbe83a57db7 --- .gitee/PULL_REQUEST_TEMPLATE.zh-CN.md | 8 + ecmascript/base/error_helper.cpp | 6 +- ecmascript/compiler/pass_manager.cpp | 2 +- ecmascript/dfx/cpu_profiler/cpu_profiler.cpp | 10 +- ecmascript/ecma_vm.cpp | 6 +- ecmascript/ecma_vm.h | 6 +- .../jspandafile/debug_info_extractor.cpp | 27 +- ecmascript/jspandafile/debug_info_extractor.h | 37 +-- ecmascript/jspandafile/js_pandafile.cpp | 2 +- ecmascript/jspandafile/js_pandafile.h | 12 +- .../jspandafile/js_pandafile_executor.cpp | 4 +- .../jspandafile/js_pandafile_executor.h | 4 +- .../jspandafile/js_pandafile_manager.cpp | 16 +- ecmascript/jspandafile/js_pandafile_manager.h | 18 +- .../jspandafile/module_data_extractor.cpp | 4 +- .../jspandafile/module_data_extractor.h | 2 +- .../jspandafile/panda_file_translator.cpp | 2 +- .../jspandafile/scope_info_extractor.cpp | 2 +- ecmascript/jspandafile/scope_info_extractor.h | 2 +- ecmascript/mem/c_string.cpp | 8 +- ecmascript/mem/c_string.h | 26 ++ ecmascript/module/js_module_manager.cpp | 12 +- ecmascript/module/js_module_manager.h | 6 +- ecmascript/module/js_module_source_text.cpp | 10 +- ecmascript/napi/jsnapi.cpp | 8 +- ecmascript/snapshot/mem/snapshot.cpp | 12 +- ecmascript/snapshot/mem/snapshot.h | 8 +- ecmascript/tooling/agent/debugger_impl.cpp | 13 +- ecmascript/tooling/agent/debugger_impl.h | 4 +- ecmascript/tooling/agent/js_backend.cpp | 113 +++++---- ecmascript/tooling/agent/js_backend.h | 35 ++- ecmascript/tooling/agent/js_pt_hooks.cpp | 4 +- ecmascript/tooling/agent/runtime_impl.cpp | 4 +- ecmascript/tooling/agent/runtime_impl.h | 4 +- ecmascript/tooling/base/pt_events.cpp | 34 +-- ecmascript/tooling/base/pt_events.h | 43 ++-- ecmascript/tooling/base/pt_params.cpp | 30 +-- ecmascript/tooling/base/pt_params.h | 32 +-- ecmascript/tooling/base/pt_returns.cpp | 2 +- ecmascript/tooling/base/pt_returns.h | 17 +- ecmascript/tooling/base/pt_script.cpp | 10 +- ecmascript/tooling/base/pt_script.h | 23 +- ecmascript/tooling/base/pt_types.cpp | 86 +++---- ecmascript/tooling/base/pt_types.h | 120 +++++---- ecmascript/tooling/debugger_service.cpp | 2 +- ecmascript/tooling/dispatcher.cpp | 5 +- ecmascript/tooling/dispatcher.h | 15 +- ecmascript/tooling/interface/debugger_api.cpp | 57 ++--- ecmascript/tooling/interface/debugger_api.h | 17 +- ecmascript/tooling/interface/js_debugger.cpp | 22 +- ecmascript/tooling/interface/js_debugger.h | 1 - ecmascript/tooling/js_pt_extractor.cpp | 2 +- ecmascript/tooling/js_pt_extractor.h | 10 +- ecmascript/tooling/protocol_handler.cpp | 4 +- ecmascript/tooling/protocol_handler.h | 3 - ecmascript/tooling/test/debugger_api_test.cpp | 4 +- .../tooling/test/debugger_events_test.cpp | 110 ++++---- .../tooling/test/debugger_returns_test.cpp | 26 +- .../tooling/test/debugger_script_test.cpp | 4 +- .../tooling/test/debugger_types_test.cpp | 238 +++++++++--------- ecmascript/tooling/test/js_pt_hooks_test.cpp | 2 +- .../tooling/test/utils/test_extractor.cpp | 2 +- .../tooling/test/utils/test_extractor.h | 8 +- ecmascript/tooling/test/utils/test_util.h | 18 +- .../test/utils/testcases/js_breakpoint_test.h | 1 - .../test/utils/testcases/js_exception_test.h | 1 - .../test/utils/testcases/test_list.cpp | 4 +- .../tooling/test/utils/testcases/test_list.h | 4 +- ecmascript/ts_types/ts_loader.cpp | 2 +- ecmascript/ts_types/ts_type_table.cpp | 4 +- 70 files changed, 706 insertions(+), 694 deletions(-) create mode 100644 .gitee/PULL_REQUEST_TEMPLATE.zh-CN.md diff --git a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md new file mode 100644 index 0000000000..1a5db44cde --- /dev/null +++ b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md @@ -0,0 +1,8 @@ +### 相关的Issue + +### 原因(目的、解决的问题等) + +### 描述(做了什么,变更了什么) + +### 测试用例(新增、改动、可能影响的功能) +UT/test262/启动应用/调试应用 diff --git a/ecmascript/base/error_helper.cpp b/ecmascript/base/error_helper.cpp index cb173c3226..72e4cb6d07 100644 --- a/ecmascript/base/error_helper.cpp +++ b/ecmascript/base/error_helper.cpp @@ -215,10 +215,10 @@ CString ErrorHelper::BuildNativeEcmaStackTrace(JSThread *thread) } data.push_back(':'); // line number and column number - auto callbackFunc = [&data](size_t line, size_t column) -> bool { - data += ToCString(static_cast(line) + 1); + auto callbackFunc = [&data](int32_t line, int32_t column) -> bool { + data += ToCString(line + 1); data.push_back(':'); - data += ToCString(static_cast(column) + 1); + data += ToCString(column + 1); return true; }; if (!debugExtractor->MatchWithOffset(callbackFunc, method->GetFileId(), frameHandler.GetBytecodeOffset())) { diff --git a/ecmascript/compiler/pass_manager.cpp b/ecmascript/compiler/pass_manager.cpp index 976c08cac4..0b4811284d 100644 --- a/ecmascript/compiler/pass_manager.cpp +++ b/ecmascript/compiler/pass_manager.cpp @@ -57,7 +57,7 @@ bool PassManager::CollectInfoOfPandaFile(const std::string &fileName, BytecodeTr return false; } const JSPandaFile *jsPandaFile = - JSPandaFileManager::GetInstance()->LoadAotInfoFromPf(fileName, &(translateInfo->methodPcInfos)); + JSPandaFileManager::GetInstance()->LoadAotInfoFromPf(fileName.c_str(), &(translateInfo->methodPcInfos)); if (jsPandaFile == nullptr) { return false; } diff --git a/ecmascript/dfx/cpu_profiler/cpu_profiler.cpp b/ecmascript/dfx/cpu_profiler/cpu_profiler.cpp index e5a68acddf..563346cc12 100644 --- a/ecmascript/dfx/cpu_profiler/cpu_profiler.cpp +++ b/ecmascript/dfx/cpu_profiler/cpu_profiler.cpp @@ -222,11 +222,11 @@ void CpuProfiler::ParseMethodInfo(JSMethod *method, InterpretedFrameHandler fram } } // line number - int lineNumber = 0; - int columnNumber = 0; - auto callbackFunc = [&](size_t line, size_t column) -> bool { - lineNumber = static_cast(line) + 1; - columnNumber = static_cast(column) + 1; + int32_t lineNumber = 0; + int32_t columnNumber = 0; + auto callbackFunc = [&](int32_t line, int32_t column) -> bool { + lineNumber = line + 1; + columnNumber = column + 1; return true; }; if (!debugExtractor->MatchWithOffset(callbackFunc, method->GetFileId(), frameHandler.GetBytecodeOffset())) { diff --git a/ecmascript/ecma_vm.cpp b/ecmascript/ecma_vm.cpp index 9f4088d839..e1e4dcc7b3 100644 --- a/ecmascript/ecma_vm.cpp +++ b/ecmascript/ecma_vm.cpp @@ -136,8 +136,8 @@ EcmaVM::EcmaVM(JSRuntimeOptions options) if (!snapshotSerializeEnable_) { snapshotDeserializeEnable_ = options_.IsSnapshotDeserializeEnabled(); } - snapshotFileName_ = options_.GetSnapshotFile(); - frameworkAbcFileName_ = options_.GetFrameworkAbcFile(); + snapshotFileName_ = options_.GetSnapshotFile().c_str(); + frameworkAbcFileName_ = options_.GetFrameworkAbcFile().c_str(); options_.ParseAsmInterOption(); auto runtime = Runtime::GetCurrent(); @@ -583,7 +583,7 @@ void EcmaVM::RemoveFromNativePointerList(JSNativePointer *array) } // Do not support snapshot on windows -bool EcmaVM::VerifyFilePath(const std::string &filePath) const +bool EcmaVM::VerifyFilePath(const CString &filePath) const { #ifndef PANDA_TARGET_WINDOWS if (filePath.size() > PATH_MAX) { diff --git a/ecmascript/ecma_vm.h b/ecmascript/ecma_vm.h index 0b467ea4eb..2c01f021e8 100644 --- a/ecmascript/ecma_vm.h +++ b/ecmascript/ecma_vm.h @@ -412,7 +412,7 @@ private: void InitializeEcmaScriptRunStat(); - bool VerifyFilePath(const std::string &filePath) const; + bool VerifyFilePath(const CString &filePath) const; void ClearBufferData(); @@ -454,8 +454,8 @@ private: EcmaRuntimeStat *runtimeStat_ {nullptr}; // For framewrok file snapshot. - std::string snapshotFileName_; - std::string frameworkAbcFileName_; + CString snapshotFileName_; + CString frameworkAbcFileName_; JSTaggedValue frameworkProgram_ {JSTaggedValue::Hole()}; const JSPandaFile *frameworkPandaFile_ {nullptr}; CMap cachedConstpools_ {}; diff --git a/ecmascript/jspandafile/debug_info_extractor.cpp b/ecmascript/jspandafile/debug_info_extractor.cpp index cf8a5961a6..4f030c03df 100644 --- a/ecmascript/jspandafile/debug_info_extractor.cpp +++ b/ecmascript/jspandafile/debug_info_extractor.cpp @@ -15,6 +15,7 @@ #include "ecmascript/jspandafile/debug_info_extractor.h" +#include "ecmascript/jspandafile/js_pandafile.h" #include "libpandabase/utils/utf.h" #include "libpandafile/class_data_accessor-inl.h" #include "libpandafile/debug_data_accessor-inl.h" @@ -33,9 +34,9 @@ static const char *GetStringFromConstantPool(const panda_file::File &pf, uint32_ return utf::Mutf8AsCString(pf.GetStringData(panda_file::File::EntityId(offset)).data); } -DebugInfoExtractor::DebugInfoExtractor(const panda_file::File *pf) +DebugInfoExtractor::DebugInfoExtractor(const JSPandaFile *jsPandaFile) { - Extract(pf); + Extract(jsPandaFile->GetPandaFile()); } class LineNumberProgramProcessor { @@ -50,7 +51,7 @@ public: void Process() { auto opcode = ReadOpcode(); - lnt_.push_back({state_.GetAddress(), state_.GetLine()}); + lnt_.push_back({static_cast(state_.GetAddress()), static_cast(state_.GetLine())}); while (opcode != Opcode::END_SEQUENCE) { switch (opcode) { case Opcode::ADVANCE_LINE: { @@ -200,7 +201,7 @@ private: { auto cn = state_.ReadULeb128(); state_.SetColumn(cn); - cnt_.push_back({state_.GetAddress(), state_.GetColumn()}); + cnt_.push_back({static_cast(state_.GetAddress()), static_cast(state_.GetColumn())}); } void HandleSpecialOpcode(LineNumberProgramItem::Opcode opcode) @@ -213,7 +214,7 @@ private: static_cast(adjustOpcode) % LineNumberProgramItem::LINE_RANGE + LineNumberProgramItem::LINE_BASE; state_.AdvancePc(pcOffset); state_.AdvanceLine(lineOffset); - lnt_.push_back({state_.GetAddress(), state_.GetLine()}); + lnt_.push_back({static_cast(state_.GetAddress()), static_cast(state_.GetLine())}); } LineProgramState state_; @@ -296,27 +297,27 @@ const LocalVariableTable &DebugInfoExtractor::GetLocalVariableTable(panda_file:: return iter->second.localVariableTable; } -const char *DebugInfoExtractor::GetSourceFile(panda_file::File::EntityId methodId) const +const CString &DebugInfoExtractor::GetSourceFile(panda_file::File::EntityId methodId) const { auto iter = methods_.find(methodId.GetOffset()); if (iter == methods_.end()) { - return ""; + return CString(""); } - return iter->second.sourceFile.c_str(); + return iter->second.sourceFile; } -const char *DebugInfoExtractor::GetSourceCode(panda_file::File::EntityId methodId) const +const CString &DebugInfoExtractor::GetSourceCode(panda_file::File::EntityId methodId) const { auto iter = methods_.find(methodId.GetOffset()); if (iter == methods_.end()) { - return ""; + return CString(""); } - return iter->second.sourceCode.c_str(); + return iter->second.sourceCode; } -std::vector DebugInfoExtractor::GetMethodIdList() const +CVector DebugInfoExtractor::GetMethodIdList() const { - std::vector list; + CVector list; for (const auto &method : methods_) { list.push_back(panda_file::File::EntityId(method.first)); diff --git a/ecmascript/jspandafile/debug_info_extractor.h b/ecmascript/jspandafile/debug_info_extractor.h index 759095b0d1..87e12a8dbd 100644 --- a/ecmascript/jspandafile/debug_info_extractor.h +++ b/ecmascript/jspandafile/debug_info_extractor.h @@ -16,41 +16,42 @@ #ifndef ECMASCRIPT_JSPANDAFILE_DEBUG_INFO_EXTRACTOR_H #define ECMASCRIPT_JSPANDAFILE_DEBUG_INFO_EXTRACTOR_H -#include -#include - +#include "ecmascript/mem/c_containers.h" +#include "ecmascript/mem/c_string.h" #include "ecmascript/common.h" #include "libpandafile/file.h" namespace panda::ecmascript { +class JSPandaFile; + struct LineTableEntry { uint32_t offset; - size_t line; + int32_t line; }; struct ColumnTableEntry { uint32_t offset; - size_t column; + int32_t column; }; -using LineNumberTable = std::vector; -using ColumnNumberTable = std::vector; +using LineNumberTable = CVector; +using ColumnNumberTable = CVector; /* * LocalVariableInfo define in frontend, now only use name and regNumber: - * std::string name - * std::string type - * std::string typeSignature + * CString name + * CString type + * CString typeSignature * int32_t regNumber * uint32_t startOffset * uint32_t endOffset */ -using LocalVariableTable = std::unordered_map; +using LocalVariableTable = CUnorderedMap; // public for debugger class PUBLIC_API DebugInfoExtractor { public: - explicit DebugInfoExtractor(const panda_file::File *pf); + explicit DebugInfoExtractor(const JSPandaFile *jsPandaFile); ~DebugInfoExtractor() = default; @@ -63,24 +64,24 @@ public: const LocalVariableTable &GetLocalVariableTable(panda_file::File::EntityId methodId) const; - const char *GetSourceFile(panda_file::File::EntityId methodId) const; + const CString &GetSourceFile(panda_file::File::EntityId methodId) const; - const char *GetSourceCode(panda_file::File::EntityId methodId) const; + const CString &GetSourceCode(panda_file::File::EntityId methodId) const; - std::vector GetMethodIdList() const; + CVector GetMethodIdList() const; private: void Extract(const panda_file::File *pf); struct MethodDebugInfo { - std::string sourceFile; - std::string sourceCode; + CString sourceFile; + CString sourceCode; LineNumberTable lineNumberTable; ColumnNumberTable columnNumberTable; LocalVariableTable localVariableTable; }; - std::unordered_map methods_; + CUnorderedMap methods_; }; } // namespace panda::ecmascript diff --git a/ecmascript/jspandafile/js_pandafile.cpp b/ecmascript/jspandafile/js_pandafile.cpp index c3258db478..ee78e7c019 100644 --- a/ecmascript/jspandafile/js_pandafile.cpp +++ b/ecmascript/jspandafile/js_pandafile.cpp @@ -18,7 +18,7 @@ #include "ecmascript/jspandafile/program_object-inl.h" namespace panda::ecmascript { -JSPandaFile::JSPandaFile(const panda_file::File *pf, const std::string &descriptor) : pf_(pf), desc_(descriptor) +JSPandaFile::JSPandaFile(const panda_file::File *pf, const CString &descriptor) : pf_(pf), desc_(descriptor) { ASSERT(pf_ != nullptr); Initialize(); diff --git a/ecmascript/jspandafile/js_pandafile.h b/ecmascript/jspandafile/js_pandafile.h index e6b4f6fb39..a4d80d0b3a 100644 --- a/ecmascript/jspandafile/js_pandafile.h +++ b/ecmascript/jspandafile/js_pandafile.h @@ -35,10 +35,10 @@ namespace ecmascript { class JSPandaFile { public: - JSPandaFile(const panda_file::File *pf, const std::string &descriptor); + JSPandaFile(const panda_file::File *pf, const CString &descriptor); ~JSPandaFile(); - const std::string &GetJSPandaFileDesc() const + const CString &GetJSPandaFileDesc() const { return desc_; } @@ -75,7 +75,7 @@ public: return mainMethodIndex_; } - const std::unordered_map &GetConstpoolMap() const + const CUnorderedMap &GetConstpoolMap() const { return constpoolMap_; } @@ -100,13 +100,13 @@ private: void Initialize(); uint32_t constpoolIndex_ {0}; - std::unordered_map constpoolMap_; + CUnorderedMap constpoolMap_; uint32_t numMethods_ {0}; uint32_t mainMethodIndex_ {0}; JSMethod *methods_ {nullptr}; - std::unordered_map methodMap_; + CUnorderedMap methodMap_; const panda_file::File *pf_ {nullptr}; - std::string desc_; + CString desc_; bool isModule_ {false}; }; } // namespace ecmascript diff --git a/ecmascript/jspandafile/js_pandafile_executor.cpp b/ecmascript/jspandafile/js_pandafile_executor.cpp index 5010a8064f..4a03c72e57 100644 --- a/ecmascript/jspandafile/js_pandafile_executor.cpp +++ b/ecmascript/jspandafile/js_pandafile_executor.cpp @@ -21,7 +21,7 @@ #include "ecmascript/module/js_module_manager.h" namespace panda::ecmascript { -bool JSPandaFileExecutor::ExecuteFromFile(JSThread *thread, const std::string &filename, std::string_view entryPoint, +bool JSPandaFileExecutor::ExecuteFromFile(JSThread *thread, const CString &filename, std::string_view entryPoint, const std::vector &args) { const JSPandaFile *jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(filename); @@ -49,7 +49,7 @@ bool JSPandaFileExecutor::ExecuteFromFile(JSThread *thread, const std::string &f bool JSPandaFileExecutor::ExecuteFromBuffer(JSThread *thread, const void *buffer, size_t size, std::string_view entryPoint, const std::vector &args, - const std::string &filename) + const CString &filename) { const JSPandaFile *jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(filename, buffer, size); if (jsPandaFile == nullptr) { diff --git a/ecmascript/jspandafile/js_pandafile_executor.h b/ecmascript/jspandafile/js_pandafile_executor.h index 6c8706f899..c9b734cf53 100644 --- a/ecmascript/jspandafile/js_pandafile_executor.h +++ b/ecmascript/jspandafile/js_pandafile_executor.h @@ -25,10 +25,10 @@ namespace panda::ecmascript { class JSPandaFileExecutor { public: - static bool ExecuteFromFile(JSThread *thread, const std::string &filename, std::string_view entryPoint, + static bool ExecuteFromFile(JSThread *thread, const CString &filename, std::string_view entryPoint, const std::vector &args); static bool ExecuteFromBuffer(JSThread *thread, const void *buffer, size_t size, std::string_view entryPoint, - const std::vector &args, const std::string &filename = ""); + const std::vector &args, const CString &filename = ""); private: static bool Execute(JSThread *thread, const JSPandaFile *jsPandaFile, std::string_view entryPoint, const std::vector &args); diff --git a/ecmascript/jspandafile/js_pandafile_manager.cpp b/ecmascript/jspandafile/js_pandafile_manager.cpp index 19a8018e7e..be99be6480 100644 --- a/ecmascript/jspandafile/js_pandafile_manager.cpp +++ b/ecmascript/jspandafile/js_pandafile_manager.cpp @@ -32,7 +32,7 @@ JSPandaFileManager::~JSPandaFileManager() } // generate aot info on host -const JSPandaFile *JSPandaFileManager::LoadAotInfoFromPf(const std::string &filename, +const JSPandaFile *JSPandaFileManager::LoadAotInfoFromPf(const CString &filename, std::vector *methodPcInfos) { JSPandaFile *jsPandaFile = OpenJSPandaFile(filename); @@ -45,7 +45,7 @@ const JSPandaFile *JSPandaFileManager::LoadAotInfoFromPf(const std::string &file return jsPandaFile; } -const JSPandaFile *JSPandaFileManager::LoadJSPandaFile(const std::string &filename) +const JSPandaFile *JSPandaFileManager::LoadJSPandaFile(const CString &filename) { ECMA_BYTRACE_NAME(BYTRACE_TAG_ARK, "JSPandaFileManager::LoadJSPandaFile"); const JSPandaFile *jsPandaFile = FindJSPandaFile(filename); @@ -64,7 +64,7 @@ const JSPandaFile *JSPandaFileManager::LoadJSPandaFile(const std::string &filena return jsPandaFile; } -const JSPandaFile *JSPandaFileManager::LoadJSPandaFile(const std::string &filename, const void *buffer, size_t size) +const JSPandaFile *JSPandaFileManager::LoadJSPandaFile(const CString &filename, const void *buffer, size_t size) { if (buffer == nullptr || size == 0) { return nullptr; @@ -95,7 +95,7 @@ JSHandle JSPandaFileManager::GenerateProgram(EcmaVM *vm, const JSPandaF return program; } -const JSPandaFile *JSPandaFileManager::FindJSPandaFile(const std::string &filename) +const JSPandaFile *JSPandaFileManager::FindJSPandaFile(const CString &filename) { if (filename.empty()) { return nullptr; @@ -156,7 +156,7 @@ void JSPandaFileManager::DecreaseRefJSPandaFile(const JSPandaFile *jsPandaFile) ReleaseJSPandaFile(jsPandaFile); } -JSPandaFile *JSPandaFileManager::OpenJSPandaFile(const std::string &filename) +JSPandaFile *JSPandaFileManager::OpenJSPandaFile(const CString &filename) { auto pf = panda_file::OpenPandaFileOrZip(filename, panda_file::File::READ_WRITE); if (pf == nullptr) { @@ -168,7 +168,7 @@ JSPandaFile *JSPandaFileManager::OpenJSPandaFile(const std::string &filename) return jsPandaFile; } -JSPandaFile *JSPandaFileManager::NewJSPandaFile(const panda_file::File *pf, const std::string &desc) +JSPandaFile *JSPandaFileManager::NewJSPandaFile(const panda_file::File *pf, const CString &desc) { return new JSPandaFile(pf, desc); } @@ -191,7 +191,7 @@ tooling::ecmascript::JSPtExtractor *JSPandaFileManager::GetJSPtExtractor(const J auto iter = extractors_.find(jsPandaFile); if (iter == extractors_.end()) { - auto extractorPtr = std::make_unique(jsPandaFile->GetPandaFile()); + auto extractorPtr = std::make_unique(jsPandaFile); tooling::ecmascript::JSPtExtractor *extractor = extractorPtr.get(); extractors_[jsPandaFile] = std::move(extractorPtr); return extractor; @@ -200,7 +200,7 @@ tooling::ecmascript::JSPtExtractor *JSPandaFileManager::GetJSPtExtractor(const J return iter->second.get(); } -const JSPandaFile *JSPandaFileManager::GenerateJSPandaFile(const panda_file::File *pf, const std::string &desc) +const JSPandaFile *JSPandaFileManager::GenerateJSPandaFile(const panda_file::File *pf, const CString &desc) { ASSERT(GetJSPandaFile(pf) == nullptr); diff --git a/ecmascript/jspandafile/js_pandafile_manager.h b/ecmascript/jspandafile/js_pandafile_manager.h index d8241450a0..d1969ec7e2 100644 --- a/ecmascript/jspandafile/js_pandafile_manager.h +++ b/ecmascript/jspandafile/js_pandafile_manager.h @@ -32,9 +32,9 @@ class EcmaVm; namespace ecmascript { class Program; -class JSPandaFileManager { +class PUBLIC_API JSPandaFileManager { public: - PUBLIC_API ~JSPandaFileManager(); + ~JSPandaFileManager(); static JSPandaFileManager *GetInstance() { @@ -44,16 +44,16 @@ public: JSHandle GenerateProgram(EcmaVM *vm, const JSPandaFile *jsPandaFile); - const JSPandaFile* PUBLIC_API LoadAotInfoFromPf(const std::string &filename, + const JSPandaFile* LoadAotInfoFromPf(const CString &filename, std::vector *methodPcInfos); - const JSPandaFile *LoadJSPandaFile(const std::string &filename); + const JSPandaFile *LoadJSPandaFile(const CString &filename); - const JSPandaFile *LoadJSPandaFile(const std::string &filename, const void *buffer, size_t size); + const JSPandaFile *LoadJSPandaFile(const CString &filename, const void *buffer, size_t size); - JSPandaFile *OpenJSPandaFile(const std::string &filename); + JSPandaFile *OpenJSPandaFile(const CString &filename); - JSPandaFile *NewJSPandaFile(const panda_file::File *pf, const std::string &desc); + JSPandaFile *NewJSPandaFile(const panda_file::File *pf, const CString &desc); tooling::ecmascript::JSPtExtractor *GetJSPtExtractor(const JSPandaFile *jsPandaFile); @@ -81,10 +81,10 @@ private: static void FreeBuffer(void *mem); }; - const JSPandaFile *GenerateJSPandaFile(const panda_file::File *pf, const std::string &desc); + const JSPandaFile *GenerateJSPandaFile(const panda_file::File *pf, const CString &desc); void ReleaseJSPandaFile(const JSPandaFile *jsPandaFile); const JSPandaFile *GetJSPandaFile(const panda_file::File *pf); - const JSPandaFile *FindJSPandaFile(const std::string &filename); + const JSPandaFile *FindJSPandaFile(const CString &filename); void InsertJSPandaFile(const JSPandaFile *jsPandaFile); void IncreaseRefJSPandaFile(const JSPandaFile *jsPandaFile); void DecreaseRefJSPandaFile(const JSPandaFile *jsPandaFile); diff --git a/ecmascript/jspandafile/module_data_extractor.cpp b/ecmascript/jspandafile/module_data_extractor.cpp index 54bbe27db8..9b6e342e23 100644 --- a/ecmascript/jspandafile/module_data_extractor.cpp +++ b/ecmascript/jspandafile/module_data_extractor.cpp @@ -27,7 +27,7 @@ using ModuleTag = jspandafile::ModuleTag; using StringData = panda_file::StringData; JSHandle ModuleDataExtractor::ParseModule(JSThread *thread, const JSPandaFile *jsPandaFile, - const std::string &descriptor) + const CString &descriptor) { const panda_file::File *pf = jsPandaFile->GetPandaFile(); Span classIndexes = pf->GetClasses(); @@ -59,7 +59,7 @@ JSHandle ModuleDataExtractor::ParseModule(JSThread *thread, const JSHandle moduleRecord = factory->NewSourceTextModule(); ModuleDataExtractor::ExtractModuleDatas(thread, jsPandaFile, moduleId, moduleRecord); - JSHandle ecmaModuleFilename = factory->NewFromStdString(descriptor); + JSHandle ecmaModuleFilename = factory->NewFromString(descriptor); moduleRecord->SetEcmaModuleFilename(thread, ecmaModuleFilename); moduleRecord->SetStatus(ModuleStatus::UNINSTANTIATED); diff --git a/ecmascript/jspandafile/module_data_extractor.h b/ecmascript/jspandafile/module_data_extractor.h index bb21dd4293..30b959aa40 100644 --- a/ecmascript/jspandafile/module_data_extractor.h +++ b/ecmascript/jspandafile/module_data_extractor.h @@ -35,7 +35,7 @@ public: panda_file::File::EntityId moduleId, JSHandle &moduleRecord); static JSHandle ParseModule(JSThread *thread, const JSPandaFile *jsPandaFile, - const std::string &descriptor); + const CString &descriptor); }; } // namespace panda::ecmascript #endif // ECMASCRIPT_JSPANDAFILE_MODULE_DATA_EXTRACTOR_H diff --git a/ecmascript/jspandafile/panda_file_translator.cpp b/ecmascript/jspandafile/panda_file_translator.cpp index 7d5e83aaff..af75a7b8ea 100644 --- a/ecmascript/jspandafile/panda_file_translator.cpp +++ b/ecmascript/jspandafile/panda_file_translator.cpp @@ -132,7 +132,7 @@ JSTaggedValue PandaFileTranslator::ParseConstPool(EcmaVM *vm, const JSPandaFile JSHandle asyncDynclass = JSHandle::Cast(env->GetAsyncFunctionClass()); JSHandle generatorDynclass = JSHandle::Cast(env->GetGeneratorFunctionClass()); - const std::unordered_map &constpoolMap = jsPandaFile->GetConstpoolMap(); + const CUnorderedMap &constpoolMap = jsPandaFile->GetConstpoolMap(); [[maybe_unused]] uint32_t mainMethodIndex = jsPandaFile->GetMainMethodIndex(); for (const auto &it : constpoolMap) { ConstPoolValue value(it.second); diff --git a/ecmascript/jspandafile/scope_info_extractor.cpp b/ecmascript/jspandafile/scope_info_extractor.cpp index a7992692d7..2dd583b439 100644 --- a/ecmascript/jspandafile/scope_info_extractor.cpp +++ b/ecmascript/jspandafile/scope_info_extractor.cpp @@ -35,7 +35,7 @@ JSTaggedValue ScopeInfoExtractor::GenerateScopeInfo(JSThread *thread, uint16_t s for (size_t i = 1; i < length; i += 2) { // 2: Each literal buffer contains a pair of key-value. JSTaggedValue val = elementsLiteral->Get(i); ASSERT(val.IsString()); - std::string name = base::StringHelper::ToStdString(EcmaString::Cast(val.GetTaggedObject())); + CString name = ConvertToString(EcmaString::Cast(val.GetTaggedObject())); uint32_t slot = elementsLiteral->Get(i + 1).GetInt(); scopeDebugInfo->scopeInfo.insert(std::make_pair(name, slot)); } diff --git a/ecmascript/jspandafile/scope_info_extractor.h b/ecmascript/jspandafile/scope_info_extractor.h index 53c2b76f68..5ac74c0971 100644 --- a/ecmascript/jspandafile/scope_info_extractor.h +++ b/ecmascript/jspandafile/scope_info_extractor.h @@ -20,7 +20,7 @@ namespace panda::ecmascript { struct ScopeDebugInfo { - std::unordered_map scopeInfo; + CUnorderedMap scopeInfo; }; class ScopeInfoExtractor { diff --git a/ecmascript/mem/c_string.cpp b/ecmascript/mem/c_string.cpp index 7869e8000a..720844c05d 100644 --- a/ecmascript/mem/c_string.cpp +++ b/ecmascript/mem/c_string.cpp @@ -24,7 +24,13 @@ #include "libpandabase/macros.h" namespace panda::ecmascript { -constexpr int BASE = 10; +long CStringToL(const CString &str) +{ + [[maybe_unused]] char *endPtr = nullptr; + int64_t result = std::strtol(str.c_str(), &endPtr, BASE); + ASSERT(!(result == 0 && str.c_str() == endPtr) && "CString argument is not long int"); + return result; +} int64_t CStringToLL(const CString &str) { diff --git a/ecmascript/mem/c_string.h b/ecmascript/mem/c_string.h index 591214ac53..a5a7cc03a6 100644 --- a/ecmascript/mem/c_string.h +++ b/ecmascript/mem/c_string.h @@ -30,9 +30,22 @@ class JSTaggedValue; using CString = std::basic_string, CAddressAllocator>; using CStringStream = std::basic_stringstream, CAddressAllocator>; +struct CStringHash { + using argument_type = panda::ecmascript::CString; + using result_type = std::size_t; + + size_t operator()(const CString &str) const noexcept + { + return std::hash()(std::string_view(str.data(), str.size())); + } +}; + +constexpr int BASE = 10; + // PRINT will skip '\0' in utf16 during conversion of utf8 enum StringConvertedUsage { PRINT, LOGICOPERATION }; +long CStringToL(const CString &str); int64_t CStringToLL(const CString &str); uint64_t CStringToULL(const CString &str); float CStringToF(const CString &str); @@ -80,4 +93,17 @@ std::enable_if_t, CString> ToCString(T number) } } // namespace panda::ecmascript +namespace std { +template <> +struct hash { + using argument_type = panda::ecmascript::CStringHash::argument_type; + using result_type = panda::ecmascript::CStringHash::result_type; + + size_t operator()(const panda::ecmascript::CString &str) const noexcept + { + return panda::ecmascript::CStringHash()(str); + } +}; +} // namespace std + #endif // ECMASCRIPT_MEM_C_STRING_H diff --git a/ecmascript/module/js_module_manager.cpp b/ecmascript/module/js_module_manager.cpp index c3c12eda47..47ee5c62c6 100644 --- a/ecmascript/module/js_module_manager.cpp +++ b/ecmascript/module/js_module_manager.cpp @@ -80,11 +80,11 @@ void ModuleManager::StoreModuleValue(JSTaggedValue key, JSTaggedValue value) currentModule->StoreModuleValue(thread, keyHandle, valueHandle); } -JSHandle ModuleManager::HostGetImportedModule(const std::string &referencingModule) +JSHandle ModuleManager::HostGetImportedModule(const CString &referencingModule) { ObjectFactory *factory = vm_->GetFactory(); JSHandle referencingHandle = - JSHandle::Cast(factory->NewFromStdString(referencingModule)); + JSHandle::Cast(factory->NewFromString(referencingModule)); int entry = NameDictionary::Cast(resolvedModules_.GetTaggedObject())->FindEntry(referencingHandle.GetTaggedValue()); LOG_IF(entry == -1, FATAL, ECMASCRIPT) << "cannot get module: " << referencingModule; @@ -93,12 +93,12 @@ JSHandle ModuleManager::HostGetImportedModule(const std::strin NameDictionary::Cast(resolvedModules_.GetTaggedObject())->GetValue(entry)); } -JSHandle ModuleManager::HostResolveImportedModule(const std::string &referencingModule) +JSHandle ModuleManager::HostResolveImportedModule(const CString &referencingModule) { JSThread *thread = vm_->GetJSThread(); ObjectFactory *factory = vm_->GetFactory(); JSHandle referencingHandle = - JSHandle::Cast(factory->NewFromStdString(referencingModule)); + JSHandle::Cast(factory->NewFromString(referencingModule)); int entry = NameDictionary::Cast(resolvedModules_.GetTaggedObject())->FindEntry(referencingHandle.GetTaggedValue()); if (entry != -1) { @@ -119,13 +119,13 @@ JSHandle ModuleManager::HostResolveImportedModule(const std::s return JSHandle::Cast(moduleRecord); } -void ModuleManager::AddResolveImportedModule(const JSPandaFile *jsPandaFile, const std::string &referencingModule) +void ModuleManager::AddResolveImportedModule(const JSPandaFile *jsPandaFile, const CString &referencingModule) { JSThread *thread = vm_->GetJSThread(); ObjectFactory *factory = vm_->GetFactory(); JSHandle moduleRecord = ModuleDataExtractor::ParseModule(thread, jsPandaFile, referencingModule); JSHandle referencingHandle = - JSHandle::Cast(factory->NewFromStdString(referencingModule)); + JSHandle::Cast(factory->NewFromString(referencingModule)); JSHandle dict(thread, resolvedModules_); resolvedModules_ = NameDictionary::Put(thread, dict, referencingHandle, moduleRecord, PropertyAttributes::Default()) diff --git a/ecmascript/module/js_module_manager.h b/ecmascript/module/js_module_manager.h index 04e5d3d34e..7cbd6e07ef 100644 --- a/ecmascript/module/js_module_manager.h +++ b/ecmascript/module/js_module_manager.h @@ -28,10 +28,10 @@ public: JSTaggedValue GetModuleValueInner(JSTaggedValue key); JSTaggedValue GetModuleValueOutter(JSTaggedValue key); void StoreModuleValue(JSTaggedValue key, JSTaggedValue value); - JSHandle HostGetImportedModule(const std::string &referencingModule); - JSHandle HostResolveImportedModule(const std::string &referencingModule); + JSHandle HostGetImportedModule(const CString &referencingModule); + JSHandle HostResolveImportedModule(const CString &referencingModule); JSTaggedValue GetModuleNamespace(JSTaggedValue localName); - void AddResolveImportedModule(const JSPandaFile *jsPandaFile, const std::string &referencingModule); + void AddResolveImportedModule(const JSPandaFile *jsPandaFile, const CString &referencingModule); void Iterate(const RootVisitor &v); private: diff --git a/ecmascript/module/js_module_source_text.cpp b/ecmascript/module/js_module_source_text.cpp index 107a7dc75d..4ea943b803 100644 --- a/ecmascript/module/js_module_source_text.cpp +++ b/ecmascript/module/js_module_source_text.cpp @@ -112,15 +112,15 @@ JSHandle SourceTextModule::HostResolveImportedModule(JSThread const JSHandle &module, const JSHandle &moduleRequest) { - std::string moduleFilename = base::StringHelper::ToStdString(EcmaString::Cast(moduleRequest->GetHeapObject())); + CString moduleFilename = ConvertToString(EcmaString::Cast(moduleRequest->GetHeapObject())); ASSERT(module->GetEcmaModuleFilename().IsHeapObject()); - std::string baseFilename = - base::StringHelper::ToStdString(EcmaString::Cast(module->GetEcmaModuleFilename().GetHeapObject())); + CString baseFilename = + ConvertToString(EcmaString::Cast(module->GetEcmaModuleFilename().GetHeapObject())); int suffixEnd = moduleFilename.find_last_of('.'); if (suffixEnd == -1) { RETURN_HANDLE_IF_ABRUPT_COMPLETION(SourceTextModule, thread); } - std::string moduleFullname; + CString moduleFullname; if (moduleFilename[0] == '/') { // absoluteFilePath moduleFullname = moduleFilename.substr(0, suffixEnd) + ".abc"; } else { @@ -657,7 +657,7 @@ void SourceTextModule::ModuleExecution(JSThread *thread, const JSHandleGetEcmaModuleFilename(); ASSERT(moduleFileName.IsString()); - std::string moduleFilenameStr = base::StringHelper::ToStdString(EcmaString::Cast(moduleFileName.GetHeapObject())); + CString moduleFilenameStr = ConvertToString(EcmaString::Cast(moduleFileName.GetHeapObject())); const JSPandaFile *jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(moduleFilenameStr); if (jsPandaFile == nullptr) { LOG_ECMA(ERROR) << "open jsPandaFile " << moduleFilenameStr << " error"; diff --git a/ecmascript/napi/jsnapi.cpp b/ecmascript/napi/jsnapi.cpp index 892b900993..eb5531b2e7 100644 --- a/ecmascript/napi/jsnapi.cpp +++ b/ecmascript/napi/jsnapi.cpp @@ -290,7 +290,7 @@ bool JSNApi::Execute(EcmaVM *vm, const std::string &fileName, const std::string std::vector argv; LOG_ECMA(DEBUG) << "start to execute ark file" << fileName; JSThread *thread = vm->GetAssociatedJSThread(); - if (!ecmascript::JSPandaFileExecutor::ExecuteFromFile(thread, fileName, entry, argv)) { + if (!ecmascript::JSPandaFileExecutor::ExecuteFromFile(thread, fileName.c_str(), entry, argv)) { LOG_ECMA(ERROR) << "Cannot execute ark file '" << fileName << "' with entry '" << entry << "'" << std::endl; return false; @@ -303,7 +303,7 @@ bool JSNApi::Execute(EcmaVM *vm, const uint8_t *data, int32_t size, { std::vector argv; JSThread *thread = vm->GetAssociatedJSThread(); - if (!ecmascript::JSPandaFileExecutor::ExecuteFromBuffer(thread, data, size, entry, argv, filename)) { + if (!ecmascript::JSPandaFileExecutor::ExecuteFromBuffer(thread, data, size, entry, argv, filename.c_str())) { LOG_ECMA(ERROR) << "Cannot execute ark buffer file '" << filename << "' with entry '" << entry << "'" << std::endl; return false; @@ -483,7 +483,7 @@ bool JSNApi::ExecuteModuleFromBuffer(EcmaVM *vm, const void *data, int32_t size, { std::vector argv; JSThread *thread = vm->GetAssociatedJSThread(); - if (!ecmascript::JSPandaFileExecutor::ExecuteFromBuffer(thread, data, size, ENTRY_POINTER, argv, file)) { + if (!ecmascript::JSPandaFileExecutor::ExecuteFromBuffer(thread, data, size, ENTRY_POINTER, argv, file.c_str())) { std::cerr << "Cannot execute panda file from memory" << std::endl; return false; } @@ -494,7 +494,7 @@ Local JSNApi::GetExportObject(EcmaVM *vm, const std::string &file, co { ecmascript::ModuleManager *moduleManager = vm->GetModuleManager(); JSThread *thread = vm->GetJSThread(); - JSHandle ecmaModule = moduleManager->HostResolveImportedModule(file); + JSHandle ecmaModule = moduleManager->HostResolveImportedModule(file.c_str()); ObjectFactory *factory = vm->GetFactory(); JSHandle keyHandle = factory->NewFromStdStringUnCheck(key, true); diff --git a/ecmascript/snapshot/mem/snapshot.cpp b/ecmascript/snapshot/mem/snapshot.cpp index 173ed23424..1a7a42bbac 100644 --- a/ecmascript/snapshot/mem/snapshot.cpp +++ b/ecmascript/snapshot/mem/snapshot.cpp @@ -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 std::string &fileName) +void SnapShot::MakeSnapShotProgramObject(Program *program, const panda_file::File *pf, const CString &fileName) { std::fstream write; - std::pair filePath = VerifyFilePath(fileName); + std::pair 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 std::string &abcFile, const std::string &snapshotFile) +const JSPandaFile *SnapShot::DeserializeGlobalEnvAndProgram(const CString &abcFile, const CString &snapshotFile) { SnapShotSerialize serialize(vm_, false); serialize.GeneratedNativeMethod(); - std::pair filePath = VerifyFilePath(snapshotFile); + std::pair filePath = VerifyFilePath(snapshotFile); if (!filePath.first) { LOG(ERROR, RUNTIME) << "snapshot file path error"; return nullptr; @@ -202,7 +202,7 @@ size_t SnapShot::AlignUpPageSize(size_t spaceSize) return PAGE_SIZE_ALIGN_UP * (spaceSize / PAGE_SIZE_ALIGN_UP + 1); } -std::pair SnapShot::VerifyFilePath(const std::string &filePath) +std::pair SnapShot::VerifyFilePath(const CString &filePath) { if (filePath.size() > PATH_MAX) { return std::make_pair(false, ""); @@ -210,7 +210,7 @@ std::pair SnapShot::VerifyFilePath(const std::string &filePat CVector resolvedPath(PATH_MAX); auto result = realpath(filePath.c_str(), resolvedPath.data()); if (result == resolvedPath.data() || errno == ENOENT) { - return std::make_pair(true, std::string(resolvedPath.data())); + return std::make_pair(true, CString(resolvedPath.data())); } return std::make_pair(false, ""); } diff --git a/ecmascript/snapshot/mem/snapshot.h b/ecmascript/snapshot/mem/snapshot.h index 71d09b4443..2b2980561f 100644 --- a/ecmascript/snapshot/mem/snapshot.h +++ b/ecmascript/snapshot/mem/snapshot.h @@ -33,9 +33,9 @@ public: ~SnapShot() = default; void MakeSnapShotProgramObject(Program *program, const panda_file::File *pf, - const std::string &fileName = "./snapshot"); - const JSPandaFile *DeserializeGlobalEnvAndProgram(const std::string &abcFile, - const std::string &snapshotFile = "./snapshot"); + const CString &fileName = "./snapshot"); + const JSPandaFile *DeserializeGlobalEnvAndProgram(const CString &abcFile, + const CString &snapshotFile = "./snapshot"); private: struct Header { @@ -45,7 +45,7 @@ private: private: size_t AlignUpPageSize(size_t spaceSize); - std::pair VerifyFilePath(const std::string &filePath); + std::pair VerifyFilePath(const CString &filePath); NO_MOVE_SEMANTIC(SnapShot); NO_COPY_SEMANTIC(SnapShot); diff --git a/ecmascript/tooling/agent/debugger_impl.cpp b/ecmascript/tooling/agent/debugger_impl.cpp index 754047c194..99861eb777 100644 --- a/ecmascript/tooling/agent/debugger_impl.cpp +++ b/ecmascript/tooling/agent/debugger_impl.cpp @@ -225,14 +225,14 @@ void DebuggerImpl::DispatcherImpl::SetBlackboxPatterns(const DispatchRequest &re DispatchResponse DebuggerImpl::Enable([[maybe_unused]] std::unique_ptr params, UniqueDebuggerId *id) { ASSERT(id != nullptr); - *id = "0"; + *id = 0; return DispatchResponse::Ok(); } DispatchResponse DebuggerImpl::EvaluateOnCallFrame(std::unique_ptr params, std::unique_ptr *result) { - CString callFrameId = params->GetCallFrameId(); + CallFrameId callFrameId = params->GetCallFrameId(); CString expression = params->GetExpression(); return DispatchResponse::Create(backend_->EvaluateValue(callFrameId, expression, result)); } @@ -248,13 +248,8 @@ DispatchResponse DebuggerImpl::GetPossibleBreakpoints(std::unique_ptr params, CString *source) { - auto scriptFunc = [source](PtScript *script) -> bool { - *source = script->GetScriptSource(); - return true; - }; - if (!backend_->MatchScripts(scriptFunc, params->GetScriptId(), ScriptMatchType::SCRIPT_ID)) { - *source = ""; - return DispatchResponse::Fail("unknown script id: " + params->GetScriptId()); + if (!backend_->GetScriptSource(params->GetScriptId(), source)) { + return DispatchResponse::Fail("unknown script id: " + ToCString(params->GetScriptId())); } return DispatchResponse::Ok(); diff --git a/ecmascript/tooling/agent/debugger_impl.h b/ecmascript/tooling/agent/debugger_impl.h index 9aa5f1c6ea..bfecf02f9a 100644 --- a/ecmascript/tooling/agent/debugger_impl.h +++ b/ecmascript/tooling/agent/debugger_impl.h @@ -22,8 +22,6 @@ #include "ecmascript/tooling/dispatcher.h" namespace panda::tooling::ecmascript { -using panda::ecmascript::CString; - class DebuggerImpl final { public: explicit DebuggerImpl(std::unique_ptr backend) : backend_(std::move(backend)) {} @@ -72,7 +70,7 @@ public: NO_MOVE_SEMANTIC(DispatcherImpl); using AgentHandler = void (DebuggerImpl::DispatcherImpl::*)(const DispatchRequest &request); - CMap dispatcherTable_ {}; + CUnorderedMap dispatcherTable_ {}; std::unique_ptr debugger_ {}; }; diff --git a/ecmascript/tooling/agent/js_backend.cpp b/ecmascript/tooling/agent/js_backend.cpp index 5f36d59ddc..dff967617f 100644 --- a/ecmascript/tooling/agent/js_backend.cpp +++ b/ecmascript/tooling/agent/js_backend.cpp @@ -13,8 +13,9 @@ * limitations under the License. */ -#include "js_backend.h" -#include +#include "ecmascript/tooling/agent/js_backend.h" + +#include "ecmascript/jspandafile/js_pandafile.h" #include "ecmascript/tooling/base/pt_events.h" #include "ecmascript/tooling/front_end.h" #include "ecmascript/tooling/protocol_handler.h" @@ -25,7 +26,7 @@ using ObjectType = RemoteObject::TypeName; using ObjectSubType = RemoteObject::SubTypeName; using ObjectClassName = RemoteObject::ClassName; -const std::string DATA_APP_PATH = "/data/"; +const CString DATA_APP_PATH = "/data/"; JSBackend::JSBackend(FrontEnd *frontend) : frontend_(frontend) { @@ -66,7 +67,7 @@ void JSBackend::NotifyPaused(std::optional location, PauseReason rea extractor = GetExtractor(detail.url_); return true; }; - auto callbackFunc = [&detail](size_t line, size_t column) -> bool { + auto callbackFunc = [&detail](int32_t line, int32_t column) -> bool { detail.line_ = line; detail.column_ = column; return true; @@ -109,7 +110,7 @@ void JSBackend::NotifyAllScriptParsed() } } -bool JSBackend::NotifyScriptParsed(int32_t scriptId, const CString &fileName) +bool JSBackend::NotifyScriptParsed(ScriptId scriptId, const CString &fileName) { auto scriptFunc = []([[maybe_unused]] PtScript *script) -> bool { return true; @@ -118,26 +119,34 @@ bool JSBackend::NotifyScriptParsed(int32_t scriptId, const CString &fileName) LOG(WARNING, DEBUGGER) << "NotifyScriptParsed: already loaded: " << fileName; return false; } - const panda_file::File *pfs = DebuggerApi::FindPandaFile(fileName); - if (pfs == nullptr) { + const JSPandaFile *jsPandaFile = nullptr; + ::panda::ecmascript::JSPandaFileManager::GetInstance()->EnumerateJSPandaFiles([&jsPandaFile, &fileName]( + const panda::ecmascript::JSPandaFile *pf) { + if (pf->GetJSPandaFileDesc() == fileName) { + jsPandaFile = pf; + return false; + } + return true; + }); + if (jsPandaFile == nullptr) { LOG(WARNING, DEBUGGER) << "NotifyScriptParsed: unknown file: " << fileName; return false; } - CString url; - CString source; - JSPtExtractor *extractor = GenerateExtractor(pfs); + JSPtExtractor *extractor = GenerateExtractor(jsPandaFile); if (extractor == nullptr) { LOG(ERROR, DEBUGGER) << "NotifyScriptParsed: Unsupported file: " << fileName; return false; } + CString url; + CString source; const uint32_t MIN_SOURCE_CODE_LENGTH = 5; // maybe return 'ANDA' when source code is empty for (const auto &method : extractor->GetMethodIdList()) { - source = CString(extractor->GetSourceCode(method)); + source = extractor->GetSourceCode(method); // only main function has source code if (source.size() >= MIN_SOURCE_CODE_LENGTH) { - url = CString(extractor->GetSourceFile(method)); + url = extractor->GetSourceFile(method); break; } } @@ -164,8 +173,8 @@ bool JSBackend::StepComplete(const PtLocation &location) extractor = GetExtractor(script->GetUrl()); return true; }; - auto callbackFunc = [](size_t line, [[maybe_unused]] size_t column) -> bool { - return line == static_cast(SPECIAL_LINE_MARK); + auto callbackFunc = [](int32_t line, [[maybe_unused]] int32_t column) -> bool { + return line == SPECIAL_LINE_MARK; }; if (MatchScripts(scriptFunc, location.GetPandaFile(), ScriptMatchType::FILE_NAME) && extractor != nullptr && extractor->MatchWithOffset(callbackFunc, location.GetMethodId(), location.GetBytecodeOffset())) { @@ -186,17 +195,14 @@ bool JSBackend::StepComplete(const PtLocation &location) std::optional JSBackend::GetPossibleBreakpoints(Location *start, [[maybe_unused]] Location *end, CVector> *locations) { - JSPtExtractor *extractor = nullptr; - auto scriptFunc = [this, &extractor](PtScript *script) -> bool { - extractor = GetExtractor(script->GetUrl()); - return true; - }; - if (!MatchScripts(scriptFunc, start->GetScriptId(), ScriptMatchType::SCRIPT_ID) || extractor == nullptr) { + auto iter = scripts_.find(start->GetScriptId()); + if (iter == scripts_.end()) { return Error(Error::Type::INVALID_BREAKPOINT, "extractor not found"); } + JSPtExtractor *extractor = GetExtractor(iter->second->GetUrl()); - size_t line = start->GetLine(); - size_t column = start->GetColumn(); + int32_t line = start->GetLine(); + int32_t column = start->GetColumn(); auto callbackFunc = []([[maybe_unused]] File::EntityId id, [[maybe_unused]] uint32_t offset) -> bool { return true; }; @@ -209,8 +215,8 @@ std::optional JSBackend::GetPossibleBreakpoints(Location *start, [[maybe_ return {}; } -std::optional JSBackend::SetBreakpointByUrl(const CString &url, size_t lineNumber, - size_t columnNumber, CString *out_id, CVector> *outLocations) +std::optional JSBackend::SetBreakpointByUrl(const CString &url, int32_t lineNumber, + int32_t columnNumber, CString *out_id, CVector> *outLocations) { JSPtExtractor *extractor = GetExtractor(url); if (extractor == nullptr) { @@ -218,7 +224,7 @@ std::optional JSBackend::SetBreakpointByUrl(const CString &url, size_t li return Error(Error::Type::METHOD_NOT_FOUND, "Extractor not found"); } - CString scriptId; + ScriptId scriptId; CString fileName; auto scriptFunc = [&scriptId, &fileName](PtScript *script) -> bool { scriptId = script->GetScriptId(); @@ -283,7 +289,7 @@ std::optional JSBackend::RemoveBreakpoint(const BreakpointDetails &metaDa return Error(Error::Type::INVALID_BREAKPOINT, "Breakpoint not found"); } - LOG(INFO, DEBUGGER) << "remove breakpoint line number:" << metaData.line_; + LOG(INFO, DEBUGGER) << "remove breakpoint32_t line number:" << metaData.line_; return ret; } @@ -304,7 +310,7 @@ std::optional JSBackend::Resume() std::optional JSBackend::StepInto() { JSMethod *method = DebuggerApi::GetMethod(ecmaVm_); - JSPtExtractor *extractor = GetExtractor(method->GetPandaFile()); + JSPtExtractor *extractor = GetExtractor(method->GetJSPandaFile()); if (extractor == nullptr) { LOG(ERROR, DEBUGGER) << "StepInto: extractor is null"; return Error(Error::Type::METHOD_NOT_FOUND, "Extractor not found"); @@ -319,7 +325,7 @@ std::optional JSBackend::StepInto() std::optional JSBackend::StepOver() { JSMethod *method = DebuggerApi::GetMethod(ecmaVm_); - JSPtExtractor *extractor = GetExtractor(method->GetPandaFile()); + JSPtExtractor *extractor = GetExtractor(method->GetJSPandaFile()); if (extractor == nullptr) { LOG(ERROR, DEBUGGER) << "StepOver: extractor is null"; return Error(Error::Type::METHOD_NOT_FOUND, "Extractor not found"); @@ -334,7 +340,7 @@ std::optional JSBackend::StepOver() std::optional JSBackend::StepOut() { JSMethod *method = DebuggerApi::GetMethod(ecmaVm_); - JSPtExtractor *extractor = GetExtractor(method->GetPandaFile()); + JSPtExtractor *extractor = GetExtractor(method->GetJSPandaFile()); if (extractor == nullptr) { LOG(ERROR, DEBUGGER) << "StepOut: extractor is null"; return Error(Error::Type::METHOD_NOT_FOUND, "Extractor not found"); @@ -346,7 +352,7 @@ std::optional JSBackend::StepOut() return {}; } -std::optional JSBackend::EvaluateValue(const CString &callFrameId, const CString &expression, +std::optional JSBackend::EvaluateValue(CallFrameId callFrameId, const CString &expression, std::unique_ptr *result) { JSMethod *method = DebuggerApi::GetMethod(ecmaVm_); @@ -356,7 +362,7 @@ std::optional JSBackend::EvaluateValue(const CString &callFrameId, const Exception::EvalError(ecmaVm_, StringRef::NewFromUtf8(ecmaVm_, "Runtime internal error"))); return Error(Error::Type::METHOD_NOT_FOUND, "Native Frame not support"); } - JSPtExtractor *extractor = GetExtractor(method->GetPandaFile()); + JSPtExtractor *extractor = GetExtractor(method->GetJSPandaFile()); if (extractor == nullptr) { LOG(ERROR, DEBUGGER) << "EvaluateValue: extractor is null"; *result = RemoteObject::FromTagged(ecmaVm_, @@ -371,7 +377,7 @@ std::optional JSBackend::EvaluateValue(const CString &callFrameId, const varValue = Trim(expression.substr(indexEqual + 1, expression.length())); } - if (!varValue.empty() && callFrameId != "0") { + if (!varValue.empty() && callFrameId != 0) { *result = RemoteObject::FromTagged(ecmaVm_, Exception::EvalError(ecmaVm_, StringRef::NewFromUtf8(ecmaVm_, "Only allow set value in current frame"))); return Error(Error::Type::METHOD_NOT_FOUND, "Unsupported parent frame set value"); @@ -412,20 +418,21 @@ CString JSBackend::Trim(const CString &str) return ret; } -JSPtExtractor *JSBackend::GenerateExtractor(const panda_file::File *file) +JSPtExtractor *JSBackend::GenerateExtractor(const JSPandaFile *jsPandaFile) { - if (file->GetFilename().substr(0, DATA_APP_PATH.length()) != DATA_APP_PATH) { + const CString &fileName = jsPandaFile->GetJSPandaFileDesc(); + if (fileName.substr(0, DATA_APP_PATH.length()) != DATA_APP_PATH) { return nullptr; } - auto extractor = std::make_unique(file); + auto extractor = std::make_unique(jsPandaFile); JSPtExtractor *res = extractor.get(); - extractors_[file->GetFilename()] = std::move(extractor); + extractors_[fileName] = std::move(extractor); return res; } -JSPtExtractor *JSBackend::GetExtractor(const panda_file::File *file) +JSPtExtractor *JSBackend::GetExtractor(const JSPandaFile *jsPandaFile) { - const std::string fileName = file->GetFilename(); + const CString &fileName = jsPandaFile->GetJSPandaFileDesc(); if (extractors_.find(fileName) == extractors_.end()) { return nullptr; } @@ -449,7 +456,7 @@ JSPtExtractor *JSBackend::GetExtractor(const CString &url) bool JSBackend::GenerateCallFrames(CVector> *callFrames) { - int32_t callFrameId = 0; + CallFrameId callFrameId = 0; auto walkerFunc = [this, &callFrameId, &callFrames](const InterpretedFrameHandler *frameHandler) -> StackState { JSMethod *method = DebuggerApi::GetMethod(frameHandler); if (method->IsNative()) { @@ -471,11 +478,10 @@ bool JSBackend::GenerateCallFrames(CVector> *callFram } bool JSBackend::GenerateCallFrame(CallFrame *callFrame, - const InterpretedFrameHandler *frameHandler, int32_t callFrameId) + const InterpretedFrameHandler *frameHandler, CallFrameId callFrameId) { JSMethod *method = DebuggerApi::GetMethod(frameHandler); - auto *pf = method->GetPandaFile(); - JSPtExtractor *extractor = GetExtractor(pf); + JSPtExtractor *extractor = GetExtractor(method->GetJSPandaFile()); if (extractor == nullptr) { LOG(ERROR, DEBUGGER) << "GenerateCallFrame: extractor is null"; return false; @@ -492,7 +498,7 @@ bool JSBackend::GenerateCallFrame(CallFrame *callFrame, LOG(ERROR, DEBUGGER) << "GenerateCallFrame: Unknown url: " << url; return false; } - auto callbackFunc = [&location](size_t line, size_t column) -> bool { + auto callbackFunc = [&location](int32_t line, int32_t column) -> bool { location->SetLine(line); location->SetColumn(column); return true; @@ -513,7 +519,7 @@ bool JSBackend::GenerateCallFrame(CallFrame *callFrame, // functionName CString functionName = DebuggerApi::ParseFunctionName(method); - callFrame->SetCallFrameId(DebuggerApi::ToCString(callFrameId)) + callFrame->SetCallFrameId(callFrameId) .SetFunctionName(functionName) .SetLocation(std::move(location)) .SetUrl(url) @@ -535,7 +541,7 @@ std::unique_ptr JSBackend::GetLocalScopeChain(const InterpretedFrameHandl .SetDescription(RemoteObject::ObjectDescription); propertiesPair_[curObjectId_++] = Global(ecmaVm_, localObject); - JSPtExtractor *extractor = GetExtractor(DebuggerApi::GetMethod(frameHandler)->GetPandaFile()); + JSPtExtractor *extractor = GetExtractor(DebuggerApi::GetMethod(frameHandler)->GetJSPandaFile()); if (extractor == nullptr) { LOG(ERROR, DEBUGGER) << "GetScopeChain: extractor is null"; return localScope; @@ -603,6 +609,18 @@ std::unique_ptr JSBackend::GetGlobalScopeChain() return globalScope; } +bool JSBackend::GetScriptSource(ScriptId scriptId, CString *source) +{ + auto iter = scripts_.find(scriptId); + if (iter == scripts_.end()) { + *source = ""; + return false; + } + + *source = iter->second->GetScriptSource(); + return true; +} + void JSBackend::SetPauseOnException(bool flag) { pauseOnException_ = flag; @@ -722,7 +740,7 @@ void JSBackend::GetProtoOrProtoType(const Local &value, bool isOwn, outPropertyDesc->emplace_back(std::move(debuggerProperty)); } -void JSBackend::GetProperties(uint32_t objectId, bool isOwn, bool isAccessorOnly, +void JSBackend::GetProperties(RemoteObjectId objectId, bool isOwn, bool isAccessorOnly, CVector> *outPropertyDesc) { auto iter = propertiesPair_.find(objectId); @@ -773,7 +791,8 @@ void JSBackend::GetProperties(uint32_t objectId, bool isOwn, bool isAccessorOnly GetProtoOrProtoType(value, isOwn, isAccessorOnly, outPropertyDesc); } -void JSBackend::CallFunctionOn([[maybe_unused]] const CString &functionDeclaration, [[maybe_unused]] uint32_t objectId, +void JSBackend::CallFunctionOn([[maybe_unused]] const CString &functionDeclaration, + [[maybe_unused]] RemoteObjectId objectId, [[maybe_unused]] const CVector> *arguments, [[maybe_unused]] bool isSilent, [[maybe_unused]] bool returnByValue, [[maybe_unused]] bool generatePreview, [[maybe_unused]] bool userGesture, [[maybe_unused]] bool awaitPromise, [[maybe_unused]] ExecutionContextId executionContextId, diff --git a/ecmascript/tooling/agent/js_backend.h b/ecmascript/tooling/agent/js_backend.h index 8dc5e6c8f5..60b0389709 100644 --- a/ecmascript/tooling/agent/js_backend.h +++ b/ecmascript/tooling/agent/js_backend.h @@ -23,8 +23,6 @@ #include "libpandabase/macros.h" namespace panda::tooling::ecmascript { -using panda::ecmascript::CString; - class JSBackend { public: explicit JSBackend(FrontEnd *frontend); @@ -36,7 +34,7 @@ public: void NotifyPaused(std::optional location, PauseReason reason); void NotifyResume(); void NotifyAllScriptParsed(); - bool NotifyScriptParsed(int32_t scriptId, const CString &fileName); + bool NotifyScriptParsed(ScriptId scriptId, const CString &fileName); bool StepComplete(const PtLocation &location); std::optional GetPossibleBreakpoints(Location *start, Location *end, @@ -46,7 +44,7 @@ public: return debugger_; } - std::optional SetBreakpointByUrl(const CString &url, size_t lineNumber, size_t columnNumber, + std::optional SetBreakpointByUrl(const CString &url, int32_t lineNumber, int32_t columnNumber, CString *outId, CVector> *outLocations); std::optional RemoveBreakpoint(const BreakpointDetails &metaData); @@ -56,7 +54,7 @@ public: std::optional StepInto(); std::optional StepOver(); std::optional StepOut(); - std::optional EvaluateValue(const CString &callFrameId, const CString &expression, + std::optional EvaluateValue(CallFrameId callFrameId, const CString &expression, std::unique_ptr *result); /** @@ -70,10 +68,6 @@ public: for (const auto &script : scripts_) { CString value; switch (type) { - case ScriptMatchType::SCRIPT_ID: { - value = script.second->GetScriptId(); - break; - } case ScriptMatchType::URL: { value = script.second->GetUrl(); break; @@ -97,10 +91,12 @@ public: return false; } + bool GetScriptSource(ScriptId scriptId, CString *source); + void SetPauseOnException(bool flag); - void GetProperties(uint32_t objectId, bool isOwn, bool isAccessorOnly, + void GetProperties(RemoteObjectId objectId, bool isOwn, bool isAccessorOnly, CVector> *outPropertyDesc); - void CallFunctionOn(const CString &functionDeclaration, uint32_t objectId, + void CallFunctionOn(const CString &functionDeclaration, RemoteObjectId objectId, const CVector> *arguments, bool isSilent, bool returnByValue, bool generatePreview, bool userGesture, bool awaitPromise, ExecutionContextId executionContextId, const CString &objectGroup, bool throwOnSideEffect, std::unique_ptr *outRemoteObject); @@ -115,16 +111,17 @@ private: NO_MOVE_SEMANTIC(JSBackend); NO_COPY_SEMANTIC(JSBackend); CString Trim(const CString &str); - JSPtExtractor *GenerateExtractor(const panda_file::File *file); - JSPtExtractor *GetExtractor(const panda_file::File *file); + JSPtExtractor *GenerateExtractor(const JSPandaFile *jsPandaFile); + JSPtExtractor *GetExtractor(const JSPandaFile *jsPandaFile); JSPtExtractor *GetExtractor(const CString &url); - bool GenerateCallFrame(CallFrame *callFrame, const InterpretedFrameHandler *frameHandler, int32_t frameId); + bool GenerateCallFrame(CallFrame *callFrame, const InterpretedFrameHandler *frameHandler, CallFrameId frameId); std::unique_ptr GetLocalScopeChain(const InterpretedFrameHandler *frameHandler, std::unique_ptr *thisObj); std::unique_ptr GetGlobalScopeChain(); std::optional ConvertToLocal(Local &taggedValue, std::unique_ptr *result, const CString &varValue); - std::optional SetVregValue(int32_t regIndex, std::unique_ptr *result, const CString &varValue); + std::optional SetVregValue(int32_t regIndex, std::unique_ptr *result, + const CString &varValue); std::optional SetLexicalValue(int32_t level, std::unique_ptr *result, const CString &varValue, uint32_t slot); std::optional GetVregValue(int32_t regIndex, std::unique_ptr *result); @@ -137,10 +134,10 @@ private: const EcmaVM *ecmaVm_ {nullptr}; std::unique_ptr hooks_ {nullptr}; JSDebugger *debugger_ {nullptr}; - CMap> extractors_ {}; - CMap> scripts_ {}; - CMap> propertiesPair_ {}; - uint32_t curObjectId_ {0}; + CUnorderedMap> extractors_ {}; + CUnorderedMap> scripts_ {}; + CUnorderedMap> propertiesPair_ {}; + RemoteObjectId curObjectId_ {0}; bool pauseOnException_ {false}; bool pauseOnNextByteCode_ {false}; std::unique_ptr singleStepper_ {nullptr}; diff --git a/ecmascript/tooling/agent/js_pt_hooks.cpp b/ecmascript/tooling/agent/js_pt_hooks.cpp index 197b1c9723..dfd47e7712 100644 --- a/ecmascript/tooling/agent/js_pt_hooks.cpp +++ b/ecmascript/tooling/agent/js_pt_hooks.cpp @@ -74,8 +74,8 @@ void JSPtHooks::LoadModule(std::string_view pandaFileName) [[maybe_unused]] LocalScope scope(backend_->ecmaVm_); - static int32_t scriptId = 0; - if (backend_->NotifyScriptParsed(scriptId++, DebuggerApi::ConvertToString(pandaFileName.data()))) { + static uint32_t scriptId = 0; + if (backend_->NotifyScriptParsed(scriptId++, pandaFileName.data())) { firstTime_ = true; } } diff --git a/ecmascript/tooling/agent/runtime_impl.cpp b/ecmascript/tooling/agent/runtime_impl.cpp index d0108adc5c..e983986b33 100644 --- a/ecmascript/tooling/agent/runtime_impl.cpp +++ b/ecmascript/tooling/agent/runtime_impl.cpp @@ -116,7 +116,7 @@ DispatchResponse RuntimeImpl::GetProperties(std::unique_ptr [[maybe_unused]] std::optional>> *outPrivateProps, [[maybe_unused]] std::optional> *outExceptionDetails) { - backend_->GetProperties(DebuggerApi::CStringToULL(params->GetObjectId()), + backend_->GetProperties(params->GetObjectId(), params->GetOwnProperties(), params->GetAccessPropertiesOnly(), outPropertyDesc); @@ -128,7 +128,7 @@ DispatchResponse RuntimeImpl::CallFunctionOn(std::unique_ptr> *outExceptionDetails) { backend_->CallFunctionOn(params->GetFunctionDeclaration(), - DebuggerApi::CStringToULL(params->GetObjectId()), + params->GetObjectId(), params->GetArguments(), params->GetSilent(), params->GetReturnByValue(), diff --git a/ecmascript/tooling/agent/runtime_impl.h b/ecmascript/tooling/agent/runtime_impl.h index a78e71d9ed..b1e69f7104 100644 --- a/ecmascript/tooling/agent/runtime_impl.h +++ b/ecmascript/tooling/agent/runtime_impl.h @@ -22,8 +22,6 @@ #include "ecmascript/tooling/dispatcher.h" namespace panda::tooling::ecmascript { -using panda::ecmascript::CString; - class RuntimeImpl final { public: explicit RuntimeImpl(JSBackend *backend) : backend_(backend) {} @@ -55,7 +53,7 @@ public: private: using AgentHandler = void (RuntimeImpl::DispatcherImpl::*)(const DispatchRequest &request); - CMap dispatcherTable_ {}; + CUnorderedMap dispatcherTable_ {}; std::unique_ptr runtime_ {}; NO_COPY_SEMANTIC(DispatcherImpl); diff --git a/ecmascript/tooling/base/pt_events.cpp b/ecmascript/tooling/base/pt_events.cpp index 6d1e1fd4aa..fa907756f5 100644 --- a/ecmascript/tooling/base/pt_events.cpp +++ b/ecmascript/tooling/base/pt_events.cpp @@ -29,7 +29,7 @@ std::unique_ptr BreakpointResolved::Create(const EcmaVM *ecm Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "breakpointId"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - breakpointResolved->breakpointId_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + breakpointResolved->breakpointId_ = DebuggerApi::ToCString(result); } else { error += "'breakpointId' should a String;"; } @@ -113,7 +113,7 @@ std::unique_ptr Paused::Create(const EcmaVM *ecmaVm, const Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "reason"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - paused->reason_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + paused->reason_ = DebuggerApi::ToCString(result); } else { error += "'reason' should a String;"; } @@ -141,7 +141,7 @@ std::unique_ptr Paused::Create(const EcmaVM *ecmaVm, const LocalToString())); + breakPoints.emplace_back(DebuggerApi::ToCString(result)); } paused->hitBreakpoints_ = std::move(breakPoints); } else { @@ -224,7 +224,7 @@ std::unique_ptr ScriptFailedToParse::Create(const EcmaVM *e Local result = Local(params)->Get(ecmaVm, StringRef::NewFromUtf8(ecmaVm, "scriptId")); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - scriptEvent->scriptId_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + scriptEvent->scriptId_ = DebuggerApi::StringToInt(result); } else { error += "'scriptId' should a String;"; } @@ -234,7 +234,7 @@ std::unique_ptr ScriptFailedToParse::Create(const EcmaVM *e result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "url"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - scriptEvent->url_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + scriptEvent->url_ = DebuggerApi::ToCString(result); } else { error += "'url' should a String;"; } @@ -295,7 +295,7 @@ std::unique_ptr ScriptFailedToParse::Create(const EcmaVM *e result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "hash"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - scriptEvent->hash_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + scriptEvent->hash_ = DebuggerApi::ToCString(result); } else { error += "'hash' should a String;"; } @@ -314,7 +314,7 @@ std::unique_ptr ScriptFailedToParse::Create(const EcmaVM *e result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "sourceMapURL"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - scriptEvent->sourceMapUrl_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + scriptEvent->sourceMapUrl_ = DebuggerApi::ToCString(result); } else { error += "'sourceMapURL' should a String;"; } @@ -354,7 +354,7 @@ std::unique_ptr ScriptFailedToParse::Create(const EcmaVM *e result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptLanguage"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - scriptEvent->scriptLanguage_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + scriptEvent->scriptLanguage_ = DebuggerApi::ToCString(result); } else { error += "'scriptLanguage' should a String;"; } @@ -362,7 +362,7 @@ std::unique_ptr ScriptFailedToParse::Create(const EcmaVM *e result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "embedderName"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - scriptEvent->embedderName_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + scriptEvent->embedderName_ = DebuggerApi::ToCString(result); } else { error += "'embedderName' should a String;"; } @@ -381,7 +381,7 @@ Local ScriptFailedToParse::ToObject(const EcmaVM *ecmaVm) params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId")), - Local(StringRef::NewFromUtf8(ecmaVm, scriptId_.c_str()))); + Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(scriptId_).c_str()))); params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "url")), Local(StringRef::NewFromUtf8(ecmaVm, url_.c_str()))); @@ -477,7 +477,7 @@ std::unique_ptr ScriptParsed::Create(const EcmaVM *ecmaVm, const L Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - scriptEvent->scriptId_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + scriptEvent->scriptId_ = DebuggerApi::StringToInt(result); } else { error += "'scriptId' should a String;"; } @@ -487,7 +487,7 @@ std::unique_ptr ScriptParsed::Create(const EcmaVM *ecmaVm, const L result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "url"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - scriptEvent->url_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + scriptEvent->url_ = DebuggerApi::ToCString(result); } else { error += "'url' should a String;"; } @@ -548,7 +548,7 @@ std::unique_ptr ScriptParsed::Create(const EcmaVM *ecmaVm, const L result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "hash"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - scriptEvent->hash_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + scriptEvent->hash_ = DebuggerApi::ToCString(result); } else { error += "'hash' should a String;"; } @@ -575,7 +575,7 @@ std::unique_ptr ScriptParsed::Create(const EcmaVM *ecmaVm, const L result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "sourceMapURL"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - scriptEvent->sourceMapUrl_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + scriptEvent->sourceMapUrl_ = DebuggerApi::ToCString(result); } else { error += "'sourceMapURL' should a String;"; } @@ -615,7 +615,7 @@ std::unique_ptr ScriptParsed::Create(const EcmaVM *ecmaVm, const L result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptLanguage"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - scriptEvent->scriptLanguage_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + scriptEvent->scriptLanguage_ = DebuggerApi::ToCString(result); } else { error += "'scriptLanguage' should a String;"; } @@ -623,7 +623,7 @@ std::unique_ptr ScriptParsed::Create(const EcmaVM *ecmaVm, const L result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "embedderName"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - scriptEvent->embedderName_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + scriptEvent->embedderName_ = DebuggerApi::ToCString(result); } else { error += "'embedderName' should a String;"; } @@ -642,7 +642,7 @@ Local ScriptParsed::ToObject(const EcmaVM *ecmaVm) params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId")), - Local(StringRef::NewFromUtf8(ecmaVm, scriptId_.c_str()))); + Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(scriptId_).c_str()))); params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "url")), Local(StringRef::NewFromUtf8(ecmaVm, url_.c_str()))); diff --git a/ecmascript/tooling/base/pt_events.h b/ecmascript/tooling/base/pt_events.h index b30c03888f..a8102fcfca 100644 --- a/ecmascript/tooling/base/pt_events.h +++ b/ecmascript/tooling/base/pt_events.h @@ -23,7 +23,6 @@ #include "ecmascript/tooling/base/pt_script.h" #include "ecmascript/tooling/base/pt_types.h" #include "ecmascript/tooling/dispatcher.h" -#include "ecmascript/mem/c_containers.h" namespace panda::tooling::ecmascript { using panda::ecmascript::EcmaVM; @@ -99,13 +98,13 @@ public: return &callFrames_; } - Paused &SetCallFrames(CVector> call_frames) + Paused &SetCallFrames(CVector> callFrames) { - callFrames_ = std::move(call_frames); + callFrames_ = std::move(callFrames); return *this; } - CString GetReason() const + const CString &GetReason() const { return reason_; } @@ -238,13 +237,13 @@ public: return scriptId_; } - ScriptFailedToParse &SetScriptId(const ScriptId &scriptId) + ScriptFailedToParse &SetScriptId(ScriptId scriptId) { scriptId_ = scriptId; return *this; } - CString GetUrl() const + const CString &GetUrl() const { return url_; } @@ -310,7 +309,7 @@ public: return *this; } - CString GetHash() const + const CString &GetHash() const { return hash_; } @@ -337,9 +336,9 @@ public: return execContextAuxData_.has_value(); } - CString GetSourceMapURL() const + const CString &GetSourceMapURL() const { - return sourceMapUrl_.value_or(""); + return sourceMapUrl_.value(); } ScriptFailedToParse &SetSourceMapURL(const CString &sourceMapUrl) @@ -417,9 +416,9 @@ public: return codeOffset_.has_value(); } - CString GetScriptLanguage() const + const CString &GetScriptLanguage() const { - return scriptLanguage_.value_or(""); + return scriptLanguage_.value(); } ScriptFailedToParse &SetScriptLanguage(const CString &scriptLanguage) @@ -433,9 +432,9 @@ public: return scriptLanguage_.has_value(); } - CString GetEmbedderName() const + const CString &GetEmbedderName() const { - return embedderName_.value_or(""); + return embedderName_.value(); } ScriptFailedToParse &SetEmbedderName(const CString &embedderName) @@ -489,13 +488,13 @@ public: return scriptId_; } - ScriptParsed &SetScriptId(const ScriptId &scriptId) + ScriptParsed &SetScriptId(ScriptId scriptId) { scriptId_ = scriptId; return *this; } - CString GetUrl() const + const CString &GetUrl() const { return url_; } @@ -561,7 +560,7 @@ public: return *this; } - CString GetHash() const + const CString &GetHash() const { return hash_; } @@ -604,9 +603,9 @@ public: return execContextAuxData_.has_value(); } - CString GetSourceMapURL() const + const CString &GetSourceMapURL() const { - return sourceMapUrl_.value_or(""); + return sourceMapUrl_.value(); } ScriptParsed &SetSourceMapURL(const CString &sourceMapUrl) @@ -684,9 +683,9 @@ public: return codeOffset_.has_value(); } - CString GetScriptLanguage() const + const CString &GetScriptLanguage() const { - return scriptLanguage_.value_or(""); + return scriptLanguage_.value(); } ScriptParsed &SetScriptLanguage(const CString &scriptLanguage) @@ -700,9 +699,9 @@ public: return scriptLanguage_.has_value(); } - CString GetEmbedderName() const + const CString &GetEmbedderName() const { - return embedderName_.value_or(""); + return embedderName_.value(); } ScriptParsed &SetEmbedderName(const CString &embedderName) diff --git a/ecmascript/tooling/base/pt_params.cpp b/ecmascript/tooling/base/pt_params.cpp index dea50b9673..42577fbd67 100644 --- a/ecmascript/tooling/base/pt_params.cpp +++ b/ecmascript/tooling/base/pt_params.cpp @@ -58,7 +58,7 @@ std::unique_ptr EvaluateOnCallFrameParams::Create(con Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "callFrameId"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - paramsObject->callFrameId_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + paramsObject->callFrameId_ = DebuggerApi::StringToInt(result); } else { error += "'callframeid' should be a String;"; } @@ -69,7 +69,7 @@ std::unique_ptr EvaluateOnCallFrameParams::Create(con result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "expression"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - paramsObject->expression_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + paramsObject->expression_ = DebuggerApi::ToCString(result); } else { error += "'expression' should be a String;"; } @@ -79,7 +79,7 @@ std::unique_ptr EvaluateOnCallFrameParams::Create(con result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "objectGroup"))); if (!result.IsEmpty() && result->IsString()) { - paramsObject->objectGroup_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + paramsObject->objectGroup_ = DebuggerApi::ToCString(result); } result = Local(params)->Get(ecmaVm, @@ -189,7 +189,7 @@ std::unique_ptr GetScriptSourceParams::Create(const EcmaV Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - paramsObject->scriptId_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + paramsObject->scriptId_ = DebuggerApi::StringToInt(result); } else { error += "'scriptId' should be a String;"; } @@ -219,7 +219,7 @@ std::unique_ptr RemoveBreakpointParams::Create(const Ecm Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "breakpointId"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - paramsObject->breakpointId_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + paramsObject->breakpointId_ = DebuggerApi::ToCString(result); } else { error += "'breakpointId' should be a String;"; } @@ -314,7 +314,7 @@ std::unique_ptr SetBlackboxPatternsParams::Create(con Local value = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); if (value->IsString()) { paramsObject->patterns_.emplace_back( - DebuggerApi::ConvertToString(StringRef::Cast(*value)->ToString())); + DebuggerApi::ToCString(value)); } else { error += "'patterns' items should be a String;"; } @@ -358,7 +358,7 @@ std::unique_ptr SetBreakpointByUrlParams::Create(const result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "url"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - paramsObject->url_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + paramsObject->url_ = DebuggerApi::ToCString(result); } else { error += "'url' should be a String;"; } @@ -366,7 +366,7 @@ std::unique_ptr SetBreakpointByUrlParams::Create(const result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "urlRegex"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - paramsObject->urlRegex_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + paramsObject->urlRegex_ = DebuggerApi::ToCString(result); } else { error += "'urlRegex' should be a String;"; } @@ -374,7 +374,7 @@ std::unique_ptr SetBreakpointByUrlParams::Create(const result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptHash"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - paramsObject->scriptHash_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + paramsObject->scriptHash_ = DebuggerApi::ToCString(result); } else { error += "'scriptHash' should be a String;"; } @@ -390,7 +390,7 @@ std::unique_ptr SetBreakpointByUrlParams::Create(const result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "condition"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - paramsObject->condition_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + paramsObject->condition_ = DebuggerApi::ToCString(result); } else { error += "'condition' should be a String;"; } @@ -418,7 +418,7 @@ std::unique_ptr SetPauseOnExceptionsParams::Create(c Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "state"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - if (!paramsObject->StoreState(DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()))) { + if (!paramsObject->StoreState(DebuggerApi::ToCString(result))) { error += "'state' is invalid;"; } } else { @@ -543,7 +543,7 @@ std::unique_ptr GetPropertiesParams::Create(const EcmaVM *e Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "objectId"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - paramsObject->objectId_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + paramsObject->objectId_ = DebuggerApi::StringToInt(result); } else { error += "'objectId' should be a String;"; } @@ -600,7 +600,7 @@ std::unique_ptr CallFunctionOnParams::Create(const EcmaVM Local(StringRef::NewFromUtf8(ecmaVm, "functionDeclaration"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - paramsObject->functionDeclaration_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + paramsObject->functionDeclaration_ = DebuggerApi::ToCString(result); } else { error += "'functionDeclaration' should be a String;"; } @@ -611,7 +611,7 @@ std::unique_ptr CallFunctionOnParams::Create(const EcmaVM result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "objectId"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - paramsObject->objectId_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + paramsObject->objectId_ = DebuggerApi::StringToInt(result); } else { error += "'objectId' should be a String;"; } @@ -701,7 +701,7 @@ std::unique_ptr CallFunctionOnParams::Create(const EcmaVM result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "objectGroup"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - paramsObject->objectGroup_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + paramsObject->objectGroup_ = DebuggerApi::ToCString(result); } else { error += "'objectGroup' should be a String;"; } diff --git a/ecmascript/tooling/base/pt_params.h b/ecmascript/tooling/base/pt_params.h index ac71cd6e46..8aefd27d95 100644 --- a/ecmascript/tooling/base/pt_params.h +++ b/ecmascript/tooling/base/pt_params.h @@ -70,12 +70,12 @@ public: return Local(); } - CString GetCallFrameId() + CallFrameId GetCallFrameId() { return callFrameId_; } - CString GetExpression() + const CString &GetExpression() { return expression_; } @@ -84,7 +84,7 @@ private: NO_COPY_SEMANTIC(EvaluateOnCallFrameParams); NO_MOVE_SEMANTIC(EvaluateOnCallFrameParams); - CString callFrameId_ {}; + CallFrameId callFrameId_ {}; CString expression_ {}; std::optional objectGroup_ {}; std::optional includeCommandLineApi_ {}; @@ -277,9 +277,9 @@ public: return line_; } - CString GetUrl() const + const CString &GetUrl() const { - return url_.value_or(""); + return url_.value(); } bool HasUrl() const @@ -287,9 +287,9 @@ public: return url_.has_value(); } - CString GetUrlRegex() const + const CString &GetUrlRegex() const { - return urlRegex_.value_or(""); + return urlRegex_.value(); } bool HasUrlRegex() const @@ -297,9 +297,9 @@ public: return urlRegex_.has_value(); } - CString GetScriptHash() const + const CString &GetScriptHash() const { - return scriptHash_.value_or(""); + return scriptHash_.value(); } bool HasScriptHash() const @@ -317,9 +317,9 @@ public: return column_.has_value(); } - CString GetCondition() const + const CString &GetCondition() const { - return condition_.value_or(""); + return condition_.value(); } bool HasCondition() const @@ -331,11 +331,11 @@ private: NO_COPY_SEMANTIC(SetBreakpointByUrlParams); NO_MOVE_SEMANTIC(SetBreakpointByUrlParams); - size_t line_ {0}; + int32_t line_ {0}; std::optional url_ {}; std::optional urlRegex_ {}; std::optional scriptHash_ {}; - std::optional column_ {0}; + std::optional column_ {0}; std::optional condition_ {}; }; @@ -520,7 +520,7 @@ public: return Local(); } - CString GetFunctionDeclaration() + const CString &GetFunctionDeclaration() { return functionDeclaration_; } @@ -620,9 +620,9 @@ public: return executionContextId_.has_value(); } - CString GetObjectGroup() const + const CString &GetObjectGroup() const { - return objectGroup_.value_or(""); + return objectGroup_.value(); } bool HasObjectGroup() const diff --git a/ecmascript/tooling/base/pt_returns.cpp b/ecmascript/tooling/base/pt_returns.cpp index d812ac0a88..92a03d5282 100644 --- a/ecmascript/tooling/base/pt_returns.cpp +++ b/ecmascript/tooling/base/pt_returns.cpp @@ -22,7 +22,7 @@ Local EnableReturns::ToObject(const EcmaVM *ecmaVm) result->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "debuggerId")), - Local(StringRef::NewFromUtf8(ecmaVm, debuggerId_.c_str()))); + Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(debuggerId_).c_str()))); return result; } diff --git a/ecmascript/tooling/base/pt_returns.h b/ecmascript/tooling/base/pt_returns.h index 9a68fd087d..ee2f05743a 100644 --- a/ecmascript/tooling/base/pt_returns.h +++ b/ecmascript/tooling/base/pt_returns.h @@ -19,8 +19,6 @@ #include "ecmascript/tooling/base/pt_types.h" namespace panda::tooling::ecmascript { -using panda::ecmascript::CString; - class PtBaseReturns : public PtBaseTypes { public: PtBaseReturns() = default; @@ -38,7 +36,7 @@ private: class EnableReturns : public PtBaseReturns { public: - explicit EnableReturns(UniqueDebuggerId id) : debuggerId_(std::move(id)) {} + explicit EnableReturns(UniqueDebuggerId id) : debuggerId_(id) {} ~EnableReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) override; @@ -53,8 +51,8 @@ private: class SetBreakpointByUrlReturns : public PtBaseReturns { public: - explicit SetBreakpointByUrlReturns(CString id, CVector> locations) - : id_(std::move(id)), locations_(std::move(locations)) + explicit SetBreakpointByUrlReturns(const CString &id, CVector> locations) + : id_(id), locations_(std::move(locations)) {} ~SetBreakpointByUrlReturns() override = default; @@ -124,7 +122,8 @@ private: class RestartFrameReturns : public PtBaseReturns { public: - explicit RestartFrameReturns(CVector> callFrames) : callFrames_(std::move(callFrames)) + explicit RestartFrameReturns(CVector> callFrames) + : callFrames_(std::move(callFrames)) {} ~RestartFrameReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) override; @@ -154,8 +153,8 @@ private: class SetBreakpointReturns : public PtBaseReturns { public: - explicit SetBreakpointReturns(CString id, std::unique_ptr location) - : breakpointId_(std::move(id)), location_(std::move(location)) + explicit SetBreakpointReturns(const CString &id, std::unique_ptr location) + : breakpointId_(id), location_(std::move(location)) {} ~SetBreakpointReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) override; @@ -170,7 +169,7 @@ private: class SetInstrumentationBreakpointReturns : public PtBaseReturns { public: - explicit SetInstrumentationBreakpointReturns(CString id) : breakpointId_(std::move(id)) + explicit SetInstrumentationBreakpointReturns(const CString &id) : breakpointId_(id) {} ~SetInstrumentationBreakpointReturns() override = default; Local ToObject(const EcmaVM *ecmaVm) override; diff --git a/ecmascript/tooling/base/pt_script.cpp b/ecmascript/tooling/base/pt_script.cpp index 5389f6fdd5..e53065efc6 100644 --- a/ecmascript/tooling/base/pt_script.cpp +++ b/ecmascript/tooling/base/pt_script.cpp @@ -17,11 +17,11 @@ #include "ecmascript/tooling/interface/debugger_api.h" namespace panda::tooling::ecmascript { -PtScript::PtScript(int32_t scriptId, CString fileName, CString url, CString source) - : scriptId_(DebuggerApi::ToCString(scriptId)), - fileName_(std::move(fileName)), - url_(std::move(url)), - scriptSource_(std::move(source)) +PtScript::PtScript(ScriptId scriptId, const CString &fileName, const CString &url, const CString &source) + : scriptId_(scriptId), + fileName_(fileName), + url_(url), + scriptSource_(source) { endLine_ = std::count(scriptSource_.begin(), scriptSource_.end(), '\n'); } diff --git a/ecmascript/tooling/base/pt_script.h b/ecmascript/tooling/base/pt_script.h index a88ece95e3..bdb73e5ebf 100644 --- a/ecmascript/tooling/base/pt_script.h +++ b/ecmascript/tooling/base/pt_script.h @@ -17,13 +17,10 @@ #define ECMASCRIPT_TOOLING_BASE_PT_SCRIPT_H #include "libpandabase/macros.h" -#include "ecmascript/mem/c_string.h" +#include "ecmascript/tooling/base/pt_types.h" namespace panda::tooling::ecmascript { -using panda::ecmascript::CString; - enum class ScriptMatchType : uint8_t { - SCRIPT_ID, URL, FILE_NAME, HASH, @@ -31,20 +28,20 @@ enum class ScriptMatchType : uint8_t { class PtScript { public: - PtScript(int32_t scriptId, CString fileName, CString url, CString source); + PtScript(ScriptId scriptId, const CString &fileName, const CString &url, const CString &source); ~PtScript() = default; - CString GetScriptId() const + ScriptId GetScriptId() const { return scriptId_; } - void SetScriptId(const CString &scriptId) + void SetScriptId(ScriptId scriptId) { scriptId_ = scriptId; } - CString GetFileName() const + const CString &GetFileName() const { return fileName_; } @@ -54,7 +51,7 @@ public: fileName_ = fileName; } - CString GetUrl() const + const CString &GetUrl() const { return url_; } @@ -64,7 +61,7 @@ public: url_ = url; } - CString GetHash() const + const CString &GetHash() const { return hash_; } @@ -74,7 +71,7 @@ public: hash_ = hash; } - CString GetScriptSource() const + const CString &GetScriptSource() const { return scriptSource_; } @@ -84,7 +81,7 @@ public: scriptSource_ = scriptSource; } - CString GetSourceMapUrl() const + const CString &GetSourceMapUrl() const { return sourceMapUrl_; } @@ -108,7 +105,7 @@ private: NO_COPY_SEMANTIC(PtScript); NO_MOVE_SEMANTIC(PtScript); - CString scriptId_ {}; // start from 0, such as "0","1","2"... + ScriptId scriptId_ {}; // start from 0, such as "0","1","2"... CString fileName_ {}; // binary file name, such as xx.bin CString url_ {}; // source file name, such as xx.js CString hash_ {}; // js source file hash code diff --git a/ecmascript/tooling/base/pt_types.cpp b/ecmascript/tooling/base/pt_types.cpp index f03005a953..508fb4f0be 100644 --- a/ecmascript/tooling/base/pt_types.cpp +++ b/ecmascript/tooling/base/pt_types.cpp @@ -175,7 +175,7 @@ PrimitiveRemoteObject::PrimitiveRemoteObject(const EcmaVM *ecmaVm, const LocalSetType(ObjectType::Undefined); } else if (tagged->IsNumber()) { this->SetType(ObjectType::Number) - .SetDescription(DebuggerApi::ConvertToString(tagged->ToString(ecmaVm)->ToString())); + .SetDescription(DebuggerApi::ToCString(tagged->ToString(ecmaVm))); double val = Local(tagged)->Value(); if (!std::isfinite(val) || (val == 0 && ((bit_cast(val) & DOUBLE_SIGN_MASK) == DOUBLE_SIGN_MASK))) { this->SetUnserializableValue(this->GetDescription()); @@ -237,32 +237,32 @@ CString ObjectRemoteObject::DescriptionForObject(const EcmaVM *ecmaVm, const Loc CString ObjectRemoteObject::DescriptionForArray(const EcmaVM *ecmaVm, const Local &tagged) { - CString description = "Array(" + DebuggerApi::ToCString(tagged->Length(ecmaVm)) + ")"; + CString description = "Array(" + ToCString(tagged->Length(ecmaVm)) + ")"; return description; } CString ObjectRemoteObject::DescriptionForRegexp(const EcmaVM *ecmaVm, const Local &tagged) { - CString regexpSource = DebuggerApi::ConvertToString(tagged->GetOriginalSource(ecmaVm)->ToString()); + CString regexpSource = DebuggerApi::ToCString(tagged->GetOriginalSource(ecmaVm)); CString description = "/" + regexpSource + "/"; return description; } CString ObjectRemoteObject::DescriptionForDate(const EcmaVM *ecmaVm, const Local &tagged) { - CString description = DebuggerApi::ConvertToString(tagged->ToString(ecmaVm)->ToString()); + CString description = DebuggerApi::ToCString(tagged->ToString(ecmaVm)); return description; } CString ObjectRemoteObject::DescriptionForMap(const Local &tagged) { - CString description = ("Map(" + DebuggerApi::ToCString(tagged->GetSize()) + ")"); + CString description = ("Map(" + ToCString(tagged->GetSize()) + ")"); return description; } CString ObjectRemoteObject::DescriptionForSet(const Local &tagged) { - CString description = ("Set(" + DebuggerApi::ToCString(tagged->GetSize()) + ")"); + CString description = ("Set(" + ToCString(tagged->GetSize()) + ")"); return description; } @@ -270,20 +270,20 @@ CString ObjectRemoteObject::DescriptionForError(const EcmaVM *ecmaVm, const Loca { Local stack = StringRef::NewFromUtf8(ecmaVm, "stack"); Local result = Local(tagged)->Get(ecmaVm, stack); - return DebuggerApi::ConvertToString(result->ToString(ecmaVm)->ToString()); + return DebuggerApi::ToCString(result->ToString(ecmaVm)); } CString ObjectRemoteObject::DescriptionForArrayBuffer(const EcmaVM *ecmaVm, const Local &tagged) { int32_t len = tagged->ByteLength(ecmaVm); - CString description = ("ArrayBuffer(" + DebuggerApi::ToCString(len) + ")"); + CString description = ("ArrayBuffer(" + ToCString(len) + ")"); return description; } CString SymbolRemoteObject::DescriptionForSymbol(const EcmaVM *ecmaVm, const Local &tagged) const { CString description = - "Symbol(" + DebuggerApi::ConvertToString(Local(tagged->GetDescription(ecmaVm))->ToString()) + ")"; + "Symbol(" + DebuggerApi::ToCString(tagged->GetDescription(ecmaVm)) + ")"; return description; } @@ -296,7 +296,7 @@ CString FunctionRemoteObject::DescriptionForFunction(const EcmaVM *ecmaVm, const sourceCode = "[js code]"; } Local name = tagged->GetName(ecmaVm); - CString description = "function " + DebuggerApi::ConvertToString(name->ToString()) + "() { " + sourceCode + " }"; + CString description = "function " + DebuggerApi::ToCString(name) + "( { " + sourceCode + " }"; return description; } @@ -313,7 +313,7 @@ std::unique_ptr RemoteObject::Create(const EcmaVM *ecmaVm, const L Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "type"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - auto type = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + auto type = DebuggerApi::ToCString(result); if (ObjectType::Valid(type)) { remoteObject->type_ = type; } else { @@ -328,7 +328,7 @@ std::unique_ptr RemoteObject::Create(const EcmaVM *ecmaVm, const L result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "subtype"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - auto type = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + auto type = DebuggerApi::ToCString(result); if (ObjectSubType::Valid(type)) { remoteObject->subtype_ = type; } else { @@ -341,7 +341,7 @@ std::unique_ptr RemoteObject::Create(const EcmaVM *ecmaVm, const L result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "className"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - remoteObject->className_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + remoteObject->className_ = DebuggerApi::ToCString(result); } else { error += "'className' should be a String;"; } @@ -354,7 +354,7 @@ std::unique_ptr RemoteObject::Create(const EcmaVM *ecmaVm, const L Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "unserializableValue"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - remoteObject->unserializableValue_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + remoteObject->unserializableValue_ = DebuggerApi::ToCString(result); } else { error += "'unserializableValue' should be a String;"; } @@ -362,7 +362,7 @@ std::unique_ptr RemoteObject::Create(const EcmaVM *ecmaVm, const L result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "description"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - remoteObject->description_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + remoteObject->description_ = DebuggerApi::ToCString(result); } else { error += "'description' should be a String;"; } @@ -370,7 +370,7 @@ std::unique_ptr RemoteObject::Create(const EcmaVM *ecmaVm, const L result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "objectId"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - remoteObject->objectId_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + remoteObject->objectId_ = DebuggerApi::StringToInt(result); } else { error += "'objectId' should be a String;"; } @@ -416,7 +416,7 @@ Local RemoteObject::ToObject(const EcmaVM *ecmaVm) if (objectId_) { params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "objectId")), - Local(StringRef::NewFromUtf8(ecmaVm, objectId_->c_str()))); + Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(objectId_.value()).c_str()))); } return params; @@ -445,7 +445,7 @@ std::unique_ptr ExceptionDetails::Create(const EcmaVM *ecmaVm, result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "text"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - exceptionDetails->text_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + exceptionDetails->text_ = DebuggerApi::ToCString(result); } else { error += "'text' should be a String;"; } @@ -475,7 +475,7 @@ std::unique_ptr ExceptionDetails::Create(const EcmaVM *ecmaVm, result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - exceptionDetails->scriptId_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + exceptionDetails->scriptId_ = DebuggerApi::StringToInt(result); } else { error += "'scriptId' should be a String;"; } @@ -483,7 +483,7 @@ std::unique_ptr ExceptionDetails::Create(const EcmaVM *ecmaVm, result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "url"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - exceptionDetails->url_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + exceptionDetails->url_ = DebuggerApi::ToCString(result); } else { error += "'url' should be a String;"; } @@ -536,7 +536,7 @@ Local ExceptionDetails::ToObject(const EcmaVM *ecmaVm) if (scriptId_) { params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId")), - Local(StringRef::NewFromUtf8(ecmaVm, scriptId_->c_str()))); + Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(scriptId_.value()).c_str()))); } if (url_) { params->Set(ecmaVm, @@ -572,7 +572,7 @@ std::unique_ptr InternalPropertyDescriptor::Create(c Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "name"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - internalPropertyDescriptor->name_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + internalPropertyDescriptor->name_ = DebuggerApi::ToCString(result); } else { error += "'name' should be a String;"; } @@ -631,7 +631,7 @@ std::unique_ptr PrivatePropertyDescriptor::Create(con Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "name"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - propertyDescriptor->name_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + propertyDescriptor->name_ = DebuggerApi::ToCString(result); } else { error += "'name' should be a String;"; } @@ -723,10 +723,10 @@ std::unique_ptr PropertyDescriptor::FromProperty(const EcmaV if (name->IsSymbol()) { Local symbol(name); nameStr = - "Symbol(" + DebuggerApi::ConvertToString(Local(name)->GetDescription(ecmaVm)->ToString()) + ")"; + "Symbol(" + DebuggerApi::ToCString(Local(name)->GetDescription(ecmaVm)) + ")"; debuggerProperty->symbol_ = RemoteObject::FromTagged(ecmaVm, name); } else { - nameStr = DebuggerApi::ConvertToString(name->ToString(ecmaVm)->ToString()); + nameStr = DebuggerApi::ToCString(name->ToString(ecmaVm)); } debuggerProperty->name_ = nameStr; @@ -762,7 +762,7 @@ std::unique_ptr PropertyDescriptor::Create(const EcmaVM *ecm Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "name"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - propertyDescriptor->name_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + propertyDescriptor->name_ = DebuggerApi::ToCString(result); } else { error += "'name' should be a String;"; } @@ -946,7 +946,7 @@ std::unique_ptr CallArgument::Create(const EcmaVM *ecmaVm, const L Local(StringRef::NewFromUtf8(ecmaVm, "unserializableValue"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - callArgument->unserializableValue_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + callArgument->unserializableValue_ = DebuggerApi::ToCString(result); } else { error += "'unserializableValue' should be a String;"; } @@ -954,7 +954,7 @@ std::unique_ptr CallArgument::Create(const EcmaVM *ecmaVm, const L result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "objectId"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - callArgument->objectId_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + callArgument->objectId_ = DebuggerApi::StringToInt(result); } else { error += "'objectId' should be a String;"; } @@ -982,7 +982,7 @@ Local CallArgument::ToObject(const EcmaVM *ecmaVm) if (objectId_) { params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "objectId")), - Local(StringRef::NewFromUtf8(ecmaVm, objectId_->c_str()))); + Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(objectId_.value()).c_str()))); } return params; @@ -1001,7 +1001,7 @@ std::unique_ptr Location::Create(const EcmaVM *ecmaVm, const Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - location->scriptId_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + location->scriptId_ = DebuggerApi::StringToInt(result); } else { error += "'scriptId' should be a String;"; } @@ -1040,7 +1040,7 @@ Local Location::ToObject(const EcmaVM *ecmaVm) params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId")), - Local(StringRef::NewFromUtf8(ecmaVm, scriptId_.c_str()))); + Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(scriptId_).c_str()))); params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber")), IntegerRef::New(ecmaVm, line_)); if (column_) { @@ -1126,7 +1126,7 @@ std::unique_ptr SearchMatch::Create(const EcmaVM *ecmaVm, const Loc result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineContent"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - locationSearch->lineContent_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + locationSearch->lineContent_ = DebuggerApi::ToCString(result); } else { error += "'lineContent' should be a String;"; } @@ -1167,7 +1167,7 @@ std::unique_ptr LocationRange::Create(const EcmaVM *ecmaVm, const Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - locationRange->scriptId_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + locationRange->scriptId_ = DebuggerApi::StringToInt(result); } else { error += "'scriptId' should be a String;"; } @@ -1218,7 +1218,7 @@ Local LocationRange::ToObject(const EcmaVM *ecmaVm) params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId")), - Local(StringRef::NewFromUtf8(ecmaVm, scriptId_.c_str()))); + Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(scriptId_).c_str()))); ASSERT(start_ != nullptr); params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "object")), @@ -1243,7 +1243,7 @@ std::unique_ptr BreakLocation::Create(const EcmaVM *ecmaVm, const Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - breakLocation->scriptId_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + breakLocation->scriptId_ = DebuggerApi::StringToInt(result); } else { error += "'scriptId' should be a String;"; } @@ -1271,7 +1271,7 @@ std::unique_ptr BreakLocation::Create(const EcmaVM *ecmaVm, const result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "type"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - auto type = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + auto type = DebuggerApi::ToCString(result); if (BreakType::Valid(type)) { breakLocation->type_ = type; } else { @@ -1295,7 +1295,7 @@ Local BreakLocation::ToObject(const EcmaVM *ecmaVm) params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId")), - Local(StringRef::NewFromUtf8(ecmaVm, scriptId_.c_str()))); + Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(scriptId_).c_str()))); params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber")), IntegerRef::New(ecmaVm, line_)); if (column_) { @@ -1325,7 +1325,7 @@ std::unique_ptr Scope::Create(const EcmaVM *ecmaVm, const Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "type"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - auto type = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + auto type = DebuggerApi::ToCString(result); if (Scope::Type::Valid(type)) { scope->type_ = type; } else { @@ -1355,7 +1355,7 @@ std::unique_ptr Scope::Create(const EcmaVM *ecmaVm, const Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "name"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - scope->name_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + scope->name_ = DebuggerApi::ToCString(result); } else { error += "'name' should be a String;"; } @@ -1439,7 +1439,7 @@ std::unique_ptr CallFrame::Create(const EcmaVM *ecmaVm, const Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "callFrameId"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - callFrame->callFrameId_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + callFrame->callFrameId_ = DebuggerApi::StringToInt(result); } else { error += "'callFrameId' should be a String;"; } @@ -1449,7 +1449,7 @@ std::unique_ptr CallFrame::Create(const EcmaVM *ecmaVm, const Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "functionName"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - callFrame->functionName_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + callFrame->functionName_ = DebuggerApi::ToCString(result); } else { error += "'functionName' should be a String;"; } @@ -1488,7 +1488,7 @@ std::unique_ptr CallFrame::Create(const EcmaVM *ecmaVm, const Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "url"))); if (!result.IsEmpty() && !result->IsUndefined()) { if (result->IsString()) { - callFrame->url_ = DebuggerApi::ConvertToString(StringRef::Cast(*result)->ToString()); + callFrame->url_ = DebuggerApi::ToCString(result); } else { error += "'url' should be a String;"; } @@ -1558,7 +1558,7 @@ Local CallFrame::ToObject(const EcmaVM *ecmaVm) params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "callFrameId")), - Local(StringRef::NewFromUtf8(ecmaVm, callFrameId_.c_str()))); + Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(callFrameId_).c_str()))); params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "functionName")), Local(StringRef::NewFromUtf8(ecmaVm, functionName_.c_str()))); diff --git a/ecmascript/tooling/base/pt_types.h b/ecmascript/tooling/base/pt_types.h index 2bb2caca86..5204164e2b 100644 --- a/ecmascript/tooling/base/pt_types.h +++ b/ecmascript/tooling/base/pt_types.h @@ -26,10 +26,10 @@ namespace panda::tooling::ecmascript { using panda::ecmascript::CList; -using panda::ecmascript::CMap; -using panda::ecmascript::CQueue; +using panda::ecmascript::CUnorderedMap; using panda::ecmascript::CString; using panda::ecmascript::CVector; +using panda::ecmascript::ToCString; // ========== Base types begin class PtBaseTypes { @@ -55,7 +55,7 @@ using BreakpointId = CString; struct BreakpointDetails { static BreakpointId ToString(const BreakpointDetails &metaData) { - return "id:" + DebuggerApi::ToCString(metaData.line_) + ":" + DebuggerApi::ToCString(metaData.column_) + ":" + + return "id:" + ToCString(metaData.line_) + ":" + ToCString(metaData.column_) + ":" + metaData.url_; } @@ -76,27 +76,27 @@ struct BreakpointDetails { CString lineStr = id.substr(lineStart + 1, columnStart - lineStart - 1); CString columnStr = id.substr(columnStart + 1, urlStart - columnStart - 1); CString url = id.substr(urlStart + 1); - metaData->line_ = DebuggerApi::CStringToULL(lineStr); - metaData->column_ = DebuggerApi::CStringToULL(columnStr); + metaData->line_ = DebuggerApi::CStringToInt(lineStr); + metaData->column_ = DebuggerApi::CStringToInt(columnStr); metaData->url_ = url; return true; } - size_t line_ {0}; - size_t column_ {0}; + int32_t line_ {0}; + int32_t column_ {0}; CString url_ {}; }; // Debugger.CallFrameId -using CallFrameId = CString; +using CallFrameId = uint32_t; // ========== Runtime types begin // Runtime.ScriptId -using ScriptId = CString; +using ScriptId = uint32_t; // Runtime.RemoteObjectId -using RemoteObjectId = CString; +using RemoteObjectId = uint32_t; // Runtime.ExecutionContextId using ExecutionContextId = int32_t; @@ -105,7 +105,7 @@ using ExecutionContextId = int32_t; using UnserializableValue = CString; // Runtime.UniqueDebuggerId -using UniqueDebuggerId = CString; +using UniqueDebuggerId = uint32_t; // Runtime.RemoteObject class RemoteObject : public PtBaseTypes { @@ -120,7 +120,7 @@ public: /* * @see {#ObjectType} */ - CString GetType() const + const CString &GetType() const { return type_; } @@ -133,9 +133,9 @@ public: /* * @see {#ObjectSubType} */ - CString GetSubType() const + const CString &GetSubType() const { - return subtype_.value_or(""); + return subtype_.value(); } RemoteObject &SetSubType(const CString &type) @@ -149,9 +149,9 @@ public: return subtype_.has_value(); } - CString GetClassName() const + const CString &GetClassName() const { - return className_.value_or(""); + return className_.value(); } RemoteObject &SetClassName(const CString &className) @@ -181,9 +181,9 @@ public: return value_.has_value(); } - UnserializableValue GetUnserializableValue() const + const UnserializableValue &GetUnserializableValue() const { - return unserializableValue_.value_or(""); + return unserializableValue_.value(); } RemoteObject &SetUnserializableValue(const UnserializableValue &unserializableValue) @@ -197,9 +197,9 @@ public: return unserializableValue_.has_value(); } - CString GetDescription() const + const CString &GetDescription() const { - return description_.value_or(""); + return description_.value(); } RemoteObject &SetDescription(const CString &description) @@ -215,21 +215,15 @@ public: RemoteObjectId GetObjectId() const { - return objectId_.value_or(""); + return objectId_.value_or(0); } - RemoteObject &SetObjectId(const RemoteObjectId &objectId) + RemoteObject &SetObjectId(RemoteObjectId objectId) { objectId_ = objectId; return *this; } - RemoteObject &SetObjectId(uint32_t objectId) - { - objectId_ = DebuggerApi::ToCString(objectId); - return *this; - } - bool HasObjectId() const { return objectId_.has_value(); @@ -426,7 +420,7 @@ public: return *this; } - CString GetText() const + const CString &GetText() const { return text_; } @@ -442,7 +436,7 @@ public: return line_; } - ExceptionDetails &SetLine(size_t line) + ExceptionDetails &SetLine(int32_t line) { line_ = line; return *this; @@ -453,7 +447,7 @@ public: return column_; } - ExceptionDetails &SetColumn(size_t column) + ExceptionDetails &SetColumn(int32_t column) { column_ = column; return *this; @@ -461,10 +455,10 @@ public: ScriptId GetScriptId() const { - return scriptId_.value_or(""); + return scriptId_.value_or(0); } - ExceptionDetails &SetScriptId(const ScriptId &scriptId) + ExceptionDetails &SetScriptId(ScriptId scriptId) { scriptId_ = scriptId; return *this; @@ -475,9 +469,9 @@ public: return scriptId_.has_value(); } - CString GetUrl() const + const CString &GetUrl() const { - return url_.value_or(""); + return url_.value(); } ExceptionDetails &SetUrl(const CString &url) @@ -532,8 +526,8 @@ private: int32_t exceptionId_ {0}; CString text_ {}; - size_t line_ {0}; - size_t column_ {0}; + int32_t line_ {0}; + int32_t column_ {0}; std::optional scriptId_ {}; std::optional url_ {}; std::optional> exception_ {}; @@ -883,9 +877,9 @@ public: return value_.has_value(); } - UnserializableValue GetUnserializableValue() const + const UnserializableValue &GetUnserializableValue() const { - return unserializableValue_.value_or(""); + return unserializableValue_.value(); } CallArgument &SetUnserializableValue(const UnserializableValue &unserializableValue) @@ -901,10 +895,10 @@ public: RemoteObjectId GetObjectId() const { - return objectId_.value_or(""); + return objectId_.value_or(0); } - CallArgument &SetObjectId(const RemoteObjectId &objectId) + CallArgument &SetObjectId(RemoteObjectId objectId) { objectId_ = objectId; return *this; @@ -955,7 +949,7 @@ public: return scriptId_; } - Location &SetScriptId(const ScriptId &scriptId) + Location &SetScriptId(ScriptId scriptId) { scriptId_ = scriptId; return *this; @@ -966,7 +960,7 @@ public: return line_; } - Location &SetLine(size_t line) + Location &SetLine(int32_t line) { line_ = line; return *this; @@ -977,7 +971,7 @@ public: return column_.value_or(-1); } - Location &SetColumn(size_t column) + Location &SetColumn(int32_t column) { column_ = column; return *this; @@ -993,7 +987,7 @@ private: NO_MOVE_SEMANTIC(Location); ScriptId scriptId_ {}; - size_t line_ {0}; + int32_t line_ {0}; std::optional column_ {}; }; @@ -1011,7 +1005,7 @@ public: return line_; } - ScriptPosition &SetLine(size_t line) + ScriptPosition &SetLine(int32_t line) { line_ = line; return *this; @@ -1022,7 +1016,7 @@ public: return column_; } - ScriptPosition &SetColumn(size_t column) + ScriptPosition &SetColumn(int32_t column) { column_ = column; return *this; @@ -1032,8 +1026,8 @@ private: NO_COPY_SEMANTIC(ScriptPosition); NO_MOVE_SEMANTIC(ScriptPosition); - size_t line_ {0}; - size_t column_ {0}; + int32_t line_ {0}; + int32_t column_ {0}; }; // Debugger.SearchMatch @@ -1048,7 +1042,7 @@ private: NO_COPY_SEMANTIC(SearchMatch); NO_MOVE_SEMANTIC(SearchMatch); - size_t lineNumber_ {0}; + int32_t lineNumber_ {0}; CString lineContent_ {}; }; @@ -1066,7 +1060,7 @@ public: return scriptId_; } - LocationRange &SetScriptId(const ScriptId &scriptId) + LocationRange &SetScriptId(ScriptId scriptId) { scriptId_ = scriptId; return *this; @@ -1117,7 +1111,7 @@ public: return scriptId_; } - BreakLocation &SetScriptId(const ScriptId &scriptId) + BreakLocation &SetScriptId(ScriptId scriptId) { scriptId_ = scriptId; return *this; @@ -1128,7 +1122,7 @@ public: return line_; } - BreakLocation &SetLine(size_t line) + BreakLocation &SetLine(int32_t line) { line_ = line; return *this; @@ -1139,7 +1133,7 @@ public: return column_.value_or(-1); } - BreakLocation &SetColumn(size_t column) + BreakLocation &SetColumn(int32_t column) { column_ = column; return *this; @@ -1153,9 +1147,9 @@ public: /* * @see {#BreakType} */ - CString GetType() const + const CString &GetType() const { - return type_.value_or(""); + return type_.value(); } BreakLocation &SetType(const CString &type) @@ -1193,7 +1187,7 @@ private: NO_MOVE_SEMANTIC(BreakLocation); ScriptId scriptId_ {}; - size_t line_ {0}; + int32_t line_ {0}; std::optional column_ {}; std::optional type_ {}; }; @@ -1224,7 +1218,7 @@ public: /* * @see {#Scope::Type} */ - CString GetType() const + const CString &GetType() const { return type_; } @@ -1246,9 +1240,9 @@ public: return *this; } - CString GetName() const + const CString &GetName() const { - return name_.value_or(""); + return name_.value(); } Scope &SetName(const CString &name) @@ -1374,13 +1368,13 @@ public: return callFrameId_; } - CallFrame &SetCallFrameId(const CallFrameId &callFrameId) + CallFrame &SetCallFrameId(CallFrameId callFrameId) { callFrameId_ = callFrameId; return *this; } - CString GetFunctionName() const + const CString &GetFunctionName() const { return functionName_; } @@ -1421,7 +1415,7 @@ public: return *this; } - CString GetUrl() const + const CString &GetUrl() const { return url_; } diff --git a/ecmascript/tooling/debugger_service.cpp b/ecmascript/tooling/debugger_service.cpp index 18e9b83c7d..1ab3f396d2 100644 --- a/ecmascript/tooling/debugger_service.cpp +++ b/ecmascript/tooling/debugger_service.cpp @@ -33,7 +33,7 @@ void UninitializeDebugger() void DispatchProtocolMessage(const std::string &message) { if (g_handler != nullptr) { - g_handler->ProcessCommand(DebuggerApi::ConvertToString(message)); + g_handler->ProcessCommand(message.c_str()); } } } // namespace panda::tooling::ecmascript \ No newline at end of file diff --git a/ecmascript/tooling/dispatcher.cpp b/ecmascript/tooling/dispatcher.cpp index 5a47292c1b..d54673d2b3 100644 --- a/ecmascript/tooling/dispatcher.cpp +++ b/ecmascript/tooling/dispatcher.cpp @@ -63,8 +63,7 @@ DispatchRequest::DispatchRequest(const EcmaVM *ecmaVm, const CString &message) : LOG(ERROR, DEBUGGER) << "method format error"; return; } - CString wholeMethod = - DebuggerApi::ConvertToString(StringRef::Cast(*methodResult)->ToString()); + CString wholeMethod = DebuggerApi::ToCString(methodResult); CString::size_type length = wholeMethod.length(); CString::size_type indexPoint; indexPoint = wholeMethod.find_first_of('.', 0); @@ -106,7 +105,7 @@ DispatchResponse DispatchResponse::Create(std::optional error) DispatchResponse response; if (error.has_value()) { response.code_ = ResponseCode::NOK; - response.errorMsg_ = DebuggerApi::ConvertToString(error->GetMessage()); + response.errorMsg_ = error->GetMessage(); } return response; } diff --git a/ecmascript/tooling/dispatcher.h b/ecmascript/tooling/dispatcher.h index 9e3537704e..9fa6ae7008 100644 --- a/ecmascript/tooling/dispatcher.h +++ b/ecmascript/tooling/dispatcher.h @@ -19,15 +19,16 @@ #include #include -#include "libpandabase/macros.h" -#include "ecmascript/napi/include/jsnapi.h" #include "ecmascript/mem/c_containers.h" #include "ecmascript/mem/c_string.h" +#include "ecmascript/napi/include/jsnapi.h" #include "include/tooling/debug_interface.h" +#include "libpandabase/macros.h" namespace panda::tooling::ecmascript { -using panda::ecmascript::CMap; using panda::ecmascript::CString; +using panda::ecmascript::CUnorderedMap; + class FrontEnd; class PtBaseReturns; class PtBaseEvents; @@ -64,11 +65,11 @@ public: { return params_; } - CString GetDomain() const + const CString &GetDomain() const { return domain_; } - CString GetMethod() const + const CString &GetMethod() const { return method_; } @@ -101,7 +102,7 @@ public: return code_; } - CString GetMessage() const + const CString &GetMessage() const { return errorMsg_; } @@ -147,7 +148,7 @@ public: void Dispatch(const DispatchRequest &request); private: - CMap> dispatchers_ {}; + CUnorderedMap> dispatchers_ {}; NO_COPY_SEMANTIC(Dispatcher); NO_MOVE_SEMANTIC(Dispatcher); diff --git a/ecmascript/tooling/interface/debugger_api.cpp b/ecmascript/tooling/interface/debugger_api.cpp index 0d567e3609..8da1eeb37a 100644 --- a/ecmascript/tooling/interface/debugger_api.cpp +++ b/ecmascript/tooling/interface/debugger_api.cpp @@ -21,11 +21,12 @@ #include "ecmascript/js_handle.h" #include "ecmascript/js_method.h" #include "ecmascript/jspandafile/js_pandafile_manager.h" -#include "ecmascript/mem/c_string.h" #include "ecmascript/napi/jsnapi_helper-inl.h" #include "ecmascript/tooling/interface/js_debugger.h" namespace panda::tooling::ecmascript { +using panda::ecmascript::CStringToL; +using panda::ecmascript::EcmaString; using panda::ecmascript::JSHandle; using panda::ecmascript::JSTaggedValue; using panda::ecmascript::JSNativePointer; @@ -37,22 +38,6 @@ using panda::ecmascript::base::ALLOW_HEX; using panda::ecmascript::base::ALLOW_OCTAL; using panda::ecmascript::base::NumberHelper; -// CString -uint64_t DebuggerApi::CStringToULL(const CString &str) -{ - return panda::ecmascript::CStringToULL(str); -} - -CString DebuggerApi::ToCString(int32_t number) -{ - return panda::ecmascript::ToCString(number); -} - -CString DebuggerApi::ConvertToString(const std::string &str) -{ - return panda::ecmascript::ConvertToString(str); -} - // InterpretedFrameHandler uint32_t DebuggerApi::GetStackDepth(const EcmaVM *ecmaVm) { @@ -126,6 +111,24 @@ Local DebuggerApi::GetVRegValue(const EcmaVM *ecmaVm, return JSNApiHelper::ToLocal(handledValue); } +CString DebuggerApi::ToCString(Local str) +{ + ecmascript::JSHandle ret = JSNApiHelper::ToJSHandle(str); + ASSERT(ret->IsString()); + EcmaString *ecmaStr = EcmaString::Cast(ret.GetTaggedValue().GetTaggedObject()); + return ConvertToString(ecmaStr); +} + +int32_t DebuggerApi::CStringToInt(const CString &str) +{ + return CStringToL(str); +} + +int32_t DebuggerApi::StringToInt(Local str) +{ + return CStringToInt(ToCString(str)); +} + // JSThread Local DebuggerApi::GetException(const EcmaVM *ecmaVm) { @@ -144,22 +147,6 @@ void DebuggerApi::ClearException(const EcmaVM *ecmaVm) return ecmaVm->GetJSThread()->ClearException(); } -// EcmaVM -const panda_file::File *DebuggerApi::FindPandaFile(const CString &fileName) -{ - const panda_file::File *pfs = nullptr; - ::panda::ecmascript::JSPandaFileManager::GetInstance()->EnumerateJSPandaFiles([&pfs, fileName]( - const panda::ecmascript::JSPandaFile *jsPandaFile) { - if (ConvertToString(jsPandaFile->GetJSPandaFileDesc()) == fileName) { - pfs = jsPandaFile->GetPandaFile(); - return false; - } - return true; - }); - - return pfs; -} - // NumberHelper double DebuggerApi::StringToDouble(const uint8_t *start, const uint8_t *end, uint8_t radix) { @@ -224,7 +211,7 @@ void DebuggerApi::SetProperties(const EcmaVM *ecmaVm, int32_t level, uint32_t sl LexicalEnv::Cast(env.GetTaggedObject())->SetProperties(ecmaVm->GetJSThread(), slot, target); } -bool DebuggerApi::EvaluateLexicalValue(const EcmaVM *ecmaVm, const std::string &name, int32_t &level, uint32_t &slot) +bool DebuggerApi::EvaluateLexicalValue(const EcmaVM *ecmaVm, const CString &name, int32_t &level, uint32_t &slot) { JSTaggedValue curEnv = ecmaVm->GetJSThread()->GetCurrentLexenv(); for (; curEnv.IsTaggedArray(); curEnv = LexicalEnv::Cast(curEnv.GetTaggedObject())->GetParentEnv()) { @@ -245,7 +232,7 @@ bool DebuggerApi::EvaluateLexicalValue(const EcmaVM *ecmaVm, const std::string & return false; } -Local DebuggerApi::GetLexicalValueInfo(const EcmaVM *ecmaVm, const std::string &name) +Local DebuggerApi::GetLexicalValueInfo(const EcmaVM *ecmaVm, const CString &name) { JSThread *thread = ecmaVm->GetJSThread(); JSTaggedValue curEnv = thread->GetCurrentLexenv(); diff --git a/ecmascript/tooling/interface/debugger_api.h b/ecmascript/tooling/interface/debugger_api.h index 737e080fb3..ab675eb10a 100644 --- a/ecmascript/tooling/interface/debugger_api.h +++ b/ecmascript/tooling/interface/debugger_api.h @@ -56,11 +56,6 @@ enum StackState { class PUBLIC_API DebuggerApi { public: - // CString - static uint64_t CStringToULL(const CString &str); - static CString ToCString(int32_t number); - static CString ConvertToString(const std::string &str); - // InterpretedFrameHandler static uint32_t GetStackDepth(const EcmaVM *ecmaVm); static bool StackWalker(const EcmaVM *ecmaVm, std::function func); @@ -73,14 +68,16 @@ public: static Local GetVRegValue(const EcmaVM *ecmaVm, const InterpretedFrameHandler *frameHandler, size_t index); + // String + static int32_t CStringToInt(const CString &str); + static CString ToCString(Local str); + static int32_t StringToInt(Local str); + // JSThread static Local GetException(const EcmaVM *ecmaVm); static void SetException(const EcmaVM *ecmaVm, Local exception); static void ClearException(const EcmaVM *ecmaVm); - // EcmaVM - static const panda_file::File *FindPandaFile(const CString &fileName); - // NumberHelper static double StringToDouble(const uint8_t *start, const uint8_t *end, uint8_t radix); @@ -97,8 +94,8 @@ public: // ScopeInfo static Local GetProperties(const EcmaVM *ecmaVm, int32_t level, uint32_t slot); static void SetProperties(const EcmaVM *ecmaVm, int32_t level, uint32_t slot, Local value); - static bool EvaluateLexicalValue(const EcmaVM *ecmaVm, const std::string &name, int32_t &level, uint32_t &slot); - static Local GetLexicalValueInfo(const EcmaVM *ecmaVm, const std::string &name); + static bool EvaluateLexicalValue(const EcmaVM *ecmaVm, const CString &name, int32_t &level, uint32_t &slot); + static Local GetLexicalValueInfo(const EcmaVM *ecmaVm, const CString &name); }; } // namespace panda::tooling::ecmascript diff --git a/ecmascript/tooling/interface/js_debugger.cpp b/ecmascript/tooling/interface/js_debugger.cpp index d172630ac3..19534ed47a 100644 --- a/ecmascript/tooling/interface/js_debugger.cpp +++ b/ecmascript/tooling/interface/js_debugger.cpp @@ -28,21 +28,21 @@ std::optional JSDebugger::SetBreakpoint(const PtLocation &location) JSMethod *method = FindMethod(location); if (method == nullptr) { return Error(Error::Type::METHOD_NOT_FOUND, - std::string("Cannot find JSMethod with id ") + std::to_string(location.GetMethodId().GetOffset()) + - " in panda file '" + std::string(location.GetPandaFile()) + "'"); + "Cannot find JSMethod with id " + std::to_string(location.GetMethodId().GetOffset()) + + " in panda file '" + location.GetPandaFile() + "'"); } if (location.GetBytecodeOffset() >= method->GetCodeSize()) { - return Error(Error::Type::INVALID_BREAKPOINT, std::string("Invalid breakpoint location: bytecode offset (") + - std::to_string(location.GetBytecodeOffset()) + - ") >= JSMethod code size (" + - std::to_string(method->GetCodeSize()) + ")"); + return Error(Error::Type::INVALID_BREAKPOINT, "Invalid breakpoint location: bytecode offset (" + + std::to_string(location.GetBytecodeOffset()) + + ") >= JSMethod code size (" + + std::to_string(method->GetCodeSize()) + ")"); } if (!breakpoints_.emplace(method, location.GetBytecodeOffset()).second) { return Error(Error::Type::BREAKPOINT_ALREADY_EXISTS, - std::string("Breakpoint already exists: bytecode offset ") + - std::to_string(location.GetBytecodeOffset())); + "Breakpoint already exists: bytecode offset " + + std::to_string(location.GetBytecodeOffset())); } return {}; @@ -53,8 +53,8 @@ std::optional JSDebugger::RemoveBreakpoint(const PtLocation &location) JSMethod *method = FindMethod(location); if (method == nullptr) { return Error(Error::Type::METHOD_NOT_FOUND, - std::string("Cannot find JSMethod with id ") + std::to_string(location.GetMethodId().GetOffset()) + - " in panda file '" + std::string(location.GetPandaFile()) + "'"); + "Cannot find JSMethod with id " + std::to_string(location.GetMethodId().GetOffset()) + + " in panda file '" + location.GetPandaFile() + "'"); } if (!RemoveBreakpoint(method, location.GetBytecodeOffset())) { @@ -143,7 +143,7 @@ JSMethod *JSDebugger::FindMethod(const PtLocation &location) const JSMethod *method = nullptr; ::panda::ecmascript::JSPandaFileManager::GetInstance()->EnumerateJSPandaFiles([&method, location]( const panda::ecmascript::JSPandaFile *jsPandaFile) { - if (location.GetPandaFile() == jsPandaFile->GetJSPandaFileDesc()) { + if (jsPandaFile->GetJSPandaFileDesc() == location.GetPandaFile()) { JSMethod *methodsData = jsPandaFile->GetMethods(); uint32_t numberMethods = jsPandaFile->GetNumMethods(); for (uint32_t i = 0; i < numberMethods; ++i) { diff --git a/ecmascript/tooling/interface/js_debugger.h b/ecmascript/tooling/interface/js_debugger.h index 0207db7f8a..7e993f804f 100644 --- a/ecmascript/tooling/interface/js_debugger.h +++ b/ecmascript/tooling/interface/js_debugger.h @@ -18,7 +18,6 @@ #include "ecmascript/ecma_vm.h" #include "ecmascript/js_method.h" -#include "ecmascript/mem/c_containers.h" #include "ecmascript/tooling/interface/debugger_api.h" #include "tooling/debugger.h" diff --git a/ecmascript/tooling/js_pt_extractor.cpp b/ecmascript/tooling/js_pt_extractor.cpp index 44c6d80987..4c01693d6d 100644 --- a/ecmascript/tooling/js_pt_extractor.cpp +++ b/ecmascript/tooling/js_pt_extractor.cpp @@ -88,7 +88,7 @@ CList JSPtExtractor::GetStepRanges(File::EntityId methodId, uint32_ { CList ranges {}; auto table = GetLineNumberTable(methodId); - auto callbackFunc = [table, &ranges](size_t line, [[maybe_unused]] size_t column) -> bool { + auto callbackFunc = [table, &ranges](int32_t line, [[maybe_unused]] int32_t column) -> bool { for (auto it = table.begin(); it != table.end(); ++it) { auto next = it + 1; if (it->line == line) { diff --git a/ecmascript/tooling/js_pt_extractor.h b/ecmascript/tooling/js_pt_extractor.h index 3909dabc84..e5de959123 100644 --- a/ecmascript/tooling/js_pt_extractor.h +++ b/ecmascript/tooling/js_pt_extractor.h @@ -19,7 +19,6 @@ #include "ecmascript/js_method.h" #include "ecmascript/js_thread.h" #include "ecmascript/jspandafile/debug_info_extractor.h" -#include "ecmascript/mem/c_containers.h" #include "libpandabase/macros.h" #include "include/tooling/debug_interface.h" @@ -28,6 +27,7 @@ using panda::ecmascript::CList; using panda::ecmascript::DebugInfoExtractor; using panda::ecmascript::EcmaVM; using panda::ecmascript::JSMethod; +using panda::ecmascript::JSPandaFile; using panda::panda_file::File; class JSPtExtractor : public DebugInfoExtractor { @@ -60,11 +60,11 @@ public: Type type_; }; - explicit JSPtExtractor(const File *pf) : DebugInfoExtractor(pf) {} + explicit JSPtExtractor(const JSPandaFile *jsPandaFile) : DebugInfoExtractor(jsPandaFile) {} virtual ~JSPtExtractor() = default; template - bool MatchWithLocation(const Callback &cb, size_t line, size_t column) + bool MatchWithLocation(const Callback &cb, int32_t line, int32_t column) { auto methods = GetMethodIdList(); for (const auto &method : methods) { @@ -92,8 +92,8 @@ public: { auto lineTable = GetLineNumberTable(methodId); auto columnTable = GetColumnNumberTable(methodId); - size_t line = 0; - size_t column = 0; + int32_t line = 0; + int32_t column = 0; for (const auto &pair : lineTable) { if (offset < pair.offset) { diff --git a/ecmascript/tooling/protocol_handler.cpp b/ecmascript/tooling/protocol_handler.cpp index 61f80835e6..61f2da345d 100644 --- a/ecmascript/tooling/protocol_handler.cpp +++ b/ecmascript/tooling/protocol_handler.cpp @@ -53,8 +53,8 @@ void ProtocolHandler::ProcessCommand(const CString &msg) if (!exception->IsHole()) { DebuggerApi::SetException(vm_, exception); } - std::string startDebugging("Runtime.runIfWaitingForDebugger"); - if (msg.find(startDebugging, 0) != std::string::npos) { + CString startDebugging("Runtime.runIfWaitingForDebugger"); + if (msg.find(startDebugging, 0) != CString::npos) { waitingForDebugger_ = false; } } diff --git a/ecmascript/tooling/protocol_handler.h b/ecmascript/tooling/protocol_handler.h index 307b80821a..63afc326b8 100644 --- a/ecmascript/tooling/protocol_handler.h +++ b/ecmascript/tooling/protocol_handler.h @@ -49,9 +49,6 @@ private: std::unique_ptr dispatcher_ {}; bool waitingForDebugger_ {false}; - CQueue msgQueue_ {}; - os::memory::Mutex queueLock_; - os::memory::ConditionVariable queueCond_ GUARDED_BY(queueLock_); const EcmaVM *vm_ {nullptr}; }; } // namespace panda::tooling::ecmascript diff --git a/ecmascript/tooling/test/debugger_api_test.cpp b/ecmascript/tooling/test/debugger_api_test.cpp index a38962e584..c3e6b91190 100644 --- a/ecmascript/tooling/test/debugger_api_test.cpp +++ b/ecmascript/tooling/test/debugger_api_test.cpp @@ -60,9 +60,7 @@ HWTEST_P_L0(DebuggerApiTest, EcmaScriptSuite) ASSERT_NE(vm, nullptr); auto [pandaFile, entryPoint] = GetTestEntryPoint(testName); - std::string fileNameStr(pandaFile); - std::string entryStr(entryPoint); - auto res = JSNApi::Execute(vm, fileNameStr, entryStr); + auto res = JSNApi::Execute(vm, pandaFile.c_str(), entryPoint.c_str()); ASSERT_TRUE(res); } diff --git a/ecmascript/tooling/test/debugger_events_test.cpp b/ecmascript/tooling/test/debugger_events_test.cpp index 54a95f18b2..7c59364818 100644 --- a/ecmascript/tooling/test/debugger_events_test.cpp +++ b/ecmascript/tooling/test/debugger_events_test.cpp @@ -92,12 +92,12 @@ HWTEST_F_L0(DebuggerEventsTest, BreakpointResolvedCreateTest) EXPECT_EQ(breakpointResolved, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"location":{"scriptId":"id2","lineNumber":99}}})"; + {"location":{"scriptId":"2","lineNumber":99}}})"; breakpointResolved = BreakpointResolved::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(breakpointResolved, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"breakpointId":"00", - "location":{"scriptId":"id2","lineNumber":99}}})"; + "location":{"scriptId":"2","lineNumber":99}}})"; breakpointResolved = BreakpointResolved::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(breakpointResolved, nullptr); } @@ -109,7 +109,7 @@ HWTEST_F_L0(DebuggerEventsTest, BreakpointResolvedToObjectTest) Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "params"); msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"breakpointId":"00", - "location":{"scriptId":"id2","lineNumber":99}}})"; + "location":{"scriptId":"2","lineNumber":99}}})"; breakpointResolved = BreakpointResolved::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(breakpointResolved, nullptr); @@ -123,7 +123,7 @@ HWTEST_F_L0(DebuggerEventsTest, BreakpointResolvedToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("00", Local(result)->ToString()); + EXPECT_EQ("00", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "location"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); @@ -166,7 +166,7 @@ HWTEST_F_L0(DebuggerEventsTest, PausedCreateTest) {"callFrames":[)" + R"({"id":0,"method":"Debugger.Test","params":{ "callFrameId":10,"functionName":"name0", - "location":{"scriptId":"id5","lineNumber":19},"url":"url7","scopeChain": + "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain": [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})" + @@ -176,7 +176,7 @@ HWTEST_F_L0(DebuggerEventsTest, PausedCreateTest) msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"callFrames":[)" + R"({"callFrameId":"10","functionName":"name0", - "location":{"scriptId":"id5","lineNumber":19},"url":"url7","scopeChain": + "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain": [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}})" + @@ -193,7 +193,7 @@ HWTEST_F_L0(DebuggerEventsTest, PausedToObjectTest) msg = CString() + R"({"id":0,"method":"Debugger.Test","params": {"callFrames":[{"callFrameId":"10","functionName":"name0", - "location":{"scriptId":"id5","lineNumber":19},"url":"url7", + "location":{"scriptId":"5","lineNumber":19},"url":"url7", "scopeChain":[{"type":"global","object":{"type":"object"}}, {"type":"local","object":{"type":"object"}}], "this":{"type":"object","subtype":"v128"}}],"reason":"exception"}})"; paused = Paused::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); @@ -209,7 +209,7 @@ HWTEST_F_L0(DebuggerEventsTest, PausedToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("exception", Local(result)->ToString()); + EXPECT_EQ("exception", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "callFrames"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); @@ -230,7 +230,7 @@ HWTEST_F_L0(DebuggerEventsTest, ResumedToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); Local result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(std::string(resumed->GetName().c_str()), Local(result)->ToString()); + EXPECT_EQ(CString(resumed->GetName().c_str()), DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "params"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); @@ -265,7 +265,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseCreateTest) EXPECT_EQ(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0, "startColumn":4, @@ -276,7 +276,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseCreateTest) EXPECT_EQ(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0, "startColumn":4, @@ -286,7 +286,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseCreateTest) EXPECT_EQ(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0, "startColumn":4, @@ -295,7 +295,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseCreateTest) EXPECT_EQ(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0, "startColumn":4}})"; @@ -303,20 +303,20 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseCreateTest) EXPECT_EQ(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0}})"; parse = ScriptFailedToParse::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js"}})"; parse = ScriptFailedToParse::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00"}})"; + {"scriptId":"100"}})"; parse = ScriptFailedToParse::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(parse, nullptr); @@ -332,7 +332,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseCreateTest) EXPECT_EQ(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0, "startColumn":4, @@ -346,7 +346,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseCreateTest) "isModule":true, "length":34, "stackTrace":{"callFrames":[{"callFrameId":"10","functionName":"name0", - "location":{"scriptId":"id5","lineNumber":19},"url":"url7", + "location":{"scriptId":"5","lineNumber":19},"url":"url7", "scopeChain":[{"type":"global","object":{"type":"object"}}, {"type":"local","object":{"type":"object"}}], "this":{"type":"object","subtype":"v128"}}]}, "codeOffset":432, @@ -356,7 +356,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseCreateTest) ASSERT_NE(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0, "startColumn":4, @@ -370,7 +370,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseCreateTest) "isModule":true, "length":34, "stackTrace":{"callFrames":[{"callFrameId":"10","functionName":"name0", - "location":{"scriptId":"id5","lineNumber":19},"url":"url7", + "location":{"scriptId":"5","lineNumber":19},"url":"url7", "scopeChain":[{"type":"global","object":{"type":"object"}}, {"type":"local","object":{"type":"object"}}], "this":{"type":"object","subtype":"v128"}}]}, "codeOffset":432 @@ -379,7 +379,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseCreateTest) ASSERT_NE(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0, "startColumn":4, @@ -393,7 +393,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseCreateTest) "isModule":true, "length":34, "stackTrace":{"callFrames":[{"callFrameId":"10","functionName":"name0", - "location":{"scriptId":"id5","lineNumber":19},"url":"url7", + "location":{"scriptId":"5","lineNumber":19},"url":"url7", "scopeChain":[{"type":"global","object":{"type":"object"}}, {"type":"local","object":{"type":"object"}}], "this":{"type":"object","subtype":"v128"}}]} }})"; @@ -401,7 +401,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseCreateTest) ASSERT_NE(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0, "startColumn":4, @@ -419,7 +419,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseCreateTest) ASSERT_NE(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0, "startColumn":4, @@ -436,7 +436,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseCreateTest) ASSERT_NE(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0, "startColumn":4, @@ -452,7 +452,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseCreateTest) ASSERT_NE(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0, "startColumn":4, @@ -467,7 +467,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseCreateTest) ASSERT_NE(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0, "startColumn":4, @@ -481,7 +481,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseCreateTest) ASSERT_NE(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0, "startColumn":4, @@ -494,7 +494,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseCreateTest) ASSERT_NE(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0, "startColumn":4, @@ -508,7 +508,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseCreateTest) "isModule":true, "length":34, "stackTrace":{"callFrames":[{"callFrameId":"10","functionName":"name0", - "location":{"scriptId":"id5","lineNumber":19},"url":"url7", + "location":{"scriptId":"5","lineNumber":19},"url":"url7", "scopeChain":[{"type":"global","object":{"type":"object"}}, {"type":"local","object":{"type":"object"}}], "this":{"type":"object","subtype":"v128"}}]}, "codeOffset":432, @@ -526,7 +526,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseToObjectTest) Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "params"); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0, "startColumn":4, @@ -540,7 +540,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseToObjectTest) "isModule":true, "length":34, "stackTrace":{"callFrames":[{"callFrameId":"10","functionName":"name0", - "location":{"scriptId":"id5","lineNumber":19},"url":"url7", + "location":{"scriptId":"5","lineNumber":19},"url":"url7", "scopeChain":[{"type":"global","object":{"type":"object"}}, {"type":"local","object":{"type":"object"}}], "this":{"type":"object","subtype":"v128"}}]}, "codeOffset":432, @@ -560,13 +560,13 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("00", Local(result)->ToString()); + EXPECT_EQ("100", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "url"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("use/test.js", Local(result)->ToString()); + EXPECT_EQ("use/test.js", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "startLine"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); @@ -602,7 +602,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("hash0001", Local(result)->ToString()); + EXPECT_EQ("hash0001", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "executionContextAuxData"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); @@ -614,7 +614,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("usr/", Local(result)->ToString()); + EXPECT_EQ("usr/", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "hasSourceURL"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); @@ -644,13 +644,13 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("JavaScript", Local(result)->ToString()); + EXPECT_EQ("JavaScript", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "embedderName"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("hh", Local(result)->ToString()); + EXPECT_EQ("hh", DebuggerApi::ToCString(result)); } HWTEST_F_L0(DebuggerEventsTest, ScriptParsedCreateTest) @@ -679,7 +679,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptParsedCreateTest) EXPECT_EQ(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0, "startColumn":4, @@ -690,7 +690,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptParsedCreateTest) EXPECT_EQ(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0, "startColumn":4, @@ -700,7 +700,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptParsedCreateTest) EXPECT_EQ(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0, "startColumn":4, @@ -709,7 +709,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptParsedCreateTest) EXPECT_EQ(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0, "startColumn":4}})"; @@ -717,20 +717,20 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptParsedCreateTest) EXPECT_EQ(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0}})"; parse = ScriptParsed::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js"}})"; parse = ScriptParsed::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00"}})"; + {"scriptId":"100"}})"; parse = ScriptParsed::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(parse, nullptr); @@ -746,7 +746,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptParsedCreateTest) EXPECT_EQ(parse, nullptr); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"100", "url":"use/test.js", "startLine":0, "startColumn":4, @@ -761,7 +761,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptParsedCreateTest) "isModule":true, "length":34, "stackTrace":{"callFrames":[{"callFrameId":"10","functionName":"name0", - "location":{"scriptId":"id5","lineNumber":19},"url":"url7", + "location":{"scriptId":"5","lineNumber":19},"url":"url7", "scopeChain":[{"type":"global","object":{"type":"object"}}, {"type":"local","object":{"type":"object"}}], "this":{"type":"object","subtype":"v128"}}]}, "codeOffset":432, @@ -779,7 +779,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptParsedToObjectTest) Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "params"); msg = CString() + R"({"id":0,"method":"Debugger.Test","params": - {"scriptId":"00", + {"scriptId":"10", "url":"use/test.js", "startLine":0, "startColumn":4, @@ -794,7 +794,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptParsedToObjectTest) "isModule":true, "length":34, "stackTrace":{"callFrames":[{"callFrameId":"10","functionName":"name0", - "location":{"scriptId":"id5","lineNumber":19},"url":"url7", + "location":{"scriptId":"5","lineNumber":19},"url":"url7", "scopeChain":[{"type":"global","object":{"type":"object"}}, {"type":"local","object":{"type":"object"}}], "this":{"type":"object","subtype":"v128"}}]}, "codeOffset":432, @@ -814,13 +814,13 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptParsedToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("00", Local(result)->ToString()); + EXPECT_EQ("10", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "url"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("use/test.js", Local(result)->ToString()); + EXPECT_EQ("use/test.js", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "startLine"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); @@ -856,7 +856,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptParsedToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("hash0001", Local(result)->ToString()); + EXPECT_EQ("hash0001", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "executionContextAuxData"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); @@ -874,7 +874,7 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptParsedToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("usr/", Local(result)->ToString()); + EXPECT_EQ("usr/", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "hasSourceURL"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); @@ -904,12 +904,12 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptParsedToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("JavaScript", Local(result)->ToString()); + EXPECT_EQ("JavaScript", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "embedderName"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("hh", Local(result)->ToString()); + EXPECT_EQ("hh", DebuggerApi::ToCString(result)); } } // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tooling/test/debugger_returns_test.cpp b/ecmascript/tooling/test/debugger_returns_test.cpp index 1dc5b1abfc..fbf67b3909 100644 --- a/ecmascript/tooling/test/debugger_returns_test.cpp +++ b/ecmascript/tooling/test/debugger_returns_test.cpp @@ -64,23 +64,23 @@ protected: HWTEST_F_L0(DebuggerReturnsTest, EnableReturnsToObjectTest) { - std::unique_ptr enableReturns = std::make_unique("100"); + std::unique_ptr enableReturns = std::make_unique(100U); ASSERT_NE(enableReturns, nullptr); Local enableObject = enableReturns->ToObject(ecmaVm); Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "debuggerId"); ASSERT_TRUE(enableObject->Has(ecmaVm, tmpStr)); Local result = enableObject->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(std::string("100"), Local(result)->ToString()); + EXPECT_EQ(CString("100"), DebuggerApi::ToCString(result)); } HWTEST_F_L0(DebuggerReturnsTest, SetBreakpointByUrlReturnsToObjectTest) { auto locations = CVector>(); std::unique_ptr location = std::make_unique(); - location->SetScriptId("id_1"); + location->SetScriptId(1); locations.emplace_back(std::move(location)); - ASSERT_EQ(locations.back()->GetScriptId(), "id_1"); + ASSERT_EQ(locations.back()->GetScriptId(), 1U); std::unique_ptr setBreakpointByUrlReturns = std::make_unique("11", std::move(locations)); @@ -90,7 +90,7 @@ HWTEST_F_L0(DebuggerReturnsTest, SetBreakpointByUrlReturnsToObjectTest) ASSERT_TRUE(setObject->Has(ecmaVm, tmpStr)); Local result = setObject->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(std::string("11"), Local(result)->ToString()); + EXPECT_EQ(CString("11"), DebuggerApi::ToCString(result)); } HWTEST_F_L0(DebuggerReturnsTest, EvaluateOnCallFrameReturnsToObjectTest) @@ -138,13 +138,13 @@ HWTEST_F_L0(DebuggerReturnsTest, GetScriptSourceReturnsToObjectTest) ASSERT_TRUE(scriptObject->Has(ecmaVm, tmpStr)); Local result = scriptObject->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(std::string("source_1"), Local(result)->ToString()); + EXPECT_EQ(CString("source_1"), DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "bytecode"); ASSERT_TRUE(scriptObject->Has(ecmaVm, tmpStr)); result = scriptObject->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(std::string("bytecode_1"), Local(result)->ToString()); + EXPECT_EQ(CString("bytecode_1"), DebuggerApi::ToCString(result)); } HWTEST_F_L0(DebuggerReturnsTest, RestartFrameReturnsToObjectTest) @@ -172,7 +172,7 @@ HWTEST_F_L0(DebuggerReturnsTest, SetBreakpointReturnsToObjectTest) ASSERT_TRUE(breakObject->Has(ecmaVm, tmpStr)); Local result = breakObject->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(std::string("breakpointId_1"), Local(result)->ToString()); + EXPECT_EQ(CString("breakpointId_1"), DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "actualLocation"); ASSERT_TRUE(breakObject->Has(ecmaVm, tmpStr)); @@ -191,7 +191,7 @@ HWTEST_F_L0(DebuggerReturnsTest, SetInstrumentationBreakpointReturnsToObjectTest ASSERT_TRUE(instrumentationObject->Has(ecmaVm, tmpStr)); Local result = instrumentationObject->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(std::string("111"), Local(result)->ToString()); + EXPECT_EQ(CString("111"), DebuggerApi::ToCString(result)); } HWTEST_F_L0(DebuggerReturnsTest, SetScriptSourceReturnsToObjectTest) @@ -209,8 +209,8 @@ HWTEST_F_L0(DebuggerReturnsTest, SetScriptSourceReturnsToObjectTest) ASSERT_TRUE(result->IsArray(ecmaVm)); ASSERT_NE(setScriptSourceReturns, nullptr); - exceptionDetails->SetScriptId("id_5"); - ASSERT_EQ(exceptionDetails->GetScriptId(), "id_5"); + exceptionDetails->SetScriptId(5); + ASSERT_EQ(exceptionDetails->GetScriptId(), 5U); } HWTEST_F_L0(DebuggerReturnsTest, GetPropertiesReturnsToObjectTest) @@ -221,8 +221,8 @@ HWTEST_F_L0(DebuggerReturnsTest, GetPropertiesReturnsToObjectTest) std::unique_ptr getPropertiesReturns = std::make_unique (std::move(descriptor)); ASSERT_NE(getPropertiesReturns, nullptr); - exceptionDetails->SetScriptId("id_6"); - ASSERT_EQ(exceptionDetails->GetScriptId(), "id_6"); + exceptionDetails->SetScriptId(6); + ASSERT_EQ(exceptionDetails->GetScriptId(), 6U); Local getObject = getPropertiesReturns->ToObject(ecmaVm); Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "result"); diff --git a/ecmascript/tooling/test/debugger_script_test.cpp b/ecmascript/tooling/test/debugger_script_test.cpp index d49961318b..09b8a5dfb3 100644 --- a/ecmascript/tooling/test/debugger_script_test.cpp +++ b/ecmascript/tooling/test/debugger_script_test.cpp @@ -62,8 +62,8 @@ protected: HWTEST_F_L0(DebuggerScriptTest, ScriptIdTest) { std::unique_ptr script = std::make_unique(1, "name_1", "url_1", "source_1"); - script->SetScriptId("id_100"); - ASSERT_EQ(script->GetScriptId(), "id_100"); + script->SetScriptId(100); + ASSERT_EQ(script->GetScriptId(), 100U); } HWTEST_F_L0(DebuggerScriptTest, FileNameTest) diff --git a/ecmascript/tooling/test/debugger_types_test.cpp b/ecmascript/tooling/test/debugger_types_test.cpp index d7e19ac047..c3a18a012d 100644 --- a/ecmascript/tooling/test/debugger_types_test.cpp +++ b/ecmascript/tooling/test/debugger_types_test.cpp @@ -178,7 +178,7 @@ HWTEST_F_L0(DebuggerTypesTest, RemoteObjectCreateTest) ASSERT_NE(remoteObject, nullptr); EXPECT_EQ(ObjectType::Object, remoteObject->GetType()); ASSERT_TRUE(remoteObject->HasValue()); - EXPECT_EQ("Test", Local(remoteObject->GetValue())->ToString()); + EXPECT_EQ("Test", DebuggerApi::ToCString(remoteObject->GetValue())); // abnormal params of params.sub-key = [ type = "object", unserializableValue = 100] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + @@ -236,12 +236,12 @@ HWTEST_F_L0(DebuggerTypesTest, RemoteObjectCreateTest) // normal params of params.sub-key = [ type = "object", objectId = "id_1"] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + - R"(","objectId":"id_1"}})"; + R"(","objectId":"1"}})"; remoteObject = RemoteObject::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(remoteObject, nullptr); EXPECT_EQ(ObjectType::Object, remoteObject->GetType()); ASSERT_TRUE(remoteObject->HasObjectId()); - EXPECT_EQ("id_1", remoteObject->GetObjectId()); + EXPECT_EQ(1U, remoteObject->GetObjectId()); } HWTEST_F_L0(DebuggerTypesTest, RemoteObjectToObjectTest) @@ -253,7 +253,7 @@ HWTEST_F_L0(DebuggerTypesTest, RemoteObjectToObjectTest) msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::Array + - R"(","className":"TestClass","value":100,"unserializableValue":"Test","description":"Test","objectId":"id_1"}})"; + R"(","className":"TestClass","value":100,"unserializableValue":"Test","description":"Test","objectId":"1"}})"; remoteObject = RemoteObject::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(remoteObject, nullptr); Local object = remoteObject->ToObject(ecmaVm); @@ -262,17 +262,17 @@ HWTEST_F_L0(DebuggerTypesTest, RemoteObjectToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); Local result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(std::string(ObjectType::Object.c_str()), Local(result)->ToString()); + EXPECT_EQ(CString(ObjectType::Object.c_str()), DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "subtype"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(std::string(ObjectSubType::Array.c_str()), Local(result)->ToString()); + EXPECT_EQ(CString(ObjectSubType::Array.c_str()), DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "className"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("TestClass", Local(result)->ToString()); + EXPECT_EQ("TestClass", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "value"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); @@ -282,17 +282,17 @@ HWTEST_F_L0(DebuggerTypesTest, RemoteObjectToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("Test", Local(result)->ToString()); + EXPECT_EQ("Test", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "description"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("Test", Local(result)->ToString()); + EXPECT_EQ("Test", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "objectId"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("id_1", Local(result)->ToString()); + EXPECT_EQ("1", DebuggerApi::ToCString(result)); } HWTEST_F_L0(DebuggerTypesTest, ExceptionDetailsCreateTest) @@ -395,14 +395,14 @@ HWTEST_F_L0(DebuggerTypesTest, ExceptionDetailsCreateTest) // normal params of params.sub-key = // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"scriptId"="id0"] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"scriptId":"id0"}})"; + "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"scriptId":"0"}})"; exceptionMetaData = ExceptionDetails::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(exceptionMetaData, nullptr); EXPECT_EQ(exceptionMetaData->GetExceptionId(), 3); EXPECT_EQ("text0", exceptionMetaData->GetText()); EXPECT_EQ(exceptionMetaData->GetLine(), 10); EXPECT_EQ(exceptionMetaData->GetColumn(), 20); - EXPECT_EQ("id0", exceptionMetaData->GetScriptId()); + EXPECT_EQ(0U, exceptionMetaData->GetScriptId()); // abnormal params of params.sub-key = // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"url"=10] @@ -494,7 +494,7 @@ HWTEST_F_L0(DebuggerTypesTest, ExceptionDetailsToObjectTest) Local tmpStr; msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "exceptionId":5,"text":"text0","lineNumber":10,"columnNumber":20,"scriptId":"ScriptId0","url":"url0", + "exceptionId":5,"text":"text0","lineNumber":10,"columnNumber":20,"scriptId":"100","url":"url0", "exception":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::Error + R"("},"executionContextId":30}})"; exceptionMetaData = ExceptionDetails::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); @@ -510,7 +510,7 @@ HWTEST_F_L0(DebuggerTypesTest, ExceptionDetailsToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("text0", Local(result)->ToString()); + EXPECT_EQ("text0", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "lineNumber"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); @@ -525,12 +525,12 @@ HWTEST_F_L0(DebuggerTypesTest, ExceptionDetailsToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("ScriptId0", Local(result)->ToString()); + EXPECT_EQ("100", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "url"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("url0", Local(result)->ToString()); + EXPECT_EQ("url0", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "exception"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); @@ -540,12 +540,12 @@ HWTEST_F_L0(DebuggerTypesTest, ExceptionDetailsToObjectTest) ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); Local subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectType::Object.c_str()), Local(subResult)->ToString()); + EXPECT_EQ(CString(ObjectType::Object.c_str()), DebuggerApi::ToCString(subResult)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "subtype"); ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectSubType::Error.c_str()), Local(subResult)->ToString()); + EXPECT_EQ(CString(ObjectSubType::Error.c_str()), DebuggerApi::ToCString(subResult)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "executionContextId"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); @@ -659,7 +659,7 @@ HWTEST_F_L0(DebuggerTypesTest, InternalPropertyDescriptorToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); Local result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("name8", Local(result)->ToString()); + EXPECT_EQ("name8", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "value"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); @@ -669,12 +669,12 @@ HWTEST_F_L0(DebuggerTypesTest, InternalPropertyDescriptorToObjectTest) ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); Local subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectType::Object.c_str()), Local(subResult)->ToString()); + EXPECT_EQ(CString(ObjectType::Object.c_str()), DebuggerApi::ToCString(subResult)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "subtype"); ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectSubType::Map.c_str()), Local(subResult)->ToString()); + EXPECT_EQ(CString(ObjectSubType::Map.c_str()), DebuggerApi::ToCString(subResult)); } HWTEST_F_L0(DebuggerTypesTest, PropertyDescriptorCreateTest) @@ -927,7 +927,7 @@ HWTEST_F_L0(DebuggerTypesTest, PropertyDescriptorToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); Local result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("name8", Local(result)->ToString()); + EXPECT_EQ("name8", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "value"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); @@ -937,12 +937,12 @@ HWTEST_F_L0(DebuggerTypesTest, PropertyDescriptorToObjectTest) ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); Local subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectType::Object.c_str()), Local(subResult)->ToString()); + EXPECT_EQ(CString(ObjectType::Object.c_str()), DebuggerApi::ToCString(subResult)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "subtype"); ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectSubType::Map.c_str()), Local(subResult)->ToString()); + EXPECT_EQ(CString(ObjectSubType::Map.c_str()), DebuggerApi::ToCString(subResult)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "writable"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); @@ -957,12 +957,12 @@ HWTEST_F_L0(DebuggerTypesTest, PropertyDescriptorToObjectTest) ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectType::Object.c_str()), Local(subResult)->ToString()); + EXPECT_EQ(CString(ObjectType::Object.c_str()), DebuggerApi::ToCString(subResult)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "subtype"); ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectSubType::Regexp.c_str()), Local(subResult)->ToString()); + EXPECT_EQ(CString(ObjectSubType::Regexp.c_str()), DebuggerApi::ToCString(subResult)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "set"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); @@ -972,12 +972,12 @@ HWTEST_F_L0(DebuggerTypesTest, PropertyDescriptorToObjectTest) ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectType::Object.c_str()), Local(subResult)->ToString()); + EXPECT_EQ(CString(ObjectType::Object.c_str()), DebuggerApi::ToCString(subResult)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "subtype"); ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectSubType::Generator.c_str()), Local(subResult)->ToString()); + EXPECT_EQ(CString(ObjectSubType::Generator.c_str()), DebuggerApi::ToCString(subResult)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "configurable"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); @@ -1007,12 +1007,12 @@ HWTEST_F_L0(DebuggerTypesTest, PropertyDescriptorToObjectTest) ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectType::Object.c_str()), Local(subResult)->ToString()); + EXPECT_EQ(CString(ObjectType::Object.c_str()), DebuggerApi::ToCString(subResult)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "subtype"); ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectSubType::Proxy.c_str()), Local(subResult)->ToString()); + EXPECT_EQ(CString(ObjectSubType::Proxy.c_str()), DebuggerApi::ToCString(subResult)); } HWTEST_F_L0(DebuggerTypesTest, LocationCreateTest) @@ -1054,44 +1054,44 @@ HWTEST_F_L0(DebuggerTypesTest, LocationCreateTest) location = Location::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(location, nullptr); - // abnormal params of params.sub-key=["scriptId":"id222","lineNumber":"99"] + // abnormal params of params.sub-key=["scriptId":"222","lineNumber":"99"] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "scriptId":"id222","lineNumber":"99" + "scriptId":"222","lineNumber":"99" }})"; location = Location::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(location, nullptr); - // abnormal params of params.sub-key=["scriptId":"id222","lineNumber":[99]] + // abnormal params of params.sub-key=["scriptId":"222","lineNumber":[99]] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "scriptId":"id222","lineNumber":[99] + "scriptId":"222","lineNumber":[99] }})"; location = Location::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(location, nullptr); - // abnormal params of params.sub-key=["scriptId":"id2","lineNumber":99,"columnNumber":"18"] + // abnormal params of params.sub-key=["scriptId":"2","lineNumber":99,"columnNumber":"18"] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "scriptId":"id222","lineNumber":899,"columnNumber":"18" + "scriptId":"222","lineNumber":899,"columnNumber":"18" }})"; location = Location::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(location, nullptr); - // normal params of params.sub-key=["scriptId":"id2","lineNumber":99,"columnNumber":138] + // normal params of params.sub-key=["scriptId":"2","lineNumber":99,"columnNumber":138] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "scriptId":"id222","lineNumber":899,"columnNumber":138 + "scriptId":"222","lineNumber":899,"columnNumber":138 }})"; location = Location::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(location, nullptr); - EXPECT_EQ("id222", location->GetScriptId()); + EXPECT_EQ(222U, location->GetScriptId()); EXPECT_EQ(location->GetLine(), 899); EXPECT_EQ(location->GetColumn(), 138); - // normal params of params.sub-key=["scriptId":"id2122","lineNumber":8299] + // normal params of params.sub-key=["scriptId":"2122","lineNumber":8299] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "scriptId":"id2122","lineNumber":8299 + "scriptId":"2122","lineNumber":8299 }})"; location = Location::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(location, nullptr); - EXPECT_EQ("id2122", location->GetScriptId()); + EXPECT_EQ(2122U, location->GetScriptId()); EXPECT_EQ(location->GetLine(), 8299); } @@ -1102,7 +1102,7 @@ HWTEST_F_L0(DebuggerTypesTest, LocationToObjectTest) Local tmpStr; msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "scriptId":"id2","lineNumber":99,"columnNumber":18 + "scriptId":"2","lineNumber":99,"columnNumber":18 }})"; location = Location::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(location, nullptr); @@ -1112,7 +1112,7 @@ HWTEST_F_L0(DebuggerTypesTest, LocationToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); Local result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("id2", Local(result)->ToString()); + EXPECT_EQ("2", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "lineNumber"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); @@ -1164,59 +1164,59 @@ HWTEST_F_L0(DebuggerTypesTest, BreakLocationCreateTest) breakLocation = BreakLocation::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(breakLocation, nullptr); - // abnormal params of params.sub-key=["scriptId":"id222","lineNumber":"99"] + // abnormal params of params.sub-key=["scriptId":"222","lineNumber":"99"] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "scriptId":"id222","lineNumber":"99" + "scriptId":"222","lineNumber":"99" }})"; breakLocation = BreakLocation::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(breakLocation, nullptr); - // abnormal params of params.sub-key=["scriptId":"id222","lineNumber":[99]] + // abnormal params of params.sub-key=["scriptId":"222","lineNumber":[99]] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "scriptId":"id222","lineNumber":[99] + "scriptId":"222","lineNumber":[99] }})"; breakLocation = BreakLocation::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(breakLocation, nullptr); - // abnormal params of params.sub-key=["scriptId":"id2","lineNumber":99,"columnNumber":"18"] + // abnormal params of params.sub-key=["scriptId":"2","lineNumber":99,"columnNumber":"18"] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "scriptId":"id222","lineNumber":899,"columnNumber":"18" + "scriptId":"222","lineNumber":899,"columnNumber":"18" }})"; breakLocation = BreakLocation::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(breakLocation, nullptr); - // abnormal params of params.sub-key=["scriptId":"id2","lineNumber":99,"columnNumber":"18","type":10] + // abnormal params of params.sub-key=["scriptId":"2","lineNumber":99,"columnNumber":"18","type":10] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "scriptId":"id222","lineNumber":899,"columnNumber":"18","type":10 + "scriptId":"222","lineNumber":899,"columnNumber":"18","type":10 }})"; breakLocation = BreakLocation::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(breakLocation, nullptr); - // abnormal params of params.sub-key=["scriptId":"id2","lineNumber":99,"columnNumber":"18","type":"ee"] + // abnormal params of params.sub-key=["scriptId":"2","lineNumber":99,"columnNumber":"18","type":"ee"] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "scriptId":"id222","lineNumber":899,"columnNumber":"18","type":"ee" + "scriptId":"222","lineNumber":899,"columnNumber":"18","type":"ee" }})"; breakLocation = BreakLocation::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); EXPECT_EQ(breakLocation, nullptr); - // normal params of params.sub-key=["scriptId":"id2","lineNumber":99,"columnNumber":138,"type":"return"] + // normal params of params.sub-key=["scriptId":"2","lineNumber":99,"columnNumber":138,"type":"return"] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "scriptId":"id222","lineNumber":899,"columnNumber":138,"type":"return" + "scriptId":"222","lineNumber":899,"columnNumber":138,"type":"return" }})"; breakLocation = BreakLocation::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(breakLocation, nullptr); - EXPECT_EQ("id222", breakLocation->GetScriptId()); + EXPECT_EQ(222U, breakLocation->GetScriptId()); EXPECT_EQ(breakLocation->GetLine(), 899); EXPECT_EQ(breakLocation->GetColumn(), 138); EXPECT_EQ("return", breakLocation->GetType()); - // normal params of params.sub-key=["scriptId":"id2122","lineNumber":8299] + // normal params of params.sub-key=["scriptId":"2122","lineNumber":8299] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "scriptId":"id2122","lineNumber":8299 + "scriptId":"2122","lineNumber":8299 }})"; breakLocation = BreakLocation::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(breakLocation, nullptr); - EXPECT_EQ("id2122", breakLocation->GetScriptId()); + EXPECT_EQ(2122U, breakLocation->GetScriptId()); EXPECT_EQ(breakLocation->GetLine(), 8299); } @@ -1227,7 +1227,7 @@ HWTEST_F_L0(DebuggerTypesTest, BreakLocationToObjectTest) Local tmpStr; msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "scriptId":"id12","lineNumber":919,"columnNumber":148,"type":"call" + "scriptId":"12","lineNumber":919,"columnNumber":148,"type":"call" }})"; breakLocation = BreakLocation::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(breakLocation, nullptr); @@ -1237,7 +1237,7 @@ HWTEST_F_L0(DebuggerTypesTest, BreakLocationToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); Local result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("id12", Local(result)->ToString()); + EXPECT_EQ("12", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "lineNumber"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); @@ -1252,7 +1252,7 @@ HWTEST_F_L0(DebuggerTypesTest, BreakLocationToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("call", Local(result)->ToString()); + EXPECT_EQ("call", DebuggerApi::ToCString(result)); } HWTEST_F_L0(DebuggerTypesTest, ScopeCreateTest) @@ -1378,8 +1378,8 @@ HWTEST_F_L0(DebuggerTypesTest, ScopeToObjectTest) msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ "type":"global","object":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::Dataview + R"("},"name":"name9", - "startLocation":{"scriptId":"id2","lineNumber":99}, - "endLocation":{"scriptId":"id13","lineNumber":146} + "startLocation":{"scriptId":"2","lineNumber":99}, + "endLocation":{"scriptId":"13","lineNumber":146} }})"; scope = Scope::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(scope, nullptr); @@ -1389,7 +1389,7 @@ HWTEST_F_L0(DebuggerTypesTest, ScopeToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); Local result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("global", Local(result)->ToString()); + EXPECT_EQ("global", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "object"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); @@ -1399,17 +1399,17 @@ HWTEST_F_L0(DebuggerTypesTest, ScopeToObjectTest) ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); Local subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectType::Object.c_str()), Local(subResult)->ToString()); + EXPECT_EQ(CString(ObjectType::Object.c_str()), DebuggerApi::ToCString(subResult)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "subtype"); ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectSubType::Dataview.c_str()), Local(subResult)->ToString()); + EXPECT_EQ(CString(ObjectSubType::Dataview.c_str()), DebuggerApi::ToCString(subResult)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "name"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("name9", Local(result)->ToString()); + EXPECT_EQ("name9", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "startLocation"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); @@ -1419,7 +1419,7 @@ HWTEST_F_L0(DebuggerTypesTest, ScopeToObjectTest) ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ("id2", Local(subResult)->ToString()); + EXPECT_EQ("2", DebuggerApi::ToCString(subResult)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "lineNumber"); ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); @@ -1434,7 +1434,7 @@ HWTEST_F_L0(DebuggerTypesTest, ScopeToObjectTest) ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ("id13", Local(subResult)->ToString()); + EXPECT_EQ("13", DebuggerApi::ToCString(subResult)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "lineNumber"); ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); @@ -1470,7 +1470,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) // abnormal params of params.sub-key=[..] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ "callFrameId":10,"functionName":"name0", - "location":{"scriptId":"id5","lineNumber":19},"url":"url7","scopeChain": + "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain": [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; @@ -1479,8 +1479,8 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) // abnormal params of params.sub-key=[..] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "callFrameId":["id0"],"functionName":"name0", - "location":{"scriptId":"id5","lineNumber":19},"url":"url7","scopeChain": + "callFrameId":["0"],"functionName":"name0", + "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain": [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; @@ -1489,8 +1489,8 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) // abnormal params of params.sub-key=[..] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "callFrameId":"id0","functionName":10, - "location":{"scriptId":"id5","lineNumber":19},"url":"url7","scopeChain": + "callFrameId":"0","functionName":10, + "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain": [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; @@ -1499,8 +1499,8 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) // abnormal params of params.sub-key=[..] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "callFrameId":"id0","functionName":["name0"], - "location":{"scriptId":"id5","lineNumber":19},"url":"url7","scopeChain": + "callFrameId":"0","functionName":["name0"], + "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain": [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; @@ -1509,8 +1509,8 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) // abnormal params of params.sub-key=[..] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "callFrameId":"id0","functionName":"name0","functionLocation":10, - "location":{"scriptId":"id5","lineNumber":19},"url":"url7","scopeChain": + "callFrameId":"0","functionName":"name0","functionLocation":10, + "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain": [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; @@ -1519,8 +1519,8 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) // abnormal params of params.sub-key=[..] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "callFrameId":"id0","functionName":"name0","functionLocation":{"scriptId11":"id5","lineNumber":19}, - "location":{"scriptId":"id5","lineNumber":19},"url":"url7","scopeChain": + "callFrameId":"0","functionName":"name0","functionLocation":{"scriptId11":"id5","lineNumber":19}, + "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain": [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; @@ -1529,7 +1529,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) // abnormal params of params.sub-key=[..] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "callFrameId":"id0","functionName":"name0", + "callFrameId":"0","functionName":"name0", "location":{"scriptId2":"id5","lineNumber":19},"url":"url7","scopeChain": [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + @@ -1539,7 +1539,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) // abnormal params of params.sub-key=[..] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "callFrameId":"id0","functionName":"name0", + "callFrameId":"0","functionName":"name0", "location":10,"url":"url7","scopeChain": [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + @@ -1549,8 +1549,8 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) // abnormal params of params.sub-key=[..] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "callFrameId":"id0","functionName":"name0", - "location":{"scriptId":"id5","lineNumber":19},"url":10,"scopeChain": + "callFrameId":"0","functionName":"name0", + "location":{"scriptId":"5","lineNumber":19},"url":10,"scopeChain": [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; @@ -1559,8 +1559,8 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) // abnormal params of params.sub-key=[..] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "callFrameId":"id0","functionName":"name0", - "location":{"scriptId":"id5","lineNumber":19},"url":{"url":"url7"},"scopeChain": + "callFrameId":"0","functionName":"name0", + "location":{"scriptId":"5","lineNumber":19},"url":{"url":"url7"},"scopeChain": [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; @@ -1569,7 +1569,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) // abnormal params of params.sub-key=[..] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "callFrameId":"id0","functionName":"name0", "location":{"scriptId":"id5","lineNumber":19}, + "callFrameId":"0","functionName":"name0", "location":{"scriptId":"5","lineNumber":19}, "url":"url7","scopeChain":10,"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; callFrame = CallFrame::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); @@ -1577,8 +1577,8 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) // abnormal params of params.sub-key=[..] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "callFrameId":"id0","functionName":"name0", - "location":{"scriptId":"id5","lineNumber":19},"url":"url7","scopeChain": + "callFrameId":"0","functionName":"name0", + "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain": {"type":"22","object":{"type":")" + ObjectType::Object + R"("}},"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; @@ -1587,8 +1587,8 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) // abnormal params of params.sub-key=[..] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "callFrameId":"id0","functionName":"name0", - "location":{"scriptId":"id5","lineNumber":19},"url":"url7","scopeChain": + "callFrameId":"0","functionName":"name0", + "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain": [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":10}})"; @@ -1597,8 +1597,8 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) // abnormal params of params.sub-key=[..] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "callFrameId":"id0","functionName":"name0", - "location":{"scriptId":"id5","lineNumber":19},"url":"url7","scopeChain": + "callFrameId":"0","functionName":"name0", + "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain": [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"11":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; @@ -1607,8 +1607,8 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) // abnormal params of params.sub-key=[..] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "callFrameId":"id0","functionName":"name0", - "location":{"scriptId":"id5","lineNumber":19},"url":"url7","scopeChain": + "callFrameId":"0","functionName":"name0", + "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain": [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}, @@ -1618,8 +1618,8 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) // abnormal params of params.sub-key=[..] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "callFrameId":"id0","functionName":"name0", - "location":{"scriptId":"id5","lineNumber":19},"url":"url7","scopeChain": + "callFrameId":"0","functionName":"name0", + "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain": [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}, @@ -1629,18 +1629,18 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) // normal params of params.sub-key=[..] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "callFrameId":"id0","functionName":"name0", - "location":{"scriptId":"id5","lineNumber":19},"url":"url7","scopeChain": + "callFrameId":"0","functionName":"name0", + "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain": [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; callFrame = CallFrame::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(callFrame, nullptr); - EXPECT_EQ("id0", callFrame->GetCallFrameId()); + EXPECT_EQ(0U, callFrame->GetCallFrameId()); EXPECT_EQ("name0", callFrame->GetFunctionName()); ASSERT_FALSE(callFrame->HasFunctionLocation()); Location *location = callFrame->GetLocation(); - EXPECT_EQ("id5", location->GetScriptId()); + EXPECT_EQ(5U, location->GetScriptId()); EXPECT_EQ(location->GetLine(), 19); EXPECT_EQ("url7", callFrame->GetUrl()); const CVector> *scopeChain = callFrame->GetScopeChain(); @@ -1653,21 +1653,21 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) // normal params of params.sub-key=[..] msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "callFrameId":"id0","functionName":"name0","functionLocation":{"scriptId":"id3","lineNumber":16}, - "location":{"scriptId":"id5","lineNumber":19},"url":"url7","scopeChain": + "callFrameId":"10","functionName":"name0","functionLocation":{"scriptId":"3","lineNumber":16}, + "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain": [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("},"returnValue":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::I32 + R"("}}})"; callFrame = CallFrame::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams()); ASSERT_NE(callFrame, nullptr); - EXPECT_EQ("id0", callFrame->GetCallFrameId()); + EXPECT_EQ(10U, callFrame->GetCallFrameId()); EXPECT_EQ("name0", callFrame->GetFunctionName()); Location *functionLocation = callFrame->GetFunctionLocation(); - EXPECT_EQ("id3", functionLocation->GetScriptId()); + EXPECT_EQ(3U, functionLocation->GetScriptId()); EXPECT_EQ(functionLocation->GetLine(), 16); location = callFrame->GetLocation(); - EXPECT_EQ("id5", location->GetScriptId()); + EXPECT_EQ(5U, location->GetScriptId()); EXPECT_EQ(location->GetLine(), 19); EXPECT_EQ("url7", callFrame->GetUrl()); scopeChain = callFrame->GetScopeChain(); @@ -1689,8 +1689,8 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameToObjectTest) Local tmpStr; msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{ - "callFrameId":"id0","functionName":"name0","functionLocation":{"scriptId":"id3","lineNumber":16}, - "location":{"scriptId":"id5","lineNumber":19},"url":"url7","scopeChain": + "callFrameId":"0","functionName":"name0","functionLocation":{"scriptId":"3","lineNumber":16}, + "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain": [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::Iterator + @@ -1703,12 +1703,12 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); Local result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("id0", Local(result)->ToString()); + EXPECT_EQ("0", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "functionName"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("name0", Local(result)->ToString()); + EXPECT_EQ("name0", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "functionLocation"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); @@ -1718,7 +1718,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameToObjectTest) ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); Local subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ("id3", Local(subResult)->ToString()); + EXPECT_EQ("3", DebuggerApi::ToCString(subResult)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "lineNumber"); ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); @@ -1733,7 +1733,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameToObjectTest) ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ("id5", Local(subResult)->ToString()); + EXPECT_EQ("5", DebuggerApi::ToCString(subResult)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "lineNumber"); ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); @@ -1743,7 +1743,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameToObjectTest) ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("url7", Local(result)->ToString()); + EXPECT_EQ("url7", DebuggerApi::ToCString(result)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "scopeChain"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); @@ -1760,12 +1760,12 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameToObjectTest) ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectType::Object.c_str()), Local(subResult)->ToString()); + EXPECT_EQ(CString(ObjectType::Object.c_str()), DebuggerApi::ToCString(subResult)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "subtype"); ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectSubType::Iterator.c_str()), Local(subResult)->ToString()); + EXPECT_EQ(CString(ObjectSubType::Iterator.c_str()), DebuggerApi::ToCString(subResult)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "returnValue"); ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); result = object->Get(ecmaVm, tmpStr); @@ -1775,11 +1775,11 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameToObjectTest) ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectType::Object.c_str()), Local(subResult)->ToString()); + EXPECT_EQ(CString(ObjectType::Object.c_str()), DebuggerApi::ToCString(subResult)); tmpStr = StringRef::NewFromUtf8(ecmaVm, "subtype"); ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); subResult = Local(result)->Get(ecmaVm, tmpStr); ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectSubType::I64.c_str()), Local(subResult)->ToString()); + EXPECT_EQ(CString(ObjectSubType::I64.c_str()), DebuggerApi::ToCString(subResult)); } } // namespace panda::test diff --git a/ecmascript/tooling/test/js_pt_hooks_test.cpp b/ecmascript/tooling/test/js_pt_hooks_test.cpp index efb1d62250..24c6c7a5e5 100644 --- a/ecmascript/tooling/test/js_pt_hooks_test.cpp +++ b/ecmascript/tooling/test/js_pt_hooks_test.cpp @@ -371,7 +371,7 @@ HWTEST_F_L0(JSPtHooksTest, ExceptionRevokedTest) { auto backend = std::make_unique(ecmaVm); std::unique_ptrjspthooks = std::make_unique(backend.get()); - jspthooks->ExceptionRevoked(std::string(), panda_file::File::EntityId()); + jspthooks->ExceptionRevoked("", panda_file::File::EntityId()); ASSERT_NE(jspthooks, nullptr); } diff --git a/ecmascript/tooling/test/utils/test_extractor.cpp b/ecmascript/tooling/test/utils/test_extractor.cpp index 5e1a9027f6..08839e0afa 100644 --- a/ecmascript/tooling/test/utils/test_extractor.cpp +++ b/ecmascript/tooling/test/utils/test_extractor.cpp @@ -42,7 +42,7 @@ std::pair TestExtractor::GetBreakpointAddress(const SourceLo SourceLocation TestExtractor::GetSourceLocation(EntityId methodId, uint32_t bytecodeOffset) { SourceLocation location {GetSourceFile(methodId), 0, 0}; - auto callbackFunc = [&location](size_t line, size_t column) -> bool { + auto callbackFunc = [&location](int32_t line, int32_t column) -> bool { location.line = line; location.column = column; return true; diff --git a/ecmascript/tooling/test/utils/test_extractor.h b/ecmascript/tooling/test/utils/test_extractor.h index eb32ab1903..6388a479cd 100644 --- a/ecmascript/tooling/test/utils/test_extractor.h +++ b/ecmascript/tooling/test/utils/test_extractor.h @@ -16,19 +16,17 @@ #ifndef ECMASCRIPT_TOOLING_TEST_UTILS_TEST_EXTRACTOR_H #define ECMASCRIPT_TOOLING_TEST_UTILS_TEST_EXTRACTOR_H -#include "ecmascript/mem/c_string.h" #include "ecmascript/tooling/js_pt_extractor.h" namespace panda::tooling::ecmascript::test { using EntityId = panda_file::File::EntityId; using panda::ecmascript::CString; -using panda::tooling::ecmascript::JSPtExtractor; // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) struct SourceLocation { CString path; // NOLINT(misc-non-private-member-variables-in-classes) - size_t line; // NOLINT(misc-non-private-member-variables-in-classes) - size_t column; + int32_t line; // NOLINT(misc-non-private-member-variables-in-classes) + int32_t column; bool operator==(const SourceLocation &other) const { @@ -43,7 +41,7 @@ struct SourceLocation { class TestExtractor : public JSPtExtractor { public: - explicit TestExtractor(const panda_file::File *pandaFileData) : JSPtExtractor(pandaFileData) {} + explicit TestExtractor(const JSPandaFile *pandaFile) : JSPtExtractor(pandaFile) {} ~TestExtractor() = default; std::pair GetBreakpointAddress(const SourceLocation &sourceLocation); diff --git a/ecmascript/tooling/test/utils/test_util.h b/ecmascript/tooling/test/utils/test_util.h index 7c42b2743c..8a19373684 100644 --- a/ecmascript/tooling/test/utils/test_util.h +++ b/ecmascript/tooling/test/utils/test_util.h @@ -16,7 +16,7 @@ #ifndef ECMASCRIPT_TOOLING_TEST_UTILS_TEST_UTIL_H #define ECMASCRIPT_TOOLING_TEST_UTILS_TEST_UTIL_H -#include "ecmascript/mem/c_containers.h" +#include "ecmascript/jspandafile/js_pandafile_manager.h" #include "ecmascript/tooling/interface/js_debugger.h" #include "ecmascript/tooling/test/utils/test_events.h" #include "ecmascript/tooling/test/utils/test_extractor.h" @@ -123,26 +123,24 @@ public: return lastEvent_ == DebugEvent::VM_DEATH; } - static PtLocation GetLocation(const char *sourceFile, size_t line, size_t column, const char *pandaFile) + static PtLocation GetLocation(const char *sourceFile, int32_t line, int32_t column, const char *pandaFile) { - std::unique_ptr uFile = panda_file::File::Open(pandaFile); - const panda_file::File *pf = uFile.get(); - if (pf == nullptr) { + auto jsPandaFile = ::panda::ecmascript::JSPandaFileManager::GetInstance()->OpenJSPandaFile(pandaFile); + if (jsPandaFile == nullptr) { return PtLocation("", EntityId(0), 0); } - TestExtractor extractor(pf); + TestExtractor extractor(jsPandaFile); auto [id, offset] = extractor.GetBreakpointAddress({sourceFile, line, column}); return PtLocation(pandaFile, id, offset); } static SourceLocation GetSourceLocation(const PtLocation &location, const char *pandaFile) { - std::unique_ptr uFile = panda_file::File::Open(pandaFile); - const panda_file::File *pf = uFile.get(); - if (pf == nullptr) { + auto jsPandaFile = ::panda::ecmascript::JSPandaFileManager::GetInstance()->OpenJSPandaFile(pandaFile); + if (jsPandaFile == nullptr) { return SourceLocation(); } - TestExtractor extractor(pf); + TestExtractor extractor(jsPandaFile); return extractor.GetSourceLocation(location.GetMethodId(), location.GetBytecodeOffset()); } diff --git a/ecmascript/tooling/test/utils/testcases/js_breakpoint_test.h b/ecmascript/tooling/test/utils/testcases/js_breakpoint_test.h index 52856dc5f9..e5074122b1 100644 --- a/ecmascript/tooling/test/utils/testcases/js_breakpoint_test.h +++ b/ecmascript/tooling/test/utils/testcases/js_breakpoint_test.h @@ -16,7 +16,6 @@ #ifndef ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_BREAKPOINT_TEST_H #define ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_BREAKPOINT_TEST_H -#include "ecmascript/mem/c_string.h" #include "ecmascript/tooling/test/utils/test_util.h" namespace panda::tooling::ecmascript::test { diff --git a/ecmascript/tooling/test/utils/testcases/js_exception_test.h b/ecmascript/tooling/test/utils/testcases/js_exception_test.h index 8dd4cfdea7..48ff0c338e 100644 --- a/ecmascript/tooling/test/utils/testcases/js_exception_test.h +++ b/ecmascript/tooling/test/utils/testcases/js_exception_test.h @@ -16,7 +16,6 @@ #ifndef ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_EXCEPTION_TEST_H #define ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_EXCEPTION_TEST_H -#include "ecmascript/mem/c_string.h" #include "ecmascript/tooling/test/utils/test_util.h" namespace panda::tooling::ecmascript::test { diff --git a/ecmascript/tooling/test/utils/testcases/test_list.cpp b/ecmascript/tooling/test/utils/testcases/test_list.cpp index 0d7683c16b..594f3dc108 100644 --- a/ecmascript/tooling/test/utils/testcases/test_list.cpp +++ b/ecmascript/tooling/test/utils/testcases/test_list.cpp @@ -33,10 +33,10 @@ static void RegisterTests() TestUtil::RegisterTest(panda_file::SourceLang::ECMASCRIPT, "JsBreakpointTest", GetJsBreakpointTest()); } -std::vector GetTestList(panda_file::SourceLang language) +CVector GetTestList(panda_file::SourceLang language) { RegisterTests(); - std::vector res; + CVector res; auto &tests = TestUtil::GetTests(); auto languageIt = tests.find(language); if (languageIt == tests.end()) { diff --git a/ecmascript/tooling/test/utils/testcases/test_list.h b/ecmascript/tooling/test/utils/testcases/test_list.h index 047d159909..14b4b79152 100644 --- a/ecmascript/tooling/test/utils/testcases/test_list.h +++ b/ecmascript/tooling/test/utils/testcases/test_list.h @@ -19,13 +19,15 @@ #include #include +#include "ecmascript/mem/c_containers.h" #include "ecmascript/mem/c_string.h" #include "libpandafile/file_items.h" namespace panda::tooling::ecmascript::test { using panda::ecmascript::CString; +using panda::ecmascript::CVector; -std::vector GetTestList(panda_file::SourceLang language); +CVector GetTestList(panda_file::SourceLang language); void SetCurrentTestName(const char *testName); const char *GetCurrentTestName(); diff --git a/ecmascript/ts_types/ts_loader.cpp b/ecmascript/ts_types/ts_loader.cpp index da61276f54..83daf62afe 100644 --- a/ecmascript/ts_types/ts_loader.cpp +++ b/ecmascript/ts_types/ts_loader.cpp @@ -25,7 +25,7 @@ void TSLoader::DecodeTSTypes(const JSPandaFile *jsPandaFile) ObjectFactory *factory = vm_->GetFactory(); JSHandle table = GetTSModuleTable(); - JSHandle queryFileName = factory->NewFromStdString(jsPandaFile->GetJSPandaFileDesc()); + JSHandle queryFileName = factory->NewFromString(jsPandaFile->GetJSPandaFileDesc()); int index = table->GetGlobalModuleID(thread, queryFileName); if (index == TSModuleTable::NOT_FOUND) { CVector> recordImportModules {}; diff --git a/ecmascript/ts_types/ts_type_table.cpp b/ecmascript/ts_types/ts_type_table.cpp index b94b5d0bd2..ef07d18fba 100644 --- a/ecmascript/ts_types/ts_type_table.cpp +++ b/ecmascript/ts_types/ts_type_table.cpp @@ -33,7 +33,7 @@ void TSTypeTable::Initialize(JSThread *thread, const JSPandaFile *jsPandaFile, JSHandle tsTypetable = GenerateTypeTable(thread, jsPandaFile, recordImportModules); // Set TStypeTable -> GlobleModuleTable - JSHandle fileName = factory->NewFromStdString(jsPandaFile->GetJSPandaFileDesc()); + JSHandle fileName = factory->NewFromString(jsPandaFile->GetJSPandaFileDesc()); tsLoader->AddTypeTable(JSHandle(tsTypetable), fileName); // management dependency module @@ -63,7 +63,7 @@ JSHandle TSTypeTable::GenerateTypeTable(JSThread *thread, const JSP JSHandle table = factory->NewTSTypeTable(length); JSMutableHandle typeLiteral(thread, JSTaggedValue::Undefined()); - JSHandle fileName = factory->NewFromStdString(jsPandaFile->GetJSPandaFileDesc()); + JSHandle fileName = factory->NewFromString(jsPandaFile->GetJSPandaFileDesc()); for (; idx <= length; ++idx) { typeLiteral.Update(LiteralDataExtractor::GetDatasIgnoreType(thread, jsPandaFile, idx).GetTaggedValue()); JSHandle type = ParseType(thread, table, typeLiteral, fileName, recordImportModules); -- Gitee