11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci// Flags: --expose-internals 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_cirequire('../common'); 51cb0ef41Sopenharmony_ciconst { 61cb0ef41Sopenharmony_ci Worker, 71cb0ef41Sopenharmony_ci getEnvironmentData, 81cb0ef41Sopenharmony_ci setEnvironmentData, 91cb0ef41Sopenharmony_ci threadId, 101cb0ef41Sopenharmony_ci} = require('worker_threads'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst { assignEnvironmentData } = require('internal/worker'); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciconst { 151cb0ef41Sopenharmony_ci deepStrictEqual, 161cb0ef41Sopenharmony_ci strictEqual, 171cb0ef41Sopenharmony_ci} = require('assert'); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ciif (!process.env.HAS_STARTED_WORKER) { 201cb0ef41Sopenharmony_ci process.env.HAS_STARTED_WORKER = 1; 211cb0ef41Sopenharmony_ci setEnvironmentData('foo', 'bar'); 221cb0ef41Sopenharmony_ci setEnvironmentData('hello', { value: 'world' }); 231cb0ef41Sopenharmony_ci setEnvironmentData(1, 2); 241cb0ef41Sopenharmony_ci strictEqual(getEnvironmentData(1), 2); 251cb0ef41Sopenharmony_ci setEnvironmentData(1); // Delete it, key won't show up in the worker. 261cb0ef41Sopenharmony_ci new Worker(__filename); 271cb0ef41Sopenharmony_ci setEnvironmentData('hello'); // Delete it. Has no impact on the worker. 281cb0ef41Sopenharmony_ci} else { 291cb0ef41Sopenharmony_ci strictEqual(getEnvironmentData('foo'), 'bar'); 301cb0ef41Sopenharmony_ci deepStrictEqual(getEnvironmentData('hello'), { value: 'world' }); 311cb0ef41Sopenharmony_ci strictEqual(getEnvironmentData(1), undefined); 321cb0ef41Sopenharmony_ci assignEnvironmentData(undefined); // It won't setup any key. 331cb0ef41Sopenharmony_ci strictEqual(getEnvironmentData(undefined), undefined); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci // Recurse to make sure the environment data is inherited 361cb0ef41Sopenharmony_ci if (threadId <= 2) 371cb0ef41Sopenharmony_ci new Worker(__filename); 381cb0ef41Sopenharmony_ci} 39