-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
console: move the inspector console wrapping in a separate file
Move the wrapping of the inspector console in a separate file for clarity. In addition, save the original console from the VM explicitly via an exported property `require('internal/console/inspector').consoleFromVM` that `require('inspector').console` can alias to it later, instead of hanging the original console onto `per_thread.js` during bootstrap and counting on that `per_thread.js` only gets evaluated once and gets cached. PR-URL: #24709 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
b549058
commit 57323e8
Showing
5 changed files
with
84 additions
and
55 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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const CJSModule = require('internal/modules/cjs/loader'); | ||
const { makeRequireFunction } = require('internal/modules/cjs/helpers'); | ||
const { tryGetCwd } = require('internal/util'); | ||
const { addCommandLineAPI, consoleCall } = process.binding('inspector'); | ||
|
||
// Wrap a console implemented by Node.js with features from the VM inspector | ||
function addInspectorApis(consoleFromNode, consoleFromVM) { | ||
// Setup inspector command line API. | ||
const cwd = tryGetCwd(path); | ||
const consoleAPIModule = new CJSModule('<inspector console>'); | ||
consoleAPIModule.paths = | ||
CJSModule._nodeModulePaths(cwd).concat(CJSModule.globalPaths); | ||
addCommandLineAPI('require', makeRequireFunction(consoleAPIModule)); | ||
const config = {}; | ||
|
||
// If global console has the same method as inspector console, | ||
// then wrap these two methods into one. Native wrapper will preserve | ||
// the original stack. | ||
for (const key of Object.keys(consoleFromNode)) { | ||
if (!consoleFromVM.hasOwnProperty(key)) | ||
continue; | ||
consoleFromNode[key] = consoleCall.bind(consoleFromNode, | ||
consoleFromVM[key], | ||
consoleFromNode[key], | ||
config); | ||
} | ||
|
||
// Add additional console APIs from the inspector | ||
for (const key of Object.keys(consoleFromVM)) { | ||
if (consoleFromNode.hasOwnProperty(key)) | ||
continue; | ||
consoleFromNode[key] = consoleFromVM[key]; | ||
} | ||
} | ||
|
||
module.exports = { | ||
addInspectorApis | ||
}; | ||
|
||
// Stores the console from VM, should be set during bootstrap. | ||
let consoleFromVM; | ||
|
||
Object.defineProperty(module.exports, 'consoleFromVM', { | ||
get() { | ||
return consoleFromVM; | ||
}, | ||
set(val) { | ||
consoleFromVM = val; | ||
} | ||
}); |
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