Handle failed string conversions in console.log. (#33085)

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2024-08-16 12:49:56 -04:00 committed by GitHub
parent 4df7a1af25
commit 3829e91662
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 0 deletions

View file

@ -221,6 +221,7 @@ impl FromJSValConvertible for DOMString {
/// Convert the given `JSString` to a `DOMString`. Fails if the string does not
/// contain valid UTF-16.
pub unsafe fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString {
assert!(!s.is_null());
let latin1 = JS_DeprecatedStringHasLatin1Chars(s);
DOMString::from_string(if latin1 {
latin1_to_string(cx, s)

View file

@ -73,6 +73,9 @@ where
unsafe fn handle_value_to_string(cx: *mut jsapi::JSContext, value: HandleValue) -> DOMString {
rooted!(in(cx) let mut js_string = std::ptr::null_mut::<jsapi::JSString>());
js_string.set(JS_ValueToSource(cx, value));
if js_string.is_null() {
return "<error converting value to string>".into();
}
jsstring_to_str(cx, *js_string)
}