1'use strict';
2const common = require('../common');
3
4// Harden the thread interactions on the exit path.
5// Ensure workers are able to bail out safe at
6// arbitrary execution points. By running a lot of
7// JS code in a tight loop, the expectation
8// is that those will be at various control flow points
9// preferably in the JS land.
10
11const { Worker } = require('worker_threads');
12const code = 'setInterval(() => {' +
13      "require('v8').deserialize(require('v8').serialize({ foo: 'bar' }));" +
14      "require('vm').runInThisContext('x = \"foo\";');" +
15      "eval('const y = \"vm\";');}, 10);";
16for (let i = 0; i < 9; i++) {
17  new Worker(code, { eval: true });
18}
19new Worker(code, { eval: true }).on('online', common.mustCall((msg) => {
20  process.exit(0);
21}));
22