Thanks Zhong xiang! That seems to be exactly what I'm looking for! I'll try that!
On 9月7日, 上午1時13分, Zhong xiang <[email protected]> wrote: > You should probably use Weak persistent handle. With weak persistent handle, > you will be notified when the wrapper handle is reclaimed. > > Please check line 389 in v8.h, > /** > * Make the reference to this object weak. When only weak handles > * refer to the object, the garbage collector will perform a > * callback to the given V8::WeakReferenceCallback function, passing > * it the object reference and the given parameters. > */ > inline void MakeWeak(void* parameters, WeakReferenceCallback callback); > > Here is an > example:http://create.tpsitulsa.com/blog/2009/01/31/persistent-handles/ > <http://create.tpsitulsa.com/blog/2009/01/31/persistent-handles/> > > > > On Sun, Sep 6, 2009 at 6:41 PM, Kenji <[email protected]> wrote: > > > Hi, it's simple. I want my JS script to new/create object of my type. > > Let's say Point: > > > class Point { > > public: > > int x, y; > > }; > > > I know how to "bind" an existing c++ object to JS and so script can > > modify that object's content. But I want JS to hold the object or a > > "reference" of it. > > I'm not sure how the "construct Point function" should be written. > > I tried this: > > > Handle<Value> Point_func(const Arguments & args) { > > Point* p = new Point(); > > args.This()->SetInternalField(0, External::New(p)); > > return Undefined; > > } > > > In the setter function I can get the object pointer. But how/when can > > I free the object?? > > > Or should I provide a JS function to new my Point and c++ keeps the > > ownership of it, while JS side just keep a reference of it? > > > Can anyone help me? Do you have more documentation? > > > Many thanks~ > > > Kenji --~--~---------~--~----~------------~-------~--~----~ v8-users mailing list [email protected] http://groups.google.com/group/v8-users -~----------~----~----~----~------~----~------~--~---
