From 1e7a2f3674d4bc62ba6cc537e42b2e417a9c5ba6 Mon Sep 17 00:00:00 2001 From: Timmy Willison Date: Sat, 4 Apr 2015 15:34:07 -0400 Subject: [PATCH] Core: add workaround for iOS JIT error in isArrayLike Fixes gh-2145 --- src/core.js | 7 ++++++- test/unit/core.js | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/core.js b/src/core.js index 21a995f38..889fcd513 100644 --- a/src/core.js +++ b/src/core.js @@ -484,7 +484,12 @@ function(i, name) { }); function isArraylike( obj ) { - var length = obj.length, + + // Support: iOS 8.2 (not reproducible in simulator) + // `in` check used to prevent JIT error (gh-2145) + // hasOwn isn't used here due to false negatives + // regarding Nodelist length in IE + var length = "length" in obj && obj.length, type = jQuery.type( obj ); if ( type === "function" || jQuery.isWindow( obj ) ) { diff --git a/test/unit/core.js b/test/unit/core.js index 2c40139d3..cccb2df98 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -1186,6 +1186,27 @@ test("jQuery.each(Object,Function)", function() { equal( i, document.styleSheets.length, "Iteration over document.styleSheets" ); }); +test( "JIT compilation does not interfere with length retrieval (gh-2145)", function() { + expect( 4 ); + + var i; + + // Trigger JIT compilation of jQuery.each – and therefore isArraylike – in iOS. + // Convince JSC to use one of its optimizing compilers + // by providing code which can be LICM'd into nothing. + for ( i = 0; i < 1000; i++ ) { + jQuery.each( [] ); + } + + i = 0; + jQuery.each( { 1: "1", 2: "2", 3: "3" }, function( index ) { + equal( ++i, index, "Iteration over object with solely " + + "numeric indices (gh-2145 JIT iOS 8 bug)" ); + }); + equal( i, 3, "Iteration over object with solely " + + "numeric indices (gh-2145 JIT iOS 8 bug)" ); +}); + test("jQuery.makeArray", function(){ expect(15); -- 2.39.5