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.)

[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-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

Re: [v8-users] Need to SetInternalFieldCount for both PrototypeTemplate and FunctionTemplate?

2016-09-02 Thread Zach Bjornson
On Fri, Sep 2, 2016 at 3:54 PM, Ben Noordhuis <i...@bnoordhuis.nl> wrote: > On Fri, Sep 2, 2016 at 5:42 AM, Zach Bjornson <zbbjorn...@gmail.com> > wrote: > > Hello, > > > > I'm trying to fix some code that creates a wrapped C++ object ("Canvas",

[v8-users] Re: Right way to access ArrayBufferView and ArrayBuffer.

2016-09-01 Thread Zach Bjornson
Not sure if you still need help with this, but ... expanding on what Ben said: Node Buffers are Uint8Arrays (ArrayBufferViews) in version 4.x and later only. Small node Buffers ([currently] <4096 bytes) use a shared buffer as a backing store, which is why you see a greater byteLength. You

[v8-users] Need to SetInternalFieldCount for both PrototypeTemplate and FunctionTemplate?

2016-09-01 Thread Zach Bjornson
Hello, I'm trying to fix some code that creates a wrapped C++ object ("Canvas", emulating HTMLCanvasElement) with property accessors on the prototype. Specifically, these assertions should work to reflect browsers' HTMLCanvasElement API: var c = new Canvas(...);

[v8-users] TypedArray data access and memory allocation behavior threshold

2015-07-29 Thread Zach Bjornson
Some of this has been discussed before, but the API has changed a lot recently and I'm lost a bit in the discussion. In v8 4.2.77.20 (version in iojs 2.4.0) the following seems to work for arrays *larger than 64 bytes:* LocalUint8ClampedArray arr = args[0].AsUint8ClampedArray(); void