Re: Upgrading from Spidermonkey 1.8.5 to 45. How to get property name in getters/setters now they are JSNatives and tiny IDs have been removed?
Thomas Richter <[email protected]> Mon, 5 Jun 2017 11:44:36 +0200
| Newsgroups | gmane.comp.mozilla.devel.jseng |
|---|---|
| Message-ID | <[email protected]> |
Hi Miles,
so far I know, you have define different property getter/setter for each
property. That's the way I did it.
Thomas
Am 05.06.2017 um 11:31 schrieb Miles:
> Hi,
>
> I'm trying to upgrade my embedding from 1.8.5 to 45 and one of the things that I'm struggling with is how property getters/setters now work in 45.
>
> In 1.8.5 I used tiny IDs and JSPropertySpec to define properties and getters/setters for a class.
> e.g. In 1.8.5 I had something like
>
> enum part_tinyid {
> PART_HEADING,
> PART_PID,
> PART_SECID,
> PART_MID,
> ...
> };
>
> JSPropertySpec dj_Part_dynamic_props[] =
> {
> {"heading", PART_HEADING, flags, dj_get_part_prop, dj_set_part_prop },
> {"pid", PART_PID, flags, dj_get_part_prop, dj_set_part_prop },
> {"secid", PART_SECID, flags, dj_get_part_prop, dj_set_part_prop },
> {"mid", PART_MID, flags, dj_get_part_prop, dj_set_part_prop },
> ...
> { 0 }
> };
>
>
> and then my getter was something like
>
> JSBool dj_get_part_prop(JSContext *cx, JSObject *obj, jsid propid, jsval *vp)
> {
> jsval id = JS_IdToValue(cx, propid, &id);
> int idint = JSVAL_TO_INT(id);
>
> switch (idint)
> {
> case PART_HEADING:
> ...
> break;
>
> case PART_PID:
> ...
> break;
> }
>
> }
>
> i.e. I had a single getter and a single setter for all of the properties and I could find which property I was getting/setting from propid
>
> Now in Spidermonkey 45 Tiny IDs have been removed and dj_get_part_prop/dj_set_part_prop are JSNatives so I have something like:
>
> JSPropertySpec dj_Part_dynamic_props[] =
> {
> JS_PSGS("heading", dj_get_part_prop, dj_set_part_prop, flags),
> JS_PSGS("pid", dj_get_part_prop, dj_set_part_prop, flags),
> JS_PSGS("secid", dj_get_part_prop, dj_set_part_prop, flags),
> JS_PSGS("mid", dj_get_part_prop, dj_set_part_prop, flags),
> ...
> JS_PS_END
> };
>
>
> JSBool dj_get_part_prop(JSContext *cx, unsigned int argc, JS::Value *vp)
> {
> JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
> JS::RootedObject obj(cx, JS_THIS_OBJECT(cx, vp));
> }
>
> I can get the object by using JS_THIS_OBJECT and I can see that in the getter argc is 0, in the setter argc is 1 and args[0] contains the value of the property to set.
> However, I can't see any way to find out *which* property I am getting/setting.
>
> Am I being stupid here? How can I find out which property I am getting/setting? I know that tiny IDs have gone so I was expecting the property to be passed as a string or something.
> Or is there no way of getting the property name and I have to use a different property getter/setter for each property?
>
> If someone can help me I would be very grateful.
>
> Thanks
>
> Miles
> _______________________________________________
> dev-tech-js-engine mailing list
> [email protected]
> https://lists.mozilla.org/listinfo/dev-tech-js-engine
>
--
Dipl.-Ing. Thomas Richter
otris software AG
Königswall 21
D-44137 Dortmund
Fon +49 (0)231 958069-0
Fax +49 (0)231 958069-44
www.otris.de
GPG/PGP: 0x37739AF8
HRB 15040, Amtsgericht Dortmund
Vorstand: Dr. Frank Hofmann, Dr. Christoph Niemann
Aufsichtsratsvorsitzender: Norbert Niemann
_______________________________________________
dev-tech-js-engine mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine