mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Don't pass nullable strings to native DOM methods that want non-nullable strings. Fixes #1207.
This commit is contained in:
parent
803cd4b7cf
commit
08afc6d19d
75 changed files with 968 additions and 966 deletions
|
@ -272,19 +272,24 @@ pub fn jsval_to_domstring(cx: *JSContext, v: JSVal) -> Result<Option<DOMString>,
|
|||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub unsafe fn str_to_jsval(cx: *JSContext, string: &DOMString) -> JSVal {
|
||||
do string.to_utf16().as_imm_buf |buf, len| {
|
||||
let jsstr = JS_NewUCStringCopyN(cx, buf, len as libc::size_t);
|
||||
if jsstr.is_null() {
|
||||
// FIXME: is there something else we should do on failure?
|
||||
JSVAL_NULL
|
||||
} else {
|
||||
RUST_STRING_TO_JSVAL(jsstr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[fixed_stack_segment]
|
||||
pub unsafe fn domstring_to_jsval(cx: *JSContext, string: &Option<DOMString>) -> JSVal {
|
||||
match string {
|
||||
&None => JSVAL_NULL,
|
||||
&Some(ref s) => do s.to_utf16().as_imm_buf |buf, len| {
|
||||
let jsstr = JS_NewUCStringCopyN(cx, buf, len as libc::size_t);
|
||||
if jsstr.is_null() {
|
||||
// FIXME: is there something else we should do on failure?
|
||||
JSVAL_NULL
|
||||
} else {
|
||||
RUST_STRING_TO_JSVAL(jsstr)
|
||||
}
|
||||
}
|
||||
&Some(ref s) => str_to_jsval(cx, s),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue