aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbors-servo <release+servo@mozilla.com>2014-03-19 14:47:13 -0400
committerbors-servo <release+servo@mozilla.com>2014-03-19 14:47:13 -0400
commitcc77b287617e857b45282d0f39bcac6f9cf5bdd1 (patch)
treee4ab7a205dd503a596130e14e173f7b9217584d5 /src
parentf7aa6e3d9b8bfcc0565624f1094241b3b8658bd8 (diff)
parent6ecb9ba4b6f801020e3f33556e81deaa90bfa555 (diff)
downloadservo-cc77b287617e857b45282d0f39bcac6f9cf5bdd1.tar.gz
servo-cc77b287617e857b45282d0f39bcac6f9cf5bdd1.zip
auto merge of #1925 : saneyuki/servo/1874, r=jdm
Fix #1874
Diffstat (limited to 'src')
-rw-r--r--src/components/script/dom/node.rs10
-rw-r--r--src/test/content/test_document_getElementById.html19
2 files changed, 21 insertions, 8 deletions
diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs
index dcb360e0425..71b2b121136 100644
--- a/src/components/script/dom/node.rs
+++ b/src/components/script/dom/node.rs
@@ -404,10 +404,12 @@ impl NodeHelpers for JS<Node> {
assert!(self.parent_node().is_some());
let document = document_from_node(self);
- for node in self.traverse_preorder() {
- if node.is_element() {
- let element: JS<Element> = ElementCast::to(&node);
- element.bind_to_tree_impl();
+ if self.is_in_doc() {
+ for node in self.traverse_preorder() {
+ if node.is_element() {
+ let element: JS<Element> = ElementCast::to(&node);
+ element.bind_to_tree_impl();
+ }
}
}
diff --git a/src/test/content/test_document_getElementById.html b/src/test/content/test_document_getElementById.html
index 92040c8f257..9d066137ef3 100644
--- a/src/test/content/test_document_getElementById.html
+++ b/src/test/content/test_document_getElementById.html
@@ -66,21 +66,32 @@
is(e2, null, "test3-2, the method should return null when the passed id is none in document.");
}
+ // test 4
{
// Ensure that the id attribute only affects elements present in a document
let e = document.createElement('div');
e.id = "should-not-exist";
- is(document.getElementById("should-not-exist"), null);
+ is(document.getElementById("should-not-exist"), null, "test 4-0");
document.body.appendChild(e);
- is(document.getElementById("should-not-exist"), e);
+ is(document.getElementById("should-not-exist"), e, "test 4-1");
}
// TODO:
- // test4: "in tree order, within the context object's tree"
+ // test5: "in tree order, within the context object's tree"
// http://dom.spec.whatwg.org/#dom-document-getelementbyid.
// TODO:
- // test5: innerHTML
+ // test6: innerHTML
+
+ // test 7
+ {
+ // Test that we only cache elements by ID if they're in a document (see #1874).
+ let s = document.createElement("div");
+ s.setAttribute("id", "x");
+ document.createElement("div").appendChild(s);
+ is(document.getElementById("x"), null, "test 7-0");
+ }
+
finish();
</script>
</body>