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

Function instance_to_string_func

gjs/byteArray.cpp:59–80  ·  view source on GitHub ↗

Workaround to keep existing code compatible. This function is tacked onto any * Uint8Array instances created in situations where previously a ByteArray would * have been created. It logs a compatibility warning. */

Source from the content-addressed store, hash-verified

57 * Uint8Array instances created in situations where previously a ByteArray would
58 * have been created. It logs a compatibility warning. */
59GJS_JSAPI_RETURN_CONVENTION
60static bool instance_to_string_func(JSContext* cx, unsigned argc,
61 JS::Value* vp) {
62 GJS_GET_THIS(cx, argc, vp, args, this_obj);
63 JS::UniqueChars encoding;
64
65 gjs_warn_deprecated_once_per_callsite(
66 cx, GjsDeprecationMessageId::ByteArrayInstanceToString);
67
68 if (!gjs_parse_call_args(cx, "toString", args, "|s", "encoding", &encoding))
69 return false;
70
71 const char* actual_encoding = encoding ? encoding.get() : "utf-8";
72 JS::RootedString str{cx, gjs_decode_from_uint8array(
73 cx, this_obj, actual_encoding,
74 GjsStringTermination::ZERO_TERMINATED, true)};
75 if (!str)
76 return false;
77
78 args.rval().setString(str);
79 return true;
80}
81
82GJS_JSAPI_RETURN_CONVENTION
83static bool define_legacy_tostring(JSContext* cx, JS::HandleObject array) {

Callers

nothing calls this directly

Calls 4

gjs_parse_call_argsFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected