Use an Atom for Event.type

This commit is contained in:
David Zbarsky 2015-10-25 10:29:33 -07:00
parent 601169c0e5
commit 0070adb71f
5 changed files with 27 additions and 21 deletions

View file

@ -13,6 +13,7 @@ use dom::eventtarget::EventTarget;
use std::borrow::ToOwned;
use std::cell::Cell;
use std::default::Default;
use string_cache::Atom;
use time;
use util::str::DOMString;
@ -43,7 +44,7 @@ pub struct Event {
reflector_: Reflector,
current_target: MutNullableHeap<JS<EventTarget>>,
target: MutNullableHeap<JS<EventTarget>>,
type_: DOMRefCell<DOMString>,
type_: DOMRefCell<Atom>,
phase: Cell<EventPhase>,
canceled: Cell<bool>,
stop_propagation: Cell<bool>,
@ -62,7 +63,7 @@ impl Event {
reflector_: Reflector::new(),
current_target: Default::default(),
target: Default::default(),
type_: DOMRefCell::new("".to_owned()),
type_: DOMRefCell::new(atom!("")),
phase: Cell::new(EventPhase::None),
canceled: Cell::new(false),
stop_propagation: Cell::new(false),
@ -153,6 +154,11 @@ impl Event {
pub fn initialized(&self) -> bool {
self.initialized.get()
}
#[inline]
pub fn type_(&self) -> Atom {
self.type_.borrow().clone()
}
}
impl EventMethods for Event {
@ -163,7 +169,7 @@ impl EventMethods for Event {
// https://dom.spec.whatwg.org/#dom-event-type
fn Type(&self) -> DOMString {
self.type_.borrow().clone()
(*self.type_()).to_owned()
}
// https://dom.spec.whatwg.org/#dom-event-target
@ -229,7 +235,7 @@ impl EventMethods for Event {
self.canceled.set(false);
self.trusted.set(false);
self.target.set(None);
*self.type_.borrow_mut() = type_;
*self.type_.borrow_mut() = Atom::from_slice(&type_);
self.bubbles.set(bubbles);
self.cancelable.set(cancelable);
}