!2153 FunctionPrototypeToString_bugfix

Merge pull request !2153 from 杨阳/FunctionPrototypeToString_bugfix
This commit is contained in:
openharmony_ci 2022-08-25 06:16:16 +00:00 committed by Gitee
commit ce0b2b9e2d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 13 additions and 3 deletions

View File

@ -276,7 +276,11 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeToString(EcmaRuntimeCallInfo *a
tooling::JSPtExtractor *debugExtractor =
JSPandaFileManager::GetInstance()->GetJSPtExtractor(method->GetJSPandaFile());
const std::string &sourceCode = debugExtractor->GetSourceCode(method->GetMethodId());
return GetTaggedString(thread, sourceCode.c_str());
if (!sourceCode.empty()) {
return GetTaggedString(thread, sourceCode.c_str());
} else {
return GetTaggedString(thread, "Cannot get source code of funtion");
}
}
THROW_TYPE_ERROR_AND_RETURN(thread,

View File

@ -196,9 +196,15 @@ void DebugInfoExtractor::Extract(const panda_file::File *pf)
LineNumberProgramProcessor<LineNumberProgramHandler> programProcessor(program, &handler);
programProcessor.Process();
const char *sourceFile = "";
if (state.HasFile()) {
sourceFile = reinterpret_cast<const char *>(handler.GetFile());
}
const char *sourceCode = "";
if (state.HasSourceCode()) {
sourceCode = reinterpret_cast<const char *>(handler.GetSourceCode());
}
panda_file::File::EntityId methodId = mda.GetMethodId();
const char *sourceFile = reinterpret_cast<const char *>(handler.GetFile());
const char *sourceCode = reinterpret_cast<const char *>(handler.GetSourceCode());
methods_.insert(std::make_pair(methodId.GetOffset(), MethodDebugInfo {sourceFile, sourceCode,
handler.GetLineNumberTable(),
handler.GetColumnNumberTable(),