src: use std::string_view from node_report

PR-URL: https://github.com/nodejs/node/pull/60006
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
iknoom 2025-09-18 17:22:51 +09:00 committed by Anna Henningsen
parent 93ee08cf27
commit 075936b413
No known key found for this signature in database
3 changed files with 37 additions and 37 deletions

View File

@ -794,23 +794,23 @@ NODE_EXTERN v8::MaybeLocal<v8::Value> PrepareStackTraceCallback(
// is included in the report.
// Returns the filename of the written report.
NODE_EXTERN std::string TriggerNodeReport(v8::Isolate* isolate,
const char* message,
const char* trigger,
const std::string& filename,
std::string_view message,
std::string_view trigger,
std::string_view filename,
v8::Local<v8::Value> error);
NODE_EXTERN std::string TriggerNodeReport(Environment* env,
const char* message,
const char* trigger,
const std::string& filename,
std::string_view message,
std::string_view trigger,
std::string_view filename,
v8::Local<v8::Value> error);
NODE_EXTERN void GetNodeReport(v8::Isolate* isolate,
const char* message,
const char* trigger,
std::string_view message,
std::string_view trigger,
v8::Local<v8::Value> error,
std::ostream& out);
NODE_EXTERN void GetNodeReport(Environment* env,
const char* message,
const char* trigger,
std::string_view message,
std::string_view trigger,
v8::Local<v8::Value> error,
std::ostream& out);

View File

@ -553,7 +553,7 @@ static void ReportFatalException(Environment* env,
}
if (env->isolate_data()->options()->report_uncaught_exception) {
TriggerNodeReport(env, report_message.c_str(), "Exception", "", error);
TriggerNodeReport(env, report_message, "Exception", "", error);
}
if (env->options()->trace_uncaught) {

View File

@ -56,9 +56,9 @@ namespace report {
// Internal/static function declarations
static void WriteNodeReport(Isolate* isolate,
Environment* env,
const char* message,
const char* trigger,
const std::string& filename,
std::string_view message,
std::string_view trigger,
std::string_view filename,
std::ostream& out,
Local<Value> error,
bool compact,
@ -69,11 +69,11 @@ static void PrintVersionInformation(JSONWriter* writer,
static void PrintJavaScriptErrorStack(JSONWriter* writer,
Isolate* isolate,
Local<Value> error,
const char* trigger);
std::string_view trigger);
static void PrintEmptyJavaScriptStack(JSONWriter* writer);
static void PrintJavaScriptStack(JSONWriter* writer,
Isolate* isolate,
const char* trigger);
std::string_view trigger);
static void PrintJavaScriptErrorProperties(JSONWriter* writer,
Isolate* isolate,
Local<Value> error);
@ -92,9 +92,9 @@ static void PrintNetworkInterfaceInfo(JSONWriter* writer);
// sections of the report to the supplied stream
static void WriteNodeReport(Isolate* isolate,
Environment* env,
const char* message,
const char* trigger,
const std::string& filename,
std::string_view message,
std::string_view trigger,
std::string_view filename,
std::ostream& out,
Local<Value> error,
bool compact,
@ -237,7 +237,7 @@ static void WriteNodeReport(Isolate* isolate,
std::ostringstream os;
std::string name =
"Worker thread subreport [" + std::string(w->name()) + "]";
GetNodeReport(env, name.c_str(), trigger, Local<Value>(), os);
GetNodeReport(env, name, trigger, Local<Value>(), os);
Mutex::ScopedLock lock(workers_mutex);
worker_infos.emplace_back(os.str());
@ -472,7 +472,7 @@ static void PrintEmptyJavaScriptStack(JSONWriter* writer) {
// Do our best to report the JavaScript stack without calling into JavaScript.
static void PrintJavaScriptStack(JSONWriter* writer,
Isolate* isolate,
const char* trigger) {
std::string_view trigger) {
HandleScope scope(isolate);
Local<v8::StackTrace> stack;
if (!GetCurrentStackTrace(isolate, MAX_FRAME_COUNT).ToLocal(&stack)) {
@ -513,7 +513,7 @@ static void PrintJavaScriptStack(JSONWriter* writer,
static void PrintJavaScriptErrorStack(JSONWriter* writer,
Isolate* isolate,
Local<Value> error,
const char* trigger) {
std::string_view trigger) {
if (error.IsEmpty()) {
return PrintJavaScriptStack(writer, isolate, trigger);
}
@ -828,23 +828,23 @@ static void PrintRelease(JSONWriter* writer) {
std::string TriggerNodeReport(Isolate* isolate,
Environment* env,
const char* message,
const char* trigger,
const std::string& name,
std::string_view message,
std::string_view trigger,
std::string_view name,
Local<Value> error) {
std::string filename;
// Determine the required report filename. In order of priority:
// 1) supplied on API 2) configured on startup 3) default generated
if (!name.empty()) {
filename = name;
// we may not always be in a great state when generating a node report
// allow for the case where we don't have an env
if (env != nullptr) {
THROW_IF_INSUFFICIENT_PERMISSIONS(
env, permission::PermissionScope::kFileSystemWrite, name, name);
env, permission::PermissionScope::kFileSystemWrite, name, filename);
// Filename was specified as API parameter.
}
filename = name;
} else {
std::string report_filename;
{
@ -941,9 +941,9 @@ std::string TriggerNodeReport(Isolate* isolate,
// External function to trigger a report, writing to file.
std::string TriggerNodeReport(Isolate* isolate,
const char* message,
const char* trigger,
const std::string& name,
std::string_view message,
std::string_view trigger,
std::string_view name,
Local<Value> error) {
Environment* env = nullptr;
if (isolate != nullptr) {
@ -954,9 +954,9 @@ std::string TriggerNodeReport(Isolate* isolate,
// External function to trigger a report, writing to file.
std::string TriggerNodeReport(Environment* env,
const char* message,
const char* trigger,
const std::string& name,
std::string_view message,
std::string_view trigger,
std::string_view name,
Local<Value> error) {
return TriggerNodeReport(env != nullptr ? env->isolate() : nullptr,
env,
@ -968,8 +968,8 @@ std::string TriggerNodeReport(Environment* env,
// External function to trigger a report, writing to a supplied stream.
void GetNodeReport(Isolate* isolate,
const char* message,
const char* trigger,
std::string_view message,
std::string_view trigger,
Local<Value> error,
std::ostream& out) {
Environment* env = nullptr;
@ -997,8 +997,8 @@ void GetNodeReport(Isolate* isolate,
// External function to trigger a report, writing to a supplied stream.
void GetNodeReport(Environment* env,
const char* message,
const char* trigger,
std::string_view message,
std::string_view trigger,
Local<Value> error,
std::ostream& out) {
Isolate* isolate = nullptr;