Created
July 26, 2013 16:57
-
-
Save unkstar/6090453 to your computer and use it in GitHub Desktop.
safari bug demo: tested in Safari Version 6.0.5 (8536.30.1)
bad(2,1) shall always return false. But in the buggy version of safari, it will return true from 75 to 95 times it's being called.
on the other hand very very similar version good, behave just as it should.
by warming up the bad function by about 100 times, it will almost behave correct…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript"> | |
var append = function(text) { | |
document.body.appendChild(document.createTextNode(text)); | |
document.body.appendChild(document.createElement("br")); | |
} | |
bad = function(lhs, rhs) { | |
var dist = (rhs - lhs) >>> 0; | |
return dist < 256; | |
} | |
good = function(lhs, rhs) { | |
return ((rhs - lhs) >>> 0) < 256; | |
} | |
var warm_up = function(c) { | |
append("warm up starting..."); | |
for(var i = 0; i < c; ++i) { | |
bad(2, 1); | |
} | |
append("warm up done"); | |
}; | |
var bar = function() { | |
//warm_up(100) | |
for(var i = 0; i < 100; ++i) { | |
var b = bad(2, 1); | |
if(b) | |
append("count=" + i + ", bad="+ b); | |
var g = good(2, 1); | |
if(g) | |
append("count=" + i + ", good="+ g); | |
} | |
} | |
setTimeout(bar, 0); | |
</script> | |
</head> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment