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

Desobekify BrowserContext methods #1504

Merged
merged 6 commits into from
Nov 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 22 additions & 25 deletions common/browser_context_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,36 @@ func NewGeolocation() *Geolocation {
}

// Parse parses the geolocation options.
func (g *Geolocation) Parse(ctx context.Context, opts sobek.Value) error { //nolint:cyclop
rt := k6ext.Runtime(ctx)
longitude := 0.0
latitude := 0.0
accuracy := 0.0
func (g *Geolocation) Parse(ctx context.Context, sopts sobek.Value) error { //nolint:cyclop
var newgl Geolocation

if opts != nil && !sobek.IsUndefined(opts) && !sobek.IsNull(opts) {
opts := opts.ToObject(rt)
for _, k := range opts.Keys() {
switch k {
case "accuracy":
accuracy = opts.Get(k).ToFloat()
case "latitude":
latitude = opts.Get(k).ToFloat()
case "longitude":
longitude = opts.Get(k).ToFloat()
}
if !sobekValueExists(sopts) {
return fmt.Errorf("geolocation options are required")
}

opts := sopts.ToObject(k6ext.Runtime(ctx))
for _, k := range opts.Keys() {
switch k {
case "accuracy":
newgl.Accurracy = opts.Get(k).ToFloat()
case "latitude":
newgl.Latitude = opts.Get(k).ToFloat()
case "longitude":
newgl.Longitude = opts.Get(k).ToFloat()
}
}

if longitude < -180 || longitude > 180 {
return fmt.Errorf(`invalid longitude "%.2f": precondition -180 <= LONGITUDE <= 180 failed`, longitude)
if newgl.Longitude < -180 || newgl.Longitude > 180 {
return fmt.Errorf(`invalid longitude "%.2f": precondition -180 <= LONGITUDE <= 180 failed`, newgl.Longitude)
}
if latitude < -90 || latitude > 90 {
return fmt.Errorf(`invalid latitude "%.2f": precondition -90 <= LATITUDE <= 90 failed`, latitude)
if newgl.Latitude < -90 || newgl.Latitude > 90 {
return fmt.Errorf(`invalid latitude "%.2f": precondition -90 <= LATITUDE <= 90 failed`, newgl.Latitude)
}
if accuracy < 0 {
return fmt.Errorf(`invalid accuracy "%.2f": precondition 0 <= ACCURACY failed`, accuracy)
if newgl.Accurracy < 0 {
return fmt.Errorf(`invalid accuracy "%.2f": precondition 0 <= ACCURACY failed`, newgl.Accurracy)
}

g.Accurracy = accuracy
g.Latitude = latitude
g.Longitude = longitude
*g = newgl
inancgumus marked this conversation as resolved.
Show resolved Hide resolved

return nil
}
Expand Down
Loading