Subj : Re: Enumerating standard class properties & methods To : netscape.public.mozilla.jseng From : "Sterling Bates" Date : Wed Dec 17 2003 02:36 pm "Brendan Eich" wrote in message news:3FE0C28F.7060300@meer.net... > Sterling Bates wrote: > > > I agree that hardcoding is not always a good thing, but ruling it out brings > > me back to square one. I'm not aware of another option to dynamically > > discover the properties and methods of standard classes. > > If you don't need to enumerate them (JS does not), then why do you not > simply look up any name on demand, and find whether it refers to a > property of the global object (etc. down the object "tree" or graph)? I don't actually need the list of methods for the bridge code to work, I need it so that clients of the bridge will get a list of methods of all objects when they call Enumerate on them. Maybe it's easier to show the code. A TJSObject is a wrapper for any JSVAL_OBJECT (written here from memory...): TJSObject = class private JSObj: PJSObject; public [...] function Enumerate: TStringArray; procedure GetProperty(const Name: String; var retval: TJSObject); [...] end; function TJSObject.Enumerate: TStringArray; var jslist: JSIdArray; begin jslist := JS_Enumerate(self.JSObj); [... parse into Delphi string array ...] end; procedure TJSObject.GetProperty(const Name: String; var retval: TJSObject); var rval: jsval; jsobj: PJSObject; prv: Pointer; begin JS_GetProperty(Context, JSObj, PChar(Name), @rval); jsobj := JSValToObject(rval); prv := JS_GetPrivate(Context, jsobj); if (prv = nil) then retval := TJSObject.Create(JSEngine, jsobj) else retval := TJSObject(prv); end; First the user calls Enumerate for the currently wrapped jsobject (say global). When the user gets to an item of type Object (determined elsewhere), it calls the above GetProperty method, which wraps the property of that name in another TJSObject, or reuses the current wrapper for that property. It's like reconstructing the object tree, as necessary, in Delphi. When a TJSObject is wrapping a Date-classed object, the .Enumerate call will return an empty array. The ideal is to return a list of methods, since that's what the client expects. That's where I'm pondering the hardcoded list of properties. Sterling .