mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Use Cell/RefCell for interior mutability of Attr, AttrList, Blob,
BrowserContext, ClientRect, and ClientRectList.
This commit is contained in:
parent
5ae7c4cbb1
commit
46ead90515
3 changed files with 11 additions and 8 deletions
|
@ -13,6 +13,7 @@ use dom::virtualmethods::vtable_for;
|
||||||
use servo_util::namespace;
|
use servo_util::namespace;
|
||||||
use servo_util::namespace::Namespace;
|
use servo_util::namespace::Namespace;
|
||||||
use servo_util::str::DOMString;
|
use servo_util::str::DOMString;
|
||||||
|
use std::cell::Cell;
|
||||||
|
|
||||||
pub enum AttrSettingType {
|
pub enum AttrSettingType {
|
||||||
FirstSetAttr,
|
FirstSetAttr,
|
||||||
|
@ -29,7 +30,7 @@ pub struct Attr {
|
||||||
pub prefix: Option<DOMString>,
|
pub prefix: Option<DOMString>,
|
||||||
|
|
||||||
/// the element that owns this attribute.
|
/// the element that owns this attribute.
|
||||||
pub owner: JS<Element>,
|
pub owner: Cell<JS<Element>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Reflectable for Attr {
|
impl Reflectable for Attr {
|
||||||
|
@ -53,7 +54,7 @@ impl Attr {
|
||||||
name: name, //TODO: Intern attribute names
|
name: name, //TODO: Intern attribute names
|
||||||
namespace: namespace,
|
namespace: namespace,
|
||||||
prefix: prefix,
|
prefix: prefix,
|
||||||
owner: owner.unrooted(),
|
owner: Cell::new(owner.unrooted()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +66,7 @@ impl Attr {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_value(&mut self, set_type: AttrSettingType, value: DOMString) {
|
pub fn set_value(&mut self, set_type: AttrSettingType, value: DOMString) {
|
||||||
let mut owner = self.owner.root();
|
let mut owner = self.owner.get().root();
|
||||||
let node: &mut JSRef<Node> = NodeCast::from_mut_ref(&mut *owner);
|
let node: &mut JSRef<Node> = NodeCast::from_mut_ref(&mut *owner);
|
||||||
let namespace_is_null = self.namespace == namespace::Null;
|
let namespace_is_null = self.namespace == namespace::Null;
|
||||||
|
|
||||||
|
|
|
@ -39,11 +39,11 @@ pub trait AttrListMethods {
|
||||||
|
|
||||||
impl<'a> AttrListMethods for JSRef<'a, AttrList> {
|
impl<'a> AttrListMethods for JSRef<'a, AttrList> {
|
||||||
fn Length(&self) -> u32 {
|
fn Length(&self) -> u32 {
|
||||||
self.owner.root().attrs.len() as u32
|
self.owner.root().attrs.borrow().len() as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
fn Item(&self, index: u32) -> Option<Temporary<Attr>> {
|
fn Item(&self, index: u32) -> Option<Temporary<Attr>> {
|
||||||
self.owner.root().attrs.as_slice().get(index as uint).map(|x| Temporary::new(x.clone()))
|
self.owner.root().attrs.borrow().as_slice().get(index as uint).map(|x| Temporary::new(x.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Temporary<Attr>> {
|
fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Temporary<Attr>> {
|
||||||
|
|
|
@ -18,9 +18,10 @@ pub struct ClientRectList {
|
||||||
impl ClientRectList {
|
impl ClientRectList {
|
||||||
pub fn new_inherited(window: &JSRef<Window>,
|
pub fn new_inherited(window: &JSRef<Window>,
|
||||||
rects: Vec<JSRef<ClientRect>>) -> ClientRectList {
|
rects: Vec<JSRef<ClientRect>>) -> ClientRectList {
|
||||||
|
let rects = rects.iter().map(|rect| rect.unrooted()).collect();
|
||||||
ClientRectList {
|
ClientRectList {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
rects: rects.iter().map(|rect| rect.unrooted()).collect(),
|
rects: rects,
|
||||||
window: window.unrooted(),
|
window: window.unrooted(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,8 +45,9 @@ impl<'a> ClientRectListMethods for JSRef<'a, ClientRectList> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn Item(&self, index: u32) -> Option<Temporary<ClientRect>> {
|
fn Item(&self, index: u32) -> Option<Temporary<ClientRect>> {
|
||||||
if index < self.rects.len() as u32 {
|
let rects = &self.rects;
|
||||||
Some(Temporary::new(self.rects.get(index as uint).clone()))
|
if index < rects.len() as u32 {
|
||||||
|
Some(Temporary::new(rects.get(index as uint).clone()))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue