When embedding Python there is the PyCapsule type to create an object containing a C pointer which cannot be modified from Python code, i.e. it’s perfect to pass around stuff that is used only by the C code.
Since my application also supports JavaScript via the SpiderMonkey engine I’m looking for something similar in SpiderMonkey. I know that I can create a custom JSClass with the JSCLASS_HAS_PRIVATE flag but I wonder if there’s another simpler/more lightweight approach.
There is nothing similar so it is indeed necessary to create a custom class. This is the code I ended up using; it defines a new class “Resource” to store the pointer. While not as pretty as the python way it’s still very straightforward: