!6291 SetModuleName should consider harName(check @)

Merge pull request !6291 from yaochaonan/ohcard
This commit is contained in:
openharmony_ci 2024-02-27 12:56:53 +00:00 committed by Gitee
commit 1f0a2c6dc2
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 16 additions and 6 deletions

View File

@ -777,7 +777,6 @@ std::pair<std::string, std::string> EcmaVM::GetCurrentModuleInfo(bool needRecord
return std::make_pair(recordName.c_str(), fileName.c_str());
}
CString moduleName = ModulePathHelper::GetModuleName(recordName);
PathHelper::DeleteNamespace(moduleName);
if (moduleName.empty()) {
LOG_FULL(ERROR) << " GetCurrentModuleName Fail, recordName is " << recordName;
}

View File

@ -192,7 +192,9 @@ public:
pos1++;
size_t pos2 = recordName.find(PathHelper::SLASH_TAG, pos1);
if (pos2 != CString::npos) {
return recordName.substr(pos1, pos2 - pos1);
CString moduleName = recordName.substr(pos1, pos2 - pos1);
PathHelper::DeleteNamespace(moduleName);
return moduleName;
}
}
return CString();

View File

@ -2566,10 +2566,19 @@ void JSNApi::SetModuleInfo(EcmaVM *vm, const std::string &assetPath, const std::
{
SetAssetPath(vm, assetPath);
size_t pos = entryPoint.find_first_of("/");
SetBundleName(vm, entryPoint.substr(0, pos));
std::string subStr = entryPoint.substr(pos + 1); // 1: remove /
pos = subStr.find_first_of("/");
SetModuleName(vm, subStr.substr(0, pos));
if (pos != std::string::npos) {
SetBundleName(vm, entryPoint.substr(0, pos));
ecmascript::CString moduleName = ModulePathHelper::GetModuleName(entryPoint.c_str());
if (!moduleName.empty()) {
SetModuleName(vm, moduleName.c_str());
return;
}
}
std::string errmsg = "SetModuleInfo: entryPoint:" + entryPoint + "is invalid.";
LOG_ECMA(ERROR) << errmsg;
Local<StringRef> message = StringRef::NewFromUtf8(vm, errmsg.c_str());
Local<JSValueRef> error = Exception::Error(vm, message);
JSNApi::ThrowException(vm, error);
}
// note: The function SetAssetPath is a generic interface for previewing and physical machines.