From 28f8d16c87f7da49a3743585f3fb389027be04be Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Wed, 11 Jun 2014 03:03:07 +0900 Subject: [PATCH] Fix the assertion failure with inserting node contains child which has id into the document https://github.com/mozilla/servo/issues/2630 --- src/components/script/dom/node.rs | 11 +++++++---- src/test/content/test_document_getElementById.html | 12 ++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 7b095bc9c57..2e3e02d381b 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -1137,10 +1137,13 @@ impl Node { // Step 8. for node in nodes.mut_iter() { parent.add_child(node, child); - if parent.is_in_doc() { - node.flags.deref().borrow_mut().insert(IsInDoc); - } else { - node.flags.deref().borrow_mut().remove(IsInDoc); + let is_in_doc = parent.is_in_doc(); + for mut kid in node.traverse_preorder() { + if is_in_doc { + kid.flags.deref().borrow_mut().insert(IsInDoc); + } else { + kid.flags.deref().borrow_mut().remove(IsInDoc); + } } } diff --git a/src/test/content/test_document_getElementById.html b/src/test/content/test_document_getElementById.html index 382c07574a7..2617fb2e113 100644 --- a/src/test/content/test_document_getElementById.html +++ b/src/test/content/test_document_getElementById.html @@ -106,6 +106,18 @@ is(target2, null, "test 8-1, should return null after updated id via Attr.value"); } + // Test the assertion with inserting node with child having id into the document (mozilla#2630) + // This need not to port to WPF-test because this tests servo's internally flags. + { + let TEST_ID = "test-9"; + let a = document.createElement("a"); + let b = document.createElement("b"); + a.appendChild(b).id = TEST_ID; + gBody.appendChild(a); + let result = document.getElementById(TEST_ID); + is(result, b, "test 9-0"); + } + finish();