Subj : Re: gc questions (and various questions also) To : Brann Joly From : Brendan Eich Date : Wed May 12 2004 01:41 pm Brann Joly wrote: > the JS_CompileFunction has a Jsobject * param, described like this : "Object > with which the function is associated." > I assume it isn't the "this" object, because this one is specified in > Js_CallFunction, so what is this association? Is it just a GC thing (so that > my function object will not be garbage collected, because it is attached to > the global object for instance), or am i missing someting (i guess i am) It's the object in which the given name is bound as a property, with value equal to the function object created by this API. > Also, I'm wondering what's the difference between Js_DefineObject and > Js_NewObject. (Please, JS_, not Js_. My eyes ache!) JS_DefineObject is just shorthand for JS_NewObject; JS_DefineProperty. See the source. > I wonder if I understand correctly the concept of property. In my model, > only one object is created and set as a root (this object is the Document > element of a Dom tree), Server side DOM, eh? In the client, the window is the "root" (not in a GC sense, exactly, although it could be that you use JS_AddNamedRoot to keep the window object alive; Mozilla roots it by making it the global object of a context associated with it) of the tree of objects that contains document, along with history, location, Date, RegExp, etc. > and when a user wants to access a property of this > object, my getter is called, creates the object if it doesnt exist in > javascript yet, and return the adress of this object. Is it the normal way > to go? Why wouldn't you use the resolve JSClass hook instead? Lazily creating on each get adds overhead to all but the first get calls that you might want to avoid. > Since some of my Dom objects are containing attributes of types not > supported by javascript (Vector for example), how should i do? I thought > that i could create an object with 3 properties (x, y, z) and a private tag > to my vector in dom, with a specialized getter returning the ints to > spidermonkey if the user tries to access x, y or z . Is it a good idea, or > is there a better way to do that? Are these Vector objects values of properties of some other object? If you are trying to follow the DOM, might they be named by id attributes, and fetched via document.getElementById? But then they would want to be DOM Elements, not just Vectors. Before worrying about how to implement things using SpiderMonkey, you need to design your DOM. Is this some X3D or VRML (or OpenInventor, I forget) thing? /be .