mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
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.
This commit is contained in:
parent
71f4fd0478
commit
4ad3b6ccd1
6 changed files with 30 additions and 43 deletions
|
@ -282,7 +282,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,
|
||||
|
@ -311,23 +311,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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue