Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b1500d9

Browse filesBrowse 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 ee461fe commit b1500d9
Copy full SHA for b1500d9

File tree

Expand file treeCollapse file tree

3 files changed

+7
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+7
-4
lines changed
Open diff view settings
Collapse file

‎lib/internal/bootstrap/node.js‎

Copy file name to clipboardExpand all lines: lib/internal/bootstrap/node.js
+2-1Lines changed: 2 additions & 1 deletion
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();
Collapse file

‎src/node.cc‎

Copy file name to clipboardExpand all lines: src/node.cc
+4-2Lines changed: 4 additions & 2 deletions
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)
Collapse file

‎test/parallel/test-bootstrap-modules.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-bootstrap-modules.js
+1-1Lines changed: 1 addition & 1 deletion
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.