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.

Comment actions Permalink

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

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 = `{
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
Comment actions Permalink

Thanks, reproduced. Submitted to developers as

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

Comment actions Permalink

Brilliant, that worked perfectly. Thanks!


Please sign in to leave a comment.