NewFunction returns a js function value with given function template New implementation using HandleStore and JS_NewCFunction2 with magic parameter
(fn func(*Context, *Value, []*Value) *Value)
| 702 | // NewFunction returns a js function value with given function template |
| 703 | // New implementation using HandleStore and JS_NewCFunction2 with magic parameter |
| 704 | func (ctx *Context) NewFunction(fn func(*Context, *Value, []*Value) *Value) *Value { |
| 705 | // Store function in HandleStore and get int32 ID |
| 706 | fnID := ctx.handleStore.Store(fn) |
| 707 | |
| 708 | return &Value{ |
| 709 | ctx: ctx, |
| 710 | ref: C.JS_NewCFunction2( |
| 711 | ctx.ref, |
| 712 | (*C.JSCFunction)(unsafe.Pointer(C.GoFunctionProxy)), |
| 713 | nil, // name (can be set later) |
| 714 | 0, // length (auto-detected) |
| 715 | C.JS_CFUNC_generic_magic, // enable magic parameter support |
| 716 | C.int(fnID), // magic parameter passes function ID |
| 717 | ), |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | // Function returns a js function value with given function template |
| 722 | // New implementation using HandleStore and JS_NewCFunction2 with magic parameter |