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

Function to_string_func

gjs/byteArray.cpp:35–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33#include "gjs/text-encoding.h"
34
35GJS_JSAPI_RETURN_CONVENTION
36static bool to_string_func(JSContext* cx, unsigned argc, JS::Value* vp) {
37 JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
38 JS::UniqueChars encoding;
39 JS::RootedObject byte_array(cx);
40
41 if (!gjs_parse_call_args(cx, "toString", args, "o|s", "byteArray",
42 &byte_array, "encoding", &encoding))
43 return false;
44
45 const char* actual_encoding = encoding ? encoding.get() : "utf-8";
46 JS::RootedString str{cx, gjs_decode_from_uint8array(
47 cx, byte_array, actual_encoding,
48 GjsStringTermination::ZERO_TERMINATED, true)};
49 if (!str)
50 return false;
51
52 args.rval().setString(str);
53 return true;
54}
55
56/* Workaround to keep existing code compatible. This function is tacked onto any
57 * Uint8Array instances created in situations where previously a ByteArray would

Callers

nothing calls this directly

Calls 3

gjs_parse_call_argsFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected