Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

if condition

2. Step In, advances to line 33.

first line of if block

3. Step In again, advances to line 34.

second line of if block

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

first line of else block

--> 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:

enter image description here

like image 882
devuxer Avatar asked Sep 29 '22 14:09

devuxer


1 Answers

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

like image 94
Sebastian Zartner Avatar answered Oct 02 '22 17:10

Sebastian Zartner