Subj : Re: JS_ValueToString and STRING_TO_JSVAL To : Weiyang Zhou From : Brendan Eich Date : Fri Aug 12 2005 05:06 pm Weiyang Zhou wrote: > If I have the following code, do I have to add str to root too? > > jsval argv[1]; > jsval rval; > > JSString* str = JS_NewString(context, "arg from C", 10); > > argv[0] = STRING_TO_JSVAL(str); If argv is as shown above, then yes, you need to register str or argv[0] by its address as a root, or do something else to protect the new string from GC. If the above code were in a native function called by the JS engine itself, with argv as the fourth parameter (after argc, before rval as usual), then no, argv[0] is a local root, as described in that doc I linked to before (below). /be > > JS_CallFunctionName(context, object, "myfunc", 1, argv, &rval); > > > > "Brendan Eich" wrote in message > news:42FC29D9.8000408@meer.net... > >>Weiyang Zhou wrote: >> >> >>>What's the purpose of converting argv[i] to str, the assign str back to >>>argv[i]? In the end, argv[i] remain the same. >> >> >>Not if !JSVAL_IS_STRING(argv[i]) beforehand. >> >>See http://www.mozilla.org/js/spidermonkey/gctips.html for why this is >>done in native methods such as Load. >> >>/be > > > .