Debugging VM.Script with a custom filename results in being unable to step through code

I have several VM scripts that need to be able to make calls to each other. If I don't provide a filename, the default "evalmachine.<anonymous>" is used and I'm able to step through my code fine. However when one VM calls a function inside another, the debugger points to the wrong file.

I fixed this by passing in a filename into VM.Script, and while my "debugger" statement still works, I'm faced with a new problem. When I try to step through the code, the debugger immediately steps out of the VM (although the script still executes normally).

I've spent 2 days trying out different VM's and messing about with filenames and just can't get to function properly. I'd greatly appreciate some support on this topic. Thanks.

4 comments
Comment actions Permalink

Please could you share a sample code/files the issue can be repeated with?

0
Comment actions Permalink

Sure. In this example, I'm unable to step beyond the "debugger" statement in testA, whereas stepping works fine when no filename is provided.

const vm = require('vm');

let sample = `{
debugger\n
let a = 5;\n
let b = 3;\n
let c = a + b; // testA unable to step to here
}`;


let testA = new vm.Script(sample, {filename: "test.js"});
let testB = new vm.Script(sample);

testA.runInThisContext(); // Stepping broken
testB.runInThisContext(); // Stepping works
0
Comment actions Permalink

Thanks, reproduced. Submitted to developers as https://youtrack.jetbrains.com/issue/WEB-50837

As a workaround, I can suggest disabling Do not step into library scripts in Settings | Build, Execution, Deployment | Debugger | Stepping

0
Comment actions Permalink

Brilliant, that worked perfectly. Thanks!

1

Please sign in to leave a comment.