Skip to content

Commit

Permalink
Privatize Document
Browse files Browse the repository at this point in the history
  • Loading branch information
ttaubert committed Oct 13, 2014
1 parent d0addd3 commit 8825296
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 22 deletions.
2 changes: 1 addition & 1 deletion components/script/dom/browsercontext.rs
Expand Up @@ -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 {
Expand Down
26 changes: 21 additions & 5 deletions components/script/dom/document.rs
Expand Up @@ -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;

Expand All @@ -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>,
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions components/script/dom/domimplementation.rs
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/element.rs
Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/htmlimageelement.rs
Expand Up @@ -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 => {
Expand Down
16 changes: 8 additions & 8 deletions components/script/dom/node.rs
Expand Up @@ -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> {
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1516,15 +1516,15 @@ 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(..) => {
let node_elem: JSRef<Element> = ElementCast::to_ref(node).unwrap();
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,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/range.rs
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/treewalker.rs
Expand Up @@ -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)
Expand Down

0 comments on commit 8825296

Please sign in to comment.