mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
This patch directly inlines `createMessageHandler()` and `createWorkerFatalExeception()` in the new `lib/internal/main/worker_thread.js` since the implementation of the two methods are related to the execution flow of workers. PR-URL: https://github.com/nodejs/node/pull/25667 Reviewed-By: Anna Henningsen <anna@addaleax.net>
52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
// This file contains process bootstrappers that can only be
|
|
// run in the worker thread.
|
|
const {
|
|
getEnvMessagePort
|
|
} = internalBinding('worker');
|
|
|
|
const {
|
|
kWaitingStreams,
|
|
ReadableWorkerStdio,
|
|
WritableWorkerStdio
|
|
} = require('internal/worker/io');
|
|
|
|
const {
|
|
codes: { ERR_WORKER_UNSUPPORTED_OPERATION }
|
|
} = require('internal/errors');
|
|
const workerStdio = {};
|
|
|
|
function initializeWorkerStdio() {
|
|
const port = getEnvMessagePort();
|
|
port[kWaitingStreams] = 0;
|
|
workerStdio.stdin = new ReadableWorkerStdio(port, 'stdin');
|
|
workerStdio.stdout = new WritableWorkerStdio(port, 'stdout');
|
|
workerStdio.stderr = new WritableWorkerStdio(port, 'stderr');
|
|
|
|
return {
|
|
getStdout() { return workerStdio.stdout; },
|
|
getStderr() { return workerStdio.stderr; },
|
|
getStdin() { return workerStdio.stdin; }
|
|
};
|
|
}
|
|
|
|
// The execution of this function itself should not cause any side effects.
|
|
function wrapProcessMethods(binding) {
|
|
function umask(mask) {
|
|
// process.umask() is a read-only operation in workers.
|
|
if (mask !== undefined) {
|
|
throw new ERR_WORKER_UNSUPPORTED_OPERATION('Setting process.umask()');
|
|
}
|
|
|
|
return binding.umask(mask);
|
|
}
|
|
|
|
return { umask };
|
|
}
|
|
|
|
module.exports = {
|
|
initializeWorkerStdio,
|
|
wrapProcessMethods
|
|
};
|