I know I can create an object inside of C++, and set keys and values,
and pass that into JavaScript. Something like this is what I currently
do:
v8::Handle<v8::Object> obj_inject = v8::Object::New();
obj_inject->Set(v8::String::New("foo"), v8::String::New("i'm foo"));
obj_inject->Set(v8::String::New("bar"), v8::String::New("i'm bar"));
v8::Handle<v8::Value> func_args[1] = {obj_inject};
myfunc->Call(my_context->Global(), 1, func_args);
So, my question is, how do I do the reverse? How do I have a
JavaScript function that returns an object (instead of a primitive
like a string or integer) with key/value pairs in it? I've tried:
v8::TryCatch try_catch;
v8::Handle<v8::Script> script = v8::Script::Compile("myfunc();",
"inline");
if (script.IsEmpty()) {
// Print errors that happened during compilation.
ReportException(&try_catch);
}
else {
v8::Handle<v8::Value> ret = script->Run(); // works!
v8::Handle<v8::Object> obj(ret); // cast fails :(
// want then to be able to do:
std::string foo = obj->Get(v8::String::New("foo"));
}
But the compiler complains about the cast from Value to Object. So how
do I do that properly and then access the key/value pairs?
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users