* gjs_string_to_utf8: * @cx: JSContext * @value: a JS::Value containing a string * * Converts the JSString in @value to UTF-8 and puts it in @utf8_string_p. * * This function is a convenience wrapper around JS_EncodeStringToUTF8() that * typechecks the JS::Value and throws an exception if it's the wrong type. * Don't use this function if you already have a JS::RootedString, or if you * kn
| 86 | * Returns: Unique UTF8 chars, empty on exception throw. |
| 87 | */ |
| 88 | JS::UniqueChars gjs_string_to_utf8(JSContext* cx, const JS::Value value) { |
| 89 | if (!value.isString()) { |
| 90 | gjs_throw(cx, "Value is not a string, cannot convert to UTF-8"); |
| 91 | return nullptr; |
| 92 | } |
| 93 | |
| 94 | JS::RootedString str(cx, value.toString()); |
| 95 | return JS_EncodeStringToUTF8(cx, str); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * gjs_string_to_utf8_n: |