I want to have access in javascript to my c++ function with google v8 engine and return result according arguments giving in my javascript function.
My javascript function is as follow:
var result = MyFc(
{
'stringData':'abc',
'numberData':123,
'arrData':[1,2,3],
'objData':{'a':true,'b':false,'c':true},
'callback':function(){}
}
);
I used
global->Set(v8::String::New("myFc"), v8::FunctionTemplate::New(MyFc));
v8::Handle<v8::Value> MyFc(const v8::Arguments& args) {
obj = args[0]->...
if( obj->stringData != 'abc' ){
//....
}
if( obj->numberData != 123 ){
//....
}
if( obj->arrData[2] != 3 ){
//....
}
if( obj->objData->b == false ){
//....
}
if( obj->callback !='abc' ){
//....
}
}
My question is how to parse arguments object in c++ v8? I want to access to all key values of the object in arguments, values can be an number, string, array, anonymous function or object.
Use type checking methods of
v8::Value(IsBoolean(),IsArray(),IsObject()etc) and thenv8::Handle<T>::Cast(v8::Handle<S>)to castargs[i]values to corresponding types.Your code should look like this: