aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorMs2ger <ms2ger@gmail.com>2014-12-20 13:46:16 +0100
committerMs2ger <ms2ger@gmail.com>2014-12-20 13:48:21 +0100
commitb8c2573f4d7500561790428800a777deb56323c9 (patch)
tree45666a229515b9bb9065519ebd8bf37b9f682eb7 /components/script/dom
parente1dae2f59b41d9816be367f765ff3afb9abf7f06 (diff)
downloadservo-b8c2573f4d7500561790428800a777deb56323c9.tar.gz
servo-b8c2573f4d7500561790428800a777deb56323c9.zip
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.
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py6
-rw-r--r--components/script/dom/bindings/conversions.rs4
-rw-r--r--components/script/dom/bindings/utils.rs15
3 files changed, 8 insertions, 17 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index b34c6441b70..28e1b439775 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -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}
diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs
index 52150b26f9c..ceac869a19e 100644
--- a/components/script/dom/bindings/conversions.rs
+++ b/components/script/dom/bindings/conversions.rs
@@ -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())
}
}
diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs
index 4f12d1dbc7d..048a54eee4a 100644
--- a/components/script/dom/bindings/utils.rs
+++ b/components/script/dom/bindings/utils.rs
@@ -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()
}
}