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

Commit 135776b

Browse files
committed
Add executionWorld type
1 parent 0f56fbc commit 135776b

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

common/execution_context.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ const evaluationScriptURL = "__xk6_browser_evaluation_script__"
3838

3939
var sourceURLRegex = regexp.MustCompile(`^(?s)[\040\t]*//[@#] sourceURL=\s*(\S*?)\s*$`)
4040

41+
type executionWorld string
42+
4143
const (
42-
mainWorld = "main"
43-
utilityWorld = "utility"
44+
mainWorld executionWorld = "main"
45+
utilityWorld executionWorld = "utility"
4446
)
4547

4648
type evaluateOptions struct {

common/frame.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func (f *Frame) document() (*ElementHandle, error) {
337337
return f.documentHandle, err
338338
}
339339

340-
func (f *Frame) hasContext(world string) bool {
340+
func (f *Frame) hasContext(world executionWorld) bool {
341341
f.executionContextMu.RLock()
342342
defer f.executionContextMu.RUnlock()
343343

@@ -443,7 +443,7 @@ func (f *Frame) requestByID(reqID network.RequestID) *Request {
443443
return frameSession.networkManager.requestFromID(reqID)
444444
}
445445

446-
func (f *Frame) setContext(world string, execCtx frameExecutionContext) {
446+
func (f *Frame) setContext(world executionWorld, execCtx frameExecutionContext) {
447447
f.executionContextMu.Lock()
448448
defer f.executionContextMu.Unlock()
449449

@@ -472,7 +472,7 @@ func (f *Frame) setID(id cdp.FrameID) {
472472
f.id = id
473473
}
474474

475-
func (f *Frame) waitForExecutionContext(world string) {
475+
func (f *Frame) waitForExecutionContext(world executionWorld) {
476476
f.log.Debugf("Frame:waitForExecutionContext", "fid:%s furl:%q world:%s",
477477
f.ID(), f.URL(), world)
478478

@@ -490,7 +490,7 @@ func (f *Frame) waitForExecutionContext(world string) {
490490
}
491491
}
492492

493-
func (f *Frame) waitForFunction(apiCtx context.Context, world string, predicateFn goja.Value, polling PollingType, interval int64, timeout time.Duration, args ...goja.Value) (interface{}, error) {
493+
func (f *Frame) waitForFunction(apiCtx context.Context, world executionWorld, predicateFn goja.Value, polling PollingType, interval int64, timeout time.Duration, args ...goja.Value) (interface{}, error) {
494494
f.log.Debugf(
495495
"Frame:waitForFunction",
496496
"fid:%s furl:%q world:%s pt:%s timeout:%s",
@@ -1434,15 +1434,15 @@ func (f *Frame) WaitForTimeout(timeout int64) {
14341434
}
14351435
}
14361436

1437-
func (f *Frame) adoptBackendNodeID(world string, id cdp.BackendNodeID) (*ElementHandle, error) {
1437+
func (f *Frame) adoptBackendNodeID(world executionWorld, id cdp.BackendNodeID) (*ElementHandle, error) {
14381438
f.executionContextMu.RLock()
14391439
defer f.executionContextMu.RUnlock()
14401440

14411441
ec := f.getExecCtx(world)
14421442
return ec.adoptBackendNodeID(id)
14431443
}
14441444

1445-
func (f *Frame) evaluate(world string, apiCtx context.Context, opts evaluateOptions, pageFunc goja.Value, args ...goja.Value) (res interface{}, err error) {
1445+
func (f *Frame) evaluate(world executionWorld, apiCtx context.Context, opts evaluateOptions, pageFunc goja.Value, args ...goja.Value) (res interface{}, err error) {
14461446
f.executionContextMu.RLock()
14471447
defer f.executionContextMu.RUnlock()
14481448

@@ -1452,7 +1452,7 @@ func (f *Frame) evaluate(world string, apiCtx context.Context, opts evaluateOpti
14521452

14531453
// getExecCtx returns an execution context using a given world name.
14541454
// Unsafe to use concurrently.
1455-
func (f *Frame) getExecCtx(world string) frameExecutionContext {
1455+
func (f *Frame) getExecCtx(world executionWorld) frameExecutionContext {
14561456
ec := f.mainExecutionContext
14571457
if world == utilityWorld {
14581458
ec = f.utilityExecutionContext

common/frame_session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ func (fs *FrameSession) onExecutionContextCreated(event *runtime.EventExecutionC
549549
if err := json.Unmarshal(auxData, &i); err != nil {
550550
k6Throw(fs.ctx, "unable to unmarshal JSON: %w", err)
551551
}
552-
var world string = ""
552+
var world executionWorld
553553
frame := fs.manager.getFrameByID(i.FrameID)
554554
if frame != nil {
555555
if i.IsDefault {

0 commit comments

Comments
 (0)