mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Remove the proto_{id,depth} arguments from unwrap_jsmanaged.
Instead, we infer them from the type we're unwrapping into. This will prevent any mismatches between the type we return and the type we check for.
This commit is contained in:
parent
e1dae2f59b
commit
b8c2573f4d
3 changed files with 8 additions and 17 deletions
|
@ -102,17 +102,13 @@ class CastableObjectUnwrapper():
|
|||
"""
|
||||
def __init__(self, descriptor, source, codeOnFailure):
|
||||
self.substitution = {
|
||||
"type": descriptor.nativeType,
|
||||
"depth": descriptor.interface.inheritanceDepth(),
|
||||
"prototype": "PrototypeList::ID::" + descriptor.name,
|
||||
"protoID": "PrototypeList::ID::" + descriptor.name + " as uint",
|
||||
"source": source,
|
||||
"codeOnFailure": CGIndenter(CGGeneric(codeOnFailure), 4).define(),
|
||||
}
|
||||
|
||||
def __str__(self):
|
||||
return string.Template(
|
||||
"""match unwrap_jsmanaged(${source}, ${prototype}, ${depth}) {
|
||||
"""match unwrap_jsmanaged(${source}) {
|
||||
Ok(val) => val,
|
||||
Err(()) => {
|
||||
${codeOnFailure}
|
||||
|
|
|
@ -350,9 +350,7 @@ impl<T: Reflectable+IDLInterface> FromJSValConvertible<()> for JS<T> {
|
|||
if !value.is_object() {
|
||||
return Err(());
|
||||
}
|
||||
unwrap_jsmanaged(value.to_object(),
|
||||
IDLInterface::get_prototype_id(None::<T>),
|
||||
IDLInterface::get_prototype_depth(None::<T>))
|
||||
unwrap_jsmanaged(value.to_object())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -123,9 +123,9 @@ pub unsafe fn get_dom_class(obj: *mut JSObject) -> Result<DOMClass, ()> {
|
|||
/// Returns Err(()) if `obj` is an opaque security wrapper or if the object is
|
||||
/// not a reflector for a DOM object of the given type (as defined by the
|
||||
/// proto_id and proto_depth).
|
||||
pub fn unwrap_jsmanaged<T: Reflectable>(mut obj: *mut JSObject,
|
||||
proto_id: PrototypeList::ID,
|
||||
proto_depth: uint) -> Result<JS<T>, ()> {
|
||||
pub fn unwrap_jsmanaged<T>(mut obj: *mut JSObject) -> Result<JS<T>, ()>
|
||||
where T: Reflectable + IDLInterface
|
||||
{
|
||||
unsafe {
|
||||
let dom_class = try!(get_dom_class(obj).or_else(|_| {
|
||||
if IsWrapper(obj) == 1 {
|
||||
|
@ -145,6 +145,8 @@ pub fn unwrap_jsmanaged<T: Reflectable>(mut obj: *mut JSObject,
|
|||
}
|
||||
}));
|
||||
|
||||
let proto_id = IDLInterface::get_prototype_id(None::<T>);
|
||||
let proto_depth = IDLInterface::get_prototype_depth(None::<T>);
|
||||
if dom_class.interface_chain[proto_depth] == proto_id {
|
||||
debug!("good prototype");
|
||||
Ok(JS::from_raw(unwrap(obj)))
|
||||
|
@ -648,12 +650,7 @@ pub extern fn outerize_global(_cx: *mut JSContext, obj: JSHandleObject) -> *mut
|
|||
unsafe {
|
||||
debug!("outerizing");
|
||||
let obj = *obj.unnamed_field1;
|
||||
let win: Root<window::Window> =
|
||||
unwrap_jsmanaged(obj,
|
||||
IDLInterface::get_prototype_id(None::<window::Window>),
|
||||
IDLInterface::get_prototype_depth(None::<window::Window>))
|
||||
.unwrap()
|
||||
.root();
|
||||
let win: Root<window::Window> = unwrap_jsmanaged(obj).unwrap().root();
|
||||
win.browser_context().as_ref().unwrap().window_proxy()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue