diff options
author | Manolo Carrasco <manolo@apache.org> | 2010-10-25 12:38:18 +0000 |
---|---|---|
committer | Manolo Carrasco <manolo@apache.org> | 2010-10-25 12:38:18 +0000 |
commit | e0f9f511f16bdc47b4575f351cab6ca80773a587 (patch) | |
tree | bb49133b10c80eceab807e22ebb1ab293d0e11c0 /gwtquery-core | |
parent | 68b9edc0ce4995b8573ab695413b43cbb355720c (diff) | |
download | gwtquery-e0f9f511f16bdc47b4575f351cab6ca80773a587.tar.gz gwtquery-e0f9f511f16bdc47b4575f351cab6ca80773a587.zip |
fixing filter function throw exception if one element does not have parent in SelectorEngineJS (fixes issue55)
Diffstat (limited to 'gwtquery-core')
-rw-r--r-- | gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineJS.java | 4 | ||||
-rw-r--r-- | gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java | 10 |
2 files changed, 14 insertions, 0 deletions
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineJS.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineJS.java index 9ca1aa1e..5f7446b8 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineJS.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineJS.java @@ -15,6 +15,7 @@ */
package com.google.gwt.query.client.impl;
+import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
@@ -103,6 +104,9 @@ public class SelectorEngineJS extends SelectorEngineImpl { }
private static NodeList<Element> getElementsByTagName(String tag, Node ctx) {
+ if (ctx == null) {
+ return JavaScriptObject.createArray().cast();
+ }
return ((Element) ctx).getElementsByTagName(tag);
}
diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java index 2cf89263..a77e9015 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java @@ -745,5 +745,15 @@ public class GQueryCoreTest extends GWTTestCase { $("*", e).wrap("<b></b>"); assertHtmlEquals(expected, $(e).html()); } + + public void testFilterBody() { + GQuery myNewElement = $("<div>my new div</div>"); + boolean isAttachedToTheDOM = myNewElement.parents().filter("body").size() > 0; + assertEquals(false, isAttachedToTheDOM); + + myNewElement.appendTo(document); + isAttachedToTheDOM = myNewElement.parents().filter("body").size() > 0; + assertEquals(true, isAttachedToTheDOM); + } } |