You have to do this the same way you'd do it in JS: define accessor
properties on the prototype object, and use a different function for each
one. That way, each function is used to access a single specific property.
So you won't need to know which property was requested.

You can define accessor properties using `JS_InitClass`. Pass an array to
the `ps` argument. In the array, use `JS_PSG(name, getter, 0)` to specify
each accessor property, or `JS_PSGS(name, getter, setter, 0)` for
properties that have a setter. Terminate the array with `JS_PS_END`.

In the getter/setter, check the type of the this-argument to make sure it's
an object and it's got the expected JSClass. Once you have checked that,
you can extract a pointer to a native structure from this object's private
value or a reserved slot.

-j


On Fri, Dec 18, 2015 at 7:20 AM, <[email protected]> wrote:

> Hello,
>
> I faced similar problem.  I have to create multiple properties with
> getter/setters written in c++.  In callbacks (JSNative getters and setters)
> I need to know which property was requested.  Actually I prefer to pass
> pointer to native structure instead of property name.  Can someone point me
> how to make slots for JSNative getters/setters and how to use them?
>
> воскресенье, 29 марта 2015 г., 7:18:33 UTC+3 пользователь Boris Zbarsky
> написал:
> > On 3/28/15 11:48 PM, obastemur wrote:
> > > I have getter/setter implementation that makes a JS side object (an
> object created on the JS land, which doesn't have private slot or extra
> slots.
> >
> > OK, that's fine.  I'm saying your getter or setter can have extra slots
> > to store the property name in.  I'm not talking about storing anything
> > like that on the receiver object.
> >
> > > The getter/setter methods checks for the 'id' and returns / sets
> from/to external memory.
> >
> > Right, so they'd continue doing that, using the id added to them at
> > creation time.
> >
> > -Boris
> _______________________________________________
> dev-tech-js-engine-internals mailing list
> [email protected]
> https://lists.mozilla.org/listinfo/dev-tech-js-engine-internals
>
_______________________________________________
dev-tech-js-engine-internals mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-internals

Reply via email to