]> source.dussan.org Git - gwtquery.git/commitdiff
fixing filter function throw exception if one element does not have parent in Selecto...
authorManolo Carrasco <manolo@apache.org>
Mon, 25 Oct 2010 12:38:18 +0000 (12:38 +0000)
committerManolo Carrasco <manolo@apache.org>
Mon, 25 Oct 2010 12:38:18 +0000 (12:38 +0000)
gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineJS.java
gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java

index 9ca1aa1e9f029b23dae3a16814ac8c39c98fa03c..5f7446b87db562ff99c62aa6d43b3641c61d8e45 100644 (file)
@@ -15,6 +15,7 @@
  */\r
 package com.google.gwt.query.client.impl;\r
 \r
+import com.google.gwt.core.client.JavaScriptObject;\r
 import com.google.gwt.core.client.JsArray;\r
 import com.google.gwt.dom.client.Document;\r
 import com.google.gwt.dom.client.Element;\r
@@ -103,6 +104,9 @@ public class SelectorEngineJS extends SelectorEngineImpl {
   }\r
 \r
   private static NodeList<Element> getElementsByTagName(String tag, Node ctx) {\r
+    if (ctx == null) {\r
+      return JavaScriptObject.createArray().cast();\r
+    }\r
     return ((Element) ctx).getElementsByTagName(tag);\r
   }\r
 \r
index 2cf892638dd950b86a4acd699ba04d129a2edc11..a77e9015566d395f6a87cfb8d86f98a54d97e1e5 100644 (file)
@@ -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);
+  }
 
 }