1

I investigate native Node addons using Nan.

So I'm trying to return back to Node an array of strings with the following code:

NAN_METHOD(open) {
    Local<Array> v8Array = Nan::New<Array>();
    std::string str = "erwer";
    v8Array->Set(0, Nan::New<String>(str.c_str()) );
    //v8Array->Set(0, Nan::New<Integer>(12) );
    info.GetReturnValue().Set(v8Array);
}

But it isn't compiled:

error: no matching function for call to ‘v8::Array::Set(int, Nan::imp::MaybeFactoryBase<v8::String>::return_t)’ v8Array->Set(0, Nan::New<String>(str.c_str()) );

But adding an item as integer (commented line) works properly. Why can't I add a string to array?

1 Answer 1

6

So, finally I realised that the second argument in case of being a String should be wrapped with ToLocalChecked():

v8Array->Set(i, Nan::New<String>(results[i].c_str()).ToLocalChecked() );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.