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

Commit 46b7848

Browse files
authored
Merge pull request #150 from grafana/fix/slice-calls
Fix slice make calls extension wide
2 parents 6e9234d + 444929f commit 46b7848

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

chromium/browser_type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (b *BrowserType) Launch(opts goja.Value) api.Browser {
8181
launchOpts.Parse(b.Ctx, opts)
8282
b.Ctx = common.WithLaunchOptions(b.Ctx, launchOpts)
8383

84-
envs := make([]string, len(launchOpts.Env))
84+
envs := make([]string, 0, len(launchOpts.Env))
8585
for k, v := range launchOpts.Env {
8686
envs = append(envs, fmt.Sprintf("%s=%s", k, v))
8787
}

common/browser.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (b *Browser) disposeContext(id cdp.BrowserContextID) error {
137137
func (b *Browser) getPages() []*Page {
138138
b.pagesMu.RLock()
139139
defer b.pagesMu.RUnlock()
140-
pages := make([]*Page, len(b.pages))
140+
pages := make([]*Page, 0, len(b.pages))
141141
for _, p := range b.pages {
142142
pages = append(pages, p)
143143
}
@@ -359,10 +359,12 @@ func (b *Browser) Close() {
359359
func (b *Browser) Contexts() []api.BrowserContext {
360360
b.contextsMu.RLock()
361361
defer b.contextsMu.RUnlock()
362+
362363
contexts := make([]api.BrowserContext, 0, len(b.contexts))
363364
for _, b := range b.contexts {
364365
contexts = append(contexts, b)
365366
}
367+
366368
return contexts
367369
}
368370

common/element_handle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ func (h *ElementHandle) QueryAll(selector string) []api.ElementHandle {
12831283
arrayHandle := result.(api.JSHandle)
12841284
defer arrayHandle.Dispose()
12851285
properties := arrayHandle.GetProperties()
1286-
elements := make([]api.ElementHandle, len(properties))
1286+
elements := make([]api.ElementHandle, 0, len(properties))
12871287
for _, property := range properties {
12881288
elementHandle := property.AsElement()
12891289
if elementHandle != nil {

common/frame.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,8 @@ func (f *Frame) Check(selector string, opts goja.Value) {
542542
func (f *Frame) ChildFrames() []api.Frame {
543543
f.childFramesMu.RLock()
544544
defer f.childFramesMu.RUnlock()
545-
l := make([]api.Frame, len(f.childFrames))
545+
546+
l := make([]api.Frame, 0, len(f.childFrames))
546547
for child := range f.childFrames {
547548
l = append(l, child)
548549
}
@@ -1046,7 +1047,7 @@ func (f *Frame) SelectOption(selector string, values goja.Value, opts goja.Value
10461047
k6common.Throw(rt, err)
10471048
}
10481049
properties := arrayHandle.GetProperties()
1049-
strArr := make([]string, len(properties))
1050+
strArr := make([]string, 0, len(properties))
10501051
for _, property := range properties {
10511052
strArr = append(strArr, property.JSONValue().String())
10521053
property.Dispose()

common/page.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ func (p *Page) WaitForTimeout(timeout int64) {
752752

753753
// Workers returns all WebWorkers of page
754754
func (p *Page) Workers() []api.Worker {
755-
workers := make([]api.Worker, len(p.workers))
755+
workers := make([]api.Worker, 0, len(p.workers))
756756
for _, w := range p.workers {
757757
workers = append(workers, w)
758758
}

0 commit comments

Comments
 (0)