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

Prevent panic when 'options' value is nil #3947

Merged
merged 2 commits into from
Sep 12, 2024
Merged

Conversation

joanlopez
Copy link
Contributor

What?

It early returns when options is nil, to prevent reaching the point where json.Marshal(v.Export()) with v == nil.

Why?

To prevent it from panicking.

In v0.52, that code was slightly different: https://github.com/grafana/k6/blob/v0.52.0/js/bundle.go#L176, and so the value received was goja.valueUndefined, which is enough for not panicking when calling json.Marshal(v.Export()).

Since changes introduced in v0.53, v is nil, and thus it panics.

Additional comments

Another approach that I suggested was changing the behavior of SourceTextModuleInstance.GetBindingValue in Sobek, so it returns sobek.Undefined() when no getter is found, but @mstoykov had doubts around the general correctness of that approach, so I guess the least intrusive way to prevent such panics here is this.

Checklist

  • I have performed a self-review of my code.
  • I have added tests for my changes.
  • I have run linter locally (make lint) and all checks pass.
  • I have run tests locally (make tests) and all tests pass.
  • I have commented on my code, particularly in hard-to-understand areas.

Related PR(s)/Issue(s)

@joanlopez joanlopez added the bug label Sep 12, 2024
@joanlopez joanlopez self-assigned this Sep 12, 2024
@joanlopez joanlopez requested a review from a team as a code owner September 12, 2024 09:47
@joanlopez joanlopez requested review from mstoykov and olegbespalov and removed request for a team September 12, 2024 09:47
@joanlopez joanlopez added this to the v0.54.0 milestone Sep 12, 2024
@joanlopez joanlopez merged commit 535a5bb into master Sep 12, 2024
22 of 23 checks passed
@joanlopez joanlopez deleted the fix-panic-null-options branch September 12, 2024 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants