2

Using the old runtime I could set a breakpoint anywhere in my code. With the new v8 runtime breakpoints apparently have to be in the function I run from the debugger?

Is this intended behavior? Am I doing something wrong in the debugger, or in my code? Is it not structured correctly, perhaps?

MINIMAL EXAMPLE:

var test1 = 1;
var test2 = 2;
var test3 = 3;

function myFunction() {
  var test4 = 4;
  var test5 = 5;
}

V8 RUNTIME:

I can set a breakpoint on var test4 = 4 and then use the debugger and select myFunction, and the code breaks on that line.

But if I set the breakpoint on var test2 = 2 and then use the debugger, selecting myFunction, it doesn't break (It would with the old runtime).

  • 1
    I never noticed that behavior before. I guess because I don't use global variables very much. But I don't think you're doing anything wrong. But honestly I don't know if it's intended or just an oversight. You could post it as an issue to see what they say. But probably one of the other reqular volunteers here will know. – Cooper May 29 '20 at 21:50
  • wow, a rare sight these days - an interesting question :) Agreed with Cooper - you are not doing anything wrong (apart from using global variables that is). V8 engine and debugger have little to do with each other, the new engine is used, for example, by Node.js runtime, and if paired with debugger used by VSCode your example breaks fine. I am inclined to think this is an oversight (besides, variable assignment is a line of code that gets executed - why shouldn't it be inspectable?) – Oleg Valter is with Ukraine May 30 '20 at 15:29
  • @OlegValter...I agree it is rare these day:) – Cooper May 30 '20 at 17:03

1 Answers1

0

It is a new behavior related to V8 runtime

When run in debug mode a script pauses when it hits a breakpoint, which is a line you've highlighted in your script

If your breakpoint is located outside of the function - in a line that is never been called - your breakpoint will never be hit.

  • On the other hand side

Other people also noticed that this behavior is different from before and filed it on Google's Public Issue Tracker

While Google investigates either the previous or the current behavior is the intended one, as a workaround:

If you want your debugger to stop on the line var test2 = 2; which is outside of myFunction(), you need to structure your code differently, e.g.:

enter image description here

ziganotschka
  • 25,866
  • 2
  • 16
  • 33