javascript - 原子索引错误与从视频 currentTime 派生的 searchElement

标签 javascript arrays google-chrome indexof

我对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 团队。它已被修复(尽管没有已知的简单方法来确定错误是否存在于您的眨眼实现中......)

https://code.google.com/p/chromium/issues/detail?id=407946

关于javascript - 原子索引错误与从视频 currentTime 派生的 searchElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25551252/

相关文章:

javascript - While 循环在 Google Chrome 控制台中不断崩溃

javascript - 有没有更好的方法在 JavaScript 中对数组项进行部分求和?

javascript - 如何重定向 Google Chrome 扩展中的某些页面?

javascript - 从数组的javascript数组中获取未定义

javascript - 如何返回与正则表达式匹配的JavaScript字符串的一部分?

c - 不太确定怎么了

javascript - 获取 Chrome 的当前语言环境

声明 DOCTYPE 时,Javascript 在 Chrome 中不起作用

javascript - 如何将 `new Date().getTime()/1000` 的(分数)结果转换为整数?

javascript - 从复选框选择更改 AJAX jQuery url