Subj : Re: spidermonkey: reserved slot vs. private To : Jens Thiele From : Brendan Eich Date : Fri Sep 17 2004 06:43 pm Jens Thiele wrote: > Are JS_SetPrivate / JS_GetPrivate functionally "equal" > to > JS_SetReservedSlot / JS_GetReservedSlot > ? > > to use JS_SetPrivate / JS_GetPrivate one has to specify > JSCLASS_HAS_PRIVATE in the JSClass structure > > to use JS_SetReservedSlot / JS_GetReservedSlot one has to specify > JSCLASS_HAS_RESERVED_SLOTS(xxx) Slots are slot, if that's what you mean by "equal", but JSCLASS_HAS_PRIVATE predates JSCLASS_HAS_RESERVED_SLOTS(n) by many years, and backward API compatibility is king. > are reserved slots handled like "normal" properties? > (they are jsval's, they are garbage collected?, ...) > but hidden They're unnamed by any property, scanned by the GC, got and set by native code using the API. > => reserved slots could sometimes be an alternative to private data > > What I want to do: > i use SetPrivate/GetPrivate to store some pointer to an native object > (always making sure the class is correct) > > the js object finalizer should only free the native object referenced by > the pointer if the js object owns this native object > => i must store that ownership information somewhere > of course i could wrap the pointer and the ownership information in > another struct (or store this information somewhere completely > different) but if i could use the reserved slot to store the ownership > information this would be much simpler. You may use a reserved slot for this flag. Under what conditions would the JSObject *not* own the private data? In those cases, what protects the JSObject from having a dangling (or null, if you JS_SetPrivate(cx, obj, NULL)) private? /be .