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:
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.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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With