From 39eca841c30e1a54424b85f34e8dd56b2648f930 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 1 Feb 2019 23:47:38 +0100 Subject: src: split ownsProcessState off isMainThread Embedders may want to control whether a Node.js instance controls the current process, similar to what we currently have with `Worker`s. Previously, the `isMainThread` flag had a bit of a double usage, both for indicating whether we are (not) running a Worker and whether we can modify per-process state. PR-URL: https://github.com/nodejs/node/pull/25881 Reviewed-By: Colin Ihrig Reviewed-By: Joyee Cheung Reviewed-By: James M Snell --- lib/internal/bootstrap/node.js | 6 +++--- lib/internal/worker.js | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'lib/internal') diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 915d07d83d..358c4cb8c7 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -14,7 +14,7 @@ // This file is compiled as if it's wrapped in a function with arguments // passed by node::LoadEnvironment() -/* global process, loaderExports, isMainThread */ +/* global process, loaderExports, isMainThread, ownsProcessState */ const { internalBinding, NativeModule } = loaderExports; @@ -51,7 +51,7 @@ const perThreadSetup = NativeModule.require('internal/process/per_thread'); let mainThreadSetup; // Bootstrappers for the worker threads only let workerThreadSetup; -if (isMainThread) { +if (ownsProcessState) { mainThreadSetup = NativeModule.require( 'internal/process/main_thread_only' ); @@ -140,7 +140,7 @@ if (credentials.implementsPosixCredentials) { process.getegid = credentials.getegid; process.getgroups = credentials.getgroups; - if (isMainThread) { + if (ownsProcessState) { const wrapped = mainThreadSetup.wrapPosixCredentialSetters(credentials); process.initgroups = wrapped.initgroups; process.setgroups = wrapped.setgroups; diff --git a/lib/internal/worker.js b/lib/internal/worker.js index f28f4cd663..1d1a5e7d22 100644 --- a/lib/internal/worker.js +++ b/lib/internal/worker.js @@ -30,9 +30,10 @@ const { deserializeError } = require('internal/error-serdes'); const { pathToFileURL } = require('url'); const { - Worker: WorkerImpl, + ownsProcessState, + isMainThread, threadId, - isMainThread + Worker: WorkerImpl, } = internalBinding('worker'); const kHandle = Symbol('kHandle'); @@ -243,7 +244,8 @@ function pipeWithoutWarning(source, dest) { } module.exports = { + ownsProcessState, + isMainThread, threadId, Worker, - isMainThread }; -- cgit v1.2.3