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

@ankur22 ankur22 force-pushed the refactor/jsonValue branch from b8cf42d to 43c81a4 Compare January 24, 2024 12:52
@ankur22 ankur22 changed the base branch from main-next to refactor/parseConsoleRemoteObject January 24, 2024 12:52
@ankur22 ankur22 force-pushed the refactor/jsonValue branch from 43c81a4 to ebefa9d Compare January 24, 2024 12:52
@ankur22 ankur22 force-pushed the refactor/parseConsoleRemoteObject branch from 8d48cf6 to fc47e2e Compare January 25, 2024 16:01
@ankur22 ankur22 force-pushed the refactor/jsonValue branch from ebefa9d to 8c16e25 Compare January 25, 2024 16:27
@ankur22 ankur22 requested a review from inancgumus January 25, 2024 16:28
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.

🚀

@ankur22 ankur22 force-pushed the refactor/parseConsoleRemoteObject branch from b0f41e7 to 5aedac1 Compare January 29, 2024 10:53
@ankur22 ankur22 force-pushed the refactor/jsonValue branch from cd36b6f to 2da056b Compare January 29, 2024 10:54
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üş <[email protected]>
@ankur22 ankur22 force-pushed the refactor/jsonValue branch from 2da056b to 1ea662c Compare January 29, 2024 11:13
@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.

3 participants