Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit e926a36

Browse files
committed
Refactor FrameWaitForFunctionOptions.Parse
1 parent a5d43f1 commit e926a36

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

common/frame_options.go

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -611,30 +611,31 @@ func NewFrameWaitForFunctionOptions(defaultTimeout time.Duration) *FrameWaitForF
611611

612612
// Parse JavaScript waitForFunction options.
613613
func (o *FrameWaitForFunctionOptions) Parse(ctx context.Context, opts sobek.Value) error {
614-
rt := k6ext.Runtime(ctx)
614+
if !sobekValueExists(opts) {
615+
return nil
616+
}
615617

616-
if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) {
617-
opts := opts.ToObject(rt)
618-
for _, k := range opts.Keys() {
619-
v := opts.Get(k)
620-
switch k {
621-
case "timeout":
622-
o.Timeout = time.Duration(v.ToInteger()) * time.Millisecond
623-
case "polling":
624-
switch v.ExportType().Kind() { //nolint: exhaustive
625-
case reflect.Int64:
626-
o.Polling = PollingInterval
627-
o.Interval = v.ToInteger()
628-
case reflect.String:
629-
if p, ok := pollingTypeToID[v.ToString().String()]; ok {
630-
o.Polling = p
631-
break
632-
}
633-
fallthrough
634-
default:
635-
return fmt.Errorf("wrong polling option value: %q; "+
636-
`possible values: "raf", "mutation" or number`, v)
618+
rt := k6ext.Runtime(ctx)
619+
obj := opts.ToObject(rt)
620+
for _, k := range obj.Keys() {
621+
v := obj.Get(k)
622+
switch k {
623+
case "timeout":
624+
o.Timeout = time.Duration(v.ToInteger()) * time.Millisecond
625+
case "polling":
626+
switch v.ExportType().Kind() { //nolint: exhaustive
627+
case reflect.Int64:
628+
o.Polling = PollingInterval
629+
o.Interval = v.ToInteger()
630+
case reflect.String:
631+
if p, ok := pollingTypeToID[v.ToString().String()]; ok {
632+
o.Polling = p
633+
break
637634
}
635+
fallthrough
636+
default:
637+
return fmt.Errorf("wrong polling option value: %q; "+
638+
`possible values: "raf", "mutation" or number`, v)
638639
}
639640
}
640641
}

0 commit comments

Comments
 (0)