Search code examples
c++v8node.js-addon

Dynamically assigning different data type to v8::local<v8::value>argv[1]


How to assign two data type to v8::Local<v8::Value>argv[1] based on incoming data(int,string,bool) type as below.

v8::Local<v8::Value> argv[1];
 if(Isint)
{
  argv[0] = Nan::New<v8::Number>(intValue).ToLocalChecked();
}
if(IsString)
{
  argv[0] = Nan::New<v8::String>(stringValue);
 }
if(IsBool){
  argv[0] = Nan::New<v8::Boolean>(boolValue);
}

Note : Final argv[0] will hold only one value either int,string or bool based on if check performed above.

Above implementation throw run time error as terminated SIGSEGV. Please help me to fix this. This my first attemp on V8.

Can argv[0] assigned as above?


Solution

  • Your above code has no any run time error. The error is coming form any of IsInt, IsString, IsBool.