I'm trying to get a feel for how to create a C++ class and make it
available in JS.  I was able to do this with a simple C++ function,
but I'm having some trouble with the objects.  I'm following the
embedding guide directly and merely modifying shell.cc; when the code
gets to this line (v8::Local<v8::Object> obj = point_template-
>NewInstance();) it segfaults.  I've tried tracing though with gdb,
and it gets somewhere into ObjectTemplate::NewInstance() but I don't
have line numbers or anything available.

Here's the code from shell.cc after binding the version function:
  // This is me including my own custom C++ class and giving access to
JS
  v8::Handle<v8::ObjectTemplate> point_template =
v8::ObjectTemplate::New();
  point_template->SetInternalFieldCount(1); // each JS var will be
connected to one C++ object
  // all JS objects should have x and y values
  point_template->SetAccessor(v8::String::New("x"), getXValue,
setXValue);
  point_template->SetAccessor(v8::String::New("y"), getYValue,
setYValue);
  Point* p = new Point();
printf("Everything is OK\n");
  point_template->NewInstance();
//  v8::Local<v8::Object> obj = point_template->NewInstance();
printf("Everything is *not* OK\n");
//  obj->SetInternalField(0, v8::External::New(p));

The Point class is the same as the example except I made the members
private and gave them accessors.  getXValue, getYValue, setXValue, and
setYValue are all pulled from the embedding guide (except they use the
accessors to get/set values instead of a simple assignment operator).

My question is this: how can I debug the v8 lib (and have line numbers
source code available to gdb, etc)?  Also, if anyone knows why it's
segfaulting, I'm a bit curious where I've gone awry.

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

Reply via email to