mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Eliminate a mem::transmute in CodeGen
This commit is contained in:
parent
a1e4c547f0
commit
214db8d9f0
2 changed files with 18 additions and 19 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue