| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ce5e484 commit 542f5e7
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -123,6 +123,12 @@ function patchProcessObject(expandArgv1) { | |||
| 123 | 123 | } | |
| 124 | 124 | } | |
| 125 | 125 | ||
| 126 | + // We need to initialize the global console here again with process.stdout | ||
| 127 | + // and friends for snapshot deserialization. | ||
| 128 | + const globalConsole = require('internal/console/global'); | ||
| 129 | + const { initializeGlobalConsole } = require('internal/console/constructor'); | ||
| 130 | + initializeGlobalConsole(globalConsole); | ||
| 131 | + | ||
| 126 | 132 | // TODO(joyeecheung): most of these should be deprecated and removed, | |
| 127 | 133 | // except some that we need to be able to mutate during run time. | |
| 128 | 134 | addReadOnlyProcessAlias('_eval', '--eval'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -122,27 +122,53 @@ let stdin; | |||
| 122 | 122 | let stdout; | |
| 123 | 123 | let stderr; | |
| 124 | 124 | ||
| 125 | + let stdoutDestroy; | ||
| 126 | + let stderrDestroy; | ||
| 127 | + | ||
| 128 | + function refreshStdoutOnSigWinch() { | ||
| 129 | + stdout._refreshSize(); | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + function refreshStderrOnSigWinch() { | ||
| 133 | + stderr._refreshSize(); | ||
| 134 | + } | ||
| 135 | + | ||
| 125 | 136 | function getStdout() { | |
| 126 | 137 | if (stdout) return stdout; | |
| 127 | 138 | stdout = createWritableStdioStream(1); | |
| 128 | 139 | stdout.destroySoon = stdout.destroy; | |
| 129 | 140 | // Override _destroy so that the fd is never actually closed. | |
| 141 | + stdoutDestroy = stdout._destroy; | ||
| 130 | 142 | stdout._destroy = dummyDestroy; | |
| 131 | 143 | if (stdout.isTTY) { | |
| 132 | - process.on('SIGWINCH', () => stdout._refreshSize()); | ||
| 144 | + process.on('SIGWINCH', refreshStdoutOnSigWinch); | ||
| 133 | 145 | } | |
| 146 | + | ||
| 147 | + internalBinding('mksnapshot').cleanups.push(function cleanupStdout() { | ||
| 148 | + stdout._destroy = stdoutDestroy; | ||
| 149 | + stdout.destroy(); | ||
| 150 | + process.removeListener('SIGWINCH', refreshStdoutOnSigWinch); | ||
| 151 | + stdout = undefined; | ||
| 152 | + }); | ||
| 134 | 153 | return stdout; | |
| 135 | 154 | } | |
| 136 | 155 | ||
| 137 | 156 | function getStderr() { | |
| 138 | 157 | if (stderr) return stderr; | |
| 139 | 158 | stderr = createWritableStdioStream(2); | |
| 140 | 159 | stderr.destroySoon = stderr.destroy; | |
| 160 | + stderrDestroy = stderr._destroy; | ||
| 141 | 161 | // Override _destroy so that the fd is never actually closed. | |
| 142 | 162 | stderr._destroy = dummyDestroy; | |
| 143 | 163 | if (stderr.isTTY) { | |
| 144 | - process.on('SIGWINCH', () => stderr._refreshSize()); | ||
| 164 | + process.on('SIGWINCH', refreshStderrOnSigWinch); | ||
| 145 | 165 | } | |
| 166 | + internalBinding('mksnapshot').cleanups.push(function cleanupStderr() { | ||
| 167 | + stderr._destroy = stderrDestroy; | ||
| 168 | + stderr.destroy(); | ||
| 169 | + process.removeListener('SIGWINCH', refreshStderrOnSigWinch); | ||
| 170 | + stderr = undefined; | ||
| 171 | + }); | ||
| 146 | 172 | return stderr; | |
| 147 | 173 | } | |
| 148 | 174 | ||
@@ -233,6 +259,10 @@ function getStdin() { | |||
| 233 | 259 | } | |
| 234 | 260 | } | |
| 235 | 261 | ||
| 262 | + internalBinding('mksnapshot').cleanups.push(function cleanupStdin() { | ||
| 263 | + stdin.destroy(); | ||
| 264 | + stdin = undefined; | ||
| 265 | + }); | ||
| 236 | 266 | return stdin; | |
| 237 | 267 | } | |
| 238 | 268 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -669,9 +669,15 @@ Console.prototype.dirxml = Console.prototype.log; | |||
| 669 | 669 | Console.prototype.error = Console.prototype.warn; | |
| 670 | 670 | Console.prototype.groupCollapsed = Console.prototype.group; | |
| 671 | 671 | ||
| 672 | + function initializeGlobalConsole(globalConsole) { | ||
| 673 | + globalConsole[kBindStreamsLazy](process); | ||
| 674 | + globalConsole[kBindProperties](true, 'auto'); | ||
| 675 | + } | ||
| 676 | + | ||
| 672 | 677 | module.exports = { | |
| 673 | 678 | Console, | |
| 674 | 679 | kBindStreamsLazy, | |
| 675 | 680 | kBindProperties, | |
| 681 | + initializeGlobalConsole, | ||
| 676 | 682 | formatTime // exported for tests | |
| 677 | 683 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,9 +21,7 @@ const { | |||
| 21 | 21 | } = primordials; | |
| 22 | 22 | ||
| 23 | 23 | const { | |
| 24 | - Console, | ||
| 25 | - kBindStreamsLazy, | ||
| 26 | - kBindProperties | ||
| 24 | + Console | ||
| 27 | 25 | } = require('internal/console/constructor'); | |
| 28 | 26 | ||
| 29 | 27 | const globalConsole = ObjectCreate({}); | |
@@ -44,9 +42,6 @@ for (const prop of ReflectOwnKeys(Console.prototype)) { | |||
| 44 | 42 | ReflectDefineProperty(globalConsole, prop, desc); | |
| 45 | 43 | } | |
| 46 | 44 | ||
| 47 | - globalConsole[kBindStreamsLazy](process); | ||
| 48 | - globalConsole[kBindProperties](true, 'auto'); | ||
| 49 | - | ||
| 50 | 45 | // This is a legacy feature - the Console constructor is exposed on | |
| 51 | 46 | // the global console instance. | |
| 52 | 47 | globalConsole.Console = Console; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments