Bug Tracker

Ticket #3039 (assigned bug)

Opened 7 months ago

Last modified 3 months ago

Older Safari versions crash in makeArray

Reported by: kloor Assigned to: flesler (accepted)
Type: bug Priority: minor
Milestone: 1.3 Component: core
Version: 1.2.6 Keywords: safari 2
Cc: kloor, mnash Needs: Review

Description

The attached test case consistently crashes older versions of Safari. This appears due to the following line makeArray: http://dev.jquery.com/browser/trunk/jquery/src/core.js?rev=5700#L1134

jQuery version 1.2.3 does not crash.

Attachments

index.html (351 bytes) - added by kloor 7 months ago.
Test Case

Change History

Changed 7 months ago by kloor

Test Case

  Changed 7 months ago by flesler

  • keywords set to safari 2
  • priority changed from major to minor

  Changed 6 months ago by lukemelia

We've run into this problem as well with jQuery 1.2.6 and Safari 2.0.4. Confirmed that reverting to the definition of makeArray in 1.2.3 fixes the problem.

  Changed 6 months ago by flesler

  • owner set to flesler
  • status changed from new to assigned

Ok, will check this out for 1.3.

  Changed 5 months ago by mnash

In version 1.2.3, the code has a comment: // Need to use typeof to fight Safari childNodes crashes

if ( typeof array != "array" )

After swapping out in 1.2.6 line 1131 - "if( array != null ){" with the above code - Safari no longer crashes and all the other browsers work.

follow-ups: ↓ 6 ↓ 7   Changed 5 months ago by flesler

  • cc set to kloor

That's not a compatible replacement. Try

if ( typeof array != "undefined" )

in reply to: ↑ 5   Changed 5 months ago by mnash

Thank you - that works just as well

in reply to: ↑ 5   Changed 5 months ago by kloor

That fixes the test case I posted, but it still crashes for actual script. I think the crash is caused by the if statement on line 1134, it's just that we prevented Safari from reaching that line for the test case.

I'll have to look into developing another test case.

  Changed 5 months ago by flesler

  • cc changed from kloor to kloor, mnash

Can you try using the most recent version from the trunk (revision 5289 I think) Try with and without the replacement I mentioned.

Thanks

  Changed 3 months ago by harawata

I have tried the test case against jQuery (Rev: 5829) on Safari 2.0.4 and it still crashes.

  Changed 3 months ago by korpios

We still haven't been able to upgrade past jQuery 1.2.3 at The Onion because of this bug; a non-negligible portion of our audience is still on Safari 2.

  Changed 3 months ago by harawata

I found that calling array.setInterval actually caused the crash.
So I modified the method as follows and ran the test case (I couldn't find a better way of debugging in Safari 2).

makeArray: function( array ) {
  var ret = [];
  if( array != null ){
    k += typeof array + ",";
  }
  return ret;
},

On Firefox, the variable k contained object,object,object,.
On Safari, the variable k contained object,function,object,.

I have no idea what causes the difference and why it crashes Safari 2, but adding a simple type check could be a temporary workaround.

For revision 5829.

makeArray: function( array ) {
  var ret = [];
  if( array != null ){
    var i = array.length;
    // The window, strings (and functions) also have 'length'
    if( i == null || typeof array == 'string' || (typeof array != 'function' && array.setInterval) )
      ret[0] = array;
    else
      while( i )
        ret[--i] = array[i];
  }
  return ret;
},

For jQuery 1.2.6.

makeArray: function( array ) {
  var ret = [];
  if( array != null ){
    var i = array.length;
    //the window, strings and functions also have 'length'
    if( i == null || ( typeof array != 'function' && ( array.split || array.setInterval || array.call ) ) )
      ret[0] = array;
    else
      while( i )
        ret[--i] = array[i];
  }
  return ret;
},

Hope this helps you fix the issue.

  Changed 3 months ago by harawata

Note: See TracTickets for help on using tickets.