mirror of
https://github.com/servo/servo.git
synced 2025-06-21 15:49:04 +01:00
Factor out a helper for eagerly creating JS wrappers
This commit is contained in:
parent
797143a1d3
commit
30a9fb2f45
4 changed files with 21 additions and 27 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue