]> source.dussan.org Git - jquery.git/commitdiff
Add some tests for jQuery.isWindow and make sure that we're operating against an...
authorjeresig <jeresig@gmail.com>
Wed, 22 Sep 2010 20:50:38 +0000 (16:50 -0400)
committerjeresig <jeresig@gmail.com>
Wed, 22 Sep 2010 20:50:38 +0000 (16:50 -0400)
src/core.js
test/unit/core.js

index 9cb519be574742f1fa8a86f99a677262a9cda674..b747e5beaa669e57018767d7c65067f99e686ed6 100644 (file)
@@ -476,7 +476,7 @@ jQuery.extend({
 
        // A crude way of determining if an object is a window
        isWindow: function( obj ) {
-               return "setInterval" in obj;
+               return obj && typeof obj === "object" && "setInterval" in obj;
        },
 
        type: function( obj ) {
index 811d13fb4aa33a521faa51b73cda209d5a6d934d..eec3d7cdfdce3443f1db3796d1bd48a45cb6cd0b 100644 (file)
@@ -432,6 +432,25 @@ test("isXMLDoc - XML", function() {
 });
 }
 
+test("isWindow", function() {
+       expect( 12 );
+
+       ok( jQuery.isWindow(window), "window" );
+       ok( !jQuery.isWindow(), "empty" );
+       ok( !jQuery.isWindow(null), "null" );
+       ok( !jQuery.isWindow(undefined), "undefined" );
+       ok( !jQuery.isWindow(document), "document" );
+       ok( !jQuery.isWindow(document.documentElement), "documentElement" );
+       ok( !jQuery.isWindow(""), "string" );
+       ok( !jQuery.isWindow(1), "number" );
+       ok( !jQuery.isWindow(true), "boolean" );
+       ok( !jQuery.isWindow({}), "object" );
+       // HMMM
+       // ok( !jQuery.isWindow({ setInterval: function(){} }), "fake window" );
+       ok( !jQuery.isWindow(/window/), "regexp" );
+       ok( !jQuery.isWindow(function(){}), "function" );
+});
+
 test("jQuery('html')", function() {
        expect(15);