hi guys. i'm trying to make an IRCClient class. it has a method called
"connect". Here's my code

v8::Handle<v8::Value> IRCClient(const v8::Arguments& args) {
        v8::HandleScope handle_scope;
        v8::Local<v8::Object> self = args.Holder();
        printf("IRCClient called, internal field count=%d\n", self-
>InternalFieldCount());
        IRC::Client *c = new IRC::Client;
        self->SetInternalField(0, v8::External::New(c));
        return v8::Undefined();
}

v8::Handle<v8::Value> IRCClientConnect(const v8::Arguments& args) {
        printf("IRCClientConnect called\n");
        v8::HandleScope handle_scope;
        v8::Local<v8::Object> self = args.Holder();
        v8::Local<v8::External> wrap = v8::Local<v8::External>::Cast(self-
>GetInternalField(0));
        IRC::Client *c = (IRC::Client *)wrap->Value();
        v8::String::Utf8Value host(args[0]);
        printf("host: %s\n", ToCString(host));
        return v8::Undefined();
}

int initjs(int argc, char* argv[]) {
  v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
  v8::HandleScope handle_scope;
  // Create a template for the global object.
  v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
  // Bind the global 'print' function to the C++ Print callback.
  global->Set(v8::String::New("print"),
v8::FunctionTemplate::New(Print));
  // Bind the 'quit' function
  global->Set(v8::String::New("quit"),
v8::FunctionTemplate::New(Quit));
  // Bind the 'version' function
  global->Set(v8::String::New("version"),
v8::FunctionTemplate::New(Version));

  v8::Local<v8::FunctionTemplate> irct =
v8::FunctionTemplate::New(IRCClient);
  v8::Local<v8::ObjectTemplate> ircpt = irct->PrototypeTemplate();
  ircpt->SetInternalFieldCount(1);
  ircpt->Set("connect", v8::FunctionTemplate::New(IRCClientConnect));
  global->Set(v8::String::New("IRCClient"), irct);

  // Create a new execution environment containing the built-in
  // functions
  context = v8::Context::New(NULL, global);
  // Enter the newly created execution environment.
  return 0;
}
// I'm also using some functions from the sample code


and here's the error i get:

irc = new IRCClient; // this is the code i run
IRCClient called, internal field count=0

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

Aborted

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

Reply via email to