Hi all,
 I am customizing the FunctionTemplate of a constructor, so that the
 constructed objects have the necessary bindings. However, I still
have
 my C++ callback called by the js constructor, so that I can create
the
 native part and set the object's internal fields.

Here is how I create the constructor

         Handle<FunctionTemplate> ctor =
FunctionTemplate::New(jsCtorCallback,
 External::New(userdata));
         Handle <ObjectTemplate> objTempl = ctor->PrototypeTemplate();
         customizeObjectTemplate(objTempl);

I cache objTempl to a Persistent<ObjectTemplate> handle in my app, so
that I can avoid re-creating the template eveyr time the ctor is
called.

 Later, from inside the the ctor callback, I try to create the object
 with:
         objTempl->NewInstance();

 However, when the constructor callback returns, the app crashes with
 access violation. It seems I am doing it wrong, but what exactly?

P.S.
Seems the problem is unrelated to the function. If I create an
ordinary object template:

  Persistent<ObjectTemplate> objt(ObjectTemplate::New());
  customizeObjectTemplate(objt);

in the place where I obtained one from the constructor function, and
then store the persistent handle, using it later results in the same
crash.

However, if I write the above 2 lines in the ctor callback itself,
when constructing the object, that is - if I construct the object via
a freshly created and customized object template, everything works
fine. I am using this 'caching' with an initially-created template, to
optimize performance. But if I don't find the cause for the crash I
will create the template every time the ctor is called.
Any ideas?

Alex

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

Reply via email to