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

Method Call

value.go:390–413  ·  view source on GitHub ↗

Call calls the function with the given arguments.

(fname string, args ...*Value)

Source from the content-addressed store, hash-verified

388
389// Call calls the function with the given arguments.
390func (v *Value) Call(fname string, args ...*Value) *Value {
391 if !v.isAlive() {
392 return nil
393 }
394 var fnamePtr *C.char
395 if len(fname) > 0 {
396 fnamePtr = (*C.char)(unsafe.Pointer(unsafe.StringData(fname)))
397 }
398 cargs := []C.JSValue{}
399 for _, x := range args {
400 if !x.belongsTo(v.ctx) {
401 return nil
402 }
403 cargs = append(cargs, x.ref)
404 }
405 var ref C.JSValue
406 if len(cargs) == 0 {
407 ref = C.CallPropertyByNameLen(v.ctx.ref, v.ref, fnamePtr, C.size_t(len(fname)), C.int(0), nil)
408 } else {
409 ref = C.CallPropertyByNameLen(v.ctx.ref, v.ref, fnamePtr, C.size_t(len(fname)), C.int(len(cargs)), &cargs[0])
410 }
411
412 return &Value{ctx: v.ctx, ref: ref}
413}
414
415// Execute the function with the given arguments.
416func (v *Value) Execute(this *Value, args ...*Value) *Value {

Calls 2

isAliveMethod · 0.95
belongsToMethod · 0.80