Setting property attributes after calling JS_SetProperty()

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Setting property attributes after calling JS_SetProperty()

harry.buttery33
Hi,


I'm currently trying to upgrade a program from using JS 1.8.5 to JS 76. In doing this, I've come across a function in which we try to:

- set a property that doesn't initially exist on an object, using JS_SetProperty(),

- then set that property's attributes to be JSPROP_PERMANENT, using JS_SetPropertyAttributes().

However, in JS 76, JS_SetPropertyAttributes() doesn't appear to exist. Instead, I've had to:

- get the property descriptor, using JS_GetPropertyDescriptor(),

- then set the attributes using .setAttributes().

I'm struggling to find any documentation on the matter so I'm not sure if this is even correct. Is there a new/alternative function to replace JS_SetPropertyAttributes() with?


Many thanks,
Harry
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Reply | Threaded
Open this post in threaded view
|

Re: Setting property attributes after calling JS_SetProperty()

Tom Schuster
Hi!

You can instead use JS_DefineProperty to directly set the property
attributes while defining a new property.

Example:
if (!JS_DefineProperty(cx, object, "name", value, JSPROP_PERMANENT)) {
return false;
}

Cheers,
Tom

On Wed, Jul 1, 2020 at 6:00 PM <[hidden email]> wrote:

>
> Hi,
>
>
> I'm currently trying to upgrade a program from using JS 1.8.5 to JS 76. In doing this, I've come across a function in which we try to:
>
> - set a property that doesn't initially exist on an object, using JS_SetProperty(),
>
> - then set that property's attributes to be JSPROP_PERMANENT, using JS_SetPropertyAttributes().
>
> However, in JS 76, JS_SetPropertyAttributes() doesn't appear to exist. Instead, I've had to:
>
> - get the property descriptor, using JS_GetPropertyDescriptor(),
>
> - then set the attributes using .setAttributes().
>
> I'm struggling to find any documentation on the matter so I'm not sure if this is even correct. Is there a new/alternative function to replace JS_SetPropertyAttributes() with?
>
>
> Many thanks,
> Harry
> _______________________________________________
> dev-tech-js-engine mailing list
> [hidden email]
> https://lists.mozilla.org/listinfo/dev-tech-js-engine
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine