summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-02-01 23:47:38 +0100
committerAnna Henningsen <anna@addaleax.net>2019-02-05 21:55:54 +0100
commit39eca841c30e1a54424b85f34e8dd56b2648f930 (patch)
tree2ab9c7bc285e20f85cefff16c6441c726bbed126 /lib
parent8d63f4037e52eda125c5a70dafa602f47c13d0ad (diff)
downloadandroid-node-v8-39eca841c30e1a54424b85f34e8dd56b2648f930.tar.gz
android-node-v8-39eca841c30e1a54424b85f34e8dd56b2648f930.tar.bz2
android-node-v8-39eca841c30e1a54424b85f34e8dd56b2648f930.zip
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 <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/bootstrap/node.js6
-rw-r--r--lib/internal/worker.js8
-rw-r--r--lib/trace_events.js4
3 files changed, 10 insertions, 8 deletions
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
};
diff --git a/lib/trace_events.js b/lib/trace_events.js
index d2977679e1..41c4dbe741 100644
--- a/lib/trace_events.js
+++ b/lib/trace_events.js
@@ -13,8 +13,8 @@ const {
ERR_INVALID_ARG_TYPE
} = require('internal/errors').codes;
-const { isMainThread } = require('internal/worker');
-if (!hasTracing || !isMainThread)
+const { ownsProcessState } = require('internal/worker');
+if (!hasTracing || !ownsProcessState)
throw new ERR_TRACE_EVENTS_UNAVAILABLE();
const { CategorySet, getEnabledCategories } = internalBinding('trace_events');