What does “info.GetReturnValue().Set(obj);” return

22 views
Skip to first unread message

Nitish Saboo

unread,
Apr 29, 2019, 3:00:15 PM4/29/19
to nodejs
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


Ben Noordhuis

unread,
May 1, 2019, 8:41:39 PM5/1/19
to nod...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages