mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Remove unnecessary generic from private_from_proto_check.
This commit is contained in:
parent
9788c5c7f4
commit
6dc4488bc7
2 changed files with 25 additions and 12 deletions
|
@ -404,6 +404,11 @@ pub unsafe fn get_dom_class(obj: *mut JSObject) -> Result<&'static DOMClass, ()>
|
|||
Err(())
|
||||
}
|
||||
|
||||
pub(crate) enum PrototypeCheck {
|
||||
Derive(fn(&'static DOMClass) -> bool),
|
||||
Depth { depth: usize, proto_id: u16 },
|
||||
}
|
||||
|
||||
/// Get a `*const libc::c_void` for the given DOM object, unwrapping any
|
||||
/// wrapper around it first, and checking if the object is of the correct type.
|
||||
///
|
||||
|
@ -411,14 +416,11 @@ pub unsafe fn get_dom_class(obj: *mut JSObject) -> Result<&'static DOMClass, ()>
|
|||
/// not an object for a DOM object of the given type (as defined by the
|
||||
/// proto_id and proto_depth).
|
||||
#[inline]
|
||||
pub unsafe fn private_from_proto_check<F>(
|
||||
pub(crate) unsafe fn private_from_proto_check(
|
||||
mut obj: *mut JSObject,
|
||||
cx: *mut JSContext,
|
||||
proto_check: F,
|
||||
) -> Result<*const libc::c_void, ()>
|
||||
where
|
||||
F: Fn(&'static DOMClass) -> bool,
|
||||
{
|
||||
proto_check: PrototypeCheck,
|
||||
) -> Result<*const libc::c_void, ()> {
|
||||
let dom_class = get_dom_class(obj).or_else(|_| {
|
||||
if IsWrapper(obj) {
|
||||
trace!("found wrapper");
|
||||
|
@ -437,7 +439,14 @@ where
|
|||
}
|
||||
})?;
|
||||
|
||||
if proto_check(dom_class) {
|
||||
let prototype_matches = match proto_check {
|
||||
PrototypeCheck::Derive(f) => (f)(dom_class),
|
||||
PrototypeCheck::Depth { depth, proto_id } => {
|
||||
dom_class.interface_chain[depth] as u16 == proto_id
|
||||
},
|
||||
};
|
||||
|
||||
if prototype_matches {
|
||||
trace!("good prototype");
|
||||
Ok(private_from_object(obj))
|
||||
} else {
|
||||
|
@ -471,7 +480,10 @@ pub fn native_from_object<T>(obj: *mut JSObject, cx: *mut JSContext) -> Result<*
|
|||
where
|
||||
T: DomObject + IDLInterface,
|
||||
{
|
||||
unsafe { private_from_proto_check(obj, cx, T::derives).map(|ptr| ptr as *const T) }
|
||||
unsafe {
|
||||
private_from_proto_check(obj, cx, PrototypeCheck::Derive(T::derives))
|
||||
.map(|ptr| ptr as *const T)
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a `*const T` for a DOM object accessible from a `JSObject`, where the DOM object
|
||||
|
|
|
@ -7,7 +7,9 @@
|
|||
use crate::dom::bindings::codegen::InterfaceObjectMap;
|
||||
use crate::dom::bindings::codegen::PrototypeList;
|
||||
use crate::dom::bindings::codegen::PrototypeList::{MAX_PROTO_CHAIN_LENGTH, PROTO_OR_IFACE_LENGTH};
|
||||
use crate::dom::bindings::conversions::{jsstring_to_str, private_from_proto_check};
|
||||
use crate::dom::bindings::conversions::{
|
||||
jsstring_to_str, private_from_proto_check, PrototypeCheck,
|
||||
};
|
||||
use crate::dom::bindings::error::throw_invalid_this;
|
||||
use crate::dom::bindings::inheritance::TopTypeId;
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
|
@ -507,9 +509,8 @@ unsafe fn generic_call(
|
|||
} else {
|
||||
GetNonCCWObjectGlobal(JS_CALLEE(cx, vp).to_object_or_null())
|
||||
});
|
||||
let depth = (*info).__bindgen_anon_3.depth;
|
||||
let proto_check =
|
||||
|class: &'static DOMClass| class.interface_chain[depth as usize] as u16 == proto_id;
|
||||
let depth = (*info).__bindgen_anon_3.depth as usize;
|
||||
let proto_check = PrototypeCheck::Depth { depth, proto_id };
|
||||
let this = match private_from_proto_check(obj.get(), cx, proto_check) {
|
||||
Ok(val) => val,
|
||||
Err(()) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue