JSCLASS_HAS_PRIVATE, JS::GetPrivate and JS::SetPrivate removed in 102ESR. What to replace with?

Hi,
I’m trying to update my embedding from 91ESR to 102ESR.
I’ve now compiled the library on windows and Linux and am starting to look at what has changed in the JS API as I am getting lots of errors when tryign to compile my code.

The first problem I have come across is that the JSCLASS_HAS_PRIVATE flag has been removed and JS::GetPrivate & JS::SetPrivate no longer exist.

I used this to store/get/set a private (void *) pointer for objects in my embedding. If this is no longer available what can I use instead?
Looking in Class.h I can see

// First reserved slot is PrivateValue(nsISupports*) or UndefinedValue.
static constexpr uint32_t JSCLASS_SLOT0_IS_NSISUPPORTS = 1 << 3

which looks like it could maybe be used to store a private value but I have no idea if this is correct, and if so, how to use it.

Can anyone point me in the right direction here? Is there an example anywhere that I could use to see how a private (void *) pointer can be stored for an object?

Apologies in advance. I suspect that this could be the first of several questions!
Is there any documentation anywhere describing what has changed between 91ESR and 102ESR in the JS API so I don’t ask stupid questions?

Many thanks

Miles

1 Like

You are correct. Previously, PrivateValue had alignment restrictions and so could not be used to store arbitrary pointers. We’ve removed that restriction, so the separate JSCLASS_HAS_PRIVATE mechanism is no longer needed and it is expected that you would replace its usage with a PrivateValue in a reserved slot.

PrivateValue still can’t handle any arbitrary 64 bits, though. The top 16 bits need to be clear. (We support a 48-bit address space.)

As a bonus, if you were storing a GC pointer into the private slot, you would have been tracing it with a custom trace hook. Now you can store it as a PrivateGCThingValue and it will be automatically traced during GC. (You’d still need a trace hook for a pointer to a regular C++ structure that itself contains GC pointers, or if the private pointer is something other than a regular strong edge. But this removes one common reason for needing a trace hook.)

Thanks for the reply.
You said
the separate JSCLASS_HAS_PRIVATE mechanism is no longer needed and it is expected that you would replace its usage with a PrivateValue in a reserved slot.
Errrm. Probably a very silly question, but how to I do that then? I’ve never used “slots” before. Is there an example anywhere that I can follow?

Thanks

Miles

There are examples in the ESR102 migration guide (which unfortunately has yet to be merged)

Thanks for reply.
I did manage to work out how to do it in the end by looking in the source code. It was actually very easy.
Upgrading my embedding from ESR91 to ESR102 was fairly painless and easy and all seems to work without any problems so far :slight_smile:
I think that the JSAPI sems to be a lot more stable these days which makes it much easier. Thanks!