summaryrefslogtreecommitdiff
path: root/extensions/console/02_console.js
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/console/02_console.js')
-rw-r--r--extensions/console/02_console.js27
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);