Skip to content

Commit

Permalink
Fix to avoid attribute name clash between Document/HTMLDocument
Browse files Browse the repository at this point in the history
Use children() instead of traverse_preorder(), and avoid having
GetHead() in both Document and HTMLDocument.

Closes #1465.
  • Loading branch information
brunoabinader committed Jan 8, 2014
1 parent 728fb9a commit b5eba00
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Expand Up @@ -17,7 +17,7 @@ interface HTMLDocument : Document {
// getter object (DOMString name);
/*[SetterThrows]
attribute HTMLElement? body;*/
readonly attribute HTMLHeadElement? head;
// readonly attribute HTMLHeadElement? head;
readonly attribute HTMLCollection images;
readonly attribute HTMLCollection embeds;
readonly attribute HTMLCollection plugins;
Expand Down
3 changes: 2 additions & 1 deletion src/components/script/dom/document.rs
Expand Up @@ -306,12 +306,13 @@ impl Document {
// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-head
pub fn GetHead(&self) -> Option<AbstractNode> {
self.get_html_element().and_then(|root| {
root.traverse_preorder().find(|child| {
root.children().find(|child| {
child.type_id() == ElementNodeTypeId(HTMLHeadElementTypeId)
})
})
}

// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body
pub fn GetBody(&self, _: AbstractDocument) -> Option<AbstractNode> {
match self.get_html_element() {
None => None,
Expand Down
8 changes: 0 additions & 8 deletions src/components/script/dom/htmldocument.rs
Expand Up @@ -33,14 +33,6 @@ impl HTMLDocument {
}

impl HTMLDocument {
pub fn GetHead(&self) -> Option<AbstractNode> {
self.parent.GetDocumentElement().and_then(|root| {
root.traverse_preorder().find(|child| {
child.type_id() == ElementNodeTypeId(HTMLHeadElementTypeId)
})
})
}

pub fn Images(&self) -> @mut HTMLCollection {
self.parent.createHTMLCollection(|elem| eq_slice(elem.tag_name, "img"))
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/html/content/test_document_head.html
Expand Up @@ -29,6 +29,17 @@
is(new_document.head, new_head, "test2-4, append head to a new document");
}

// test3: head's parent should be document element
{
let new_document = new Document();
let html = new_document.createElement("html");
let foo = new_document.createElement("foo");
let head = new_document.createElement("head");
new_document.appendChild(html);
html.appendChild(foo);
foo.appendChild(head);
is(new_document.head, null, "test3-0, head's parent should be document element");
}
finish();
</script>
</body>
Expand Down

5 comments on commit b5eba00

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging brunoabinader/servo/document-head = b5eba00 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brunoabinader/servo/document-head = b5eba00 merged ok, testing candidate = e8b0eae

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = e8b0eae

Please sign in to comment.