Firefox debugger jumps from an if-block directly to an else-block

为君一笑 提交于 2020-01-02 04:55:10

问题


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:


回答1:


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




回答2:


Unfortunately there are some really odd behaviors with the debugger in Firefox. I wouldn't be surprised if what you describe might be related to this bug. The "step" functionality sometimes doesn't do what you would expect, or what Chromium browser does.



来源:https://stackoverflow.com/questions/26419249/firefox-debugger-jumps-from-an-if-block-directly-to-an-else-block

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!