Skip to content
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

Refactor JSONValue to use parseConsoleRemoteObject #1190

Merged
merged 7 commits into from Jan 29, 2024
Merged

Conversation

ankur22
Copy link
Collaborator

@ankur22 ankur22 commented Jan 24, 2024

What?

Refactor JSONValue to use parseConsoleRemoteObject.

Why?

This will help avoid working with the goja runtime outside of the mapping layer and therefore avoid possible race conditions with the unsafe goja runtime. JSONValue wasn't ever working with the goja values and so it made sense to always work with string values.

Checklist

  • I have performed a self-review of my code
  • I have added tests for my changes
  • I have commented on my code, particularly in hard-to-understand areas

Related PR(s)/Issue(s)

Updates: #1168

Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but one last thing.

common/js_handle.go Outdated Show resolved Hide resolved
common/js_handle.go Outdated Show resolved Hide resolved
common/js_handle.go Outdated Show resolved Hide resolved
common/js_handle.go Outdated Show resolved Hide resolved
Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

inancgumus
inancgumus previously approved these changes Jan 29, 2024
Base automatically changed from refactor/parseConsoleRemoteObject to main January 29, 2024 11:12
@ankur22 ankur22 dismissed inancgumus’s stale review January 29, 2024 11:12

The base branch was changed.

ankur22 and others added 7 commits January 29, 2024 11:13
Just wanted to clarify this with a comment that the browser module
does capture other log types other than the usual info, warn, error and
debug, such as console.table, but it defaults to debug.
JSONValue was using valueFromRemoteObject which returns a goja.Value
but then converts that back to a string. This conversion is:

1. unnecessary, and it should just work with parseConsoleRemoteObject
   which returns a string.
2. dangerous since it could be called off the main goja thread (i.e. in
   a new goroutine or promise) which could cause unwanted panics since
   goja runtime should only be used on the main goja thread.
Instead of panicking which can cause unexpected side affects, return
an error.
This refactors the implementation to make it clearer and to avoid
duplication.
It's not needed and the return value can be added directly to
remoteObject.
Co-authored-by: İnanç Gümüş <inanc.gumus@grafana.com>
@ankur22 ankur22 merged commit 3eadfb4 into main Jan 29, 2024
17 checks passed
@ankur22 ankur22 deleted the refactor/jsonValue branch January 29, 2024 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants