mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
ba5b5acaf1
PR-URL: https://github.com/nodejs/node/pull/41818 Refs: https://coverage.nodejs.org/coverage-7123a00b03a90862/lib/internal/worker.js.html#L412 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
'use strict';
|
|
// Flags: --expose-internals
|
|
|
|
require('../common');
|
|
const {
|
|
Worker,
|
|
getEnvironmentData,
|
|
setEnvironmentData,
|
|
threadId,
|
|
} = require('worker_threads');
|
|
|
|
const { assignEnvironmentData } = require('internal/worker');
|
|
|
|
const {
|
|
deepStrictEqual,
|
|
strictEqual,
|
|
} = require('assert');
|
|
|
|
if (!process.env.HAS_STARTED_WORKER) {
|
|
process.env.HAS_STARTED_WORKER = 1;
|
|
setEnvironmentData('foo', 'bar');
|
|
setEnvironmentData('hello', { value: 'world' });
|
|
setEnvironmentData(1, 2);
|
|
strictEqual(getEnvironmentData(1), 2);
|
|
setEnvironmentData(1); // Delete it, key won't show up in the worker.
|
|
new Worker(__filename);
|
|
setEnvironmentData('hello'); // Delete it. Has no impact on the worker.
|
|
} else {
|
|
strictEqual(getEnvironmentData('foo'), 'bar');
|
|
deepStrictEqual(getEnvironmentData('hello'), { value: 'world' });
|
|
strictEqual(getEnvironmentData(1), undefined);
|
|
assignEnvironmentData(undefined); // It won't setup any key.
|
|
strictEqual(getEnvironmentData(undefined), undefined);
|
|
|
|
// Recurse to make sure the environment data is inherited
|
|
if (threadId <= 2)
|
|
new Worker(__filename);
|
|
}
|