已开启
Stack parsing code optimization and UT additions #20313
Stack parsing code optimization and UT additions #20313
已开启
rentangyu创建于 12 天前
1 个文件变更+14-7
@@ -62,7 +62,6 @@
62#include "extractor.h"62#include "extractor.h"
63#include "replace_intl_module.h"63#include "replace_intl_module.h"
64#include "system_ability_definition.h"64#include "system_ability_definition.h"
65-#include "dfx_jsnapi.h"
66#include "worker_info.h"65#include "worker_info.h"
67#include "ffrt.h"66#include "ffrt.h"
68 67 
@@ -1011,17 +1010,25 @@ void JsRuntime::InitSourceMap(const std::string bundleName)
1011 CHECK_POINTER(jsEnv_);1010 CHECK_POINTER(jsEnv_);
1012 1011 
1013 auto init = [bundleName]() {1012 auto init = [bundleName]() {
1014- DFXJSNApi::SourceMapSetInitStatus(false);1013+ DFXJSNApi::SourceMapSetInitStatus(panda::ecmascript::InitStatus::IN_EXECUTED);
1015 std::vector<std::string> hapList;1014 std::vector<std::string> hapList;
1016 JsModuleReader::GetHapPathList(bundleName, hapList);1015 JsModuleReader::GetHapPathList(bundleName, hapList);
1016+ bool hasSourceMap = false;
1017 for (auto &hapInfo : hapList) {1017 for (auto &hapInfo : hapList) {
1018- if (!hapInfo.empty()) {1018+ if (hapInfo.empty()) {
A
Aafwk_helper12 天前

🤖 AI 代码检视意见(回复本评论可解决检视意见,点击被检视代码行左侧的小头像可收起检视意见)


🟠 全局状态 IsRelease 在循环内被反复覆盖,存在逻辑隐患

位置: L1018-L1027 | 严重程度: High

❓ 问题描述

在遍历 hapList 的循环内部,代码根据 ReadSourceMapData 的结果调用 DFXJSNApi::SourceMapSetIsRelease 修改全局状态。如果列表中包含多个 HAP(例如一个调试应用依赖了一个发布模式的共享包),全局标志的最终值将完全取决于 HAP 的迭代顺序,最后一个处理的 HAP 会覆盖之前的状态。此外,如果 hapList 为空,IsRelease 将保持旧值不变,可能导致使用了过期的全局状态。

💡 修复建议

修改建议:避免在循环内部修改全局的 IsRelease 状态。应在循环外部确定当前 bundle 的发布状态,或者仅在循环结束后根据综合判断结果设置一次全局标志。

1018: if (hapInfo.empty()) { 1019: continue; 1020: } 1021: std::string sourceMapData; 1022: if (JsRuntime::ReadSourceMapData(hapInfo, MERGE_SOURCE_MAP_PATH, sourceMapData)) { 1023: // Process source map data 1024: DFXJSNApi::SourceMapSplitSourceMap(sourceMapData); 1025: } 1026: // Removed global state modification inside the loop


likedislike
1019- std::string sourceMapData;1019+ continue;
1020- JsRuntime::ReadSourceMapData(hapInfo, MERGE_SOURCE_MAP_PATH, sourceMapData);
1021- DFXJSNApi::SourceMapSplitSourceMap(sourceMapData);
1022 }1020 }
1021+ std::string sourceMapData;
1022+ if (JsRuntime::ReadSourceMapData(hapInfo, MERGE_SOURCE_MAP_PATH, sourceMapData)) {
1023+ hasSourceMap = true;
1024+ }
1025+ DFXJSNApi::SourceMapSplitSourceMap(sourceMapData);
1026+ }
1027+ if (hasSourceMap) {
1028+ DFXJSNApi::SourceMapSetInitStatus(panda::ecmascript::InitStatus::EXECUTED_SUCCESSFULLY);
1029+ } else {
1030+ DFXJSNApi::SourceMapSetInitStatus(panda::ecmascript::InitStatus::NO_SOURCEMAP);
1023 }1031 }
1024- DFXJSNApi::SourceMapSetInitStatus(true);
1025 };1032 };
1026 1033 
1027 ffrt::submit(init, {}, {}, ffrt::task_attr().qos(ffrt::qos_user_initiated));1034 ffrt::submit(init, {}, {}, ffrt::task_attr().qos(ffrt::qos_user_initiated));