我对Mac上当前版本的Chrome 37.0.2062.94中数组indexOf的不可预测的结果感到困惑。当使用视频元素的时间码创建 searchElement 时,array.indexOf 有时无法正常工作。
要查看错误,请让视频播放几秒钟,然后在发生 array.indexOf 错误时停止播放。看来这是原子操作的一个bug?有什么我忽略的吗?
这是一个垃圾箱 http://jsbin.com/lobifotoxeyi/1/
<!DOCTYPE html>
<html>
<video id="video">
<source id="mp4" src="http://media.w3.org/2010/05/sintel/trailer.mp4" type="video/mp4">
</video>
<script>
var trippedBugTimes = 0;
function tick() {
var nowTime = document.getElementById('video').currentTime;
//this seems to be crucial... if val is just assigned 100, we don't get the bug.
var val = (nowTime - nowTime) + 100;
//this also seems to be important.. we cannot put val in as the sole member of the array, it has to be a different variable.
var a = [100];
var idx = a.indexOf( val );
if (idx == -1) {
console.log( "*bug*",
"idx ->", idx,
"val -> ", val,
"a ->", a,
"a[0] === val ->", a[0] === val,
"typeof a[0] ->", typeof a[0],
"typeof val ->", typeof val );
document.getElementById('video').pause();
trippedBugTimes += 1;
}
if (trippedBugTimes < 100) {
requestAnimationFrame(tick);
}
else {
console.log( "Bug reporting complete" );
}
}
requestAnimationFrame(tick);
setTimeout( document.getElementById('video').play(), 1000 );
</script>
</html>
最佳答案
正如原始帖子下的评论中所述,此错误已报告给 chromium 团队。它已被修复(尽管没有已知的简单方法来确定错误是否存在于您的眨眼实现中......)
关于javascript - 原子索引错误与从视频 currentTime 派生的 searchElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25551252/