asyncInvokeBindingMethodFromNativeImpl function

Future<void> asyncInvokeBindingMethodFromNativeImpl(
  1. WebFViewController view,
  2. Pointer<BindingObjectAsyncCallContext> asyncCallContext,
  3. Pointer<NativeBindingObject> nativeBindingObject
)

Implementation

Future<void> asyncInvokeBindingMethodFromNativeImpl(WebFViewController view,
    Pointer<BindingObjectAsyncCallContext> asyncCallContext, Pointer<NativeBindingObject> nativeBindingObject) async {
  Pointer<NativeValue> returnValue = malloc.allocate(sizeOf<NativeValue>());

  DartBindingObjectAsyncCallCallback f;
  // This is an optimization for dedication thread mode for creating an small, short-running, non-blocking functions which are not allowed to
  // call back into Dart or use any Dart VM APIs
  if (isContextDedicatedThread(view.contextId)) {
    f = asyncCallContext.ref.callback.asFunction(isLeaf: true);
  } else {
    f = asyncCallContext.ref.callback.asFunction();
  }

  try {
    await _invokeBindingMethodFromNativeImpl(view.contextId, nativeBindingObject, returnValue,
        asyncCallContext.ref.methodName, asyncCallContext.ref.argc, asyncCallContext.ref.argv);

    f(asyncCallContext.ref.resolver, returnValue, nullptr);
  } catch (e, stack) {
    f(asyncCallContext.ref.resolver, nullptr, '$e\n$stack'.toNativeUtf8());
  }

  malloc.free(asyncCallContext.ref.argv);
  malloc.free(asyncCallContext);
}