Subj : Re: Checking JSObject class type To : netscape.public.mozilla.jseng From : Brian Genisio Date : Mon Jan 26 2004 02:22 pm t o b e wrote: >>>Could you use >>> >>> JS_GetClass(new_obj) == classSpec >> >>Well, I suppose I can do that, but I would have to define an "==" >>operator, which would have to consist of a check of the name value, in >>addition to everything else... > > > Eh ?? That's a direct comparison of the address of the class object from > which the object was made with the address of an arbitrary class object. If > the two are the same then new_obj is of the type classSpec describes. > > Simple as that... no strings involved whatsoever. > > t o b e > > > > Yeah, that would work, but it assumes a specific implementation of the jsapi... it assumes that the object's class spec has the same pointer as the spec used to initialize the class. If the jsapi ever changes it's implementation, and makes it's own copy of the JSClass structure, this check will fail. But, along those lines, if I know that the JSClass I am using has a finalize methiod, I can check finalize pointers... Js_GetClass(new_obj)->finalize == classSpec.finalize But then, if some maintainer of my code in the future pulls out the finalize method, it would break this line, as all objects without finalize methods would evaluate as true. I was comparing strings, because that seems to be the only unique, and guaranteed way of checking classes that I have been able to find so far. Brian .