Add a to_js method to the casting trait code in CodegenRust.py

Replace the manual checks and calls to transmute_copy in /layout/wrapper.rs with calls to to_js

Fixes #3616
This commit is contained in:
Kasey Carrothers 2014-10-11 16:02:59 -07:00
parent 3eb6b17137
commit 6d91e92c90
2 changed files with 69 additions and 61 deletions

View file

@ -5480,6 +5480,17 @@ class GlobalGenRoots():
}
}
#[inline(always)]
#[allow(unrooted_must_root)]
fn to_js<T: ${toBound}+Reflectable>(base: &JS<T>) -> Option<JS<Self>> {
unsafe {
match (*base.unsafe_get()).${checkFn}() {
true => Some(base.transmute_copy()),
false => None
}
}
}
#[inline(always)]
fn from_ref<'a, T: ${fromBound}+Reflectable>(derived: JSRef<'a, T>) -> JSRef<'a, Self> {
unsafe { derived.transmute() }