Use internal mutability for Document::{quirks_mode, encoding_name}.

This commit is contained in:
Ms2ger 2014-06-10 17:48:42 +02:00
parent e9b64dc361
commit 23a6b6823b
2 changed files with 16 additions and 16 deletions

View file

@ -49,7 +49,7 @@ use servo_util::str::{DOMString, null_str_as_empty_ref};
use collections::hashmap::HashMap; use collections::hashmap::HashMap;
use js::jsapi::JSContext; use js::jsapi::JSContext;
use std::ascii::StrAsciiExt; use std::ascii::StrAsciiExt;
use std::cell::Cell; use std::cell::{Cell, RefCell};
use url::{Url, from_str}; use url::{Url, from_str};
#[deriving(Eq,Encodable)] #[deriving(Eq,Encodable)]
@ -66,10 +66,10 @@ pub struct Document {
pub idmap: HashMap<DOMString, Vec<JS<Element>>>, pub idmap: HashMap<DOMString, Vec<JS<Element>>>,
pub implementation: Cell<Option<JS<DOMImplementation>>>, pub implementation: Cell<Option<JS<DOMImplementation>>>,
pub content_type: DOMString, pub content_type: DOMString,
pub encoding_name: DOMString, pub encoding_name: Untraceable<RefCell<DOMString>>,
pub is_html_document: bool, pub is_html_document: bool,
pub url: Untraceable<Url>, pub url: Untraceable<Url>,
pub quirks_mode: Untraceable<QuirksMode>, pub quirks_mode: Untraceable<Cell<QuirksMode>>,
} }
impl DocumentDerived for EventTarget { impl DocumentDerived for EventTarget {
@ -81,8 +81,8 @@ impl DocumentDerived for EventTarget {
pub trait DocumentHelpers { pub trait DocumentHelpers {
fn url<'a>(&'a self) -> &'a Url; fn url<'a>(&'a self) -> &'a Url;
fn quirks_mode(&self) -> QuirksMode; fn quirks_mode(&self) -> QuirksMode;
fn set_quirks_mode(&mut self, mode: QuirksMode); fn set_quirks_mode(&self, mode: QuirksMode);
fn set_encoding_name(&mut self, name: DOMString); fn set_encoding_name(&self, name: DOMString);
fn content_changed(&self); fn content_changed(&self);
fn damage_and_reflow(&self, damage: DocumentDamageLevel); fn damage_and_reflow(&self, damage: DocumentDamageLevel);
fn wait_until_safe_to_modify_dom(&self); fn wait_until_safe_to_modify_dom(&self);
@ -97,15 +97,15 @@ impl<'a> DocumentHelpers for JSRef<'a, Document> {
} }
fn quirks_mode(&self) -> QuirksMode { fn quirks_mode(&self) -> QuirksMode {
*self.quirks_mode self.quirks_mode.deref().get()
} }
fn set_quirks_mode(&mut self, mode: QuirksMode) { fn set_quirks_mode(&self, mode: QuirksMode) {
*self.quirks_mode = mode; self.quirks_mode.deref().set(mode);
} }
fn set_encoding_name(&mut self, name: DOMString) { fn set_encoding_name(&self, name: DOMString) {
self.encoding_name = name; *self.encoding_name.deref().borrow_mut() = name;
} }
fn content_changed(&self) { fn content_changed(&self) {
@ -227,9 +227,9 @@ impl Document {
}, },
url: Untraceable::new(url), url: Untraceable::new(url),
// http://dom.spec.whatwg.org/#concept-document-quirks // http://dom.spec.whatwg.org/#concept-document-quirks
quirks_mode: Untraceable::new(NoQuirks), quirks_mode: Untraceable::new(Cell::new(NoQuirks)),
// http://dom.spec.whatwg.org/#concept-document-encoding // http://dom.spec.whatwg.org/#concept-document-encoding
encoding_name: "utf-8".to_string(), encoding_name: Untraceable::new(RefCell::new("utf-8".to_string())),
is_html_document: is_html_document == HTMLDocument, is_html_document: is_html_document == HTMLDocument,
} }
} }
@ -358,7 +358,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
// http://dom.spec.whatwg.org/#dom-document-compatmode // http://dom.spec.whatwg.org/#dom-document-compatmode
fn CompatMode(&self) -> DOMString { fn CompatMode(&self) -> DOMString {
match *self.quirks_mode { match self.quirks_mode.deref().get() {
NoQuirks => "CSS1Compat".to_string(), NoQuirks => "CSS1Compat".to_string(),
LimitedQuirks | FullQuirks => "BackCompat".to_string() LimitedQuirks | FullQuirks => "BackCompat".to_string()
} }
@ -366,7 +366,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
// http://dom.spec.whatwg.org/#dom-document-characterset // http://dom.spec.whatwg.org/#dom-document-characterset
fn CharacterSet(&self) -> DOMString { fn CharacterSet(&self) -> DOMString {
self.encoding_name.as_slice().to_ascii_lower() self.encoding_name.deref().borrow().as_slice().to_ascii_lower()
} }
// http://dom.spec.whatwg.org/#dom-document-content_type // http://dom.spec.whatwg.org/#dom-document-content_type

View file

@ -1284,8 +1284,8 @@ impl Node {
match node.type_id() { match node.type_id() {
DocumentNodeTypeId => { DocumentNodeTypeId => {
let node_doc: &JSRef<Document> = DocumentCast::to_ref(node).unwrap(); let node_doc: &JSRef<Document> = DocumentCast::to_ref(node).unwrap();
let copy_doc: &mut JSRef<Document> = DocumentCast::to_mut_ref(&mut *copy).unwrap(); let copy_doc: &JSRef<Document> = DocumentCast::to_ref(&*copy).unwrap();
copy_doc.set_encoding_name(node_doc.encoding_name.clone()); copy_doc.set_encoding_name(node_doc.encoding_name.deref().borrow().clone());
copy_doc.set_quirks_mode(node_doc.quirks_mode()); copy_doc.set_quirks_mode(node_doc.quirks_mode());
}, },
ElementNodeTypeId(..) => { ElementNodeTypeId(..) => {