Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions lib/internal/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

const {
ArrayIsArray,
ArrayPrototypeForEach,
ArrayPrototypeMap,
ArrayPrototypePush,
Float64Array,
Expand All @@ -14,7 +15,9 @@ const {
ObjectEntries,
Promise,
PromiseResolve,
ReflectApply,
RegExpPrototypeTest,
SafeArrayIterator,
String,
Symbol,
SymbolFor,
Expand Down Expand Up @@ -155,8 +158,10 @@ class Worker extends EventEmitter {
let env;
if (typeof options.env === 'object' && options.env !== null) {
env = ObjectCreate(null);
for (const [ key, value ] of ObjectEntries(options.env))
env[key] = `${value}`;
ArrayPrototypeForEach(
ObjectEntries(options.env),
({ 0: key, 1: value }) => { env[key] = `${value}`; }
);
} else if (options.env == null) {
env = process.env;
} else if (options.env !== SHARE_ENV) {
Expand Down Expand Up @@ -209,12 +214,13 @@ class Worker extends EventEmitter {
const transferList = [port2];
// If transferList is provided.
if (options.transferList)
ArrayPrototypePush(transferList, ...options.transferList);
ArrayPrototypePush(transferList,
...new SafeArrayIterator(options.transferList));

this[kPublicPort] = port1;
for (const event of ['message', 'messageerror']) {
ArrayPrototypeForEach(['message', 'messageerror'], (event) => {
this[kPublicPort].on(event, (message) => this.emit(event, message));
}
});
setupPortReferencing(this[kPublicPort], this, 'message');
this[kPort].postMessage({
argv,
Expand Down Expand Up @@ -279,8 +285,9 @@ class Worker extends EventEmitter {
{
const { stream, chunks } = message;
const readable = this[kParentSideStdio][stream];
for (const { chunk, encoding } of chunks)
ArrayPrototypeForEach(chunks, ({ chunk, encoding }) => {
readable.push(chunk, encoding);
});
return;
}
case messageTypes.STDIO_WANTS_MORE_DATA:
Expand Down Expand Up @@ -314,7 +321,7 @@ class Worker extends EventEmitter {
postMessage(...args) {
if (this[kPublicPort] === null) return;

this[kPublicPort].postMessage(...args);
ReflectApply(this[kPublicPort].postMessage, this[kPublicPort], args);
}

terminate(callback) {
Expand Down