github.com/MontFerret/ferret@v0.18.0/pkg/drivers/cdp/eval/function_compiled.go (about) 1 package eval 2 3 import "github.com/mafredri/cdp/protocol/runtime" 4 5 type CompiledFunction struct { 6 id runtime.ScriptID 7 src *Function 8 } 9 10 func CF(id runtime.ScriptID, src *Function) *CompiledFunction { 11 op := new(CompiledFunction) 12 op.id = id 13 op.src = src 14 15 return op 16 } 17 18 func (fn *CompiledFunction) returnNothing() *CompiledFunction { 19 fn.src.returnNothing() 20 21 return fn 22 } 23 24 func (fn *CompiledFunction) returnRef() *CompiledFunction { 25 fn.src.returnRef() 26 27 return fn 28 } 29 30 func (fn *CompiledFunction) returnValue() *CompiledFunction { 31 fn.src.returnValue() 32 33 return fn 34 } 35 36 func (fn *CompiledFunction) call(ctx runtime.ExecutionContextID) *runtime.RunScriptArgs { 37 call := runtime.NewRunScriptArgs(fn.id). 38 SetAwaitPromise(fn.src.async). 39 SetReturnByValue(fn.src.returnType == ReturnValue) 40 41 if ctx != EmptyExecutionContextID { 42 call.SetExecutionContextID(ctx) 43 } 44 45 return call 46 }