From 4c5a5c64fbdb68f6ef5c4f23b34d429887ebb729 Mon Sep 17 00:00:00 2001 From: vdeturckheim Date: Fri, 11 Sep 2020 19:20:48 +0200 Subject: [PATCH 1/2] process: introduce codeGenerationFromString event The 'codeGenerationFromString' event is emitted when a call is made to `eval` or `new Function`. Co-authored-by: Thomas Watson --- doc/api/process.md | 26 +++++++++ lib/internal/bootstrap/node.js | 20 +++++++ src/node_process_methods.cc | 58 +++++++++++++++++++ .../test-process-codegen-from-string.js | 39 +++++++++++++ 4 files changed, 143 insertions(+) create mode 100644 test/parallel/test-process-codegen-from-string.js diff --git a/doc/api/process.md b/doc/api/process.md index 28db286bd90fd2..31dbff4d7b02fd 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -81,6 +81,32 @@ console.log('This message is displayed first.'); // Process exit event with code: 0 ``` +### Event: `'codeGenerationFromString'` + + + +The `'codeGenerationFromString'` event is emitted when a call is made to `eval(str)` +or `new Function(str)`. +The event will be emitted with the argument passed to `eval` or the +`Function` constructor. +The call to `eval` or `new Function` will happen after the event is emitted. + +```js +process.on('codeGenerationFromString', (code) => { + console.log(`Generating code from string '${code}'`); +}); +const item = { foo: 0 }; +eval('item.foo++'); +``` + +will log + +```text +Generating code from string 'item.foo++' +``` + ### Event: `'disconnect'`