This is an archived page. It's not actively maintained.


This article covers features introduced in SpiderMonkey 31

Convert any JavaScript value to a string.


#include "js/Conversions.h" // as of SpiderMonkey 38; previously in jsapi.h

JS::ToString(JSContext *cx, JS::HandleValue v)
Name Type Description
cx JSContext * The context in which to perform the conversion. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
v JS::HandleValue The value to convert.


JS::ToString returns a string representation of a JavaScript value.

If v.isString() is true, it calls v.toString(). Otherwise, it converts the value to string.

On success, JS::ToString returns a JSString instance. On error or exception, it returns nullptr.

See Also