-2

I'm running Firefox 72.0.2 on Win 10. This is more a question of how to use the inbuild debugger or developer tools properly.

When loading test.html the console shows the unreachable code after return statement warning twice now.
The return is in a switch-case construct, which is itself in a function importExport.
The importExport function is only referenced in a couple of static html span-elements' onkeypress and onclick events:
onkeypress="this.onclick();event.preventDefault();" onclick="importExport('import','options');"
and
onkeypress="this.onclick();event.preventDefault();" onclick="importExport('export','options');"
By adding console.log('...'); at the start of the function I can see that it is never called.

Is there any way I could make Firefox showing me, why this warning message is shown twice now? (I'm fairly sure it wasn't just a little time ago.)

> unreachable code after return statement test.html:2246:4
> Passwort-Felder sind auf einer unsicheren (http://) Seite vorhanden. Dies ist ein Sicherheitsrisiko, durch das Zugangsdaten gestohlen werden können. test.html 
> unreachable code after return statement test.html:2246:4



Edit: It's gone like it has come: Now the warning is only shown once again.
Though that doesn't change the question, if the console or debugger offers a chance to find out why the warning was shown twice.

Bill
  • 45
  • 3
  • 1
    how can anyone help if you don't show the code around line 2264 in test.html? – Jaromanda X May 31 '20 at 23:02
  • Without seeing the code, I'm not clear of the situation here? I know what the message means, and why, but you can add a simplified code example that shows the issue. – Paul T. May 31 '20 at 23:03
  • The question is if the Firefox developer tools have any option to tell me why it is shown twice: Does it parse the code twice? Why? Just right now it again only shows the warning once. There are no other warnings or errors beside those I cited. Maybe it's more a question of how to use the inbuild debugger properly. – Bill Jun 01 '20 at 00:10
  • It could have simply been a bug that the message was shown twice. You're also using an outdated version of Firefox. So the first thing you should do is update your browser to the current version. And yes, the code could have been parsed twice, but without seeing the code and being able to reproduce it, it is impossible to say what caused it. – Sebastian Zartner Jun 01 '20 at 14:42
  • @SebastianZartner Do you know when the mechanism to parse the code twice is triggered? Has that mechanic a name, or do you know the code section or help page about that at mozilla? – Bill Jun 08 '20 at 02:23
  • I've added an answer below explaining why the message appears twice. – Sebastian Zartner Jun 08 '20 at 17:21
  • Note that to get rid of the warning message you simply have to remove the code after the return statement. – Sebastian Zartner Jun 09 '20 at 10:21

1 Answers1

0

The error message is shown for the same line of code once after the code got parsed (i.e. read and analyzed by the browser engine) and once when it's executed. I.e. in your case that is when the element is clicked and the importExport() function is executed.

Here's a simple example:

function x() {
  return;
  let foo="bar";
}
div {
  width: 100px;
  height: 100px;
  background-color: skyblue;
  display: flex;
  justify-content: center;
  align-items: center;
}
<div onclick="x()">Click me</div>

Warning for unreachable code after return statement

Note that the warning is already shown before you click the element. Once you click it, it will be logged a second time (indicated by the counter at the right side of the warning).

You can verify that by just having the function without any call. If you paste the following code into your address bar, the warning also gets logged:

data:text/html,<script>function x(){return;let foo="bar";}</script>

For more information on the message itself, please read the related MDN page, which is linked to from the "Learn more" link besides the message in the Console.

Sebastian Zartner
  • 18,808
  • 10
  • 90
  • 132
  • By adding console.log('...'); at the start of the function I can see that it is never called. – Bill Jun 09 '20 at 00:11
  • Yes, but it is parsed by Firefox's JavaScript engine, nonetheless. That's why you are seeing the message only once. In the snippet above you will also see the warning being shown already *before* you click the element. – Sebastian Zartner Jun 09 '20 at 10:06
  • I have extended my answer to explain a bit more what's happening. – Sebastian Zartner Jun 09 '20 at 10:28
  • I'm sorry that you spend so much time on it, but the real question was, why it was shown twice, and if there are inbuilt tools to find out about such things. It actually only could have to do with the parser. After some minor code changes, not even in the function that contains the `return`, the message again only shows once. - Seems I better ask directly at Mozilla's forums for this specific parsing/compiling question. – Bill Jul 08 '20 at 16:21
  • In the first sentence of my answer I explained why it is shown twice, the first time when it is parsed, the second time when it is executed. If you still want to ask in a Mozilla forum, please post the link to it here, so people reading this answer can follow it. – Sebastian Zartner Jul 09 '20 at 08:12
  • The function is not called, which I checked by adding a console.log-statement in the function. ("By adding console.log('...'); at the start of the function I can see that it is never called.") - Do you mean anything else by "executed"? Would that explain why the doublette vanished? – Bill Jul 10 '20 at 15:25
  • Yes, the reason why the message is only logged once is that the function is not called (anymore) but only parsed. – Sebastian Zartner Jul 15 '20 at 16:41
  • Just a comment for who might read up to here. In the described setting, the function was not called, neither when the warning was shown twice, nor when it was shown once. (I really made that abundantly clear.) – Bill Jul 18 '20 at 13:27