JSCFunctionType.defGenericMagic constructor
JSCFunctionType.defGenericMagic(
- JSContext _ctx, {
- JSCFunctionGenericMagicFunction? func,
- bool autoDispose = true,
Implementation
JSCFunctionType.defGenericMagic(
this._ctx, {
JSCFunctionGenericMagicFunction? func,
bool autoDispose = true,
}) {
_cfuncGenericMagicFuncNC = NativeCallable.isolateLocal((
JSContextRef ctx,
JSValue_ thiz,
int argc,
JSValueRef argv,
int magic,
) {
JSValue_ result;
if (func == null) {
_jsValueRef = calloc.call<JSValue_>(sizeOf<JSValue_>());
result = _jsValueRef!.ref;
} else {
result =
func
.call(
JSContext(ctx),
JSValue.ptr(_ctx, thiz),
argv.toList(_ctx, argc),
magic,
)
.ref
.ref;
}
try {
return result;
} finally {
if (_jsValueRef != null && _jsValueRef != nullptr) {
calloc.free(_jsValueRef!);
}
}
});
_ref = calloc.call(sizeOf<JSCFunctionType_>())
..ref.generic_magic = _cfuncGenericMagicFuncNC!.nativeFunction;
attach(calloc.nativeFree, _ref.cast(), autoDispose: autoDispose);
}