On Sat, Sep 3, 2016 at 1:32 AM, Ben Noordhuis <[email protected]> wrote:
> On Sat, Sep 3, 2016 at 12:58 AM, Zach Bjornson <[email protected]> > wrote: > > On Fri, Sep 2, 2016 at 3:54 PM, Ben Noordhuis <[email protected]> > wrote: > >> > >> On Fri, Sep 2, 2016 at 5:42 AM, Zach Bjornson <[email protected]> > >> wrote: > >> > 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(...); > >> > assert(!c.hasOwnProperty("width")); > >> > assert("width" in c); > >> > assert(HTMLCanvasElement.prototype.hasOwnProperty("width")); > >> > > >> > Currently there's an assertion failure (from nan) because the > >> > InternalFieldCount for the PrototypeTemplate is 0. Setting it to 1 > fixes > >> > this problem, but without touching the rest of the code, both the > >> > FunctionTemplate and the PrototypeTemplate now have an > >> > InternalFieldCount of > >> > 1. Is that the correct situation? I can't find any examples of setting > >> > accessors on prototypes to work from. > >> > > >> > The class in question is this: > >> > https://github.com/Automattic/node-canvas/blob/master/src/ > Canvas.cc#L30 > >> > (sorry it uses nan's macros and not raw v8 APIs) > >> > and the patch setting the PrototypeTemplate's InternalFieldCount is > >> > > >> > https://github.com/Automattic/node-canvas/issues/803# > issuecomment-244275154 > >> > > >> > Thanks, > >> > Zach > >> > >> Nan maintainer here. What you describe sounds correct; setting the > >> internal field count on a template reserves that many slots in > >> instances of that template. > >> > > > > Thanks. To be totally clear -- setting the IFC on *both* the > > PrototypeTemplate and FunctionTemplate is reasonable? > > > > -Zach > > FunctionTemplates don't have an SetInternalFieldCount() method, only > ObjectTemplates do. Did you mean PrototypeTemplate() and > InstanceTemplate()? > > Setting the count on one should not affect the other, i.e., you would > have to set it explicitly on both if they both should have data slots > - and yes, that is a reasonable thing to do. > > Oops, yes -- meant InstanceTemplate. Thanks for your help! -- -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
