fromString() function implementation
| 88 | |
| 89 | // fromString() function implementation |
| 90 | GJS_JSAPI_RETURN_CONVENTION |
| 91 | static 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 | |
| 110 | GJS_JSAPI_RETURN_CONVENTION |
| 111 | static bool from_gbytes_func(JSContext* cx, unsigned argc, JS::Value* vp) { |
nothing calls this directly
no test coverage detected