Eliminate a mem::transmute in CodeGen

This commit is contained in:
Gregory Katz 2017-02-17 14:31:22 -05:00
parent a1e4c547f0
commit 214db8d9f0
2 changed files with 18 additions and 19 deletions

View file

@ -177,20 +177,20 @@ 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`.
/// Find the enum equivelent of a string given by `v` in `pairs`.
/// Returns `Err(())` on JSAPI failure (there is a pending exception), and
/// `Ok((None, value))` if there was no matching string.
pub unsafe fn find_enum_string_index(cx: *mut JSContext,
pub unsafe fn find_enum_value<'a, T>(cx: *mut JSContext,
v: HandleValue,
values: &[&'static str])
-> Result<(Option<usize>, DOMString), ()> {
pairs: &'a [(&'static str, T)])
-> Result<(Option<&'a T>, 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), search))
Ok((pairs.iter().find(|&&(key, _)| search == *key).map(|&(_, ref ev)| ev), search))
}
/// Returns wether `obj` is a platform object