mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
codegen: Throw a more descriptive invalid enum message
This commit is contained in:
parent
e50d4b7624
commit
91101f6226
2 changed files with 10 additions and 9 deletions
|
@ -39,6 +39,7 @@ use std::ptr;
|
|||
use std::slice;
|
||||
use util::non_geckolib::jsstring_to_str;
|
||||
use util::prefs;
|
||||
use util::str::DOMString;
|
||||
|
||||
/// Proxy handler for a WindowProxy.
|
||||
pub struct WindowProxyHandler(pub *const libc::c_void);
|
||||
|
@ -182,18 +183,18 @@ pub fn get_array_index_from_id(_cx: *mut JSContext, id: HandleId) -> Option<u32>
|
|||
|
||||
/// Find the index of a string given by `v` in `values`.
|
||||
/// Returns `Err(())` on JSAPI failure (there is a pending exception), and
|
||||
/// `Ok(None)` if there was no matching string.
|
||||
/// `Ok((None, value))` if there was no matching string.
|
||||
pub unsafe fn find_enum_string_index(cx: *mut JSContext,
|
||||
v: HandleValue,
|
||||
values: &[&'static str])
|
||||
-> Result<Option<usize>, ()> {
|
||||
-> Result<(Option<usize>, DOMString), ()> {
|
||||
let jsstr = ToString(cx, v);
|
||||
if jsstr.is_null() {
|
||||
return Err(());
|
||||
}
|
||||
|
||||
let search = jsstring_to_str(cx, jsstr);
|
||||
Ok(values.iter().position(|value| search == *value))
|
||||
Ok((values.iter().position(|value| search == *value), search))
|
||||
}
|
||||
|
||||
/// Returns wether `obj` is a platform object
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue