Skip to content

Commit

Permalink
Fix an NPD when handle is overwritten with nil
Browse files Browse the repository at this point in the history
Call the defer function with the non nil handle, and allow the handle
to be overwritten later. Now the handle in the defer will still be
non-nil.
  • Loading branch information
ankur22 committed Jan 24, 2025
1 parent 454253f commit 86e90c4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/js/modules/k6/browser/common/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,12 +500,12 @@ func (f *Frame) waitForSelector(selector string, opts *FrameWaitForSelectorOptio
// an element should belong to the current execution context.
// otherwise, we should adopt it to this execution context.
if ec != handle.execCtx {
defer func() {
defer func(handle *ElementHandle) {
if err := handle.Dispose(); err != nil {
err = fmt.Errorf("disposing element handle: %w", err)
rerr = errors.Join(err, rerr)
}
}()
}(handle)
if handle, err = ec.adoptElementHandle(handle); err != nil {
return nil, fmt.Errorf("waiting for selector %q: adopting element handle: %w", selector, err)
}
Expand Down

0 comments on commit 86e90c4

Please sign in to comment.