Use the try macro in unwrap_jsmanaged.

This commit is contained in:
Ms2ger 2014-12-20 13:42:38 +01:00
parent 58e7b8c154
commit e1dae2f59b

View file

@ -127,7 +127,7 @@ pub fn unwrap_jsmanaged<T: Reflectable>(mut obj: *mut JSObject,
proto_id: PrototypeList::ID, proto_id: PrototypeList::ID,
proto_depth: uint) -> Result<JS<T>, ()> { proto_depth: uint) -> Result<JS<T>, ()> {
unsafe { unsafe {
let dom_class = get_dom_class(obj).or_else(|_| { let dom_class = try!(get_dom_class(obj).or_else(|_| {
if IsWrapper(obj) == 1 { if IsWrapper(obj) == 1 {
debug!("found wrapper"); debug!("found wrapper");
obj = UnwrapObject(obj, /* stopAtOuter = */ 0, ptr::null_mut()); obj = UnwrapObject(obj, /* stopAtOuter = */ 0, ptr::null_mut());
@ -143,17 +143,15 @@ pub fn unwrap_jsmanaged<T: Reflectable>(mut obj: *mut JSObject,
debug!("not a dom wrapper"); debug!("not a dom wrapper");
Err(()) Err(())
} }
}); }));
dom_class.and_then(|dom_class| { if dom_class.interface_chain[proto_depth] == proto_id {
if dom_class.interface_chain[proto_depth] == proto_id { debug!("good prototype");
debug!("good prototype"); Ok(JS::from_raw(unwrap(obj)))
Ok(JS::from_raw(unwrap(obj))) } else {
} else { debug!("bad prototype");
debug!("bad prototype"); Err(())
Err(()) }
}
})
} }
} }