diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2021-06-27 02:27:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-27 02:27:50 +0200 |
commit | 7b9737b9f4c25e1d25bfb352198cf24a50ceb2de (patch) | |
tree | 4f853a8218f5d0607304db33e2b02d87976678a7 /extensions/console/02_console.js | |
parent | 015f252066c21bd6d36e5b4d58a34dd40e4c0db0 (diff) |
feat(inspector): pipe console messages between terminal and inspector (#11134)
This commit adds support for piping console messages to inspector.
This is done by "wrapping" Deno's console implementation with default
console provided by V8 by the means of "Deno.core.callConsole" binding.
Effectively each call to "console.*" methods calls a method on Deno's
console and V8's console.
Diffstat (limited to 'extensions/console/02_console.js')
-rw-r--r-- | extensions/console/02_console.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/extensions/console/02_console.js b/extensions/console/02_console.js index ddfcbf47a..2d293a1eb 100644 --- a/extensions/console/02_console.js +++ b/extensions/console/02_console.js @@ -1774,6 +1774,32 @@ }); } + // A helper function that will bind our own console implementation + // with default implementation of Console from V8. This will cause + // console messages to be piped to inspector console. + // + // We are using `Deno.core.callConsole` binding to preserve proper stack + // frames in inspector console. This has to be done because V8 considers + // the last JS stack frame as gospel for the inspector. In our case we + // specifically want the latest user stack frame to be the one that matters + // though. + // + // Inspired by: + // https://github.com/nodejs/node/blob/1317252dfe8824fd9cfee125d2aaa94004db2f3b/lib/internal/util/inspector.js#L39-L61 + function wrapConsole(consoleFromDeno, consoleFromV8) { + const callConsole = core.callConsole; + + for (const key of Object.keys(consoleFromV8)) { + if (consoleFromDeno.hasOwnProperty(key)) { + consoleFromDeno[key] = callConsole.bind( + consoleFromDeno, + consoleFromV8[key], + consoleFromDeno[key], + ); + } + } + } + // Expose these fields to internalObject for tests. window.__bootstrap.internals = { ...window.__bootstrap.internals ?? {}, @@ -1790,5 +1816,6 @@ Console, customInspect, inspect, + wrapConsole, }; })(this); |