Firefox调试器从一个if块直接跳转到一个else块 [英] Firefox debugger jumps from an if-block directly to an else-block

查看:224
本文介绍了Firefox调试器从一个if块直接跳转到一个else块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



以下是有问题的功能:

  WebSocketConnector.prototype.sendMessage = function(message){
if(socket!== null){
socket.send(message);
console.log('Sent:'+ message);
} else {
alert('无法发送消息,WebSocket连接未建立。
}
};

以下是调试此函数调用时发生的情况:

1。从第32行开始。



2>

2。进入第33行。





3。再次进入第34行。





4。再一次,前进到第36行





- >如何控制可能直接从块的最后一行块到 else 块的第一行



一些重要的事实:




    $ b


  1. 我只调用 sendMessage 来自一个地方,而且我正在记录何时该呼叫发生。在日志中没有下载 sendMessage 调用,所以我不相信异步是一个解释。

  2. 我也尝试了同样的事情与Firebug调试器和同样的疯狂的事情发生。

    $ b $ h3编辑/跟进

    如果我将一个console.log语句添加到else块的第一行(将警报下推到第37行),控制权将从第34行到第37行(跳过console.log语句)。



    另外,我应该提到,即使直接进入代码,也不会出现任何提示。 > Edit 2

    下面是 sendMessage 函数的间距和CRLF:

    这是因为在返回到调用栈帧之前,调试器跳到最后一个可执行文件行。在你的情况下,这是第36行,包含 alert()函数。如果调试器跳到函数的最后一个大括号,也就是第38行,就会更清楚。



    已经有一个报告来改变这个行为:



    https://bugzil.la/1013219


    I'm wondering how the sequence shown below could possibly occur.

    Here is the function in question:

    WebSocketConnector.prototype.sendMessage = function(message) {
        if (socket !== null) {
            socket.send(message);
            console.log('Sent: ' + message);
        } else {
            alert('Failed to send message. WebSocket connection not established.');
        }
    };
    

    And here is what happens when I debug a call to this function:

    1. Start at line 32.

    2. Step In, advances to line 33.

    3. Step In again, advances to line 34.

    4. Step in one more time, advances to line 36???

    --> How can control possibly go directly from the last line of the if block to the first line of the else block?

    Some important facts:

    1. There are no missing steps here.
    2. This really happened.
    3. I'm only calling sendMessage from one place, and I'm logging when that call occurs. There are no unaccounted for sendMessage calls in the log, so I don't believe asynchrony is an explanation.
    4. I also tried the same thing with the Firebug debugger and the same crazy thing happens.

    Edit/Followup

    If I add a console.log statement to the first line of the else block (pushing the alert down to line 37), the control will go right from line 34 to line 37 (skipping the console.log statement).

    Also, I should have mentioned, no alert actually ever appears, even when stepping directly into that code.

    Edit 2

    Here is the spacing and CRLF's of the sendMessage function:

    解决方案

    This is because the debugger steps to the last executable line before returning to the calling stack frame. In your case this is line 36 containing the alert() function. It would be clearer if the debugger jumped to the closing curly brace of the function, i.e. line 38.

    There is already a report to change this behavior:

    https://bugzil.la/1013219

    这篇关于Firefox调试器从一个if块直接跳转到一个else块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆