Subj : Re: define new function in Class String (Spidermonkey) To : Blaubaer From : Brendan Eich Date : Tue Jan 04 2005 04:39 pm Blaubaer wrote: > I want's to define a new function in jsstr.c and I want to change the value > of the String. > > OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE); works but: > OBJ_SET_SLOT(cx, obj, JSSLOT_PRIVATE, val); resets the value after leaving > the funtion? :-( You don't want to do that. First, put extensions in separate files, and add your methods to the object you get back in v from: JSBool ok; jsval v; const char Sp[] = "String.prototype"; ok = JS_EvaluateScript(cx, global, Sp, sizeof Sp - 1, NULL, 0, &v); Second, by changing the private data of a String object wrapper, you are not affecting the characters in the primitive type string value. Nor can you, for several good reasons including ECMA-262 and sharing sanity. Why do you think you want to mutate a string, anyway? /be .