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

Commit 6987036

Browse files
committed
Rename evaluate to eval in ExecutionContext
ExecutionContext: Evaluate -> Eval EvaluateHandle -> EvalHandle evaluate -> eval evaluateOptions -> evalOptions Resolves: #196 (comment)
1 parent 019f8ec commit 6987036

File tree

7 files changed

+63
-64
lines changed

7 files changed

+63
-64
lines changed

common/element_handle.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func (h *ElementHandle) checkHitTargetAt(apiCtx context.Context, point Position)
231231
return injected.checkHitTargetAt(node, point);
232232
}
233233
`
234-
opts := evaluateOptions{
234+
opts := evalOptions{
235235
forceCallable: true,
236236
returnByValue: true,
237237
}
@@ -257,7 +257,7 @@ func (h *ElementHandle) checkElementState(apiCtx context.Context, state string)
257257
return injected.checkElementState(node, state);
258258
}
259259
`
260-
opts := evaluateOptions{
260+
opts := evalOptions{
261261
forceCallable: true,
262262
returnByValue: true,
263263
}
@@ -378,7 +378,7 @@ func (h *ElementHandle) dispatchEvent(apiCtx context.Context, typ string, eventI
378378
injected.dispatchEvent(node, type, eventInit);
379379
}
380380
`
381-
opts := evaluateOptions{
381+
opts := evalOptions{
382382
forceCallable: true,
383383
returnByValue: true,
384384
}
@@ -392,7 +392,7 @@ func (h *ElementHandle) fill(apiCtx context.Context, value string) (interface{},
392392
return injected.fill(node, value);
393393
}
394394
`
395-
opts := evaluateOptions{
395+
opts := evalOptions{
396396
forceCallable: true,
397397
returnByValue: true,
398398
}
@@ -415,7 +415,7 @@ func (h *ElementHandle) focus(apiCtx context.Context, resetSelectionIfNotFocused
415415
return injected.focusNode(node, resetSelectionIfNotFocused);
416416
}
417417
`
418-
opts := evaluateOptions{
418+
opts := evalOptions{
419419
forceCallable: true,
420420
returnByValue: true,
421421
}
@@ -438,7 +438,7 @@ func (h *ElementHandle) getAttribute(apiCtx context.Context, name string) (inter
438438
return element.getAttribute('` + name + `');
439439
}
440440
`
441-
opts := evaluateOptions{
441+
opts := evalOptions{
442442
forceCallable: true,
443443
returnByValue: true,
444444
}
@@ -455,7 +455,7 @@ func (h *ElementHandle) innerHTML(apiCtx context.Context) (interface{}, error) {
455455
return element.innerHTML;
456456
}
457457
`
458-
opts := evaluateOptions{
458+
opts := evalOptions{
459459
forceCallable: true,
460460
returnByValue: true,
461461
}
@@ -468,7 +468,7 @@ func (h *ElementHandle) innerText(apiCtx context.Context) (interface{}, error) {
468468
return element.innerText;
469469
}
470470
`
471-
opts := evaluateOptions{
471+
opts := evalOptions{
472472
forceCallable: true,
473473
returnByValue: true,
474474
}
@@ -484,7 +484,7 @@ func (h *ElementHandle) inputValue(apiCtx context.Context) (interface{}, error)
484484
return element.value;
485485
}
486486
`
487-
opts := evaluateOptions{
487+
opts := evalOptions{
488488
forceCallable: true,
489489
returnByValue: true,
490490
}
@@ -521,7 +521,7 @@ func (h *ElementHandle) offsetPosition(apiCtx context.Context, offset *Position)
521521
return injected.getElementBorderWidth(node);
522522
}
523523
`
524-
opts := evaluateOptions{
524+
opts := evalOptions{
525525
forceCallable: true,
526526
returnByValue: true,
527527
}
@@ -685,7 +685,7 @@ func (h *ElementHandle) selectOption(apiCtx context.Context, values goja.Value)
685685
return injected.selectOptions(node, values);
686686
}
687687
`
688-
opts := evaluateOptions{
688+
opts := evalOptions{
689689
forceCallable: true,
690690
returnByValue: false,
691691
}
@@ -708,7 +708,7 @@ func (h *ElementHandle) selectText(apiCtx context.Context) error {
708708
return injected.selectText(node);
709709
}
710710
`
711-
opts := evaluateOptions{
711+
opts := evalOptions{
712712
forceCallable: true,
713713
returnByValue: true,
714714
}
@@ -760,7 +760,7 @@ func (h *ElementHandle) textContent(apiCtx context.Context) (interface{}, error)
760760
return element.textContent;
761761
}
762762
`
763-
opts := evaluateOptions{
763+
opts := evalOptions{
764764
forceCallable: true,
765765
returnByValue: true,
766766
}
@@ -787,7 +787,7 @@ func (h *ElementHandle) waitAndScrollIntoViewIfNeeded(apiCtx context.Context, fo
787787
return [window.scrollX, window.scrollY];
788788
}
789789
`
790-
opts := evaluateOptions{
790+
opts := evalOptions{
791791
forceCallable: true,
792792
returnByValue: true,
793793
}
@@ -807,7 +807,7 @@ func (h *ElementHandle) waitForElementState(apiCtx context.Context, states []str
807807
return injected.waitForElementStates(node, states, timeout);
808808
}
809809
`
810-
opts := evaluateOptions{
810+
opts := evalOptions{
811811
forceCallable: true,
812812
returnByValue: true,
813813
}
@@ -839,7 +839,7 @@ func (h *ElementHandle) waitForSelector(apiCtx context.Context, selector string,
839839
return injected.waitForSelector(selector, node, strict, state, 'raf', timeout, ...args);
840840
}
841841
`
842-
eopts := evaluateOptions{
842+
eopts := evalOptions{
843843
forceCallable: true,
844844
returnByValue: false,
845845
}
@@ -1111,7 +1111,7 @@ func (h *ElementHandle) OwnerFrame() api.Frame {
11111111
return injected.getDocumentElement(node);
11121112
}
11131113
`
1114-
opts := evaluateOptions{
1114+
opts := evalOptions{
11151115
forceCallable: true,
11161116
returnByValue: false,
11171117
}
@@ -1167,7 +1167,7 @@ func (h *ElementHandle) Query(selector string) api.ElementHandle {
11671167
return injected.querySelector(selector, node || document, false);
11681168
}
11691169
`
1170-
opts := evaluateOptions{
1170+
opts := evalOptions{
11711171
forceCallable: true,
11721172
returnByValue: false,
11731173
}
@@ -1203,7 +1203,7 @@ func (h *ElementHandle) QueryAll(selector string) []api.ElementHandle {
12031203
return injected.querySelectorAll(selector, node || document, false);
12041204
}
12051205
`
1206-
opts := evaluateOptions{
1206+
opts := evalOptions{
12071207
forceCallable: true,
12081208
returnByValue: false,
12091209
}
@@ -1402,7 +1402,7 @@ func (h *ElementHandle) WaitForSelector(selector string, opts goja.Value) api.El
14021402
// The js code can call helper functions from injected_script.js.
14031403
func (h *ElementHandle) evalWithScript(
14041404
ctx context.Context,
1405-
opts evaluateOptions, js string, args ...interface{},
1405+
opts evalOptions, js string, args ...interface{},
14061406
) (interface{}, error) {
14071407
script, err := h.execCtx.getInjectedScript(h.ctx)
14081408
if err != nil {
@@ -1415,7 +1415,7 @@ func (h *ElementHandle) evalWithScript(
14151415
// eval evaluates the given js code in the scope of this ElementHandle and returns the result.
14161416
func (h *ElementHandle) eval(
14171417
ctx context.Context,
1418-
opts evaluateOptions, js string, args ...interface{},
1418+
opts evalOptions, js string, args ...interface{},
14191419
) (interface{}, error) {
14201420
// passing `h` makes it evaluate js code in the element handle's scope.
14211421
args = append([]interface{}{h}, args...)
@@ -1424,7 +1424,7 @@ func (h *ElementHandle) eval(
14241424
for i, arg := range args {
14251425
gargs[i] = rt.ToValue(arg)
14261426
}
1427-
result, err := h.execCtx.evaluate(ctx, opts, rt.ToValue(js), gargs...)
1427+
result, err := h.execCtx.eval(ctx, opts, rt.ToValue(js), gargs...)
14281428
if err != nil {
14291429
err = fmt.Errorf("element handle cannot evaluate: %w", err)
14301430
}

common/execution_context.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ func (ew executionWorld) valid() bool {
4949
return ew == mainWorld || ew == utilityWorld
5050
}
5151

52-
type evaluateOptions struct {
52+
type evalOptions struct {
5353
forceCallable, returnByValue bool
5454
}
5555

56-
func (ea evaluateOptions) String() string {
56+
func (ea evalOptions) String() string {
5757
return fmt.Sprintf("forceCallable:%t returnByValue:%t", ea.forceCallable, ea.returnByValue)
5858
}
5959

@@ -162,11 +162,10 @@ func (e *ExecutionContext) adoptElementHandle(eh *ElementHandle) (*ElementHandle
162162
return e.adoptBackendNodeID(node.BackendNodeID)
163163
}
164164

165-
// evaluate will evaluate provided callable within this execution context
166-
// and return by value or handle
167-
func (e *ExecutionContext) evaluate(
165+
// eval will evaluate provided callable within this execution context and return by value or handle.
166+
func (e *ExecutionContext) eval(
168167
apiCtx context.Context,
169-
opts evaluateOptions, pageFunc goja.Value, args ...goja.Value,
168+
opts evalOptions, pageFunc goja.Value, args ...goja.Value,
170169
) (res interface{}, err error) {
171170
e.logger.Debugf(
172171
"ExecutionContext:evaluate",
@@ -290,11 +289,11 @@ func (e *ExecutionContext) getInjectedScript(apiCtx context.Context) (api.JSHand
290289
expressionWithSourceURL = expression + "\n" + suffix
291290
}
292291

293-
opts := evaluateOptions{
292+
opts := evalOptions{
294293
forceCallable: false,
295294
returnByValue: false,
296295
}
297-
handle, err := e.evaluate(apiCtx, opts, rt.ToValue(expressionWithSourceURL))
296+
handle, err := e.eval(apiCtx, opts, rt.ToValue(expressionWithSourceURL))
298297
if handle == nil || err != nil {
299298
return nil, fmt.Errorf("cannot get injected script (%q): %w", suffix, err)
300299
}
@@ -303,28 +302,28 @@ func (e *ExecutionContext) getInjectedScript(apiCtx context.Context) (api.JSHand
303302
return e.injectedScript, nil
304303
}
305304

306-
// Evaluate will evaluate provided page function within this execution context
307-
func (e *ExecutionContext) Evaluate(
305+
// Eval will evaluate provided page function within this execution context
306+
func (e *ExecutionContext) Eval(
308307
apiCtx context.Context,
309308
pageFunc goja.Value, args ...goja.Value,
310309
) (interface{}, error) {
311-
opts := evaluateOptions{
310+
opts := evalOptions{
312311
forceCallable: true,
313312
returnByValue: true,
314313
}
315-
return e.evaluate(apiCtx, opts, pageFunc, args...)
314+
return e.eval(apiCtx, opts, pageFunc, args...)
316315
}
317316

318-
// EvaluateHandle will evaluate provided page function within this execution context
319-
func (e *ExecutionContext) EvaluateHandle(
317+
// EvalHandle will evaluate provided page function within this execution context
318+
func (e *ExecutionContext) EvalHandle(
320319
apiCtx context.Context,
321320
pageFunc goja.Value, args ...goja.Value,
322321
) (api.JSHandle, error) {
323-
opts := evaluateOptions{
322+
opts := evalOptions{
324323
forceCallable: true,
325324
returnByValue: false,
326325
}
327-
res, err := e.evaluate(apiCtx, opts, pageFunc, args...)
326+
res, err := e.eval(apiCtx, opts, pageFunc, args...)
328327
if err != nil {
329328
return nil, err
330329
}

common/frame.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ func (f *Frame) document() (*ElementHandle, error) {
321321

322322
f.waitForExecutionContext(mainWorld)
323323

324-
opts := evaluateOptions{
324+
opts := evalOptions{
325325
forceCallable: false,
326326
returnByValue: false,
327327
}
@@ -531,11 +531,11 @@ func (f *Frame) waitForFunction(
531531
} else {
532532
predicate = fmt.Sprintf("return (%s)(...args);", predicateFn.ToString().String())
533533
}
534-
opts := evaluateOptions{
534+
opts := evalOptions{
535535
forceCallable: true,
536536
returnByValue: false,
537537
}
538-
result, err := execCtx.evaluate(
538+
result, err := execCtx.eval(
539539
apiCtx, opts, pageFn, append([]goja.Value{
540540
rt.ToValue(injected),
541541
rt.ToValue(predicate),
@@ -721,7 +721,7 @@ func (f *Frame) Evaluate(pageFunc goja.Value, args ...goja.Value) interface{} {
721721

722722
f.waitForExecutionContext(mainWorld)
723723

724-
opts := evaluateOptions{
724+
opts := evalOptions{
725725
forceCallable: true,
726726
returnByValue: true,
727727
}
@@ -750,7 +750,7 @@ func (f *Frame) EvaluateHandle(pageFunc goja.Value, args ...goja.Value) (handle
750750
if ec == nil {
751751
k6common.Throw(rt, fmt.Errorf("cannot find execution context: %q", mainWorld))
752752
}
753-
handle, err = ec.EvaluateHandle(f.ctx, pageFunc, args...)
753+
handle, err = ec.EvalHandle(f.ctx, pageFunc, args...)
754754
}
755755
f.executionContextMu.RUnlock()
756756
if err != nil {
@@ -1245,7 +1245,7 @@ func (f *Frame) SetContent(html string, opts goja.Value) {
12451245

12461246
f.waitForExecutionContext(utilityWorld)
12471247

1248-
eopts := evaluateOptions{
1248+
eopts := evalOptions{
12491249
forceCallable: true,
12501250
returnByValue: true,
12511251
}
@@ -1474,7 +1474,7 @@ func (f *Frame) adoptBackendNodeID(world executionWorld, id cdp.BackendNodeID) (
14741474
func (f *Frame) evaluate(
14751475
apiCtx context.Context,
14761476
world executionWorld,
1477-
opts evaluateOptions, pageFunc goja.Value, args ...goja.Value,
1477+
opts evalOptions, pageFunc goja.Value, args ...goja.Value,
14781478
) (interface{}, error) {
14791479
f.log.Debugf("Frame:evaluate", "fid:%s furl:%q world:%s opts:%s", f.ID(), f.URL(), world, opts)
14801480

@@ -1485,7 +1485,7 @@ func (f *Frame) evaluate(
14851485
if ec == nil {
14861486
return nil, fmt.Errorf("cannot find execution context: %q", world)
14871487
}
1488-
eh, err := ec.evaluate(apiCtx, opts, pageFunc, args...)
1488+
eh, err := ec.eval(apiCtx, opts, pageFunc, args...)
14891489
if err != nil {
14901490
return nil, fmt.Errorf("frame cannot evaluate: %w", err)
14911491
}
@@ -1502,28 +1502,28 @@ type frameExecutionContext interface {
15021502
// execution context from another execution context.
15031503
adoptElementHandle(elementHandle *ElementHandle) (*ElementHandle, error)
15041504

1505-
// evaluate will evaluate provided callable within this execution
1505+
// eval will evaluate provided callable within this execution
15061506
// context and return by value or handle.
1507-
evaluate(
1507+
eval(
15081508
apiCtx context.Context,
1509-
opts evaluateOptions,
1509+
opts evalOptions,
15101510
pageFunc goja.Value, args ...goja.Value,
15111511
) (res interface{}, err error)
15121512

15131513
// getInjectedScript returns a JS handle to the injected script of helper
15141514
// functions.
15151515
getInjectedScript(apiCtx context.Context) (api.JSHandle, error)
15161516

1517-
// Evaluate will evaluate provided page function within this execution
1517+
// Eval will evaluate provided page function within this execution
15181518
// context.
1519-
Evaluate(
1519+
Eval(
15201520
apiCtx context.Context,
15211521
pageFunc goja.Value, args ...goja.Value,
15221522
) (interface{}, error)
15231523

1524-
// EvaluateHandle will evaluate provided page function within this
1524+
// EvalHandle will evaluate provided page function within this
15251525
// execution context.
1526-
EvaluateHandle(
1526+
EvalHandle(
15271527
apiCtx context.Context,
15281528
pageFunc goja.Value, args ...goja.Value,
15291529
) (api.JSHandle, error)

0 commit comments

Comments
 (0)