JSCFunctionType.defGetter constructor

JSCFunctionType.defGetter(
  1. JSContext _ctx, {
  2. JSCFunctionGetterFunction? func,
  3. bool autoDispose = true,
})

Implementation

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