Factor out a helper for eagerly creating JS wrappers

This commit is contained in:
Keegan McAllister 2013-10-21 13:31:48 -07:00
parent 797143a1d3
commit 30a9fb2f45
4 changed files with 21 additions and 27 deletions

View file

@ -5,6 +5,7 @@
use dom::bindings::codegen::PrototypeList;
use dom::bindings::codegen::PrototypeList::MAX_PROTO_CHAIN_LENGTH;
use dom::bindings::node;
use dom::window;
use dom::node::{AbstractNode, ScriptView};
use std::libc::c_uint;
@ -544,6 +545,20 @@ pub trait Reflectable {
fn GetParentObject(&self, cx: *JSContext) -> Option<@mut Reflectable>;
}
pub fn reflect_dom_object<T: Reflectable>
(obj: @mut T,
window: &window::Window,
wrap_fn: extern "Rust" fn(*JSContext, *JSObject, @mut T) -> *JSObject)
-> @mut T {
let cx = window.get_cx();
let scope = window.reflector().get_jsobject();
if wrap_fn(cx, scope, obj).is_null() {
fail!("Could not eagerly wrap object");
}
assert!(obj.reflector().get_jsobject().is_not_null());
obj
}
pub struct Reflector {
object: *JSObject
}