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

Function from_string_func

gjs/byteArray.cpp:90–108  ·  view source on GitHub ↗

fromString() function implementation

Source from the content-addressed store, hash-verified

88
89// fromString() function implementation
90GJS_JSAPI_RETURN_CONVENTION
91static bool from_string_func(JSContext* cx, unsigned argc, JS::Value* vp) {
92 JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
93 JS::RootedString str(cx);
94 JS::UniqueChars encoding;
95 if (!gjs_parse_call_args(cx, "fromString", args, "S|s", "string", &str,
96 "encoding", &encoding))
97 return false;
98
99 const char* actual_encoding = encoding ? encoding.get() : "utf-8";
100 JS::RootedObject uint8array(
101 cx, gjs_encode_to_uint8array(cx, str, actual_encoding,
102 GjsStringTermination::ZERO_TERMINATED));
103 if (!uint8array || !define_legacy_tostring(cx, uint8array))
104 return false;
105
106 args.rval().setObject(*uint8array);
107 return true;
108}
109
110GJS_JSAPI_RETURN_CONVENTION
111static bool from_gbytes_func(JSContext* cx, unsigned argc, JS::Value* vp) {

Callers

nothing calls this directly

Calls 4

gjs_parse_call_argsFunction · 0.85
gjs_encode_to_uint8arrayFunction · 0.85
define_legacy_tostringFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected