Converting from v8::Arguments to C++ Types Converting from v8::Arguments to C++ Types node.js node.js

Converting from v8::Arguments to C++ Types


I know this is an older topic, but the way I tend to do this is as follows:

Handle<Value> MethodName (const Arguments& args) {    // get the param    v8::String::Utf8Value param1(args[0]->ToString());    // convert it to string    std::string foo = std::string(*param1);    }


If you are using NaN (native abstractions for node) then try this code:

std::string myString(*NanAsciiString(args[0])); 


The best way I can find to convert to and from JS types and C++ types, is using v8-juice, which provides type casting methods. Specifically I'm using v8-convert, which is a spin off of v8-juice, that includes only the conversion methods.

Converting args[0] to std::list is one line:

std::list<std::string> values = cvv8::CastFromJS<std::list<std::string> >(args[0]);