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 RangeError {
    // SCE74. `RangeError extends ArgumentError` and `IndexError implements
    // RangeError`, so without this arm the clause below swallows every SDK
    // RANGE failure a bridged method raises and reissues it as an
    // uncatchable `RuntimeD4rtException`. A script written the idiomatic way
    // — `try { q.elementAt(0); } on RangeError { ... }` — did not catch, and
    // the recovery path its author wrote never ran.
    //
    // Narrowed rather than deleted, which is the SCE67 shape: the clause
    // below still earns its keep for a plain `ArgumentError`, which an
    // ADAPTER raises for arity and argument-shape problems that have no SDK
    // counterpart. Nothing in `stdlib` throws a bare RangeError or
    // IndexError (measured 2026-09-21: zero sites) — the interpreter's own
    // range failures use `Ranged4rtException` — so letting this one through
    // cannot leak an interpreter error into a script's `on RangeError`.
    rethrow;
  } 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,
    );
  }
}