call method

  1. @override
Object? call(
  1. InterpreterVisitor visitor,
  2. List<Object?> positionalArguments, [
  3. Map<String, Object?> namedArguments = const {},
  4. List<RuntimeType>? typeArguments,
])
override

Implementation

@override
Object? call(
  InterpreterVisitor visitor,
  List<Object?> positionalArguments, [
  Map<String, Object?> namedArguments = const {},
  List<RuntimeType>? typeArguments,
]) {
  try {
    // C6b fix (mirror of tom_d4rt/callable.dart): wrap adapter dispatch
    // in `D4.withActiveVisitor` so visitor-less D4 helpers invoked inside
    // the adapter (e.g. `D4.coerceList<T>` walking interface proxies for
    // higher-kinded generics like `ThemeExtension<ThemeExtension<dynamic>>`)
    // can resolve InterpretedInstance values via registered interface
    // proxies. Without this wrap, `_activeVisitor` is null and the proxy
    // walk is skipped, causing argument-cast failures on raw bridged
    // instance method calls.
    return D4.withActiveVisitor(
      visitor,
      () => _adapter(
        visitor,
        _instance.nativeObject,
        positionalArguments,
        namedArguments,
        typeArguments,
      ),
    );
  } on ArgumentError catch (e) {
    // Convert native ArgumentError to RuntimeError
    throw RuntimeD4rtException(
      "Invalid arguments for bridged method '${_instance.bridgedClass.name}.$_methodName': ${e.message}",
    );
  } catch (e, s) {
    // Handle other native errors
    Logger.error(
      "[BridgedMethodCallable] Native exception during call to '${_instance.bridgedClass.name}.$_methodName': $e\n$s",
    );
    throw RuntimeD4rtException(
      "Native error in bridged method '${_instance.bridgedClass.name}.$_methodName': $e",
      originalException: e,
      originalStackTrace: s,
    );
  }
}