codegen: Throw a more descriptive invalid enum message

This commit is contained in:
Emilio Cobos Álvarez 2016-05-13 10:36:41 +02:00
parent e50d4b7624
commit 91101f6226
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 10 additions and 9 deletions

View file

@ -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