Skip to content

Commit 980e038

Browse files
committed
fixup! report: expose report public native apis
1 parent 8c148bf commit 980e038

7 files changed

Lines changed: 30 additions & 36 deletions

File tree

src/node.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@
7575
#include "v8-platform.h" // NOLINT(build/include_order)
7676
#include "node_version.h" // NODE_MODULE_VERSION
7777

78-
#include <memory>
7978
#include <functional>
79+
#include <memory>
80+
#include <ostream>
8081

8182
// We cannot use __POSIX__ in this header because that's only defined when
8283
// building Node.js.
@@ -620,16 +621,15 @@ NODE_EXTERN v8::MaybeLocal<v8::Value> PrepareStackTraceCallback(
620621
// Writes a diagnostic report to a file. If filename is not provided, the
621622
// default filename includes the date, time, PID, and a sequence number.
622623
// The report's JavaScript stack trace is taken from err, if present.
623-
// If isolate or env is nullptr, no information about the isolate and env
624+
// If isolate is nullptr, no information about the JavaScript environment
624625
// is included in the report.
626+
// Returns the filename of the written report.
625627
NODE_EXTERN std::string TriggerNodeReport(v8::Isolate* isolate,
626-
Environment* env,
627628
const char* message,
628629
const char* trigger,
629630
const std::string& filename,
630631
v8::Local<v8::Value> error);
631632
NODE_EXTERN void GetNodeReport(v8::Isolate* isolate,
632-
Environment* env,
633633
const char* message,
634634
const char* trigger,
635635
v8::Local<v8::Value> error,

src/node_errors.cc

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -474,18 +474,14 @@ void OnFatalError(const char* location, const char* message) {
474474
}
475475

476476
Isolate* isolate = Isolate::TryGetCurrent();
477-
Environment* env = nullptr;
478-
if (isolate != nullptr) {
479-
env = Environment::GetCurrent(isolate);
480-
}
481477
bool report_on_fatalerror;
482478
{
483479
Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
484480
report_on_fatalerror = per_process::cli_options->report_on_fatalerror;
485481
}
486482

487483
if (report_on_fatalerror) {
488-
TriggerNodeReport(isolate, env, message, "FatalError", "", Local<Object>());
484+
TriggerNodeReport(isolate, message, "FatalError", "", Local<Object>());
489485
}
490486

491487
fflush(stderr);
@@ -503,18 +499,14 @@ void OOMErrorHandler(const char* location, bool is_heap_oom) {
503499
}
504500

505501
Isolate* isolate = Isolate::TryGetCurrent();
506-
Environment* env = nullptr;
507-
if (isolate != nullptr) {
508-
env = Environment::GetCurrent(isolate);
509-
}
510502
bool report_on_fatalerror;
511503
{
512504
Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
513505
report_on_fatalerror = per_process::cli_options->report_on_fatalerror;
514506
}
515507

516508
if (report_on_fatalerror) {
517-
TriggerNodeReport(isolate, env, message, "OOMError", "", Local<Object>());
509+
TriggerNodeReport(isolate, message, "OOMError", "", Local<Object>());
518510
}
519511

520512
fflush(stderr);

src/node_report.cc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,15 @@ static void PrintRelease(JSONWriter* writer) {
790790

791791
// External function to trigger a report, writing to file.
792792
std::string TriggerNodeReport(Isolate* isolate,
793-
Environment* env,
794793
const char* message,
795794
const char* trigger,
796795
const std::string& name,
797796
Local<Value> error) {
797+
Environment* env = nullptr;
798+
if (isolate != nullptr) {
799+
env = Environment::GetCurrent(isolate);
800+
}
801+
798802
std::string filename;
799803

800804
// Determine the required report filename. In order of priority:
@@ -875,6 +879,20 @@ std::string TriggerNodeReport(Isolate* isolate,
875879
}
876880

877881
// External function to trigger a report, writing to a supplied stream.
882+
void GetNodeReport(Isolate* isolate,
883+
const char* message,
884+
const char* trigger,
885+
Local<Value> error,
886+
std::ostream& out) {
887+
Environment* env = nullptr;
888+
if (isolate != nullptr) {
889+
env = Environment::GetCurrent(isolate);
890+
}
891+
report::WriteNodeReport(
892+
isolate, env, message, trigger, "", out, error, false);
893+
}
894+
895+
// Helper function to get report for an environment.
878896
void GetNodeReport(Isolate* isolate,
879897
Environment* env,
880898
const char* message,

src/node_report.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,7 @@ void GetReport(const v8::FunctionCallbackInfo<v8::Value>& info);
3636

3737
} // namespace report
3838

39-
// Function declarations - functions in src/node_report.cc
40-
std::string TriggerNodeReport(v8::Isolate* isolate,
41-
Environment* env,
42-
const char* message,
43-
const char* trigger,
44-
const std::string& name,
45-
v8::Local<v8::Value> error);
39+
// Helper function to get report for an environment.
4640
void GetNodeReport(v8::Isolate* isolate,
4741
Environment* env,
4842
const char* message,

src/node_report_module.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ void WriteReport(const FunctionCallbackInfo<Value>& info) {
4444
else
4545
error = Local<Value>();
4646

47-
filename = TriggerNodeReport(
48-
isolate, env, *message, *trigger, filename, error);
47+
filename = TriggerNodeReport(isolate, *message, *trigger, filename, error);
4948
// Return value is the report filename
5049
info.GetReturnValue().Set(
5150
String::NewFromUtf8(isolate, filename.c_str()).ToLocalChecked());

test/addons/report-api/binding.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ void TriggerReport(const FunctionCallbackInfo<Value>& args) {
1111
Isolate* isolate = args.GetIsolate();
1212

1313
node::TriggerNodeReport(
14-
isolate,
15-
node::GetCurrentEnvironment(isolate->GetCurrentContext()),
16-
"FooMessage",
17-
"BarTrigger",
18-
std::string(),
19-
Local<Value>());
14+
isolate, "FooMessage", "BarTrigger", std::string(), Local<Value>());
2015
}
2116

2217
void init(Local<Object> exports) {

test/cctest/test_report.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ TEST_F(ReportTest, ReportWithNoIsolateAndEnv) {
2929
SealHandleScope handle_scope(isolate_);
3030

3131
std::ostringstream oss;
32-
node::GetNodeReport(
33-
nullptr, nullptr, "FooMessage", "BarTrigger", Local<Value>(), oss);
32+
node::GetNodeReport(nullptr, "FooMessage", "BarTrigger", Local<Value>(), oss);
3433

3534
// Simple checks on the output string contains the message and trigger.
3635
std::string actual = oss.str();
@@ -48,12 +47,9 @@ TEST_F(ReportTest, ReportWithIsolateAndEnv) {
4847
Function::New(context, [](const FunctionCallbackInfo<Value>& args) {
4948
Isolate* isolate = args.GetIsolate();
5049
HandleScope scope(isolate);
51-
Environment* env =
52-
node::GetCurrentEnvironment(isolate->GetCurrentContext());
5350

5451
std::ostringstream oss;
55-
node::GetNodeReport(
56-
isolate, env, "FooMessage", "BarTrigger", args[0], oss);
52+
node::GetNodeReport(isolate, "FooMessage", "BarTrigger", args[0], oss);
5753

5854
// Simple checks on the output string contains the message and trigger.
5955
std::string actual = oss.str();

0 commit comments

Comments
 (0)