New to v8, I'm compiling a script that returns a JS object, and I'd
like to keep a handle to a function that is a property of that object.
I'm creating a persistent handle to it, but it's not working. I assume
because the underlying handle is going out of scope?
v8::Persistent<v8::Context> context;
v8::Persistent<v8::Function> update;
void Foo() {
v8::HandleScope handle_scope;
context = v8::Context::New(NULL, global);
v8::Context::Scope context_scope(context);
v8::Local<v8::Script> script = // script compiles fine
v8::Local<v8::Value> result = script->Run();
v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(result);
// i've tried creating a persistent handle to obj and using
that from here down. doesn't work either
v8::Local<v8::Value> update_val = obj-
>Get(v8::Local<v8::String>(v8::String::New("update")));
v8::Local<v8::Function> update_fun =
v8::Local<v8::Function>::Cast(update_val);
// create persistent handle to keep around
update = v8::Persistent<v8::Function>::New(update_fun);
// calling now works fine
v8::Local<v8::Number> v = v8::Number::New(0.2);
v8::Local<v8::Value> val[1] = { v };
update->Call(context->Global(), 1, val);
}
void Bar() {
// calling here doesn't work
v8::Local<v8::Number> v = v8::Number::New(0.2);
v8::Local<v8::Value> val[1] = { v };
update->Call(context->Global(), 1, val);
}
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users