MCPcopy Create free account
hub / github.com/GNOME/gjs / gjs_string_get_char16_data

Function gjs_string_get_char16_data

gjs/jsapi-util-string.cpp:281–306  ·  view source on GitHub ↗

* gjs_string_get_char16_data: * @cx: js context * @str: a rooted JSString * @data_p: address to return allocated data buffer * @len_p: address to return length of data (number of 16-bit characters) * * Get the binary data (as a sequence of 16-bit characters) in @str. * * Returns: false if exception thrown */

Source from the content-addressed store, hash-verified

279 * Returns: false if exception thrown
280 */
281bool gjs_string_get_char16_data(JSContext* cx, JS::HandleString str,
282 char16_t** data_p, size_t* len_p) {
283 if (JS::StringHasLatin1Chars(str))
284 return from_latin1(cx, str, data_p, len_p);
285
286 /* From this point on, crash if a GC is triggered while we are using the
287 * string's chars */
288 JS::AutoCheckCannotGC nogc;
289
290 const char16_t* js_data =
291 JS_GetTwoByteStringCharsAndLength(cx, nogc, str, len_p);
292
293 if (js_data == nullptr)
294 return false;
295
296 mozilla::CheckedInt<size_t> len_bytes =
297 mozilla::CheckedInt<size_t>(*len_p) * sizeof(*js_data);
298 if (!len_bytes.isValid()) {
299 JS_ReportOutOfMemory(cx); // cannot call gjs_throw, it may GC
300 return false;
301 }
302
303 *data_p = static_cast<char16_t*>(g_memdup2(js_data, len_bytes.value()));
304
305 return true;
306}
307
308/**
309 * gjs_string_to_ucs4:

Callers 3

gjs_string_to_intarrayFunction · 0.85
compile_moduleFunction · 0.85

Calls 2

from_latin1Function · 0.85
valueMethod · 0.45

Tested by 1