Subj : Re: [SpiderMonkey] Confused about class property To : netscape.public.mozilla.jseng From : Peter Paulus Date : Fri Oct 07 2005 02:56 pm Brendan Eich wrote: > Peter Paulus wrote: > >> >> >> Not just to start a monologue, I've disassembled the javascript: >> >> var x = ColorSpace.lab; >> >> into: >> >> 00000: 0 defvar "x" >> main: >> 00003: 0 bindname "x" >> 00006: 0 name "ColorSpace" >> 00009: 0 getprop "lab" >> 00012: 0 setname "x" >> 00015: 0 pop >> >> So I guess it must be the interpreter that turns ColorSpace into a >> Function object, rather than an 'ColorSpace' object. >> >> Are there flags on my JSClass struct or otherwise to manipulate this >> behavior? > > > If you don't want your call to JS_InitClass to bind a constructor to the > class name in the global object, pass null for the |constructor| formal > parameter. Then the class name will denote a prototype object of your > class, containing the properties and methods (not the static properties > and methods) you specify. > > /be I'm not sure I want to bind a constructor. I've looked at the constructor as a convenient place to bind private data to an object (JS_SetPrivate()). Up till now I've been passing the constructor function to JS_InitClass() and was still able to handle JSBool getClassProperty(JSContext*, JSObject*, jsid, jsval*) for any class. This has worked fine, since every JSClass pointed to it's own static JSBool getClassProperty(JSContext*, JSObject*, jsid, jsval*) function. Implicitely, when this function is called, you know for which class this is. There was never a need to examine the JSObject* in this case. Based on the id I could return an appropriate result. In my current project I'm trying to build classes dynamically in SpiderMonkey from Adobe InDesign's ExtendScript, in order to use their native objects from Spidermonkey. In this setup I have exactly one static method: JSBool getClassProperty(JSContext*, JSObject*, jsid, jsval*) to serve all classes. Now I was suprised to find that JSObject* pointed to a "Function" object. If I omit the constructor function with JS_InitClass() indeed the getClassProperty() contains the right kind of object. But then I have lost my place to augment a JSObject with my private data. Can you advise me of a suitable place to add private data to a JSObject? Am I not missing out on the constructor function in case some script uses: var x = new ColorSpace() var y = ColorSpace() ? I've been trying to read the ECMA spec on this subject (section 11.2.1, Property Accessors). Can you elaborate on this some more, because I was expecting to find some reference to [Construct]? With kind regards, Peter Paulus .