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 using a number of 7// internal modules as load candidates, the expectation 8// is that those will be at various control flow points 9// preferably in the C++ land. 10 11const { Worker } = require('worker_threads'); 12const modules = [ 'fs', 'assert', 'async_hooks', 'buffer', 'child_process', 13 'net', 'http', 'os', 'path', 'v8', 'vm', 14]; 15if (common.hasCrypto) { 16 modules.push('https'); 17} 18 19for (let i = 0; i < 10; i++) { 20 new Worker(`const modules = [${modules.map((m) => `'${m}'`)}];` + 21 'modules.forEach((module) => {' + 22 'const m = require(module);' + 23 '});', { eval: true }); 24} 25 26// Allow workers to go live. 27setTimeout(() => { 28 process.exit(0); 29}, 200); 30