11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ci// Harden the thread interactions on the exit path.
51cb0ef41Sopenharmony_ci// Ensure workers are able to bail out safe at
61cb0ef41Sopenharmony_ci// arbitrary execution points. By using a number of
71cb0ef41Sopenharmony_ci// internal modules as load candidates, the expectation
81cb0ef41Sopenharmony_ci// is that those will be at various control flow points
91cb0ef41Sopenharmony_ci// preferably in the C++ land.
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst { Worker } = require('worker_threads');
121cb0ef41Sopenharmony_ciconst modules = [ 'fs', 'assert', 'async_hooks', 'buffer', 'child_process',
131cb0ef41Sopenharmony_ci                  'net', 'http', 'os', 'path', 'v8', 'vm',
141cb0ef41Sopenharmony_ci];
151cb0ef41Sopenharmony_ciif (common.hasCrypto) {
161cb0ef41Sopenharmony_ci  modules.push('https');
171cb0ef41Sopenharmony_ci}
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_cifor (let i = 0; i < 10; i++) {
201cb0ef41Sopenharmony_ci  new Worker(`const modules = [${modules.map((m) => `'${m}'`)}];` +
211cb0ef41Sopenharmony_ci    'modules.forEach((module) => {' +
221cb0ef41Sopenharmony_ci    'const m = require(module);' +
231cb0ef41Sopenharmony_ci    '});', { eval: true });
241cb0ef41Sopenharmony_ci}
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci// Allow workers to go live.
271cb0ef41Sopenharmony_cisetTimeout(() => {
281cb0ef41Sopenharmony_ci  process.exit(0);
291cb0ef41Sopenharmony_ci}, 200);
30