-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get console
messages to go code
#77
base: master
Are you sure you want to change the base?
Conversation
Btw, the initial code here predates the previous PR. I noticed I have created If you expressed your opinion on that topic, I have missed that. |
I was just browsing the Go documentation, and I notice that CGo has a mechanism for passing Go values to C, and get it back again: https://pkg.go.dev/runtime/cgo#Handle So the registry thing seems unnecessary. |
No, I didn't. I don't see the point of the Ptr types, but I also don't have a strong opinion. |
Allright, I'll replace it with normal pointers, IMHO it's a code convention that adds more code in type declarations with no apparent benefit. I can easily imagine it's a result of finally finding a solution that compiles after struggling with the Go-compatible C-types vs. C++ types problem. |
Currently there is no actual usable client, and no handling of diposal yet.
Finally got around to update this. I added documentation to types, replaced the
Controlling time isn't achieved through the inspector, but |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a CHANGELOG entry for this added functionality.
inspector.cc
Outdated
void InspectorContextCreated(InspectorPtr inspector, ContextPtr context) { | ||
LOCAL_CONTEXT(context); | ||
int groupId = 1; | ||
StringView name = StringView((const uint8_t*)"Test", 4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this used for? Why "Test"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm. It's called "humanReadableName", though I haven't found out where it's used. But I didn't realise you can create a StringView
without constructor args.
The groupId
appears to be sent back to the caller in the callback, consoleAPIMessage
. It must be non-zero (no messages are received if it's zero).
Maybe I should expose both of these as arguments to the caller, but I was preferring a more minimal interface, rather than forcing the caller to pass arguments it has no use for.
"unicode/utf16" | ||
) | ||
|
||
type MessageErrorLevel uint8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to take the values from the underlying enum, but at least document this is a copy of v8::Isolate::MessageErrorLevel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. For the values, I adapted how e.g., PropertyAttribute
is also implemented.
I think even linking to v8 documentation would make sense, but this doesn't look like a stable URL>
https://v8.github.io/api/head/classv8_1_1Isolate.html#acfc7c4d5c93913201249045e2655d3dd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, though https://v8.github.io/api/head/classv8_1_1Isolate.html is probably useful on its own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add some documentation for the exported functions and types? Ideally for someone who hasn't (yet) read the C++ docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume, you mean the "exported to C" code function? goHandleConsoleAPIMessageCallback
? Done!
inspector.go
Outdated
Url string | ||
LineNumber uint | ||
ColumnNumber uint | ||
// stackTrace StackTrace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this and the TODO below and instead document that stack traces aren't implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment about how the fields map to C++ function arguments, and a link to the InspectorClient
C++ class documentation.
Represents the purpose of the value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay.
"unicode/utf16" | ||
) | ||
|
||
type MessageErrorLevel uint8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, though https://v8.github.io/api/head/classv8_1_1Isolate.html is probably useful on its own.
He, me too, I think there are still a few things I wanted to follow up on, in particular having a test case with special characters that have larger utf16-sequences. |
For the utf-16->utf-8 decoding, I had two ideas
However, I'm not sure that is the right way. Looking at
This indicates that the |
Regarding the context group id specified here (where I found that it doesn't work with zero-value)
There are functions on the My conclusion is that the intention is that e.g., for a web page with This is just FYI, just sharing what I learned about the apparent purpose of these undocumented values are used. Didn't yet find where the "human readable name" is used, but didn't specifically look for it either. |
This adds the ability to get
console
messages to Go, but to do that you need to tap into the "inspector", which is also AFAIK the entry point to controlling the debugger. I just need the console messages. Although it seems that I can also use it to control time; which would be useful for my purpose.This is still WIP, functionally close to done (for my needs), but I'd appreciate feedback, and opinion on code structure.
I also intend to add code-doc before merging.
Inheriting from InspectorClient
In C++, you must create a class inheriting from
InspectorClient
. This must then be installed usingInspector::Create
, and you need to manually attach to each v8 context.The
InspectorClient
has all virtual functions, and the client code overrides the ones they care about.My idea was to create a Go interface for each capability. The user can choose to implement the functions they care about.
So far, I only care about console messages, so that's what I have now. It it still lacking stack traces, but should be simple enough.
When registering an inspector, you need a name, and a contextGroupId. I have no idea what they are used for, except contextGroupId must be <> 0, otherwise nothing happens. Right now they are hardcoded in C++ code.
That also means that I don't know if it makes sense to control from Go code or not.
The client itself does not seem to be related to an isolate. I don't know if it's valid to use the same client for multiple isolates. The code seems to indicate it's possible.
Utility types
The code uses a
StringView
type for strings. In reality; they're always utf16le (i.e. no byte order mark). Nothing is documented, so all is from experimenting, and only on one platform, my M2 mac. Btw, there must be a better way of converting[]byte
to[]uint16
, but I didn't find anything. Btw, I will add a test case that uses some weird unicode characters that take up more than one element in utf16. I did test that manually, and it did work, but better have it in the tests.I created a more generic type for registering "callbacks". Just like the
Isolate
registers function callbacks, which I think should just be replaced with that type; which should be moved somewhere else.Package name
If we follow the idea to create a separate interface for each capability that the inspector supports, it will be quite a lot of types, not necessarily with a sensible name of their own without some context. Prefixing them with
InspectorClient
makes them even longer, they're long enough IMHO.I was wondering if it would make sense to put it in a sub-package,
v8go/inspector
. The C++ code does have it's own namespace,v8_inspector
.p.s. it's only now I see that I have reformatted
function_template.go
. I have just opened and saved it