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

Method Execute

value.go:416–435  ·  view source on GitHub ↗

Execute the function with the given arguments.

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

Source from the content-addressed store, hash-verified

414
415// Execute the function with the given arguments.
416func (v *Value) Execute(this *Value, args ...*Value) *Value {
417 if !v.isAlive() || !this.belongsTo(v.ctx) {
418 return nil
419 }
420 cargs := []C.JSValue{}
421 for _, x := range args {
422 if !x.belongsTo(v.ctx) {
423 return nil
424 }
425 cargs = append(cargs, x.ref)
426 }
427 var val *Value
428 if len(cargs) == 0 {
429 val = &Value{ctx: v.ctx, ref: C.JS_Call(v.ctx.ref, v.ref, this.ref, C.int(0), nil)}
430 } else {
431 val = &Value{ctx: v.ctx, ref: C.JS_Call(v.ctx.ref, v.ref, this.ref, C.int(len(cargs)), &cargs[0])}
432 }
433
434 return val
435}
436
437// New calls the constructor with the given arguments.
438func (v *Value) New(args ...*Value) *Value {

Calls 2

isAliveMethod · 0.95
belongsToMethod · 0.80