Thanks.  Putting my code after "v8::Context::Scope context_scope(context);"
did fix the crash.  I'll have to dig more into the context vars to see how
merely declaring a variable can affect code later which doesn't seem to
reference my context variable at all (i.e. my point_template doesn't seem
like it should know about my context variable as I'm not passing in the
context to the constructor nor any methods).

But first I have to figure out why Point() is undefined:
[EMAIL PROTECTED]:~/v8/samples$ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./shell
V8 version 0.3.5
DC949's JS Shell> var myPoint = new Point();
(shell):1: ReferenceError: Point is not defined
var myPoint = new Point();
^

as I thought these lines would define a Point (with the accessor code prior
to this):
Point* p = new Point();
Local<Object> obj = point_templ->NewInstance();
obj->SetInternalField(0, External::New(p));



Also, it looks like I was using the release build of the lib; I didn't
realize that the debug build would have a different filename, so I copied
the release build by mistake.  I also think there's something wrong with the
way I'm compiling it, because now it can't find libv8.so unless I set
LD_LIBRARY_PATH to include "."

I compiled my program with this:
g++ -ggdb -g -o shell.o -c -O2 -Iinclude shell.cc && \
        g++ -ggdb -g -o point.o -c -O2 -Iinclude Point.cpp && \
        g++ -ggdb -g -o shell shell.o point.o -L. -lv8 -lpthread

I've also tried making the last command `g++ -ggdb -g -o shell shell.o
point.o -lpthread libv8.so` which should be equivalent (and I get the same
results)

Thanks again,
Adam

On Wed, Oct 22, 2008 at 6:27 AM, Christian Plesner Hansen <
[EMAIL PROTECTED]> wrote:

>
> Hi Adam
> It sounds like you're running the release version of the library.  Try
> building with 'mode=debug', that should give you debugging support.
>
> If you've added this code immediately after the version function is
> set in the shell sample then the problem is probably that no context
> has been created yet.  You can only create instances after you've
> entered a context so if you just move the instance creation to after
>
>  v8::Context::Scope context_scope(context);
>
> I think it will work.
>
>
> -- Christian
>
> On Tue, Oct 21, 2008 at 8:43 AM, Adam Nichols <[EMAIL PROTECTED]>
> wrote:
> >
> > 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