aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/window.rs
diff options
context:
space:
mode:
authorbors-servo <release+servo@mozilla.com>2014-03-19 19:01:48 -0400
committerbors-servo <release+servo@mozilla.com>2014-03-19 19:01:48 -0400
commit7f188500a12373677c7ef9feb999276c30f1068a (patch)
tree3dceb32bd373a305f494160c037700cbd5b03956 /src/components/script/dom/window.rs
parent26f9543e60414d5ff3890d36c5370d0804c2cf18 (diff)
parent4ad3b6ccd160107d96df4d6925a8241403f2242a (diff)
downloadservo-7f188500a12373677c7ef9feb999276c30f1068a.tar.gz
servo-7f188500a12373677c7ef9feb999276c30f1068a.zip
auto merge of #1915 : Ms2ger/servo/wrap-return-js, r=jdm
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/window.rs')
-rw-r--r--src/components/script/dom/window.rs25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs
index 2ef70b0eac7..18a7fd73059 100644
--- a/src/components/script/dom/window.rs
+++ b/src/components/script/dom/window.rs
@@ -284,7 +284,7 @@ impl Window {
compositor: ~ScriptListener,
image_cache_task: ImageCacheTask)
-> JS<Window> {
- let mut win = ~Window {
+ let win = ~Window {
eventtarget: EventTarget::new_inherited(WindowTypeId),
script_chan: script_chan.clone(),
console: None,
@@ -314,23 +314,22 @@ impl Window {
next_timer_handle: 0
};
- let raw: *mut Window = &mut *win;
let global = WindowBinding::Wrap(cx, win);
- assert!(global.is_not_null());
- unsafe {
- let fn_names = ["window","self"];
- for str in fn_names.iter() {
- (*str).to_c_str().with_ref(|name| {
- JS_DefineProperty(cx, global, name,
- ObjectValue(&*global),
+ let fn_names = ["window", "self"];
+ for str in fn_names.iter() {
+ (*str).to_c_str().with_ref(|name| {
+ let object = global.reflector().get_jsobject();
+ assert!(object.is_not_null());
+ unsafe {
+ JS_DefineProperty(cx, object, name,
+ ObjectValue(&*object),
Some(cast::transmute(GetJSClassHookStubPointer(PROPERTY_STUB))),
Some(cast::transmute(GetJSClassHookStubPointer(STRICT_PROPERTY_STUB))),
JSPROP_ENUMERATE);
- })
-
- }
+ }
+ })
- JS::from_raw(raw)
}
+ global
}
}