Skip to content

Commit 1e7a2f3

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

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
@@ -484,7 +484,12 @@ function(i, name) {
484484
});
485485

486486
function isArraylike( obj ) {
487-
var length = obj.length,
487+
488+
// Support: iOS 8.2 (not reproducible in simulator)
489+
// `in` check used to prevent JIT error (gh-2145)
490+
// hasOwn isn't used here due to false negatives
491+
// regarding Nodelist length in IE
492+
var length = "length" in obj && obj.length,
488493
type = jQuery.type( obj );
489494

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

test/unit/core.js

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

1189+
test( "JIT compilation does not interfere with length retrieval (gh-2145)", function() {
1190+
expect( 4 );
1191+
1192+
var i;
1193+
1194+
// Trigger JIT compilation of jQuery.each – and therefore isArraylike – in iOS.
1195+
// Convince JSC to use one of its optimizing compilers
1196+
// by providing code which can be LICM'd into nothing.
1197+
for ( i = 0; i < 1000; i++ ) {
1198+
jQuery.each( [] );
1199+
}
1200+
1201+
i = 0;
1202+
jQuery.each( { 1: "1", 2: "2", 3: "3" }, function( index ) {
1203+
equal( ++i, index, "Iteration over object with solely " +
1204+
"numeric indices (gh-2145 JIT iOS 8 bug)" );
1205+
});
1206+
equal( i, 3, "Iteration over object with solely " +
1207+
"numeric indices (gh-2145 JIT iOS 8 bug)" );
1208+
});
1209+
11891210
test("jQuery.makeArray", function(){
11901211
expect(15);
11911212

0 commit comments

Comments
 (0)