From 6c40fe817ff93452ea3bf76b15704489be25c7d7 Mon Sep 17 00:00:00 2001 From: Balazs Andorko Date: Sat, 2 Dec 2023 00:56:51 +0100 Subject: [PATCH] Fix issues found during code review --- common/element_handle_options.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/common/element_handle_options.go b/common/element_handle_options.go index 201544bdc..f7e30c1b3 100644 --- a/common/element_handle_options.go +++ b/common/element_handle_options.go @@ -195,7 +195,6 @@ func (o *ElementHandleCheckOptions) Parse(ctx context.Context, opts goja.Value) func NewElementHandleSetInputFilesOptions(defaultTimeout time.Duration) *ElementHandleSetInputFilesOption { return &ElementHandleSetInputFilesOption{ ElementHandleBaseOptions: *NewElementHandleBaseOptions(defaultTimeout), - Payload: []File{}, } } @@ -205,17 +204,20 @@ func (o *ElementHandleSetInputFilesOption) Parse(ctx context.Context, opts goja. if err := o.ElementHandleBaseOptions.Parse(ctx, opts); err != nil { return err } - if opts != nil && !goja.IsUndefined(opts) && !goja.IsNull(opts) { - opts := opts.ToObject(rt) - for _, k := range opts.Keys() { - if k == "payload" { - var p []File - if err := rt.ExportTo(opts.Get(k), &p); err != nil { - return fmt.Errorf("unable to parse SetInputFileOptions; reason: %w", err) - } - o.Payload = p - } + if !gojaValueExists(opts) { + return nil + } + gopts := opts.ToObject(rt) + for _, k := range gopts.Keys() { + if k != "payload" { + continue } + var p []File + if err := rt.ExportTo(gopts.Get(k), &p); err != nil { + return fmt.Errorf("unable to parse SetInputFileOptions; reason: %w", err) + } + o.Payload = p + } return nil