Bug 774914 - Ensure newNode is orphan before replacing a node in JSDOMParser (r=mfinkle)
authorLucas Rocha <lucasr@mozilla.com>
Sat, 25 Aug 2012 11:27:27 +0100
changeset 105460 8182bfe539f8e94c93e9048db41309903bbcbb15
parent 105459 7e5db456160a178717f044d5fba40862c7402141
child 105461 5e2b2c9c4f670491189755b90f319da0d78e63f3
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersmfinkle
bugs774914
milestone17.0a1
Bug 774914 - Ensure newNode is orphan before replacing a node in JSDOMParser (r=mfinkle)
mobile/android/chrome/content/JSDOMParser.js
--- a/mobile/android/chrome/content/JSDOMParser.js
+++ b/mobile/android/chrome/content/JSDOMParser.js
@@ -318,16 +318,19 @@
     },
 
     replaceChild: function (newNode, oldNode) {
       let childNodes = this.childNodes;
       let childIndex = childNodes.indexOf(oldNode);
       if (childIndex == -1) {
         throw "replaceChild: node not found";
       } else {
+        if (newNode.parentNode)
+          newNode.parentNode.removeChild(newNode);
+
         childNodes[childIndex] = newNode;
         newNode.parentNode = this;
         oldNode.parentNode = null;
         return oldNode;
       }
     }
   };