JSCFunctionType.defSetter constructor
JSCFunctionType.defSetter(
- JSContext _ctx, {
- JSCFunctionSetterFunction? func,
- bool autoDispose = true,
Implementation
JSCFunctionType.defSetter(
this._ctx, {
JSCFunctionSetterFunction? func,
bool autoDispose = true,
}) {
_cfuncSetterFuncNC = NativeCallable.isolateLocal((
JSContextRef ctx,
JSValue_ thiz,
JSValue_ val,
) {
JSValue_ result;
if (func == null) {
_jsValueRef = calloc.call<JSValue_>(sizeOf<JSValue_>());
result = _jsValueRef!.ref;
} else {
result =
func
.call(
JSContext(ctx),
JSValue.ptr(_ctx, thiz),
JSValue.ptr(_ctx, val),
)
.ref
.ref;
}
try {
return result;
} finally {
if (_jsValueRef != null && _jsValueRef != nullptr) {
calloc.free(_jsValueRef!);
}
}
});
_ref = calloc.call(sizeOf<JSCFunctionType_>())
..ref.setter = _cfuncSetterFuncNC!.nativeFunction;
attach(calloc.nativeFree, _ref.cast(), autoDispose: autoDispose);
}