Fix for isOrHasChild() null & exception cases.
Issues: 671, 872
Patch by: ecc, jat, fredsa, jgw
Review by: jgw, ecc
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@921 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/impl/DOMImplMozilla.java b/user/src/com/google/gwt/user/client/impl/DOMImplMozilla.java
index a5f2657..d06557a 100644
--- a/user/src/com/google/gwt/user/client/impl/DOMImplMozilla.java
+++ b/user/src/com/google/gwt/user/client/impl/DOMImplMozilla.java
@@ -98,8 +98,17 @@
if (parent.isSameNode(child)) {
return true;
}
- child = child.parentNode;
- if (child.nodeType != 1) {
+
+ try {
+ child = child.parentNode;
+ } catch(e) {
+ // Give up on 'Permission denied to get property
+ // HTMLDivElement.parentNode'
+ // See https://bugzilla.mozilla.org/show_bug.cgi?id=208427
+ return false;
+ }
+
+ if (child && (child.nodeType != 1)) {
child = null;
}
}
diff --git a/user/src/com/google/gwt/user/client/impl/DOMImplStandard.java b/user/src/com/google/gwt/user/client/impl/DOMImplStandard.java
index 34e00a9..00ff995 100644
--- a/user/src/com/google/gwt/user/client/impl/DOMImplStandard.java
+++ b/user/src/com/google/gwt/user/client/impl/DOMImplStandard.java
@@ -197,11 +197,13 @@
public native boolean isOrHasChild(Element parent, Element child) /*-{
while (child) {
- if (parent == child)
+ if (parent == child) {
return true;
+ }
child = child.parentNode;
- if (child.nodeType != 1)
+ if (child && (child.nodeType != 1)) {
child = null;
+ }
}
return false;
}-*/;
diff --git a/user/test/com/google/gwt/user/client/ui/DOMTest.java b/user/test/com/google/gwt/user/client/ui/DOMTest.java
index 710138e..8c3b1fd 100644
--- a/user/test/com/google/gwt/user/client/ui/DOMTest.java
+++ b/user/test/com/google/gwt/user/client/ui/DOMTest.java
@@ -20,7 +20,7 @@
import com.google.gwt.user.client.Element;
/**
- * TODO: document me.
+ * Test DOM methods.
*/
public class DOMTest extends GWTTestCase {
@@ -69,6 +69,15 @@
// top of the parent hierarchy.
}
+ public void testIsOrHasChild() {
+ Element div = DOM.createDiv();
+ Element childDiv = DOM.createDiv();
+ assertFalse(DOM.isOrHasChild(div, childDiv));
+ DOM.appendChild(div, childDiv);
+ assertTrue(DOM.isOrHasChild(div, childDiv));
+ assertFalse(DOM.isOrHasChild(childDiv, div));
+ }
+
public void testSetInnerText() {
Element tableElem = DOM.createTable();