Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
Use nan helpers to set exports
Browse files Browse the repository at this point in the history
Fixes compilation errors when built on Node.js master with V8 7.4.

`NAN_EXPORT()` requires the function name exported to JavaScript land
and the exported C++ method to match. Change the exported C++ methods
to begin with a lower case character to preserve the existing casing of
the name exported to JavaScript.

PR-URL: #125
Fixes: #116
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
  • Loading branch information
richardlau committed Mar 31, 2019
1 parent 0e87572 commit fabac78
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions src/module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extern std::string commandline_string;
* External JavaScript API for triggering a report
*
******************************************************************************/
NAN_METHOD(TriggerReport) {
NAN_METHOD(triggerReport) {
Nan::HandleScope scope;
v8::Isolate* isolate = info.GetIsolate();
char filename[NR_MAXNAME + 1] = "";
Expand Down Expand Up @@ -81,7 +81,7 @@ NAN_METHOD(TriggerReport) {
* External JavaScript API for returning a report
*
******************************************************************************/
NAN_METHOD(GetReport) {
NAN_METHOD(getReport) {
Nan::HandleScope scope;
v8::Isolate* isolate = info.GetIsolate();
std::ostringstream out;
Expand All @@ -100,7 +100,7 @@ NAN_METHOD(GetReport) {
* External JavaScript APIs for node-report configuration
*
******************************************************************************/
NAN_METHOD(SetEvents) {
NAN_METHOD(setEvents) {
Nan::Utf8String parameter(info[0]);
v8::Isolate* isolate = info.GetIsolate();
unsigned int previous_events = nodereport_events; // save previous settings
Expand Down Expand Up @@ -132,7 +132,7 @@ NAN_METHOD(SetEvents) {
}
#endif
}
NAN_METHOD(SetSignal) {
NAN_METHOD(setSignal) {
#ifndef _WIN32
Nan::Utf8String parameter(info[0]);
unsigned int previous_signal = nodereport_signal; // save previous setting
Expand All @@ -145,15 +145,15 @@ NAN_METHOD(SetSignal) {
}
#endif
}
NAN_METHOD(SetFileName) {
NAN_METHOD(setFileName) {
Nan::Utf8String parameter(info[0]);
ProcessNodeReportFileName(*parameter);
}
NAN_METHOD(SetDirectory) {
NAN_METHOD(setDirectory) {
Nan::Utf8String parameter(info[0]);
ProcessNodeReportDirectory(*parameter);
}
NAN_METHOD(SetVerbose) {
NAN_METHOD(setVerbose) {
Nan::Utf8String parameter(info[0]);
nodereport_verbose = ProcessNodeReportVerboseSwitch(*parameter);
}
Expand Down Expand Up @@ -375,7 +375,7 @@ static void SetupSignalHandler() {
* Native module initializer function, called when the module is require'd
*
******************************************************************************/
void Initialize(v8::Local<v8::Object> exports) {
NAN_MODULE_INIT(Initialize) {
v8::Isolate* isolate = Isolate::GetCurrent();
node_isolate = isolate;

Expand Down Expand Up @@ -426,20 +426,13 @@ void Initialize(v8::Local<v8::Object> exports) {
}
#endif

exports->Set(Nan::New("triggerReport").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(TriggerReport)->GetFunction());
exports->Set(Nan::New("getReport").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(GetReport)->GetFunction());
exports->Set(Nan::New("setEvents").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(SetEvents)->GetFunction());
exports->Set(Nan::New("setSignal").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(SetSignal)->GetFunction());
exports->Set(Nan::New("setFileName").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(SetFileName)->GetFunction());
exports->Set(Nan::New("setDirectory").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(SetDirectory)->GetFunction());
exports->Set(Nan::New("setVerbose").ToLocalChecked(),
Nan::New<v8::FunctionTemplate>(SetVerbose)->GetFunction());
NAN_EXPORT(target, triggerReport);
NAN_EXPORT(target, getReport);
NAN_EXPORT(target, setEvents);
NAN_EXPORT(target, setSignal);
NAN_EXPORT(target, setFileName);
NAN_EXPORT(target, setDirectory);
NAN_EXPORT(target, setVerbose);

if (nodereport_verbose) {
#ifdef _WIN32
Expand Down

0 comments on commit fabac78

Please sign in to comment.