已开启
Stack parsing code optimization and UT additions #20313
rentangyu创建于 12 天前
Stack parsing code optimization and UT additions #20313
已开启
共 1 个文件变更+14-7
| @@ -62,7 +62,6 @@ | |||
| 62 | 62 | ||
| 63 | 63 | ||
| 64 | 64 | ||
| 65 | - | ||
| 66 | 65 | ||
| 67 | 66 | ||
| 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 | |||
| 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)); |
🤖 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