mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Handle failed string conversions in console.log. (#33085)
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
4df7a1af25
commit
3829e91662
2 changed files with 4 additions and 0 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue