How do I get internal data for function callbacks?   The approach I'm
currently taking is to use the function's prototype object where I can
declare an internal field and then set it at context time.   However,
I get an error about the internal field count when I retrieve the
prototype and try to set data (code and error shown below).

I'm also not sure about how to unpack the data in the handler.

erik


v8::Handle<v8::Value> myHandler(const v8::Arguments& args) {
    nd::unused(args);
    using namespace v8;
    return Undefined();
}


using namespace v8;
HandleScope handle_scope;

v8::Persistent<v8::ObjectTemplate> global_template =
Persistent<ObjectTemplate>::New(ObjectTemplate::New());

Handle<FunctionTemplate> tmpl = FunctionTemplate::New(myHandler);

Handle<ObjectTemplate> proto_t = tmpl->PrototypeTemplate();
proto_t->SetInternalFieldCount(1);

global_template->Set(String::New("myFunction"),tmpl);

Persistent<Context> context = Context::New(0, global_template);

Context::Scope context_scope(context);

Handle<Function> fn = tmpl->GetFunction();
Handle<Object> proto = Handle<Object>::Cast(fn->GetPrototype());

void *data(0);
proto->SetInternalField(0, External::New(data));



#
# Fatal error in v8::Object::SetInternalField()
# Writing internal field out of bounds
#


-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to