aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorTim Taubert <tim@timtaubert.de>2014-10-12 23:29:52 +0200
committerTim Taubert <tim@timtaubert.de>2014-10-13 13:25:43 +0200
commit88252968690511cc8d06ece32ded42f915d41d09 (patch)
tree4e6410f80d83bfdb4c7a20e7cbc014d7d6f8875b /components/script
parentd0addd36bb83d56071200b051e21ae3ad7417ac2 (diff)
downloadservo-88252968690511cc8d06ece32ded42f915d41d09.tar.gz
servo-88252968690511cc8d06ece32ded42f915d41d09.zip
Privatize Document
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/browsercontext.rs2
-rw-r--r--components/script/dom/document.rs26
-rw-r--r--components/script/dom/domimplementation.rs6
-rw-r--r--components/script/dom/element.rs4
-rw-r--r--components/script/dom/htmlimageelement.rs2
-rw-r--r--components/script/dom/node.rs16
-rw-r--r--components/script/dom/range.rs2
-rw-r--r--components/script/dom/treewalker.rs2
8 files changed, 38 insertions, 22 deletions
diff --git a/components/script/dom/browsercontext.rs b/components/script/dom/browsercontext.rs
index 78b940aa240..9f6041710e3 100644
--- a/components/script/dom/browsercontext.rs
+++ b/components/script/dom/browsercontext.rs
@@ -39,7 +39,7 @@ impl BrowserContext {
pub fn active_window(&self) -> Temporary<Window> {
let doc = self.active_document().root();
- Temporary::new(doc.window.clone())
+ Temporary::new(doc.window().clone())
}
pub fn window_proxy(&self) -> *mut JSObject {
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index c67604942da..f37a8feb2f6 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -62,7 +62,7 @@ use url::Url;
use std::collections::hashmap::HashMap;
use std::ascii::StrAsciiExt;
-use std::cell::{Cell, RefCell};
+use std::cell::{Cell, Ref, RefCell};
use std::default::Default;
use time;
@@ -75,16 +75,17 @@ pub enum IsHTMLDocument {
#[jstraceable]
#[must_root]
+#[privatize]
pub struct Document {
- pub node: Node,
+ node: Node,
reflector_: Reflector,
- pub window: JS<Window>,
+ window: JS<Window>,
idmap: RefCell<HashMap<Atom, Vec<JS<Element>>>>,
implementation: MutNullableJS<DOMImplementation>,
content_type: DOMString,
last_modified: RefCell<Option<DOMString>>,
- pub encoding_name: RefCell<DOMString>,
- pub is_html_document: bool,
+ encoding_name: RefCell<DOMString>,
+ is_html_document: bool,
url: Url,
quirks_mode: Cell<QuirksMode>,
images: MutNullableJS<HTMLCollection>,
@@ -343,6 +344,21 @@ impl Document {
node.set_owner_doc(*document);
Temporary::from_rooted(*document)
}
+
+ #[inline]
+ pub fn window<'a>(&'a self) -> &'a JS<Window> {
+ &self.window
+ }
+
+ #[inline]
+ pub fn encoding_name(&self) -> Ref<DOMString> {
+ self.encoding_name.borrow()
+ }
+
+ #[inline]
+ pub fn is_html_document(&self) -> bool {
+ self.is_html_document
+ }
}
impl Reflectable for Document {
diff --git a/components/script/dom/domimplementation.rs b/components/script/dom/domimplementation.rs
index 39c39454e60..7e23d86f2bc 100644
--- a/components/script/dom/domimplementation.rs
+++ b/components/script/dom/domimplementation.rs
@@ -39,7 +39,7 @@ impl DOMImplementation {
}
pub fn new(document: JSRef<Document>) -> Temporary<DOMImplementation> {
- let window = document.window.root();
+ let window = document.window().root();
reflect_dom_object(box DOMImplementation::new_inherited(document),
&Window(*window),
DOMImplementationBinding::Wrap)
@@ -73,7 +73,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> {
fn CreateDocument(self, namespace: Option<DOMString>, qname: DOMString,
maybe_doctype: Option<JSRef<DocumentType>>) -> Fallible<Temporary<Document>> {
let doc = self.document.root();
- let win = doc.window.root();
+ let win = doc.window().root();
// Step 1.
let doc = Document::new(*win, None, NonHTMLDocument, None).root();
@@ -118,7 +118,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> {
// http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
fn CreateHTMLDocument(self, title: Option<DOMString>) -> Temporary<Document> {
let document = self.document.root();
- let win = document.window.root();
+ let win = document.window().root();
// Step 1-2.
let doc = Document::new(*win, None, HTMLDocument, None).root();
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index 580b79276a6..8a929bd913a 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -268,7 +268,7 @@ impl LayoutElementHelpers for JS<Element> {
}
let node: JS<Node> = self.transmute_copy();
let owner_doc = node.owner_doc_for_layout().unsafe_get();
- (*owner_doc).is_html_document
+ (*owner_doc).is_html_document()
}
}
@@ -631,7 +631,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
let node: JSRef<Node> = NodeCast::from_ref(self);
node.owner_doc().root()
};
- let window = doc.window.root();
+ let window = doc.window().root();
let list = NamedNodeMap::new(*window, self);
self.attr_list.assign(Some(list));
}
diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs
index e9c916e2eec..0a616d9585d 100644
--- a/components/script/dom/htmlimageelement.rs
+++ b/components/script/dom/htmlimageelement.rs
@@ -48,7 +48,7 @@ impl<'a> PrivateHTMLImageElementHelpers for JSRef<'a, HTMLImageElement> {
fn update_image(self, value: Option<(DOMString, &Url)>) {
let node: JSRef<Node> = NodeCast::from_ref(self);
let document = node.owner_doc().root();
- let window = document.window.root();
+ let window = document.window().root();
let image_cache = &window.image_cache_task;
match value {
None => {
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index 68119f33d23..448d50620fb 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -741,7 +741,7 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> {
}
fn is_in_html_doc(self) -> bool {
- self.owner_doc().root().is_html_document
+ self.owner_doc().root().is_html_document()
}
fn children(self) -> AbstractNodeChildrenIterator<'a> {
@@ -1112,7 +1112,7 @@ impl Node {
document: JSRef<Document>,
wrap_fn: extern "Rust" fn(*mut JSContext, &GlobalRef, Box<N>) -> Temporary<N>)
-> Temporary<N> {
- let window = document.window.root();
+ let window = document.window().root();
reflect_dom_object(node, &global::Window(*window), wrap_fn)
}
@@ -1474,11 +1474,11 @@ impl Node {
},
DocumentNodeTypeId => {
let document: JSRef<Document> = DocumentCast::to_ref(node).unwrap();
- let is_html_doc = match document.is_html_document {
+ let is_html_doc = match document.is_html_document() {
true => HTMLDocument,
false => NonHTMLDocument
};
- let window = document.window.root();
+ let window = document.window().root();
let document = Document::new(*window, Some(document.url().clone()),
is_html_doc, None);
NodeCast::from_temporary(document)
@@ -1516,7 +1516,7 @@ impl Node {
DocumentNodeTypeId => {
let node_doc: JSRef<Document> = DocumentCast::to_ref(node).unwrap();
let copy_doc: JSRef<Document> = DocumentCast::to_ref(*copy).unwrap();
- copy_doc.set_encoding_name(node_doc.encoding_name.borrow().clone());
+ copy_doc.set_encoding_name(node_doc.encoding_name().clone());
copy_doc.set_quirks_mode(node_doc.quirks_mode());
},
ElementNodeTypeId(..) => {
@@ -1524,7 +1524,7 @@ impl Node {
let copy_elem: JSRef<Element> = ElementCast::to_ref(*copy).unwrap();
// FIXME: https://github.com/mozilla/servo/issues/1737
- let window = document.window.root();
+ let window = document.window().root();
for attr in node_elem.attrs.borrow().iter().map(|attr| attr.root()) {
copy_elem.attrs.borrow_mut().push_unrooted(
&Attr::new(*window,
@@ -1667,7 +1667,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
}
let doc = self.owner_doc().root();
- let window = doc.window.root();
+ let window = doc.window().root();
let child_list = NodeList::new_child_list(*window, self);
self.child_list.assign(Some(child_list));
self.child_list.get().unwrap()
@@ -2125,7 +2125,7 @@ pub fn document_from_node<T: NodeBase+Reflectable>(derived: JSRef<T>) -> Tempora
pub fn window_from_node<T: NodeBase+Reflectable>(derived: JSRef<T>) -> Temporary<Window> {
let document = document_from_node(derived).root();
- Temporary::new(document.window.clone())
+ Temporary::new(document.window().clone())
}
impl<'a> VirtualMethods for JSRef<'a, Node> {
diff --git a/components/script/dom/range.rs b/components/script/dom/range.rs
index 0fe0c7f1751..a611604e6bb 100644
--- a/components/script/dom/range.rs
+++ b/components/script/dom/range.rs
@@ -26,7 +26,7 @@ impl Range {
}
pub fn new(document: JSRef<Document>) -> Temporary<Range> {
- let window = document.window.root();
+ let window = document.window().root();
reflect_dom_object(box Range::new_inherited(),
&Window(*window),
RangeBinding::Wrap)
diff --git a/components/script/dom/treewalker.rs b/components/script/dom/treewalker.rs
index bc12f165595..f9100dd15be 100644
--- a/components/script/dom/treewalker.rs
+++ b/components/script/dom/treewalker.rs
@@ -49,7 +49,7 @@ impl TreeWalker {
root_node: JSRef<Node>,
what_to_show: u32,
filter: Filter) -> Temporary<TreeWalker> {
- let window = document.window.root();
+ let window = document.window().root();
reflect_dom_object(box TreeWalker::new_inherited(root_node, what_to_show, filter),
&Window(*window),
TreeWalkerBinding::Wrap)