On Mon, Apr 29, 2019 at 9:00 PM Nitish Saboo <nitish.sabo...@gmail.com> wrote:
> 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?

It's not making changes to `obj` but it stores it in a slot on the
`info` object.

> 2)What is being returned from this method?

In C++? Nothing (i.e., void.)

The JS return value is stored out of line.

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/CAHQurc9QJaimABQCsnDdphHWLKymNOcfz%3Db_6qwkrXwrb31xUQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to