Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Node 12 #16

Closed
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
'targets': [
{
'include_dirs':[
'<(module_root_dir)/node_modules/nan',
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to change binding.gyp to pull from the server node_modules directory if at all possible, but I don't think I can.

],
'target_name': 'syslog',
'sources': [ 'src/syslog.cc' ]
}
]
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
"install": "node-gyp rebuild"
},
"dependencies": {
"bindings": "*",
"colors": "~0.6.0-1",
"bindings": "*"
"nan": "^2.14.1"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bringing in nan to help with some of the string and integer types.

},
"main": "rconsole.js",
"devDependencies": {},
Expand Down
24 changes: 13 additions & 11 deletions src/syslog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <node.h>
#include <syslog.h>
#include <string>
#include <nan.h>

using namespace std;
using namespace node;
Expand All @@ -33,36 +34,37 @@ using namespace v8;
char title[1024];

void open(const FunctionCallbackInfo<v8::Value>& args) {
args[0]->ToString()->WriteUtf8((char*) &title);
int facility = args[1]->ToInteger()->Int32Value();
int log_upto = args[2]->ToInteger()->Int32Value();
v8::Isolate* isolate = args.GetIsolate();
args[0]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local<v8::String>())->WriteUtf8(isolate, (char*) &title);
int32_t facility = args[1]->ToInt32(Nan::GetCurrentContext()).ToLocalChecked()->Value();
int32_t log_upto = args[2]->ToInt32(Nan::GetCurrentContext()).ToLocalChecked()->Value();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helpful notes on migration from another repo bcoin-org/bcrypto#7

setlogmask(LOG_UPTO(log_upto));
openlog(title, LOG_PID | LOG_NDELAY, facility);

v8::Isolate* isolate = args.GetIsolate();
v8::HandleScope scope(isolate);
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "true"));
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "true", v8::NewStringType::kNormal).ToLocalChecked());
}

void exit(const FunctionCallbackInfo<v8::Value>& args) {
closelog();

v8::Isolate* isolate = args.GetIsolate();
v8::HandleScope scope(isolate);
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "true"));
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "true", v8::NewStringType::kNormal).ToLocalChecked());
}

void log(const FunctionCallbackInfo<v8::Value>& args) {
int severity = args[0]->ToInteger()->Int32Value();
v8::String::Utf8Value message(args[1]->ToString());
v8::Isolate* isolate = args.GetIsolate();

int32_t severity = args[0]->ToInt32(Nan::GetCurrentContext()).ToLocalChecked()->Value();
v8::String::Utf8Value message(isolate, args[1]->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local<v8::String>()));
syslog(severity, "%s", *message );

v8::Isolate* isolate = args.GetIsolate();
v8::HandleScope scope(isolate);
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "true"));
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "true", v8::NewStringType::kNormal).ToLocalChecked());
}

void init(v8::Handle<v8::Object> target) {
void init(v8::Local<v8::Object> target) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v8::Handle has been deprecated for a while, but it was finally removed in v8 used for node 12.

NODE_SET_METHOD(target, "open", open);
NODE_SET_METHOD(target, "exit", exit);
NODE_SET_METHOD(target, "log", log);
Expand Down