JSCFunctionType.defGetterMagic constructor

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

Implementation

JSCFunctionType.defGetterMagic(
  this._ctx, {
  JSCFunctionGetterMagicFunction? func,
  bool autoDispose = true,
}) {
  _cfuncGetterMagicFuncNC = NativeCallable.isolateLocal((
    JSContextRef ctx,
    JSValue_ thiz,
    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), magic).ref.ref;
    }
    try {
      return result;
    } finally {
      if (_jsValueRef != null && _jsValueRef != nullptr) {
        calloc.free(_jsValueRef!);
      }
    }
  });
  _ref = calloc.call(sizeOf<JSCFunctionType_>())
    ..ref.getter_magic = _cfuncGetterMagicFuncNC!.nativeFunction;
  attach(calloc.nativeFree, _ref.cast(), autoDispose: autoDispose);
}