!8071 load native module throw error correctly

Merge pull request !8071 from jiachong/j30052427
This commit is contained in:
openharmony_ci 2024-07-10 20:55:32 +00:00 committed by Gitee
commit 3bec1b9301
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -742,8 +742,8 @@ JSTaggedValue BuiltinsGlobal::LoadNativeModule(EcmaRuntimeCallInfo *msg)
if (moduleName.size() != 0) {
curJsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, abcFilePath, requestPath);
if (curJsPandaFile == nullptr) {
errorMsg = "Load file with filename '" + abcFilePath +
"' failed, module name '" + requestPath + "'" + ", from load native module";
errorMsg = "Load native module failed, filename '" + abcFilePath +
", module name '" + requestPath;
auto error = GlobalError::ReferenceError(thread, errorMsg.c_str());
THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception());
}
@ -753,6 +753,14 @@ JSTaggedValue BuiltinsGlobal::LoadNativeModule(EcmaRuntimeCallInfo *msg)
} else if (ModulePathHelper::NeedTranstale(requestPath)) {
ModulePathHelper::TranstaleExpressionInput(curJsPandaFile.get(), requestPath);
}
size_t pos = requestPath.find(PathHelper::COLON_TAG);
if (pos == CString::npos) {
errorMsg = "The module name '"+ requestPath +
"' of parameters received by loadNativeModule is incorrect.";
auto error = GlobalError::ParamError(thread, errorMsg.c_str());
THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, JSTaggedValue::Exception());
}
}
ModuleManager *moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();