Take a look at GraalJS/Truffle instrumentation. It lets you easily run JS and even NodeJS on the JVM with per statement instrumentation handled at the engine layer. So it should make it very easy to add the code you need and the compatibility with modern js is great.