mirror of
https://github.com/MontFerret/ferret.git
synced 2025-07-03 00:46:51 +02:00
Feature/pre compiled eval scripts (#658)
* Added support of pre-compiled eval expressions * Added unit tests for eval.Function * Added RemoteType and RemoteObjectType enums * Refactored function generation * Refactored Document and Element loading logic * Removed redundant fields from cdp.Page * Exposed eval.Runtime to external callers * Added new eval.RemoteValue interface
This commit is contained in:
46
pkg/drivers/cdp/eval/function_compiled.go
Normal file
46
pkg/drivers/cdp/eval/function_compiled.go
Normal file
@ -0,0 +1,46 @@
|
||||
package eval
|
||||
|
||||
import "github.com/mafredri/cdp/protocol/runtime"
|
||||
|
||||
type CompiledFunction struct {
|
||||
id runtime.ScriptID
|
||||
src *Function
|
||||
}
|
||||
|
||||
func CF(id runtime.ScriptID, src *Function) *CompiledFunction {
|
||||
op := new(CompiledFunction)
|
||||
op.id = id
|
||||
op.src = src
|
||||
|
||||
return op
|
||||
}
|
||||
|
||||
func (fn *CompiledFunction) returnNothing() *CompiledFunction {
|
||||
fn.src.returnNothing()
|
||||
|
||||
return fn
|
||||
}
|
||||
|
||||
func (fn *CompiledFunction) returnRef() *CompiledFunction {
|
||||
fn.src.returnRef()
|
||||
|
||||
return fn
|
||||
}
|
||||
|
||||
func (fn *CompiledFunction) returnValue() *CompiledFunction {
|
||||
fn.src.returnValue()
|
||||
|
||||
return fn
|
||||
}
|
||||
|
||||
func (fn *CompiledFunction) call(ctx runtime.ExecutionContextID) *runtime.RunScriptArgs {
|
||||
call := runtime.NewRunScriptArgs(fn.id).
|
||||
SetAwaitPromise(fn.src.async).
|
||||
SetReturnByValue(fn.src.returnType == ReturnValue)
|
||||
|
||||
if ctx != EmptyExecutionContextID {
|
||||
call.SetExecutionContextID(ctx)
|
||||
}
|
||||
|
||||
return call
|
||||
}
|
Reference in New Issue
Block a user