worker: export workerData to ESM workers

Fixes: https://github.com/nodejs/node/issues/25765

PR-URL: https://github.com/nodejs/node/pull/25768
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Anna Henningsen 2019-01-28 15:29:48 +01:00
parent 86a49ce2d8
commit 8919169bb7
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
3 changed files with 21 additions and 1 deletions

View File

@ -17,5 +17,6 @@ module.exports = {
MessageChannel,
threadId,
Worker,
parentPort: null
parentPort: null,
workerData: null,
};

3
test/fixtures/worker-data.mjs vendored Normal file
View File

@ -0,0 +1,3 @@
import { workerData, parentPort } from 'worker_threads';
parentPort.postMessage(workerData);

View File

@ -0,0 +1,16 @@
'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const { Worker } = require('worker_threads');
const workerData = 'Hello from main thread';
const worker = new Worker(fixtures.path('worker-data.mjs'), {
workerData,
execArgv: ['--experimental-modules']
});
worker.on('message', common.mustCall((message) => {
assert.strictEqual(message, workerData);
}));