diff --git a/ecmascript/builtins/builtins_function.cpp b/ecmascript/builtins/builtins_function.cpp index d31c26f623..1c33083392 100644 --- a/ecmascript/builtins/builtins_function.cpp +++ b/ecmascript/builtins/builtins_function.cpp @@ -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, diff --git a/ecmascript/jspandafile/debug_info_extractor.cpp b/ecmascript/jspandafile/debug_info_extractor.cpp index 4cdc1a43b6..add5964886 100644 --- a/ecmascript/jspandafile/debug_info_extractor.cpp +++ b/ecmascript/jspandafile/debug_info_extractor.cpp @@ -196,9 +196,15 @@ void DebugInfoExtractor::Extract(const panda_file::File *pf) LineNumberProgramProcessor programProcessor(program, &handler); programProcessor.Process(); + const char *sourceFile = ""; + if (state.HasFile()) { + sourceFile = reinterpret_cast(handler.GetFile()); + } + const char *sourceCode = ""; + if (state.HasSourceCode()) { + sourceCode = reinterpret_cast(handler.GetSourceCode()); + } panda_file::File::EntityId methodId = mda.GetMethodId(); - const char *sourceFile = reinterpret_cast(handler.GetFile()); - const char *sourceCode = reinterpret_cast(handler.GetSourceCode()); methods_.insert(std::make_pair(methodId.GetOffset(), MethodDebugInfo {sourceFile, sourceCode, handler.GetLineNumberTable(), handler.GetColumnNumberTable(),