Skip to content

Commit

Permalink
Add URL and line numbers to console message
Browse files Browse the repository at this point in the history
  • Loading branch information
stroiman committed Dec 5, 2024
1 parent 198eb04 commit 8db5844
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
19 changes: 14 additions & 5 deletions inspector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,27 @@ class InspectorClient : public V8InspectorClient {
V8StackTrace*) override;
};

StringViewData ConvertStringView(const StringView& view) {
StringViewData msg;
msg.is8bit = view.is8Bit();
// The ? isn't necessary, the two functions return the sama pointer. But that
// has been considered an implementation detail that may change.
msg.data =
view.is8Bit() ? (void*)view.characters8() : (void*)view.characters16();
msg.length = view.length();
return msg;
}

void InspectorClient::consoleAPIMessage(int contextGroupId,
v8::Isolate::MessageErrorLevel level,
const StringView& message,
const StringView& url,
unsigned lineNumber,
unsigned columnNumber,
V8StackTrace*) {
StringViewData msg;
msg.is8bit = message.is8Bit();
msg.data = message.characters8();
msg.length = message.length();
goHandleConsoleAPIMessageCallback(_callbackRef, contextGroupId, level, msg);
goHandleConsoleAPIMessageCallback(
_callbackRef, contextGroupId, level, ConvertStringView(message),
ConvertStringView(url), lineNumber, columnNumber);
}

extern "C" {
Expand Down
17 changes: 12 additions & 5 deletions inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ type ConsoleAPIMessage struct {
contextGroupId int
ErrorLevel MessageErrorLevel
Message string
url string
lineNumber int
columnNumber int
Url string
LineNumber uint
ColumnNumber uint
// stackTrace StackTrace
}

Expand Down Expand Up @@ -140,12 +140,19 @@ func goHandleConsoleAPIMessageCallback(
contextGroupId C.int,
errorLevel C.int,
message C.StringViewData,
url C.StringViewData,
lineNumber C.uint,
columnNumber C.uint,
) {
// Convert data to Go data
client := clientRegistry.get(callbackRef)
// TODO, Stack trace
client.handler.ConsoleAPIMessage(ConsoleAPIMessage{
Message: stringViewToString(message),
ErrorLevel: MessageErrorLevel(errorLevel),
ErrorLevel: MessageErrorLevel(errorLevel),
Message: stringViewToString(message),
Url: stringViewToString(url),
LineNumber: uint(lineNumber),
ColumnNumber: uint(columnNumber),
})
// client.handleConsoleAPIMessageCallback(data)
}

0 comments on commit 8db5844

Please sign in to comment.