Skip to content

Commit

Permalink
Core: add workaround for iOS JIT error in isArrayLike
Browse files Browse the repository at this point in the history
Fixes gh-2145
  • Loading branch information
timmywil authored and markelog committed Nov 10, 2015
1 parent 6f93e07 commit 4641c23
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/core.js
Expand Up @@ -451,7 +451,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 ) ) {
Expand Down
21 changes: 21 additions & 0 deletions test/unit/core.js
Expand Up @@ -1245,6 +1245,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);

Expand Down

0 comments on commit 4641c23

Please sign in to comment.