aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMs2ger <ms2ger@gmail.com>2013-10-16 10:00:38 +0200
committerMs2ger <ms2ger@gmail.com>2013-10-16 10:15:09 +0200
commit60b6d1bb57e018526a8702bff66fce1d84644afe (patch)
tree4fe54c25f2996a480d55a69951dcd8ba75634e4b /src
parentc9c9eec3d8cdb68f43352b777c3b138c743bc103 (diff)
downloadservo-60b6d1bb57e018526a8702bff66fce1d84644afe.tar.gz
servo-60b6d1bb57e018526a8702bff66fce1d84644afe.zip
Issue #1071 - Ensure that Documents always have a non-null Window.
Diffstat (limited to 'src')
-rw-r--r--src/components/script/dom/document.rs23
-rw-r--r--src/components/script/dom/domparser.rs4
-rw-r--r--src/components/script/dom/element.rs4
-rw-r--r--src/components/script/dom/htmldocument.rs4
-rw-r--r--src/components/script/dom/htmlimageelement.rs43
-rw-r--r--src/components/script/dom/node.rs2
-rw-r--r--src/components/script/script_task.rs2
7 files changed, 29 insertions, 53 deletions
diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs
index fdf0530bdee..4687205066d 100644
--- a/src/components/script/dom/document.rs
+++ b/src/components/script/dom/document.rs
@@ -112,7 +112,7 @@ pub enum DocumentType {
pub struct Document {
priv root: Option<AbstractNode<ScriptView>>,
reflector_: Reflector,
- window: Option<@mut Window>,
+ window: @mut Window,
doctype: DocumentType,
title: ~str,
idmap: HashMap<~str, AbstractNode<ScriptView>>
@@ -120,7 +120,7 @@ pub struct Document {
impl Document {
#[fixed_stack_segment]
- pub fn new(window: Option<@mut Window>, doctype: DocumentType) -> Document {
+ pub fn new(window: @mut Window, doctype: DocumentType) -> Document {
Document {
root: None,
reflector_: Reflector::new(),
@@ -134,7 +134,7 @@ impl Document {
pub fn Constructor(owner: @mut Window) -> Fallible<AbstractDocument> {
let cx = owner.get_cx();
- let document = AbstractDocument::as_abstract(cx, @mut Document::new(None, XML));
+ let document = AbstractDocument::as_abstract(cx, @mut Document::new(owner, XML));
let root = @HTMLHtmlElement {
htmlelement: HTMLElement::new(HTMLHtmlElementTypeId, ~"html", document)
@@ -216,10 +216,7 @@ impl Reflectable for Document {
impl BindingObject for Document {
fn GetParentObject(&self, _cx: *JSContext) -> Option<@mut Reflectable> {
- match self.window {
- Some(win) => Some(win as @mut Reflectable),
- None => None
- }
+ Some(self.window as @mut Reflectable)
}
}
@@ -249,11 +246,11 @@ impl Document {
}
fn get_cx(&self) -> *JSContext {
- self.window.get_ref().get_cx()
+ self.window.get_cx()
}
fn get_scope_and_cx(&self) -> (*JSObject, *JSContext) {
- let win = self.window.get_ref();
+ let win = self.window;
(win.reflector().get_jsobject(), win.get_cx())
}
@@ -518,15 +515,11 @@ impl Document {
}
pub fn content_changed(&self) {
- for window in self.window.iter() {
- window.content_changed()
- }
+ self.window.content_changed();
}
pub fn wait_until_safe_to_modify_dom(&self) {
- for window in self.window.iter() {
- window.wait_until_safe_to_modify_dom();
- }
+ self.window.wait_until_safe_to_modify_dom();
}
pub fn register_nodes_with_id(&mut self, root: &AbstractNode<ScriptView>) {
diff --git a/src/components/script/dom/domparser.rs b/src/components/script/dom/domparser.rs
index 16d3c3ca46c..cc3db3e07a7 100644
--- a/src/components/script/dom/domparser.rs
+++ b/src/components/script/dom/domparser.rs
@@ -43,10 +43,10 @@ impl DOMParser {
let cx = self.owner.get_cx();
let document = match ty {
Text_html => {
- HTMLDocument::new(None)
+ HTMLDocument::new(self.owner)
}
Text_xml => {
- AbstractDocument::as_abstract(cx, @mut Document::new(None, XML))
+ AbstractDocument::as_abstract(cx, @mut Document::new(self.owner, XML))
}
_ => {
fail!("unsupported document type")
diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs
index 355c62307d0..fd50118a9ec 100644
--- a/src/components/script/dom/element.rs
+++ b/src/components/script/dom/element.rs
@@ -274,7 +274,7 @@ impl Element {
pub fn GetClientRects(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRectList {
let document = self.node.owner_doc;
- let win = document.with_base(|doc| doc.window).expect("no window");
+ let win = document.with_base(|doc| doc.window);
let node = abstract_self;
assert!(node.is_element());
let (port, chan) = comm::stream();
@@ -301,7 +301,7 @@ impl Element {
pub fn GetBoundingClientRect(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRect {
let document = self.node.owner_doc;
- let win = document.with_base(|doc| doc.window).expect("no window");
+ let win = document.with_base(|doc| doc.window);
let node = abstract_self;
assert!(node.is_element());
let (port, chan) = comm::stream();
diff --git a/src/components/script/dom/htmldocument.rs b/src/components/script/dom/htmldocument.rs
index 32abdd29ed9..fc521220ee3 100644
--- a/src/components/script/dom/htmldocument.rs
+++ b/src/components/script/dom/htmldocument.rs
@@ -24,12 +24,12 @@ pub struct HTMLDocument {
}
impl HTMLDocument {
- pub fn new(window: Option<@mut Window>) -> AbstractDocument {
+ pub fn new(window: @mut Window) -> AbstractDocument {
let doc = @mut HTMLDocument {
parent: Document::new(window, HTML)
};
- AbstractDocument::as_abstract(window.get_ref().get_cx(), doc)
+ AbstractDocument::as_abstract(window.get_cx(), doc)
}
}
diff --git a/src/components/script/dom/htmlimageelement.rs b/src/components/script/dom/htmlimageelement.rs
index 6903120a09e..673886037e3 100644
--- a/src/components/script/dom/htmlimageelement.rs
+++ b/src/components/script/dom/htmlimageelement.rs
@@ -44,10 +44,9 @@ impl HTMLImageElement {
if "src" == name {
let doc = self.htmlelement.element.node.owner_doc;
do doc.with_base |doc| {
- for window in doc.window.iter() {
- let url = window.page.url.map(|&(ref url, _)| url.clone());
- self.update_image(window.image_cache_task.clone(), url);
- }
+ let window = doc.window;
+ let url = window.page.url.map(|&(ref url, _)| url.clone());
+ self.update_image(window.image_cache_task.clone(), url);
}
}
}
@@ -100,19 +99,11 @@ impl HTMLImageElement {
pub fn Width(&self, abstract_self: AbstractNode<ScriptView>) -> u32 {
let node = &self.htmlelement.element.node;
- match node.owner_doc.with_base(|doc| doc.window) {
- Some(win) => {
- let page = win.page;
- let (port, chan) = stream();
- match page.query_layout(ContentBoxQuery(abstract_self, chan), port) {
- ContentBoxResponse(rect) => {
- to_px(rect.size.width) as u32
- }
- }
- }
- None => {
- debug!("no window");
- 0
+ let page = node.owner_doc.with_base(|doc| doc.window).page;
+ let (port, chan) = stream();
+ match page.query_layout(ContentBoxQuery(abstract_self, chan), port) {
+ ContentBoxResponse(rect) => {
+ to_px(rect.size.width) as u32
}
}
}
@@ -129,19 +120,11 @@ impl HTMLImageElement {
pub fn Height(&self, abstract_self: AbstractNode<ScriptView>) -> u32 {
let node = &self.htmlelement.element.node;
- match node.owner_doc.with_base(|doc| doc.window) {
- Some(win) => {
- let page = win.page;
- let (port, chan) = stream();
- match page.query_layout(ContentBoxQuery(abstract_self, chan), port) {
- ContentBoxResponse(rect) => {
- to_px(rect.size.height) as u32
- }
- }
- }
- None => {
- debug!("no window");
- 0
+ let page = node.owner_doc.with_base(|doc| doc.window).page;
+ let (port, chan) = stream();
+ match page.query_layout(ContentBoxQuery(abstract_self, chan), port) {
+ ContentBoxResponse(rect) => {
+ to_px(rect.size.height) as u32
}
}
}
diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs
index e58eb306b97..e8b5eb3fc16 100644
--- a/src/components/script/dom/node.rs
+++ b/src/components/script/dom/node.rs
@@ -664,7 +664,7 @@ impl Node<ScriptView> {
}
pub fn get_scope_and_cx(&self) -> (*JSObject, *JSContext) {
- let win = self.owner_doc.with_base(|doc| doc.window.unwrap());
+ let win = self.owner_doc.with_base(|doc| doc.window);
(win.reflector().get_jsobject(), win.get_cx())
}
diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs
index ca3a04910bc..31a0bd6eb9d 100644
--- a/src/components/script/script_task.rs
+++ b/src/components/script/script_task.rs
@@ -717,7 +717,7 @@ impl ScriptTask {
// Parse HTML.
//
// Note: We can parse the next document in parallel with any previous documents.
- let document = HTMLDocument::new(Some(window));
+ let document = HTMLDocument::new(window);
let html_parsing_result = hubbub_html_parser::parse_html(cx.ptr,
document,