MCPcopy Create free account
hub / github.com/buke/quickjs-go / Invoke

Method Invoke

context.go:850–869  ·  view source on GitHub ↗

Invoke invokes a function with given this value and arguments. Deprecated: Use Value.Execute() instead for better API consistency.

(fn *Value, this *Value, args ...*Value)

Source from the content-addressed store, hash-verified

848// Invoke invokes a function with given this value and arguments.
849// Deprecated: Use Value.Execute() instead for better API consistency.
850func (ctx *Context) Invoke(fn *Value, this *Value, args ...*Value) *Value {
851 if ctx == nil || !ctx.hasValidRef() || !fn.belongsTo(ctx) || !this.belongsTo(ctx) {
852 return nil
853 }
854
855 cargs := []C.JSValue{}
856 for _, x := range args {
857 if !x.belongsTo(ctx) {
858 return nil
859 }
860 cargs = append(cargs, x.ref)
861 }
862 var val *Value
863 if len(cargs) == 0 {
864 val = &Value{ctx: ctx, ref: C.JS_Call(ctx.ref, fn.ref, this.ref, 0, nil)}
865 } else {
866 val = &Value{ctx: ctx, ref: C.JS_Call(ctx.ref, fn.ref, this.ref, C.int(len(cargs)), &cargs[0])}
867 }
868 return val
869}
870
871type EvalOptions struct {
872 js_eval_type_global bool

Calls 2

hasValidRefMethod · 0.95
belongsToMethod · 0.80