fix: crash in utilityProcess when generating code from strings (#38040)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
This commit is contained in:
trop[bot]
2023-04-24 13:22:02 +09:00
committed by GitHub
parent d362c30b1d
commit 4d8b9a8eec
14 changed files with 72 additions and 48 deletions

View File

@@ -360,5 +360,19 @@ describe('utilityProcess module', () => {
await emittedOnce(child, 'exit');
expect(log).to.equal('hello\n');
});
it('does not crash when running eval', async () => {
const child = utilityProcess.fork('./eval.js', [], {
cwd: fixturesPath,
stdio: 'ignore'
});
await emittedOnce(child, 'spawn');
const [data] = await emittedOnce(child, 'message');
expect(data).to.equal(42);
// Cleanup.
const exit = emittedOnce(child, 'exit');
expect(child.kill()).to.be.true();
await exit;
});
});
});

View File

@@ -0,0 +1,6 @@
const vm = require('node:vm');
const contextObject = { result: 0 };
vm.createContext(contextObject);
vm.runInContext('eval(\'result = 42\')', contextObject);
process.parentPort.postMessage(contextObject.result);