Disabling JIT in Safari 6 to workaround severe Javascript JIT bugs

后端 未结 3 1619
既然无缘
既然无缘 2021-02-05 06:56

We found a severe problem with the interpretation of our Javascript code that only occurs on iOS 5/Safari 6 (then current iPad release) that we think is due to critical bug in t

3条回答
  •  北恋
    北恋 (楼主)
    2021-02-05 07:10

    Actually, the FOR loop bug is still present in Safari on iOS 7.0.4 in iPhone 4 and iPad 2. The loop failing can be significantly simpler than the illustration above, and it rakes several passes through the code to hit. Changing to a WHILE loop allows proper execution.

    Failing code:

    function zf(num,digs) 
    { 
    var out = ""; 
    var n = Math.abs(num); 
    for (digs;  digs>0||n>0; digs--)
    { 
        out = n%10 + out; 
        n = Math.floor(n/10); 
    }  
    return num<0?"-"+out:out; 
    } 
    

    Successful code:

    function zf(num,digs) 
    { 
    var out = ""; 
    var n = Math.abs(num); 
    do 
    { 
        out = n%10 + out; 
        n = Math.floor(n/10); 
    } 
    while (--digs>0||n>0) 
    return num<0?"-"+out:out; 
    } 
    

提交回复
热议问题