diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index cbe9ea18e8..dddb2963e6 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -48,10 +48,15 @@ OpenLayers.Pixel.prototype = { * @param {OpenLayers.Pixel} px * * @return whether or not the point passed in as parameter is equal to this + * note that if px passed in is null, returns false * @type bool */ equals:function(px) { - return ((this.x == px.x) && (this.y == px.y)); + var equals = false; + if (px != null) { + equals = ((this.x == px.x) && (this.y == px.y)); + } + return equals; }, /** @@ -127,11 +132,16 @@ OpenLayers.Size.prototype = { * @param {OpenLayers.Size} sz * @returns Boolean value indicating whether the passed-in OpenLayers.Size * object has the same w and h components as this + * note that if sz passed in is null, returns false * * @type bool */ equals:function(sz) { - return ((this.w == sz.w) && (this.h == sz.h)); + var equals = false; + if (sz != null) { + equals = ((this.w == sz.w) && (this.h == sz.h)); + } + return equals; }, /** @final @type String */ @@ -203,11 +213,16 @@ OpenLayers.LonLat.prototype = { * @param {OpenLayers.LonLat} ll * @returns Boolean value indicating whether the passed-in OpenLayers.LonLat * object has the same lon and lat components as this + * note that if ll passed in is null, returns false * * @type bool */ equals:function(ll) { - return ((this.lon == ll.lon) && (this.lat == ll.lat)); + var equals = false; + if (ll != null) { + equals = ((this.lon == ll.lon) && (this.lat == ll.lat)); + } + return equals; }, /** @final @type String */ @@ -282,12 +297,19 @@ OpenLayers.Bounds.prototype = { * @param {OpenLayers.Bounds} bounds * @returns Boolean value indicating whether the passed-in OpenLayers.Bounds * object has the same left, right, top, bottom components as this + * note that if bounds passed in is null, returns false * * @type bool */ equals:function(bounds) { - return ((this.left == bounds.left) && (this.right == bounds.right) && - (this.top == bounds.top) && (this.bottom == bounds.bottom)); + var equals = false; + if (bounds != null) { + equals = ((this.left == bounds.left) && + (this.right == bounds.right) && + (this.top == bounds.top) && + (this.bottom == bounds.bottom)); + } + return equals; }, /** diff --git a/tests/test_Bounds.html b/tests/test_Bounds.html index 08874a0a6a..c167fcdfef 100644 --- a/tests/test_Bounds.html +++ b/tests/test_Bounds.html @@ -171,13 +171,14 @@ } function test_11_Bounds_equals(t) { - t.plan( 2 ); + t.plan( 3 ); var boundsA = new OpenLayers.Bounds(1,2,3,4); var boundsB = new OpenLayers.Bounds(1,2,3,4); var boundsC = new OpenLayers.Bounds(1,5,3,4); t.ok( boundsA.equals(boundsB), "equals() returns true on two equal bounds." ); t.ok( !boundsA.equals(boundsC), "equals() returns false on two different bounds." ); + t.ok( !boundsA.equals(null), "equals() returns false on comparison to null"); } function test_12_Bounds_getHeight_getWidth(t) { diff --git a/tests/test_LonLat.html b/tests/test_LonLat.html index 5f8017789c..dcf5c99a02 100644 --- a/tests/test_LonLat.html +++ b/tests/test_LonLat.html @@ -52,7 +52,7 @@ } function test_06_LonLat_equals(t) { - t.plan( 4 ); + t.plan( 5 ); lonlat = new OpenLayers.LonLat(5,6); ll = new OpenLayers.LonLat(5,6); @@ -66,6 +66,9 @@ ll = new OpenLayers.LonLat(1,2); t.eq( lonlat.equals(ll), false, "(5,6) does not equal (1,2)"); + + t.ok( !lonlat.equals(null), "equals() returns false on comparison to null"); + } function test_07_LonLat_fromString(t) { diff --git a/tests/test_Pixel.html b/tests/test_Pixel.html index cda6524a10..ac377c018c 100644 --- a/tests/test_Pixel.html +++ b/tests/test_Pixel.html @@ -32,7 +32,7 @@ } function test_06_Pixel_equals(t) { - t.plan( 4 ); + t.plan( 5 ); pixel = new OpenLayers.Pixel(5,6); px = new OpenLayers.Pixel(5,6); @@ -46,6 +46,9 @@ px = new OpenLayers.Pixel(1,2); t.eq( pixel.equals(px), false, "(5,6) does not equal (1,2)"); + + t.ok( !pixel.equals(null), "equals() returns false on comparison to null"); + } function test_07_Pixel_add(t) { diff --git a/tests/test_Size.html b/tests/test_Size.html index 24e1dca2d3..30dc978601 100644 --- a/tests/test_Size.html +++ b/tests/test_Size.html @@ -33,7 +33,7 @@ } function test_04_Size_equals(t) { - t.plan( 4 ); + t.plan( 5 ); size = new OpenLayers.Size(5,6); sz = new OpenLayers.Size(5,6); @@ -47,6 +47,8 @@ sz = new OpenLayers.Size(1,2); t.eq( size.equals(sz), false, "(5,6) does not equal (1,2)"); + + t.ok( !size.equals(null), "equals() returns false on comparison to null"); } // -->