Use the conversion traits from js.

This commit is contained in:
Ms2ger 2015-11-09 16:55:58 +01:00
parent acb24e80b8
commit 6d2ae85c1f
15 changed files with 285 additions and 647 deletions

View file

@ -48,6 +48,19 @@ pub fn expand_reflector(cx: &mut ExtCtxt, span: Span, _: &MetaItem, annotatable:
impl_item.map(|it| push(Annotatable::Item(it)))
}
};
let impl_item = quote_item!(cx,
impl ::js::conversions::ToJSValConvertible for $struct_name {
#[allow(unsafe_code)]
unsafe fn to_jsval(&self,
cx: *mut ::js::jsapi::JSContext,
rval: ::js::jsapi::MutableHandleValue) {
let object = ::dom::bindings::reflector::Reflectable::reflector(self).get_jsobject();
object.to_jsval(cx, rval)
}
}
);
impl_item.map(|it| push(Annotatable::Item(it)));
} else {
cx.span_err(span, "#[dom_struct] seems to have been applied to a non-struct");
}