Skip to content

Commit b1500d9

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 <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent ee461fe commit b1500d9

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
@@ -1267,14 +1267,16 @@ void LoadEnvironment(Environment* env) {
12671267
env->process_string(),
12681268
FIXED_ONE_BYTE_STRING(isolate, "bootstrappers"),
12691269
FIXED_ONE_BYTE_STRING(isolate, "loaderExports"),
1270-
FIXED_ONE_BYTE_STRING(isolate, "triggerFatalException")};
1270+
FIXED_ONE_BYTE_STRING(isolate, "triggerFatalException"),
1271+
FIXED_ONE_BYTE_STRING(isolate, "isMainThread")};
12711272
std::vector<Local<Value>> node_args = {
12721273
process,
12731274
bootstrapper,
12741275
loader_exports.ToLocalChecked(),
12751276
env->NewFunctionTemplate(FatalException)
12761277
->GetFunction(context)
1277-
.ToLocalChecked()};
1278+
.ToLocalChecked(),
1279+
Boolean::New(isolate, env->is_main_thread())};
12781280

12791281
if (ExecuteBootstrapper(
12801282
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 ? 61 : 82;
12+
const kMaxModuleCount = isMainThread ? 60 : 82;
1313

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

0 commit comments

Comments
 (0)