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 #1167

Merged
merged 4 commits into from
Jan 24, 2024

Conversation

ankur22
Copy link
Collaborator

@ankur22 ankur22 commented Jan 19, 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 marked this pull request as draft January 19, 2024 13:41
@ankur22 ankur22 changed the base branch from main to main-next January 19, 2024 14:26
There is another use case for parseConsoleRemoteObject, which is when
JSONValue is called. At the moment this API uses valueFromRemoteObject
which returns a goja.Value. Interestingly, the return value is always
converted to string before being returned to the caller, so the extra
step to convert to goja and then back to string is not needed.
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.
@ankur22 ankur22 force-pushed the refactor/jsonValue branch from e12b7d8 to b8cf42d Compare January 19, 2024 14:26
@ankur22 ankur22 marked this pull request as ready for review January 24, 2024 12:45
@ankur22 ankur22 merged commit e51e75f into main-next Jan 24, 2024
14 checks passed
@ankur22 ankur22 deleted the refactor/jsonValue branch January 24, 2024 12:45
@ankur22 ankur22 restored the refactor/jsonValue branch January 24, 2024 12:46
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.

1 participant