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

Commit 4350722

Browse files
committed
Update to Goja fork called Sobek
More info in: - grafana/k6#3772 - grafana/k6#3773
1 parent 7cee372 commit 4350722

Some content is hidden

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

68 files changed

+878
-901
lines changed

browser/browser_context_mapping.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"reflect"
66

7-
"github.com/dop251/goja"
7+
"github.com/grafana/sobek"
88

99
"github.com/grafana/xk6-browser/common"
1010
"github.com/grafana/xk6-browser/k6error"
@@ -15,30 +15,30 @@ import (
1515
func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolint:funlen,gocognit,cyclop
1616
rt := vu.Runtime()
1717
return mapping{
18-
"addCookies": func(cookies []*common.Cookie) *goja.Promise {
18+
"addCookies": func(cookies []*common.Cookie) *sobek.Promise {
1919
return k6ext.Promise(vu.Context(), func() (any, error) {
2020
return nil, bc.AddCookies(cookies) //nolint:wrapcheck
2121
})
2222
},
23-
"addInitScript": func(script goja.Value) *goja.Promise {
23+
"addInitScript": func(script sobek.Value) *sobek.Promise {
2424
return k6ext.Promise(vu.Context(), func() (any, error) {
25-
if !gojaValueExists(script) {
25+
if !sobekValueExists(script) {
2626
return nil, nil
2727
}
2828

2929
source := ""
3030
switch script.ExportType() {
3131
case reflect.TypeOf(string("")):
3232
source = script.String()
33-
case reflect.TypeOf(goja.Object{}):
33+
case reflect.TypeOf(sobek.Object{}):
3434
opts := script.ToObject(rt)
3535
for _, k := range opts.Keys() {
3636
if k == "content" {
3737
source = opts.Get(k).String()
3838
}
3939
}
4040
default:
41-
_, isCallable := goja.AssertFunction(script)
41+
_, isCallable := sobek.AssertFunction(script)
4242
if !isCallable {
4343
source = fmt.Sprintf("(%s);", script.ToString().String())
4444
} else {
@@ -53,27 +53,27 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin
5353
// the browser is grabbed from VU.
5454
return mapBrowser(vu)
5555
},
56-
"clearCookies": func() *goja.Promise {
56+
"clearCookies": func() *sobek.Promise {
5757
return k6ext.Promise(vu.Context(), func() (any, error) {
5858
return nil, bc.ClearCookies() //nolint:wrapcheck
5959
})
6060
},
61-
"clearPermissions": func() *goja.Promise {
61+
"clearPermissions": func() *sobek.Promise {
6262
return k6ext.Promise(vu.Context(), func() (any, error) {
6363
return nil, bc.ClearPermissions() //nolint:wrapcheck
6464
})
6565
},
66-
"close": func() *goja.Promise {
66+
"close": func() *sobek.Promise {
6767
return k6ext.Promise(vu.Context(), func() (any, error) {
6868
return nil, bc.Close() //nolint:wrapcheck
6969
})
7070
},
71-
"cookies": func(urls ...string) *goja.Promise {
71+
"cookies": func(urls ...string) *sobek.Promise {
7272
return k6ext.Promise(vu.Context(), func() (any, error) {
7373
return bc.Cookies(urls...) //nolint:wrapcheck
7474
})
7575
},
76-
"grantPermissions": func(permissions []string, opts goja.Value) *goja.Promise {
76+
"grantPermissions": func(permissions []string, opts sobek.Value) *sobek.Promise {
7777
return k6ext.Promise(vu.Context(), func() (any, error) {
7878
popts := common.NewGrantPermissionsOptions()
7979
popts.Parse(vu.Context(), opts)
@@ -83,22 +83,22 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin
8383
},
8484
"setDefaultNavigationTimeout": bc.SetDefaultNavigationTimeout,
8585
"setDefaultTimeout": bc.SetDefaultTimeout,
86-
"setGeolocation": func(geolocation goja.Value) *goja.Promise {
86+
"setGeolocation": func(geolocation sobek.Value) *sobek.Promise {
8787
return k6ext.Promise(vu.Context(), func() (any, error) {
8888
return nil, bc.SetGeolocation(geolocation) //nolint:wrapcheck
8989
})
9090
},
91-
"setHTTPCredentials": func(httpCredentials goja.Value) *goja.Promise {
91+
"setHTTPCredentials": func(httpCredentials sobek.Value) *sobek.Promise {
9292
return k6ext.Promise(vu.Context(), func() (any, error) {
9393
return nil, bc.SetHTTPCredentials(httpCredentials) //nolint:staticcheck,wrapcheck
9494
})
9595
},
96-
"setOffline": func(offline bool) *goja.Promise {
96+
"setOffline": func(offline bool) *sobek.Promise {
9797
return k6ext.Promise(vu.Context(), func() (any, error) {
9898
return nil, bc.SetOffline(offline) //nolint:wrapcheck
9999
})
100100
},
101-
"waitForEvent": func(event string, optsOrPredicate goja.Value) (*goja.Promise, error) {
101+
"waitForEvent": func(event string, optsOrPredicate sobek.Value) (*sobek.Promise, error) {
102102
ctx := vu.Context()
103103
popts := common.NewWaitForEventOptions(
104104
bc.Timeout(),
@@ -120,7 +120,7 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin
120120
// before returning the result to the caller.
121121
c := make(chan bool)
122122
tq.Queue(func() error {
123-
var resp goja.Value
123+
var resp sobek.Value
124124
resp, err = popts.PredicateFn(vu.Runtime().ToValue(p))
125125
rtn = resp.ToBoolean()
126126
close(c)
@@ -145,7 +145,7 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin
145145
return mapPage(vu, p), nil
146146
}), nil
147147
},
148-
"pages": func() *goja.Object {
148+
"pages": func() *sobek.Object {
149149
var (
150150
mpages []mapping
151151
pages = bc.Pages()
@@ -160,7 +160,7 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin
160160

161161
return rt.ToValue(mpages).ToObject(rt)
162162
},
163-
"newPage": func() *goja.Promise {
163+
"newPage": func() *sobek.Promise {
164164
return k6ext.Promise(vu.Context(), func() (any, error) {
165165
page, err := bc.NewPage()
166166
if err != nil {

browser/browser_mapping.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package browser
33
import (
44
"fmt"
55

6-
"github.com/dop251/goja"
6+
"github.com/grafana/sobek"
77

88
"github.com/grafana/xk6-browser/common"
99
"github.com/grafana/xk6-browser/k6ext"
@@ -19,7 +19,7 @@ func mapBrowser(vu moduleVU) mapping { //nolint:funlen,cyclop
1919
}
2020
return mapBrowserContext(vu, b.Context()), nil
2121
},
22-
"closeContext": func() *goja.Promise {
22+
"closeContext": func() *sobek.Promise {
2323
return k6ext.Promise(vu.Context(), func() (any, error) {
2424
b, err := vu.browser()
2525
if err != nil {
@@ -35,7 +35,7 @@ func mapBrowser(vu moduleVU) mapping { //nolint:funlen,cyclop
3535
}
3636
return b.IsConnected(), nil
3737
},
38-
"newContext": func(opts goja.Value) (*goja.Promise, error) {
38+
"newContext": func(opts sobek.Value) (*sobek.Promise, error) {
3939
return k6ext.Promise(vu.Context(), func() (any, error) {
4040
b, err := vu.browser()
4141
if err != nil {
@@ -69,7 +69,7 @@ func mapBrowser(vu moduleVU) mapping { //nolint:funlen,cyclop
6969
}
7070
return b.Version(), nil
7171
},
72-
"newPage": func(opts goja.Value) *goja.Promise {
72+
"newPage": func(opts sobek.Value) *sobek.Promise {
7373
return k6ext.Promise(vu.Context(), func() (any, error) {
7474
b, err := vu.browser()
7575
if err != nil {

browser/console_message_mapping.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package browser
22

33
import (
4-
"github.com/dop251/goja"
4+
"github.com/grafana/sobek"
55

66
"github.com/grafana/xk6-browser/common"
77
)
@@ -10,7 +10,7 @@ import (
1010
func mapConsoleMessage(vu moduleVU, cm *common.ConsoleMessage) mapping {
1111
rt := vu.Runtime()
1212
return mapping{
13-
"args": func() *goja.Object {
13+
"args": func() *sobek.Object {
1414
var (
1515
margs []mapping
1616
args = cm.Args
@@ -24,14 +24,14 @@ func mapConsoleMessage(vu moduleVU, cm *common.ConsoleMessage) mapping {
2424
},
2525
// page(), text() and type() are defined as
2626
// functions in order to match Playwright's API
27-
"page": func() *goja.Object {
27+
"page": func() *sobek.Object {
2828
mp := mapPage(vu, cm.Page)
2929
return rt.ToValue(mp).ToObject(rt)
3030
},
31-
"text": func() *goja.Object {
31+
"text": func() *sobek.Object {
3232
return rt.ToValue(cm.Text).ToObject(rt)
3333
},
34-
"type": func() *goja.Object {
34+
"type": func() *sobek.Object {
3535
return rt.ToValue(cm.Type).ToObject(rt)
3636
},
3737
}

0 commit comments

Comments
 (0)