I am new to Nan and I want to get rid of the following code snippet
But before that I need to understand what exactly is being returned from this method.
Local<Object> obj;
NAN_METHOD(process) {
if (info.Length() == 0 || !info[0]->IsObject()) {
std::cerr << "Must pass event object as first argument" << std::endl;
info.GetReturnValue().Set(Nan::Null());
return;
}
auto req = info[0]->ToObject();
auto program = Nan::Get(req, Nan::New<String>("program").ToLocalChecked()).ToLocalChecked();
auto message = Nan::Get(req, Nan::New<String>("message").ToLocalChecked()).ToLocalChecked();
if (!program->IsString() || !message->IsString()) {
std::cerr << "Must provide program and message keys in event object" << std::endl;
info.GetReturnValue().Set(Nan::Null());
return;
}
Nan::Utf8String app(Nan::To<String>(program).ToLocalChecked());
Nan::Utf8String msg(Nan::To<String>(message).ToLocalChecked());
obj = req;
match(*msg, msg.length(), *app, app.length());
info.GetReturnValue().Set(obj);
}
program and message both are strings.
match is a C method that is being called with return type void.
1)What is info.GetReturnValue().Set(obj) doing? Is this making any changes to obj because of some manipulation in the match function?
2)What is being returned from this method?
Thanks