Firefox debugger jumps from if block directly to else block

I am wondering how the sequence shown below can happen.

Here is the function:

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 this is what happens when I debug this function call:

1. Start at line 32.

if condition

2. Step In, advancing to line 33.

first line of if block

3. Step Again, advancing to line 34.

second line of if block

4. A step at a time, advancing to line 36 ???

first line of else block

→ How can I control, perhaps go directly from the last line of the if block to the first line of the else block?

Some important facts:

  • There are no missing steps.
  • It really happened.
  • I only call sendMessage from one place, and I log in with this call. There are no unrecorded sendMessage calls in the sendMessage , so I do not believe that asynchrony is an explanation.
  • I also tried the same thing with the Firebug debugger, and the same crazy thing happens.

Edit / Followup

If I add the console.log statement to the first line of the else block (by clicking the warning to line 37), the control will go straight from line 34 to line 37 (skipping the console.log statement).

Also, I should have mentioned that no warnings actually ever appear, even when they go directly to this code.

Edit 2

Here is the interval and CRLF of the sendMessage function:

enter image description here

+5
source share
2 answers

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

There is already a report to change this behavior:

https://bugzil.la/1013219

+3
source

Unfortunately, there are some really strange debugging behaviors in Firefox. I would not be surprised if what you described may be related to this error . The "step" functionality sometimes does not do what you expect or what the Chromium browser does.

+1
source

Source: https://habr.com/ru/post/1204898/


All Articles