Subj : Re: [spidermonkey] getter/setter for all properties of an object To : netscape.public.mozilla.jseng From : franck Date : Wed Aug 17 2005 04:26 pm Brendan Eich wrote: > franck wrote: > >> Hello, >> >> I am tring to make a little object that allows me to listen all >> properties get and set of an object ( a kind of super watch ). >> All is working properly, however I noticed that even if I defined my >> own setProperty, the property is stored in the object ( I can see it >> using a for-in loop ). > > > > If you don't want a property to be enumerated by a for-in loop, you must > define it without the JSPROP_ENUMERATE attribute. In your example, you > set obj.foo = 1234, which makes an enumerable property, per ECMA-262. > You would have to add a resolve hook that defines the property id being > resolved with 0 attributes to avoid this. > > If you want to avoid storing the last-got or last-set value in a slot > (the normal storage for a property value, allocated by default), you > would want to use JSPROP_SHARED as the attributes when resolving. > > If you wish to resolve only when the id is being assigned to, you want > JSCLASS_NEW_RESOLVE, and in your JSNewResolveOp, define that id only if > JSRESOLVE_ASSIGNING. > > /be Thanks for your help Brendan. Now I'm using JSCLASS_SHARE_ALL_PROPERTIES in the JSClass flags, and I defined an ( empty ) newEnumerate hook to avoid for-each to detect anything. If I understood, there is no way to avoid the property name to be stored in the object ( JSPROP_SHARED is only for the value ) var obj = new ObjectEx() for ( var i=0; i<100000; i++ ) obj[i] = some_datas; This will create 100000 strings ( the name of the properties '0'...'99999' ) in the object ? .