mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-30 10:52:57 +00:00
适配热重载sourceMap解析
issues:https://gitee.com/openharmony/ability_ability_runtime/issues/I9NB8V Signed-off-by: rentangyu <rentangyu@huawei.com>
This commit is contained in:
parent
7b55168626
commit
93aa7d90d5
@ -430,7 +430,8 @@ void JsRuntime::StartProfiler(const DebugOption dOption)
|
||||
jsEnv_->StartProfiler(ARK_DEBUGGER_LIB_PATH, instanceId_, profiler, interval, getproctid(), isDebugApp);
|
||||
}
|
||||
|
||||
bool JsRuntime::GetFileBuffer(const std::string& filePath, std::string& fileFullName, std::vector<uint8_t>& buffer)
|
||||
bool JsRuntime::GetFileBuffer(const std::string& filePath, std::string& fileFullName, std::vector<uint8_t>& buffer,
|
||||
bool isABC)
|
||||
{
|
||||
Extractor extractor(filePath);
|
||||
if (!extractor.Init()) {
|
||||
@ -439,7 +440,11 @@ bool JsRuntime::GetFileBuffer(const std::string& filePath, std::string& fileFull
|
||||
}
|
||||
|
||||
std::vector<std::string> fileNames;
|
||||
extractor.GetSpecifiedTypeFiles(fileNames, ".abc");
|
||||
if (isABC) {
|
||||
extractor.GetSpecifiedTypeFiles(fileNames, ".abc");
|
||||
} else {
|
||||
extractor.GetSpecifiedTypeFiles(fileNames, ".map");
|
||||
}
|
||||
if (fileNames.empty()) {
|
||||
TAG_LOGW(
|
||||
AAFwkTag::JSRUNTIME, "GetFileBuffer, There's no abc file in hap or hqf %{private}s.", filePath.c_str());
|
||||
@ -465,6 +470,21 @@ bool JsRuntime::LoadRepairPatch(const std::string& hqfFile, const std::string& h
|
||||
auto vm = GetEcmaVm();
|
||||
CHECK_POINTER_AND_RETURN(vm, false);
|
||||
|
||||
std::string patchSoureMapFile;
|
||||
std::vector<uint8_t> soureMapBuffer;
|
||||
if (!GetFileBuffer(hqfFile, patchSoureMapFile, soureMapBuffer, false)) {
|
||||
TAG_LOGE(AAFwkTag::JSRUNTIME, "LoadRepairPatch, get patchSoureMap file buffer failed.");
|
||||
return false;
|
||||
}
|
||||
std::string str(soureMapBuffer.begin(), soureMapBuffer.end());
|
||||
auto sourceMapOperator = jsEnv_->GetSourceMapOperator();
|
||||
if (sourceMapOperator != nullptr) {
|
||||
auto sourceMapObj = sourceMapOperator->GetSourceMapObj();
|
||||
if (sourceMapObj != nullptr) {
|
||||
sourceMapObj->SplitSourceMap(str);
|
||||
}
|
||||
}
|
||||
|
||||
std::string patchFile;
|
||||
std::vector<uint8_t> patchBuffer;
|
||||
if (!GetFileBuffer(hqfFile, patchFile, patchBuffer)) {
|
||||
|
@ -114,7 +114,8 @@ public:
|
||||
|
||||
void UpdateModuleNameAndAssetPath(const std::string& moduleName);
|
||||
void RegisterQuickFixQueryFunc(const std::map<std::string, std::string>& moduleAndPath) override;
|
||||
static bool GetFileBuffer(const std::string& filePath, std::string& fileFullName, std::vector<uint8_t>& buffer);
|
||||
static bool GetFileBuffer(const std::string& filePath, std::string& fileFullName, std::vector<uint8_t>& buffer,
|
||||
bool isABC = true);
|
||||
|
||||
void InitSourceMap(const std::shared_ptr<JsEnv::SourceMapOperator> operatorImpl);
|
||||
void FreeNativeReference(std::unique_ptr<NativeReference> reference);
|
||||
|
@ -183,6 +183,7 @@ std::string SourceMap::TranslateBySourceMap(const std::string& stackStr)
|
||||
|
||||
void SourceMap::SplitSourceMap(const std::string& sourceMapData)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(sourceMapMutex_);
|
||||
if (!isModular_) {
|
||||
if (!nonModularMap_) {
|
||||
nonModularMap_ = std::make_shared<SourceMapData>();
|
||||
@ -205,7 +206,7 @@ void SourceMap::SplitSourceMap(const std::string& sourceMapData)
|
||||
std::string value = sourceMapData.substr(leftBracket, rightBracket);
|
||||
std::shared_ptr<SourceMapData> modularMap = std::make_shared<SourceMapData>();
|
||||
ExtractSourceMapData(value, modularMap);
|
||||
sourceMaps_.emplace(key, modularMap);
|
||||
sourceMaps_[key] = modularMap;
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,6 +295,8 @@ void SourceMap::ExtractSourceMapData(const std::string& sourceMapData, std::shar
|
||||
}
|
||||
curMapData->mappings_.clear();
|
||||
curMapData->mappings_.shrink_to_fit();
|
||||
sourceKey.clear();
|
||||
sourceKey.shrink_to_fit();
|
||||
}
|
||||
|
||||
MappingInfo SourceMap::Find(int32_t row, int32_t col, const SourceMapData& targetMap)
|
||||
@ -520,7 +523,7 @@ bool SourceMap::TranslateUrlPositionBySourceMap(std::string& url, int& line, int
|
||||
if (isModular_) {
|
||||
auto iter = sourceMaps_.find(url);
|
||||
if (iter != sourceMaps_.end()) {
|
||||
return GetLineAndColumnNumbers(line, column, *(iter->second));
|
||||
return GetLineAndColumnNumbers(line, column, *(iter->second), url);
|
||||
}
|
||||
JSENV_LOG_E("TranslateUrlPositionBySourceMap: stageMode sourceMaps find fail");
|
||||
return false;
|
||||
@ -528,7 +531,7 @@ bool SourceMap::TranslateUrlPositionBySourceMap(std::string& url, int& line, int
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SourceMap::GetLineAndColumnNumbers(int& line, int& column, SourceMapData& targetMap)
|
||||
bool SourceMap::GetLineAndColumnNumbers(int& line, int& column, SourceMapData& targetMap, std::string& url)
|
||||
{
|
||||
int32_t offSet = 0;
|
||||
MappingInfo mapInfo;
|
||||
@ -542,6 +545,7 @@ bool SourceMap::GetLineAndColumnNumbers(int& line, int& column, SourceMapData& t
|
||||
} else {
|
||||
line = mapInfo.row;
|
||||
column = mapInfo.col;
|
||||
url = mapInfo.sources;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,11 @@ public:
|
||||
return engine_;
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceMapOperator> GetSourceMapOperator() const
|
||||
{
|
||||
return sourceMapOperator_;
|
||||
}
|
||||
|
||||
panda::ecmascript::EcmaVM* GetVM() const
|
||||
{
|
||||
return vm_;
|
||||
|
@ -80,11 +80,11 @@ public:
|
||||
static bool ReadSourceMapData(const std::string& hapPath, const std::string& sourceMapPath, std::string& content);
|
||||
static void RegisterGetHapPathCallback(GetHapPathCallback getFunc);
|
||||
static void GetHapPath(const std::string &bundleName, std::vector<std::string> &hapList);
|
||||
bool GetLineAndColumnNumbers(int& line, int& column, SourceMapData& targetMap);
|
||||
bool GetLineAndColumnNumbers(int& line, int& column, SourceMapData& targetMap, std::string& url);
|
||||
static void ExtractStackInfo(const std::string& stackStr, std::vector<std::string>& res);
|
||||
|
||||
private:
|
||||
void SplitSourceMap(const std::string& sourceMapData);
|
||||
|
||||
private:
|
||||
void ExtractSourceMapData(const std::string& sourceMapData, std::shared_ptr<SourceMapData>& curMapData);
|
||||
void ExtractKeyInfo(const std::string& sourceMap, std::vector<std::string>& sourceKeyInfo);
|
||||
std::vector<std::string> HandleMappings(const std::string& mapping);
|
||||
|
@ -83,6 +83,11 @@ public:
|
||||
return (initStatus_ == InitStatus::EXECUTED_SUCCESSFULLY);
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceMap> GetSourceMapObj() const
|
||||
{
|
||||
return sourceMapObj_;
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string bundleName_;
|
||||
bool isModular_ = false;
|
||||
|
@ -903,6 +903,30 @@ HWTEST_F(JsRuntimeTest, StopDebugger_0100, TestSize.Level0)
|
||||
TAG_LOGI(AAFwkTag::TEST, "StopDebugger end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetFileBuffer_0100
|
||||
* @tc.desc: JsRuntime test for GetFileBuffer.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(JsRuntimeTest, GetFileBuffer_0100, TestSize.Level0)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetFileBuffer start");
|
||||
|
||||
AbilityRuntime::Runtime::Options options;
|
||||
options.preload = true;
|
||||
auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
|
||||
|
||||
ASSERT_NE(jsRuntime, nullptr);
|
||||
|
||||
std::string filePath = "";
|
||||
std::string fileFullName = "";
|
||||
std::vector<uint8_t> buffer;
|
||||
jsRuntime->GetFileBuffer(filePath, fileFullName, buffer);
|
||||
jsRuntime.reset();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetFileBuffer end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetFileBuffer_0200
|
||||
* @tc.desc: JsRuntime test for GetFileBuffer.
|
||||
@ -921,7 +945,7 @@ HWTEST_F(JsRuntimeTest, GetFileBuffer_0200, TestSize.Level0)
|
||||
std::string filePath = "";
|
||||
std::string fileFullName = "";
|
||||
std::vector<uint8_t> buffer;
|
||||
jsRuntime->GetFileBuffer(filePath, fileFullName, buffer);
|
||||
jsRuntime->GetFileBuffer(filePath, fileFullName, buffer, false);
|
||||
jsRuntime.reset();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetFileBuffer end");
|
||||
|
Loading…
Reference in New Issue
Block a user