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: https://github.com/nodejs/node/pull/25017
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Joyee Cheung 2018-12-13 23:15:37 +08:00 committed by Anna Henningsen
parent 9021b0d3fc
commit 7a6bd9f9b7
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
3 changed files with 7 additions and 4 deletions

View File

@ -15,6 +15,8 @@
// This file is compiled as if it's wrapped in a function with arguments
// passed by node::LoadEnvironment()
/* global process, bootstrappers, loaderExports, triggerFatalException */
/* global isMainThread */
const {
_setupTraceCategoryState,
_setupNextTick,
@ -28,7 +30,6 @@ const {
const { internalBinding, NativeModule } = loaderExports;
const exceptionHandlerState = { captureFn: null };
const isMainThread = internalBinding('worker').threadId === 0;
function startup() {
setupTraceCategoryState();

View File

@ -1276,14 +1276,16 @@ void LoadEnvironment(Environment* env) {
env->process_string(),
FIXED_ONE_BYTE_STRING(isolate, "bootstrappers"),
FIXED_ONE_BYTE_STRING(isolate, "loaderExports"),
FIXED_ONE_BYTE_STRING(isolate, "triggerFatalException")};
FIXED_ONE_BYTE_STRING(isolate, "triggerFatalException"),
FIXED_ONE_BYTE_STRING(isolate, "isMainThread")};
std::vector<Local<Value>> node_args = {
process,
bootstrapper,
loader_exports.ToLocalChecked(),
env->NewFunctionTemplate(FatalException)
->GetFunction(context)
.ToLocalChecked()};
.ToLocalChecked(),
Boolean::New(isolate, env->is_main_thread())};
if (ExecuteBootstrapper(
env, "internal/bootstrap/node", &node_params, &node_args)

View File

@ -9,7 +9,7 @@ const common = require('../common');
const assert = require('assert');
const isMainThread = common.isMainThread;
const kMaxModuleCount = isMainThread ? 60 : 82;
const kMaxModuleCount = isMainThread ? 59 : 82;
assert(list.length <= kMaxModuleCount,
`Total length: ${list.length}\n` + list.join('\n')