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

Fix slice make calls extension wide #150

Merged
merged 1 commit into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion chromium/browser_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (b *BrowserType) Launch(opts goja.Value) api.Browser {
launchOpts.Parse(b.Ctx, opts)
b.Ctx = common.WithLaunchOptions(b.Ctx, launchOpts)

envs := make([]string, len(launchOpts.Env))
envs := make([]string, 0, len(launchOpts.Env))
for k, v := range launchOpts.Env {
envs = append(envs, fmt.Sprintf("%s=%s", k, v))
}
Expand Down
4 changes: 3 additions & 1 deletion common/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (b *Browser) disposeContext(id cdp.BrowserContextID) error {
func (b *Browser) getPages() []*Page {
b.pagesMu.RLock()
defer b.pagesMu.RUnlock()
pages := make([]*Page, len(b.pages))
pages := make([]*Page, 0, len(b.pages))
for _, p := range b.pages {
pages = append(pages, p)
}
Expand Down Expand Up @@ -359,10 +359,12 @@ func (b *Browser) Close() {
func (b *Browser) Contexts() []api.BrowserContext {
b.contextsMu.RLock()
defer b.contextsMu.RUnlock()

contexts := make([]api.BrowserContext, 0, len(b.contexts))
for _, b := range b.contexts {
contexts = append(contexts, b)
}

return contexts
}

Expand Down
2 changes: 1 addition & 1 deletion common/element_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ func (h *ElementHandle) QueryAll(selector string) []api.ElementHandle {
arrayHandle := result.(api.JSHandle)
defer arrayHandle.Dispose()
properties := arrayHandle.GetProperties()
elements := make([]api.ElementHandle, len(properties))
elements := make([]api.ElementHandle, 0, len(properties))
for _, property := range properties {
elementHandle := property.AsElement()
if elementHandle != nil {
Expand Down
5 changes: 3 additions & 2 deletions common/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,8 @@ func (f *Frame) Check(selector string, opts goja.Value) {
func (f *Frame) ChildFrames() []api.Frame {
f.childFramesMu.RLock()
defer f.childFramesMu.RUnlock()
l := make([]api.Frame, len(f.childFrames))

l := make([]api.Frame, 0, len(f.childFrames))
for child := range f.childFrames {
l = append(l, child)
}
Expand Down Expand Up @@ -1046,7 +1047,7 @@ func (f *Frame) SelectOption(selector string, values goja.Value, opts goja.Value
k6common.Throw(rt, err)
}
properties := arrayHandle.GetProperties()
strArr := make([]string, len(properties))
strArr := make([]string, 0, len(properties))
for _, property := range properties {
strArr = append(strArr, property.JSONValue().String())
property.Dispose()
Expand Down
2 changes: 1 addition & 1 deletion common/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ func (p *Page) WaitForTimeout(timeout int64) {

// Workers returns all WebWorkers of page
func (p *Page) Workers() []api.Worker {
workers := make([]api.Worker, len(p.workers))
workers := make([]api.Worker, 0, len(p.workers))
for _, w := range p.workers {
workers = append(workers, w)
}
Expand Down