forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
console: lazy load process.stderr and process.stdout
This patch: - Refactors the Console constructor: moves the property binding code into and the writable streams binding code into two methods defined on the Console.prototype with symbols. - Refactors the global console creation: we only need to share the property binding code from the Console constructor. To bind the streams we can lazy load `process.stdio` and `process.stderr` so that we don't create these streams when they are not used. This significantly reduces the number of modules loaded during bootstrap. Also, by calling the refactored-out method directly we can skip the unnecessary typechecks when creating the global console and there is no need to create a temporary Console anymore. - Refactors the error handler creation and the `write` method: use a `kUseStdout` symbol to tell the internals which stream should be loaded from the console instance. Also put the `write` method on the Console prototype so it just loads other properties directly off the console instance which simplifies the call sites. Also leaves a few TODOs for further refactoring of the console bootstrap. PR-URL: nodejs#24534 Reviewed-By: Gus Caplan <[email protected]>
- Loading branch information
1 parent
691c9cb
commit df8ee76
Showing
3 changed files
with
133 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
/* eslint-disable node-core/required-modules */ | ||
|
||
// Flags: --expose-internals | ||
'use strict'; | ||
|
||
// Ordinarily test files must require('common') but that action causes | ||
// the global console to be compiled, defeating the purpose of this test. | ||
// This makes sure no additional files are added without carefully considering | ||
// lazy loading. Please adjust the value if necessary. | ||
|
||
// This list must be computed before we require any modules to | ||
// to eliminate the noise. | ||
const list = process.moduleLoadList.slice(); | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
assert(list.length <= 78, list); | ||
const isMainThread = common.isMainThread; | ||
const kMaxModuleCount = isMainThread ? 56 : 78; | ||
|
||
assert(list.length <= kMaxModuleCount, | ||
`Total length: ${list.length}\n` + list.join('\n') | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
calling stdout._refreshSize | ||
calling stderr._refreshSize | ||
calling stdout._refreshSize |