Skip to content

Commit d2aa790

Browse files
authored
chore: maintain StorageState type (#583)
1 parent fcd06e1 commit d2aa790

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+992
-1006
lines changed

apiresponse_assertions.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ func subString(s string, start, length int) string {
6767
length = 0
6868
}
6969
rs := []rune(s)
70-
end := start + length
71-
if end > len(rs) {
72-
end = len(rs)
73-
}
70+
end := min(start+length, len(rs))
7471
return string(rs[start:end])
7572
}

artifact.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (a *artifactImpl) PathAfterFinished() (string, error) {
2323

2424
func (a *artifactImpl) SaveAs(path string) error {
2525
if !a.connection.isRemote {
26-
_, err := a.channel.Send("saveAs", map[string]interface{}{
26+
_, err := a.channel.Send("saveAs", map[string]any{
2727
"path": path,
2828
})
2929
return err
@@ -63,7 +63,7 @@ func (a *artifactImpl) ReadIntoBuffer() ([]byte, error) {
6363
return stream.(*streamImpl).ReadAll()
6464
}
6565

66-
func newArtifact(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *artifactImpl {
66+
func newArtifact(parent *channelOwner, objectType string, guid string, initializer map[string]any) *artifactImpl {
6767
artifact := &artifactImpl{}
6868
artifact.createChannelOwner(artifact, parent, objectType, guid, initializer)
6969
return artifact

assertions.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,20 @@ type expectedTextValue struct {
4545
}
4646

4747
type frameExpectOptions struct {
48-
ExpressionArg interface{} `json:"expressionArg,omitempty"`
48+
ExpressionArg any `json:"expressionArg,omitempty"`
4949
ExpectedText []expectedTextValue `json:"expectedText,omitempty"`
5050
ExpectedNumber *float64 `json:"expectedNumber,omitempty"`
51-
ExpectedValue interface{} `json:"expectedValue,omitempty"`
51+
ExpectedValue any `json:"expectedValue,omitempty"`
5252
UseInnerText *bool `json:"useInnerText,omitempty"`
5353
IsNot bool `json:"isNot"`
5454
Timeout *float64 `json:"timeout"`
5555
}
5656

5757
type frameExpectResult struct {
58-
Matches bool `json:"matches"`
59-
Received interface{} `json:"received,omitempty"`
60-
TimedOut *bool `json:"timedOut,omitempty"`
61-
Log []string `json:"log,omitempty"`
58+
Matches bool `json:"matches"`
59+
Received any `json:"received,omitempty"`
60+
TimedOut *bool `json:"timedOut,omitempty"`
61+
Log []string `json:"log,omitempty"`
6262
}
6363

6464
type assertionsBase struct {
@@ -70,7 +70,7 @@ type assertionsBase struct {
7070
func (b *assertionsBase) expect(
7171
expression string,
7272
options frameExpectOptions,
73-
expected interface{},
73+
expected any,
7474
message string,
7575
) error {
7676
options.IsNot = b.isNot
@@ -101,7 +101,7 @@ func (b *assertionsBase) expect(
101101
}
102102

103103
func toExpectedTextValues(
104-
items []interface{},
104+
items []any,
105105
matchSubstring bool,
106106
normalizeWhiteSpace bool,
107107
ignoreCase *bool,
@@ -132,13 +132,13 @@ func toExpectedTextValues(
132132
return out, nil
133133
}
134134

135-
func convertToInterfaceList(v interface{}) []interface{} {
135+
func convertToInterfaceList(v any) []any {
136136
rv := reflect.ValueOf(v)
137137
if rv.Kind() != reflect.Slice {
138-
return []interface{}{v}
138+
return []any{v}
139139
}
140140

141-
list := make([]interface{}, rv.Len())
141+
list := make([]any, rv.Len())
142142
for i := 0; i < rv.Len(); i++ {
143143
list[i] = rv.Index(i).Interface()
144144
}

binding_call.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ type BindingSource struct {
2323
}
2424

2525
// ExposedFunction represents the func signature of an exposed function
26-
type ExposedFunction = func(args ...interface{}) interface{}
26+
type ExposedFunction = func(args ...any) any
2727

2828
// BindingCallFunction represents the func signature of an exposed binding call func
29-
type BindingCallFunction func(source *BindingSource, args ...interface{}) interface{}
29+
type BindingCallFunction func(source *BindingSource, args ...any) any
3030

3131
func (b *bindingCallImpl) Call(f BindingCallFunction) {
3232
defer func() {
3333
if r := recover(); r != nil {
34-
if _, err := b.channel.Send("reject", map[string]interface{}{
34+
if _, err := b.channel.Send("reject", map[string]any{
3535
"error": serializeError(r.(error)),
3636
}); err != nil {
3737
logger.Error("could not reject BindingCall", "error", err)
@@ -45,31 +45,31 @@ func (b *bindingCallImpl) Call(f BindingCallFunction) {
4545
Page: frame.Page(),
4646
Frame: frame,
4747
}
48-
var result interface{}
48+
var result any
4949
if handle, ok := b.initializer["handle"]; ok {
5050
result = f(source, fromChannel(handle))
5151
} else {
52-
initializerArgs := b.initializer["args"].([]interface{})
53-
funcArgs := []interface{}{}
54-
for i := 0; i < len(initializerArgs); i++ {
52+
initializerArgs := b.initializer["args"].([]any)
53+
funcArgs := []any{}
54+
for i := range initializerArgs {
5555
funcArgs = append(funcArgs, parseResult(initializerArgs[i]))
5656
}
5757
result = f(source, funcArgs...)
5858
}
59-
_, err := b.channel.Send("resolve", map[string]interface{}{
59+
_, err := b.channel.Send("resolve", map[string]any{
6060
"result": serializeArgument(result),
6161
})
6262
if err != nil {
6363
logger.Error("could not resolve BindingCall", "error", err)
6464
}
6565
}
6666

67-
func serializeError(err error) map[string]interface{} {
67+
func serializeError(err error) map[string]any {
6868
st := stack.Trace().TrimRuntime()
6969
if len(st) == 0 { // https://github.com/go-stack/stack/issues/27
7070
st = stack.Trace()
7171
}
72-
return map[string]interface{}{
72+
return map[string]any{
7373
"error": &Error{
7474
Name: "Playwright for Go Error",
7575
Message: err.Error(),
@@ -80,7 +80,7 @@ func serializeError(err error) map[string]interface{} {
8080
}
8181
}
8282

83-
func newBindingCall(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *bindingCallImpl {
83+
func newBindingCall(parent *channelOwner, objectType string, guid string, initializer map[string]any) *bindingCallImpl {
8484
bt := &bindingCallImpl{}
8585
bt.createChannelOwner(bt, parent, objectType, guid, initializer)
8686
return bt

browser.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (b *browserImpl) IsConnected() bool {
3030
}
3131

3232
func (b *browserImpl) NewContext(options ...BrowserNewContextOptions) (BrowserContext, error) {
33-
overrides := map[string]interface{}{}
33+
overrides := map[string]any{}
3434
option := BrowserNewContextOptions{}
3535
if len(options) == 1 {
3636
option = options[0]
@@ -142,7 +142,7 @@ func (b *browserImpl) Close(options ...BrowserCloseOptions) (err error) {
142142
if b.shouldCloseConnectionOnClose {
143143
err = b.connection.Stop()
144144
} else if b.closeReason != nil {
145-
_, err = b.channel.Send("close", map[string]interface{}{
145+
_, err = b.channel.Send("close", map[string]any{
146146
"reason": b.closeReason,
147147
})
148148
} else {
@@ -159,7 +159,7 @@ func (b *browserImpl) Version() string {
159159
}
160160

161161
func (b *browserImpl) StartTracing(options ...BrowserStartTracingOptions) error {
162-
overrides := map[string]interface{}{}
162+
overrides := map[string]any{}
163163
option := BrowserStartTracingOptions{}
164164
if len(options) == 1 {
165165
option = options[0]
@@ -218,7 +218,7 @@ func (b *browserImpl) OnDisconnected(fn func(Browser)) {
218218
b.On("disconnected", fn)
219219
}
220220

221-
func newBrowser(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *browserImpl {
221+
func newBrowser(parent *channelOwner, objectType string, guid string, initializer map[string]any) *browserImpl {
222222
b := &browserImpl{
223223
isConnected: true,
224224
contexts: make([]BrowserContext, 0),
@@ -230,11 +230,11 @@ func newBrowser(parent *channelOwner, objectType string, guid string, initialize
230230
return b
231231
}
232232

233-
func transformClientCertificate(clientCertificates []ClientCertificate) ([]map[string]interface{}, error) {
234-
results := make([]map[string]interface{}, 0)
233+
func transformClientCertificate(clientCertificates []ClientCertificate) ([]map[string]any, error) {
234+
results := make([]map[string]any, 0)
235235

236236
for _, cert := range clientCertificates {
237-
data := map[string]interface{}{
237+
data := map[string]any{
238238
"origin": cert.Origin,
239239
"passphrase": cert.Passphrase,
240240
}

0 commit comments

Comments
 (0)