Subj : Re: Array Object index question To : netscape.public.mozilla.jseng From : cburdon@tampabay.rr.com (Izman) Date : Tue Oct 28 2003 09:03 am Ok... I obviously asked the wrong questions in the wrong manner. First of all let me say "Thank you" to you Brendan. I am sure you are very busy and any time you take to answer posts in this newsgroup is greatly appreciated, especially by me since I am in no way a C++ or js engine guru by any stretch of the imagination. I will start by stating I am using Spidermonkey 1.5-rc5a on a Windows XP machine with MSVS6. I have been working on a solution to the problem I mentioned in the first post, although I didn't really articulate my goals very well. Ultimately what I thought I needed was an array accessible in javascript that was (in effect) linked to an array of structs in my C code. What I found out was, I was wrong. After many hours of testing and thinking, more testing and thinking, and then even more testing and thinking (about 1000 more times), I finally came up with what I hope to be the solution to my problem. I have an object (JSObject1). I added a method to the object that returns another object (JSObject3). JSObject3 has a private member variable (m_Index) that holds the array index of the struct member it is assigned to access and is set by a public member function named SetIndex. The method I implemented is as follows: JSBool JSObject1::obj3(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { long iIndex = 0; if (JSVAL_IS_INT(*argv)) { JS_ValueToInt32(cx, *argv, &iIndex); } else if (JSVAL_IS_STRING(*argv)) { // The next line is just for testing purposes. iIndex = strlen(JS_GetStringBytes(JSVAL_TO_STRING(*argv))); } JSObject *newObj = JS_ConstructObject(cx, &JSObject3::object3Class, NULL, NULL); JSObject3 *p = (JSObject3*)JS_GetPrivate(cx, newObj); p->SetIndex(iIndex); *rval = OBJECT_TO_JSVAL(newObj); return JS_TRUE; } This method (in my testing) accomplishes my goals. The method allows me to access the properties of a JSObject3 object (such as a property named prop1) through javascript, as in: Object1.obj3(2).prop1 My concern is that garbage collection may negatively impact the script or that this may cause some type of memory leak. Obviously there is some error checking that could occur in the function. Sans error checking, could someone please let me know if there is anything inherently incorrect with my solution? Thank you in advance for any help that is provided. Izman .