aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/bindings/js.rs
diff options
context:
space:
mode:
authorMs2ger <ms2ger@gmail.com>2014-03-14 13:06:48 +0100
committerMs2ger <ms2ger@gmail.com>2014-03-14 13:06:51 +0100
commit4ad3b6ccd160107d96df4d6925a8241403f2242a (patch)
tree154f5570a14136c4a77d5b02e1becd8f897d6f61 /src/components/script/dom/bindings/js.rs
parent71f4fd0478183692ba114351841b44c58691e665 (diff)
downloadservo-4ad3b6ccd160107d96df4d6925a8241403f2242a.tar.gz
servo-4ad3b6ccd160107d96df4d6925a8241403f2242a.zip
Return a JS<T> from *Binding::Wrap rather than a JSObject.
This lets us avoid the sketchy tricks in JS::new and Window::new, where we kept an unsafe pointer to the native object across the Wrap call that consumed the owned pointer.
Diffstat (limited to 'src/components/script/dom/bindings/js.rs')
-rw-r--r--src/components/script/dom/bindings/js.rs15
1 files changed, 4 insertions, 11 deletions
diff --git a/src/components/script/dom/bindings/js.rs b/src/components/script/dom/bindings/js.rs
index 9f8e44ba06f..b70a0e18057 100644
--- a/src/components/script/dom/bindings/js.rs
+++ b/src/components/script/dom/bindings/js.rs
@@ -4,7 +4,7 @@
use dom::bindings::utils::{Reflector, Reflectable};
use dom::window::Window;
-use js::jsapi::{JSContext, JSObject};
+use js::jsapi::JSContext;
use layout_interface::TrustedNodeAddress;
use std::cast;
@@ -30,17 +30,10 @@ impl <T> Clone for JS<T> {
}
impl<T: Reflectable> JS<T> {
- pub fn new(mut obj: ~T,
+ pub fn new(obj: ~T,
window: &JS<Window>,
- wrap_fn: extern "Rust" fn(*JSContext, &JS<Window>, ~T) -> *JSObject) -> JS<T> {
- let cx = window.get().get_cx();
- let raw: *mut T = &mut *obj;
- if wrap_fn(cx, window, obj).is_null() {
- fail!("Could not eagerly wrap object");
- }
- JS {
- ptr: RefCell::new(raw)
- }
+ wrap_fn: extern "Rust" fn(*JSContext, &JS<Window>, ~T) -> JS<T>) -> JS<T> {
+ wrap_fn(window.get().get_cx(), window, obj)
}
pub unsafe fn from_raw(raw: *mut T) -> JS<T> {