Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
node-report: expose initialize function
  • Loading branch information
richardlau committed Aug 14, 2018
commit 8c3290aff11ab560595d9f033bc00af781118318
35 changes: 10 additions & 25 deletions deps/node-report/src/module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ NAN_METHOD(GetReport) {
NAN_METHOD(SetEvents) {
Nan::Utf8String parameter(info[0]);
v8::Isolate* isolate = info.GetIsolate();
SetEvents(isolate, *parameter);
}
void SetEvents(v8::Isolate* isolate, const char* args) {
unsigned int previous_events = nodereport_events; // save previous settings
nodereport_events = ProcessNodeReportEvents(*parameter);
nodereport_events = ProcessNodeReportEvents(args);

// If report newly requested for fatalerror, set up the V8 callback
if ((nodereport_events & NR_FATALERROR) && (error_hook_initialised == false)) {
Expand Down Expand Up @@ -371,7 +374,7 @@ static void SetupSignalHandler() {
* Native module initializer function, called when the module is require'd
*
******************************************************************************/
void Initialize(v8::Local<v8::Object> exports) {
void InitializeNodeReport(void) {
v8::Isolate* isolate = Isolate::GetCurrent();
node_isolate = isolate;

Expand All @@ -385,7 +388,8 @@ void Initialize(v8::Local<v8::Object> exports) {
}
const char* trigger_events = secure_getenv("NODEREPORT_EVENTS");
if (trigger_events != nullptr) {
nodereport_events = ProcessNodeReportEvents(trigger_events);
// nodereport_events = ProcessNodeReportEvents(trigger_events);
SetEvents(isolate, trigger_events);
}
const char* trigger_signal = secure_getenv("NODEREPORT_SIGNAL");
if (trigger_signal != nullptr) {
Expand All @@ -399,29 +403,10 @@ void Initialize(v8::Local<v8::Object> exports) {
if (directory_name != nullptr) {
ProcessNodeReportDirectory(directory_name);
}
}

// If report requested for fatalerror, set up the V8 callback
if (nodereport_events & NR_FATALERROR) {
isolate->SetFatalErrorHandler(OnFatalError);
error_hook_initialised = true;
}

// If report requested for exceptions, tell V8 to capture stack trace and set up the callback
if (nodereport_events & NR_EXCEPTION) {
isolate->SetCaptureStackTraceForUncaughtExceptions(true, 32, v8::StackTrace::kDetailed);
// The hook for uncaught exception won't get called unless the --abort_on_uncaught_exception option is set
v8::V8::SetFlagsFromString("--abort_on_uncaught_exception", sizeof("--abort_on_uncaught_exception")-1);
isolate->SetAbortOnUncaughtExceptionCallback(OnUncaughtException);
exception_hook_initialised = true;
}

#ifndef _WIN32
// If report requested on external user signal set up watchdog thread and callbacks
if (nodereport_events & NR_SIGNAL) {
SetupSignalHandler();
}
#endif

void Initialize(v8::Local<v8::Object> exports) {
InitializeNodeReport();
exports->Set(Nan::New("triggerReport").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(TriggerReport)->GetFunction());
exports->Set(Nan::New("getReport").ToLocalChecked(),
Expand Down
3 changes: 3 additions & 0 deletions deps/node-report/src/node_report.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ typedef struct tm TIME_TYPE;
#endif
#define UNKNOWN_NODEVERSION_STRING "Unable to determine Node.js version\n"

void InitializeNodeReport(void);
void SetEvents(Isolate* isolate, const char* args);

// Function declarations - functions in src/node_report.cc
void TriggerNodeReport(Isolate* isolate, DumpEvent event, const char* message, const char* location, char* name, v8::MaybeLocal<v8::Value> error);
void GetNodeReport(Isolate* isolate, DumpEvent event, const char* message, const char* location, v8::MaybeLocal<v8::Value> error, std::ostream& out);
Expand Down