Subj : Re: JSVAL_TO_OBJECT/JS_ValueToObject etc. To : netscape.public.mozilla.jseng From : Matthew Mondor Date : Fri Aug 12 2005 06:08 pm On Thu, 11 Aug 2005 23:17:03 -0600 "Weiyang Zhou" wrote: > I have a beginner question. > > There pairs of macro and function like > JSVAL_TO_OBJECT/JS_ValueToObject to convert between jsval and JSxxx > type. I have read the API documentation, but still doesn't quite > understand. Does anyone know how do I decide whether to use the macro > or function? If your function for instance requires a JSString/string, before using the JSVAL_TO_STRING() function you would need to first verify that the jsval really represents a string using JSVAL_IS_STRING(). Using JS_ValueToString() will instead perform conversion to a JSString as necessary even if the jsval passed to the function was not really a string... Using JSVAL_IS_STRING() and JSVAL_TO_STRING() might be stricter and yield better performance, but if you want to make the function more versatile and allow the user to call it with arbitrary types, JS_ValueToString() is what you want. Consider a print() function for instance, which needs a string representation to print, user can pass an integer or double value, or even object, which is converted to a string before output. Matt -- Note: Please only reply on the list, other mail is blocked by default. Private messages from your address can be allowed by first asking. .