v8: introduce v8.emitCodeGenFromStringEvent() by vdeturckheim · Pull Request #34863 · nodejs/node
Checklist
-
make -j4 test(UNIX), orvcbuild test(Windows) passes - tests and/or benchmarks are included
- documentation is changed or added
- commit message follows commit guidelines
As of today, it is not possible to intercept calls made to eval as the method can't really be monkeypatched without breaking its behavior.
Thanksfully there is an API in V8 that can be used to place a callback when code is generated from string (eval and new Function(string). This PR introduces a way to listen on theses events from userland.
If the --disallow-code-generation-from-strings flag is used, calling emitCodeGenFromStringEvent will have no effect as calls to eval and new Function will fail anyway.
After calling v8.emitCodeGenFromStringEvent(), each time a call is made to eval or new function, an codeGenerationFromString event will be emitted on process with the code as argument.