Subj : Re: Properties not defined with JS_DefineProperty possible? To : Thomas Sondergaard From : Brendan Eich Date : Sat Jan 15 2005 06:03 pm Thomas Sondergaard wrote: > On Sat, 08 Jan 2005 14:06:46 -0800, Brendan Eich wrote: > > >>Of course -- JSClass.getProperty and JSClass.setProperty can mirror >>changes from and to your std::map. You can set the JSClass.flags bit >>JSCLASS_SHARE_ALL_PROPERTIES to avoid any parallel map being managed by >>SpiderMonkey. Then for each get or set, the appropriate JSClass hook >>will be called and you can fetch or store using your map. > > > Hi Brendan, > > Yes, I realize that I don't have to keep *values* in sync and that I can > have spidermonkey invoke the get/setProperty (JSPropertyOp) to get/set the > value from my native object, but can I avoid having to tell spidermonkey > what properties (names!) exist up front with > JSDefineProperty/JSDefineProperties? Certainly. Did you try using JSClass.getProperty? It will be called for any property get on objects of that class, whether the property is predefined or not. > As an example, let's say I have defined an object called 'data' and I want > the properties on it to reflect the contents of my c++ std::map string>. So if the expression "data['noOfImages']" (or "data.noOfImages") > is evaluated how does the js engine know which jsid to pass to my > getPropertyOp JSClass.getProperty takes a jsval id, not a jsid -- are you hacking with JSObjectOps, or just trying to follow the internals? Playing around with the "it" object in the js shell, setting it.noisy = true first, should be enlightening. > if I have not previously told the engine that the object has > a property with that name using JSDefinePropert*? Is this possible? What > I'm thinking of is a hook that the engine will call to lookup properties > on an object dynamically. The hooks you need already exist. /be .