簡體   English   中英

Firebug調試器忽略setTimeout? 怎么測試呢?

[英]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也不會顯示。

這是一個Firebug bug;)

請看看這個問題

只有在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM