Subj : Re: JS_AddNamedRoot To : netscape.public.mozilla.jseng From : "aadamov" Date : Mon Jan 05 2004 12:17 am OK, I have finally figured out that JS_AddNamedRoot had nothing to do with defining an instance of a class in the JS context. Instead I should have used JS_DefineObject. I can send examples to those who are interested. Thank you. AA "aadamov" wrote in message news:btaksc$iqn8@ripley.netscape.com... > Followinf up on the previous message. I did create a generic wrapper for DOM > embedded in SpiderMonkey, but... Couple of buts: > 1) I would still like to know if there is well thought through "standart" > implementation for that; > 2) I am stuck trying to use JS_AddNamedRoot in order to instantiate root of > the DOM object in JS context. In fact I run into problem using > JS_AddNamedRoot even for standart types. For instance: > std::string name = "red"; > JSString *jstr = JS_NewStringCopyN(cx, name.c_str(), name.length()); > JS_AddNamedRoot( cx, (void*)jstr, "myRoot" ); > std::string script = "myRoot;"; > jsval rval; > uintN lineno = 0; > JSBool ok = JS_EvaluateScript(cx, globalObj, script.c_str(), > script.length(), "script", lineno, &rval); > > Evaluating above script I get JS_FALSE return value. > I guess it only makes sense, since I am passing a void pointer to jstr in my > call to JS_AddNamedRoot. How in life would runtime know what type of an > object I just passed to it. That is unles there is some kind of reflection > mechanism build into it. Better off going to sleep now. > > .