Re: [v8-users] Storing a weak reference to a function, or otherwise avoiding a memory leak

2017-09-18 Thread Ben Noordhuis
On Mon, Sep 18, 2017 at 6:13 PM, Zach Bjornson wrote: >> `myObj.onevent()` invokes `onevent()` with `this === myObj`. Unless >> you want to deviate significantly from normal JS semantics, you would >> need to maintain a reference to `myObj` anyway. > > > (The spec I'm emulating actually states th

Re: [v8-users] Storing a weak reference to a function, or otherwise avoiding a memory leak

2017-09-18 Thread Zach Bjornson
> > `myObj.onevent()` invokes `onevent()` with `this === myObj`. Unless > you want to deviate significantly from normal JS semantics, you would > need to maintain a reference to `myObj` anyway. > (The spec I'm emulating actually states that `onevent()` is invoked with the global context.) So

Re: [v8-users] Storing a weak reference to a function, or otherwise avoiding a memory leak

2017-09-18 Thread Ben Noordhuis
On Sat, Sep 16, 2017 at 3:17 AM, Zach Bjornson wrote: > Hello, > > I'm trying to implement this type of interface: > > var myObj = new MyObj(); > myObj.onevent = function () { > // might be a reference to myObj here > } > myObj.doSomethingAsync(); // causes `onevent` to fire; can be called more

[v8-users] Storing a weak reference to a function, or otherwise avoiding a memory leak

2017-09-15 Thread Zach Bjornson
No, storing a weak reference on the object itself won't work. Maybe a map of Persistent, not associated with the MyObj instances, but keyed on the MyObj instance? SetOnevent stores to that map; firing an event involves a lookup; MyObj's destructor deletes from the map? Thanks, Zach -- -- v8-

[v8-users] Storing a weak reference to a function, or otherwise avoiding a memory leak

2017-09-15 Thread Zach Bjornson
Hello, I'm trying to implement this type of interface: var myObj = new MyObj(); myObj.onevent = function () { // might be a reference to myObj here } myObj.doSomethingAsync(); // causes `onevent` to fire; can be called more than once `onevent` (a C++ setter) currently stores the callback func