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 running a lot of
71cb0ef41Sopenharmony_ci// JS code in a tight loop, the expectation
81cb0ef41Sopenharmony_ci// is that those will be at various control flow points
91cb0ef41Sopenharmony_ci// preferably in the JS land.
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst { Worker } = require('worker_threads');
121cb0ef41Sopenharmony_ciconst code = 'setInterval(() => {' +
131cb0ef41Sopenharmony_ci      "require('v8').deserialize(require('v8').serialize({ foo: 'bar' }));" +
141cb0ef41Sopenharmony_ci      "require('vm').runInThisContext('x = \"foo\";');" +
151cb0ef41Sopenharmony_ci      "eval('const y = \"vm\";');}, 10);";
161cb0ef41Sopenharmony_cifor (let i = 0; i < 9; i++) {
171cb0ef41Sopenharmony_ci  new Worker(code, { eval: true });
181cb0ef41Sopenharmony_ci}
191cb0ef41Sopenharmony_cinew Worker(code, { eval: true }).on('online', common.mustCall((msg) => {
201cb0ef41Sopenharmony_ci  process.exit(0);
211cb0ef41Sopenharmony_ci}));
22