Skip to content

Commit

Permalink
Add temporary assertions for catching goja values
Browse files Browse the repository at this point in the history
This commit is intentionally failing
  • Loading branch information
inancgumus committed Jan 25, 2024
1 parent 9d5f65f commit 4ced96c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions common/execution_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ func (e *ExecutionContext) adoptElementHandle(eh *ElementHandle) (*ElementHandle
func (e *ExecutionContext) eval(
apiCtx context.Context, opts evalOptions, js string, args ...any,
) (any, error) {
if escapesGojaValues(args...) {
return nil, errors.New("goja.Value escaped")
}
e.logger.Debugf(
"ExecutionContext:eval",
"sid:%s stid:%s fid:%s ectxid:%d furl:%q %s",
Expand Down Expand Up @@ -289,6 +292,9 @@ func (e *ExecutionContext) getInjectedScript(apiCtx context.Context) (JSHandleAP
// Eval evaluates the provided JavaScript within this execution context and
// returns a value or handle.
func (e *ExecutionContext) Eval(apiCtx context.Context, js string, args ...any) (any, error) {
if escapesGojaValues(args...) {
return nil, errors.New("goja.Value escaped")
}
opts := evalOptions{
forceCallable: true,
returnByValue: true,
Expand All @@ -303,6 +309,9 @@ func (e *ExecutionContext) Eval(apiCtx context.Context, js string, args ...any)
// EvalHandle evaluates the provided JavaScript within this execution context
// and returns a JSHandle.
func (e *ExecutionContext) EvalHandle(apiCtx context.Context, js string, args ...any) (JSHandleAPI, error) {
if escapesGojaValues(args...) {
return nil, errors.New("goja.Value escaped")
}
opts := evalOptions{
forceCallable: true,
returnByValue: false,
Expand Down
16 changes: 16 additions & 0 deletions common/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common
import (
"context"
"encoding/json"
"errors"
"fmt"
"math"
"time"
Expand Down Expand Up @@ -35,6 +36,9 @@ func convertBaseJSHandleTypes(ctx context.Context, execCtx *ExecutionContext, ob
func convertArgument(
ctx context.Context, execCtx *ExecutionContext, arg any,
) (*cdpruntime.CallArgument, error) {
if escapesGojaValues(arg) {
return nil, errors.New("goja.Value escaped")
}
switch a := arg.(type) {
case int64:
if a > math.MaxInt32 {
Expand Down Expand Up @@ -247,3 +251,15 @@ func convert[T any](from any, to *T) error {
}
return json.Unmarshal(buf, to) //nolint:wrapcheck
}

// TODO:
// remove this temporary helper after ensuring the goja-free
// business logic works.
func escapesGojaValues(args ...any) bool {
for _, arg := range args {
if _, ok := arg.(goja.Value); ok {
return true
}
}
return false
}

0 comments on commit 4ced96c

Please sign in to comment.