Skip to content

Commit 1541664

Browse files
committed
Core: add workaround for iOS JIT error in isArrayLike
Fixes gh-2145
1 parent ab40725 commit 1541664

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/core.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,12 @@ function(i, name) {
432432
});
433433

434434
function isArraylike( obj ) {
435-
var length = obj.length,
435+
436+
// Support: iOS 8.2 (not reproducible in simulator)
437+
// `in` check used to prevent JIT error (gh-2145)
438+
// hasOwn isn't used here due to false negatives
439+
// regarding Nodelist length in IE
440+
var length = "length" in obj && obj.length,
436441
type = jQuery.type( obj );
437442

438443
if ( type === "function" || jQuery.isWindow( obj ) ) {

test/unit/core.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,27 @@ test("jQuery.each(Object,Function)", function() {
12021202
equal( i, document.styleSheets.length, "Iteration over document.styleSheets" );
12031203
});
12041204

1205+
test( "JIT compilation does not interfere with length retrieval (gh-2145)", function() {
1206+
expect( 4 );
1207+
1208+
var i;
1209+
1210+
// Trigger JIT compilation of jQuery.each – and therefore isArraylike – in iOS.
1211+
// Convince JSC to use one of its optimizing compilers
1212+
// by providing code which can be LICM'd into nothing.
1213+
for ( i = 0; i < 1000; i++ ) {
1214+
jQuery.each( [] );
1215+
}
1216+
1217+
i = 0;
1218+
jQuery.each( { 1: "1", 2: "2", 3: "3" }, function( index ) {
1219+
equal( ++i, index, "Iteration over object with solely " +
1220+
"numeric indices (gh-2145 JIT iOS 8 bug)" );
1221+
});
1222+
equal( i, 3, "Iteration over object with solely " +
1223+
"numeric indices (gh-2145 JIT iOS 8 bug)" );
1224+
});
1225+
12051226
test("jQuery.makeArray", function(){
12061227
expect(15);
12071228

0 commit comments

Comments
 (0)