Subj : Problems with garbage collection and read-only properties. To : netscape.public.mozilla.jseng From : "Chris Nuernberger" Date : Thu Nov 20 2003 11:46 am Hey, we have managed to set up a situation where we have made it difficult to mark a jsobject as a property of another object. Using prototypes and the tinyid system, we set up a few properties to be read only. Then when we actually make an object of the class, we cannot set its read-only members as properties of the new class on construction of the class (that makes sense...). But then if you run the garbage collection routine, because the read-only objects cannot be set into the objects slots, the marking phase misses them and they get nuked. To reiterate, jsobject myObject = (create new js object representation); //Property defined without initial value (just for the example, and because at the initial creation of the object we don't know what it's context will always be, we just know the script shouldn't change it) JS_DefinePropertyWithTinyId( cx, myObject, "context", blah, JSPROP_READONLY ); jsobject myContext = (create new js context); //Oops, this will not work... JS_SetProperty( blah, myObject, blah, myContext ); Even if JS_SetProperty did work it is not ideal because it calls the setter of myObject, and in the case where I want to initialize the properties from the constructor of a c++ object, the setting system may not be set up yet (I haven't set the private data of the jsobject to by my object yet), and I don't want to set the property on myself, I want to set it on the jsobject... There is no way from this point on that I can see to get myObject's slots to contain myContext, unless you perhaps used JS_DefinePropertyWithTinyId again, this time with the value you set it as, but that seems kind of retarded because I already defined details about the property, now I simply need to set the value in a slot of the jsobject. I was wondering how the system does its own read-only properties, (math for example). I was thinking about creating my own spider monkey function that is exactly the same as the SetProperty method except it does not dump out of the method if the property is read only, and it does not call SPROP_SET (because the object isn't necessarily set up yet...). This method would be called most from objects who already have prototypes set up, and needs to set the slot value correctly for read-only properties on instance objects. Any ideas? Thanks a lot, Chris .