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. */
| 57 | * Uint8Array instances created in situations where previously a ByteArray would |
| 58 | * have been created. It logs a compatibility warning. */ |
| 59 | GJS_JSAPI_RETURN_CONVENTION |
| 60 | static 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 | |
| 82 | GJS_JSAPI_RETURN_CONVENTION |
| 83 | static bool define_legacy_tostring(JSContext* cx, JS::HandleObject array) { |
nothing calls this directly
no test coverage detected