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 {
    // C10: Prefer explicit target (set by dispatch site to nativeProxy
    // / bridgedSuperObject when a native mixin instance is required);
    // fall back to the InterpretedInstance for purely interpreted
    // bridged-mixin shapes.
    //
    // Step 3 (1449 plan): the dispatch site at the bridged-mixin lookup
    // in `Instance.get` sets `target` to `nativeProxy ?? bridgedSuperObject
    // ?? this`, so when the script class is a pure interpreted class with
    // no native shadow (e.g. `class _Node with DiagnosticableTreeMixin`),
    // `target` ends up as the InterpretedInstance itself and the adapter's
    // `D4.validateTarget<T>` cast then fails. Consult the interface-proxy
    // registry keyed by the bridged-mixin name to materialise a native
    // shadow that forwards back into the interpreter (e.g.
    // `_InterpretedDiagnosticableTreeMixin` overriding `toStringShort`,
    // `debugFillProperties`, `debugDescribeChildren`). The lookup runs
    // only when the explicit target is null *or* identical to the
    // InterpretedInstance — preserving the existing nativeProxy /
    // bridgedSuperObject precedence.
    Object effectiveTarget;
    if (target == null || identical(target, instance)) {
      final proxy = D4.tryCreateInterfaceProxyByName(
          bridgedMixinName, instance, visitor);
      effectiveTarget = proxy ?? target ?? instance;
    } else {
      effectiveTarget = target!;
    }
    // D4 (Cluster D4 fix): wrap adapter dispatch in
    // `D4.withActiveVisitor` so that visitor-less D4 helpers invoked by
    // the adapter (e.g. `D4.getRequiredArg<RestorableProperty<Object?>>`
    // inside `RestorationMixin.registerForRestoration`) can resolve
    // interface proxies via `tryCreateInterfaceProxyWithVisitor<T>`.
    // Without this wrap, `_activeVisitor` is null and an
    // `InterpretedInstance` argument that needs a registered interface
    // proxy fails the `is T` cast.
    return D4.withActiveVisitor(
      visitor,
      () => adapter(visitor, effectiveTarget, positionalArguments,
          namedArguments, typeArguments),
    );
  } catch (e, s) {
    Logger.error(
        "[BridgedMixinMethodCallable] Native exception during call to '$bridgedMixinName.$methodName': $e\n$s");
    throw RuntimeD4rtException(
        "Native error in bridged mixin method '$bridgedMixinName.$methodName': $e", originalException: e);
  }
}