Subj : Re: beginner question spidermonkey To : netscape.public.mozilla.jseng From : marian simon Date : Sat Sep 04 2004 11:27 pm hi, thanks for yout hint. I think you didn't understand exaxtly what my problem was,but now (by your answer) I get ahead. (my function getname() was just a dummy-callback for debuging-purpose) I just have some startup-problems with the spidermonkey interface concept, ( not with C or C-syntax). ( It's not easy to ask a proper question if I don'k exactly know what I'm talking about ... :-) ) I have already added some functions to a SVG-player and now I want to add JS for DOM. It is necessary to call "JS_NewObject" if my "C" function returns a pointer, and store the pointer in private data. When is this new JSObject deleted ??? This is how I now think it schould work: static JSBool getElementById (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { int i; JSObject *myobj; argc--; i=JSVAL_TO_INT(argv[argc]); ele=doc->list[i]; if(JSVAL_IS_OBJECT(*rval)) //is this required ??? { // no new object because already exists ? if(! (myobj=JSVAL_TO_OBJECT(*rval))) return JS_FALSE; if( ! JS_SetPrivate(cx, myobj, (void*) ele)) return JS_FALSE; *rval = OBJECT_TO_JSVAL(myobj); }else { // create new object and save my private pointer // new ok, but when delete ? automatic ? myobj = JS_NewObject(cx, &element_class,js_element,NULL); if( ! JS_SetPrivate(cx, myobj, (void*) ele)) return JS_FALSE; *rval = OBJECT_TO_JSVAL(myobj); } return JS_TRUE; } "Sterling Bates" schrieb im Newsbeitrag news:ch8cpm$cuc1@ripley.netscape.com... > (I just received this today, but the date was August 26...?) > > "marian simon" wrote in message > news:ch83nk$d741@ripley.netscape.com... > > static JSBool getName (JSContext *cx, JSObject *obj, uintN argc, jsval > > *argv, jsval *rval) > > { > > char *name; > > > > name=ele->get_name(); //not good ?? > > printf("get_Name() name = %s obj=0x%x argc=%d \n",name,obj,argc); > > > > return JS_TRUE; > > } > > I'm not sure if this is a typo, but you're not setting *rval to the actual > name. Brendan'll correct me if I'm wrong, but you probably want this: > > JSString *str; > str = JS_NewString(cx, name, strlen(name)); > *rval = STRING_TO_JSVAL(str); > > strlen() may not be right, but I don't recall C[++]'s string length function > :) Also, it may not be right to create a new JSString for every function > call, but aside from making that a property of the object I don't know any C > solutions. > > Sterling > > .