From e0f9f511f16bdc47b4575f351cab6ca80773a587 Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Mon, 25 Oct 2010 12:38:18 +0000 Subject: [PATCH] fixing filter function throw exception if one element does not have parent in SelectorEngineJS (fixes issue55) --- .../google/gwt/query/client/impl/SelectorEngineJS.java | 4 ++++ .../com/google/gwt/query/client/GQueryCoreTest.java | 10 ++++++++++ 2 files changed, 14 insertions(+) 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 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(""); assertHtmlEquals(expected, $(e).html()); } + + public void testFilterBody() { + GQuery myNewElement = $("
my new 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); + } } -- 2.39.5