mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Implement safe rooting strategy via Unrooted, Root, JSRef, and JS.
This commit is contained in:
parent
ffdc3f5b32
commit
d7b96db33c
109 changed files with 1568 additions and 1326 deletions
|
@ -4,7 +4,7 @@
|
|||
|
||||
use dom::bindings::codegen::BindingDeclarations::MouseEventBinding;
|
||||
use dom::bindings::codegen::InheritTypes::MouseEventDerived;
|
||||
use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference};
|
||||
use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Unrooted};
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::event::{Event, MouseEventTypeId};
|
||||
|
@ -51,7 +51,7 @@ impl MouseEvent {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new(window: &JSRef<Window>) -> JS<MouseEvent> {
|
||||
pub fn new(window: &JSRef<Window>) -> Unrooted<MouseEvent> {
|
||||
reflect_dom_object(~MouseEvent::new_inherited(),
|
||||
window,
|
||||
MouseEventBinding::Wrap)
|
||||
|
@ -59,9 +59,9 @@ impl MouseEvent {
|
|||
|
||||
pub fn Constructor(owner: &JSRef<Window>,
|
||||
type_: DOMString,
|
||||
init: &MouseEventBinding::MouseEventInit) -> Fallible<JS<MouseEvent>> {
|
||||
init: &MouseEventBinding::MouseEventInit) -> Fallible<Unrooted<MouseEvent>> {
|
||||
let roots = RootCollection::new();
|
||||
let mut ev = MouseEvent::new(owner);
|
||||
let mut ev = MouseEvent::new(owner).root(&roots);
|
||||
let view = init.view.as_ref().map(|view| view.root(&roots));
|
||||
let related_target = init.relatedTarget.as_ref().map(|relatedTarget| relatedTarget.root(&roots));
|
||||
ev.get_mut().InitMouseEvent(type_, init.bubbles, init.cancelable, view.root_ref(),
|
||||
|
@ -69,7 +69,7 @@ impl MouseEvent {
|
|||
init.clientX, init.clientY, init.ctrlKey,
|
||||
init.altKey, init.shiftKey, init.metaKey,
|
||||
init.button, related_target.root_ref());
|
||||
Ok(ev)
|
||||
Ok(Unrooted::new_rooted(&*ev))
|
||||
}
|
||||
|
||||
pub fn ScreenX(&self) -> i32 {
|
||||
|
@ -113,8 +113,8 @@ impl MouseEvent {
|
|||
0
|
||||
}
|
||||
|
||||
pub fn GetRelatedTarget(&self) -> Option<JS<EventTarget>> {
|
||||
self.related_target.clone()
|
||||
pub fn GetRelatedTarget(&self) -> Option<Unrooted<EventTarget>> {
|
||||
self.related_target.clone().map(|target| Unrooted::new(target))
|
||||
}
|
||||
|
||||
pub fn GetModifierState(&self, _keyArg: DOMString) -> bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue