Skip to content

Commit 7a6bd9f

Browse files
joyeecheungaddaleax
authored andcommitted
src: pass isMainThread into bootstrap/node.js directly
Instead of loading the working binding for the sole purpose of detecting whether we are inside the main thread unconditionally. PR-URL: #25017 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 9021b0d commit 7a6bd9f

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

lib/internal/bootstrap/node.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
// This file is compiled as if it's wrapped in a function with arguments
1616
// passed by node::LoadEnvironment()
1717
/* global process, bootstrappers, loaderExports, triggerFatalException */
18+
/* global isMainThread */
19+
1820
const {
1921
_setupTraceCategoryState,
2022
_setupNextTick,
@@ -28,7 +30,6 @@ const {
2830
const { internalBinding, NativeModule } = loaderExports;
2931

3032
const exceptionHandlerState = { captureFn: null };
31-
const isMainThread = internalBinding('worker').threadId === 0;
3233

3334
function startup() {
3435
setupTraceCategoryState();

src/node.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -1276,14 +1276,16 @@ void LoadEnvironment(Environment* env) {
12761276
env->process_string(),
12771277
FIXED_ONE_BYTE_STRING(isolate, "bootstrappers"),
12781278
FIXED_ONE_BYTE_STRING(isolate, "loaderExports"),
1279-
FIXED_ONE_BYTE_STRING(isolate, "triggerFatalException")};
1279+
FIXED_ONE_BYTE_STRING(isolate, "triggerFatalException"),
1280+
FIXED_ONE_BYTE_STRING(isolate, "isMainThread")};
12801281
std::vector<Local<Value>> node_args = {
12811282
process,
12821283
bootstrapper,
12831284
loader_exports.ToLocalChecked(),
12841285
env->NewFunctionTemplate(FatalException)
12851286
->GetFunction(context)
1286-
.ToLocalChecked()};
1287+
.ToLocalChecked(),
1288+
Boolean::New(isolate, env->is_main_thread())};
12871289

12881290
if (ExecuteBootstrapper(
12891291
env, "internal/bootstrap/node", &node_params, &node_args)

test/parallel/test-bootstrap-modules.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const common = require('../common');
99
const assert = require('assert');
1010

1111
const isMainThread = common.isMainThread;
12-
const kMaxModuleCount = isMainThread ? 60 : 82;
12+
const kMaxModuleCount = isMainThread ? 59 : 82;
1313

1414
assert(list.length <= kMaxModuleCount,
1515
`Total length: ${list.length}\n` + list.join('\n')

0 commit comments

Comments
 (0)