From 3296116041ea0eb89e123c24cf092e34ccb3f380 Mon Sep 17 00:00:00 2001 From: Jordan Boesch Date: Wed, 30 Mar 2011 11:17:48 -0600 Subject: [PATCH 1/2] Bug 4366; fixing $.each(document.styleSheets) from throwing errors in IE --- src/core.js | 7 +++++-- test/unit/core.js | 9 ++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/core.js b/src/core.js index 9312ee28..1b06913c 100644 --- a/src/core.js +++ b/src/core.js @@ -610,8 +610,11 @@ jQuery.extend({ } } } else { - for ( var value = object[0]; - i < length && callback.call( value, i, value ) !== false; value = object[++i] ) {} + for ( ; i < length; ) { + if ( callback.call( object[ i ], i, object[ i++ ] ) === false ) { + break; + } + } } } diff --git a/test/unit/core.js b/test/unit/core.js index 6ee8724d..39b7d275 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -784,7 +784,7 @@ test("jQuery.extend(Object, Object)", function() { }); test("jQuery.each(Object,Function)", function() { - expect(13); + expect(14); jQuery.each( [0,1,2], function(i, n){ equals( i, n, "Check array iteration" ); }); @@ -816,6 +816,13 @@ test("jQuery.each(Object,Function)", function() { f[i] = 'baz'; }); equals( "baz", f.foo, "Loop over a function" ); + + var stylesheet_count = 0; + jQuery.each(document.styleSheets, function(i){ + stylesheet_count++; + }); + equals(stylesheet_count, 2, "should not throw an error in IE while looping over document.styleSheets and return proper amount"); + }); test("jQuery.makeArray", function(){ From 926884bf1f071b6dd92f0611d905b2cbffa16a19 Mon Sep 17 00:00:00 2001 From: Jordan Boesch Date: Wed, 30 Mar 2011 11:26:20 -0600 Subject: [PATCH 2/2] Bug 4366; removing extra space --- src/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core.js b/src/core.js index 1b06913c..7cf99372 100644 --- a/src/core.js +++ b/src/core.js @@ -611,7 +611,7 @@ jQuery.extend({ } } else { for ( ; i < length; ) { - if ( callback.call( object[ i ], i, object[ i++ ] ) === false ) { + if ( callback.call( object[ i ], i, object[ i++ ] ) === false ) { break; } }