[英]Firebug debugger ignore setTimeout? How to test it?
Windows 7
Firefox 10.0.1
我有简单的setTimeout逻辑,我想使用Firebug调试器测试几个断点。
test.js
console.log("one");
setTimeout(function(){ console.log("hmm"); }, 5000);
console.log("two"); //breakpoint here
console.log("three");
的test.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
,我将断点放在注释行(console.log(“two”))中,当我加载html页面时,我得到输出:
one
和进程按预期在断点处暂停,但setTimeout永远不会被执行。
这是firebug调试器的错误吗? 谁看过这个吗?
更新:
我调查了一下,发现:
如果在调试器模式下单击“继续”并在5000ms(在setTimeout中指定的时间)内经历断点,则会显示“hmm”消息。
如果你在断点处停止超过5000毫秒,那么即使在“继续”按钮之后,“hmm”msg也不会显示。
请看看这个问题 。
只有在Javascript执行线程变为空闲之后,即使在线程繁忙时超时, setTimeout
也会触发。 设置一个断点只是挂起线程,并在停止时保持忙碌状态。 所以,这段代码将返回
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并继续在其中进行步入
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.