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)
| 848 | // Invoke invokes a function with given this value and arguments. |
| 849 | // Deprecated: Use Value.Execute() instead for better API consistency. |
| 850 | func (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 | |
| 871 | type EvalOptions struct { |
| 872 | js_eval_type_global bool |