Firebug 调试器忽略设置超时?如何测试它

Firebug debugger ignore setTimeout? How to test it?

本文关键字:何测试 测试 调试器 设置 超时 Firebug      更新时间:2023-09-26
Windows 7
Firefox 10.0.1

我有一个简单的 setTimeout 逻辑,我想使用具有很少断点的 Firebug 调试器进行测试。

测试.js

console.log("one");   
setTimeout(function(){ console.log("hmm"); }, 5000);
console.log("two");   //breakpoint here
console.log("three");

测试.html

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <script type="text/javascript" src="../js/test.js" ></script>
    </head>
    <body>
        <h1>Hello World!</h1>
    </body>
</html>

使用Firebug debugger,我将断点放在注释行中(其中控制台.log("两个"((当我加载 html 页面时,我得到输出:

one

并且进程按预期在断点处停止,但 setTimeout 永远不会执行。

这是火虫调试器错误吗?以前有人见过吗?

更新:

我调查了更多,发现:

如果在调试器模式下单击"继续"并在 5000 毫秒内(这是 setTimeout 中指定的时间(内通过断点,则会显示"嗯"消息。

如果您在断点处停止超过 5000 毫秒,那么即使在"继续"按钮之后也不会显示"嗯"消息。

这是一个

Firebug错误;)

请调查此问题。

setTimeout仅在 Javascript 执行线程空闲后触发,即使线程繁忙时超时也是如此。放置断点只会挂起线程,并且在停止线程时保持忙碌状态。所以,这段代码将返回

one
two 
three
hmmm //(in 5 seconds, if no breakpoint, at once if you stop at a breakpoint for more than 5 seconds and then run the code further)

这是正确的setTimeout行为。

我没有问题。setTimeout 中的代码在 5 秒后执行,因此您的预期输出为

你可以在回调中设置断点到 setTimeout并继续介入其中