inspector: report kMessageLog as a level for console.log to embedder

Some embedders might want to process console.info and console.log
differently. So inspector needs to return a different level for
these console log messages.

Change-Id: I936990a25f079a0d72f877a5095ed93819fc539a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3331929
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Alexey Kozyatinskiy <kozyatinskiy@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78357}
This commit is contained in:
Aleksei Koziatinskii 2021-12-10 20:52:58 -08:00 committed by V8 LUCI CQ
parent 4c2bea9703
commit 99627ac1b8
4 changed files with 25 additions and 4 deletions

View File

@ -479,8 +479,10 @@ std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForConsoleAPI(
clientLevel = v8::Isolate::kMessageError;
} else if (type == ConsoleAPIType::kWarning) {
clientLevel = v8::Isolate::kMessageWarning;
} else if (type == ConsoleAPIType::kInfo || type == ConsoleAPIType::kLog) {
} else if (type == ConsoleAPIType::kInfo) {
clientLevel = v8::Isolate::kMessageInfo;
} else if (type == ConsoleAPIType::kLog) {
clientLevel = v8::Isolate::kMessageLog;
}
if (type != ConsoleAPIType::kClear) {

View File

@ -4,7 +4,7 @@ Running test: test
Script wasm://wasm/38e28046 byte offset 51: Wasm opcode 0x20 (kExprLocalGet)
GC triggered
Debugger.resume
Hello World (v8://test/instantiate:11:36)
log: Hello World (v8://test/instantiate:11:36)
at bar (v8://test/instantiate:11:36)
at $wasm_A (wasm://wasm/38e28046:1:54)
at test (test.js:4:20)

View File

@ -456,6 +456,25 @@ void InspectorIsolateData::consoleAPIMessage(
const v8_inspector::StringView& url, unsigned lineNumber,
unsigned columnNumber, v8_inspector::V8StackTrace* stack) {
if (!log_console_api_message_calls_) return;
switch (level) {
case v8::Isolate::kMessageLog:
fprintf(stdout, "log: ");
break;
case v8::Isolate::kMessageDebug:
fprintf(stdout, "debug: ");
break;
case v8::Isolate::kMessageInfo:
fprintf(stdout, "info: ");
break;
case v8::Isolate::kMessageError:
fprintf(stdout, "error: ");
break;
case v8::Isolate::kMessageWarning:
fprintf(stdout, "warning: ");
break;
case v8::Isolate::kMessageAll:
break;
}
Print(isolate_.get(), message);
fprintf(stdout, " (");
Print(isolate_.get(), url);

View File

@ -1,7 +1,7 @@
Checks that we passed correct arguments in V8InspectorClient::consoleAPIMessage. Note: lines and columns are 1-based.
42 (:1:9)
log: 42 (:1:9)
at (anonymous function) (:1:9)
239 (:13:15)
info: 239 (:13:15)
at b (:13:15)
at a (:15:5)
at consoleTrace (:17:3)