48a Subj : Re: Array Object index question To : Izman From : Brendan Eich Date : Tue Oct 28 2003 09:39 am Izman wrote: > 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); [. . .] > 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? > You are constructing a new object every time someone calls obj3(). Why is that? Wouldn't you rather return the same object each time? /be . 0