tryCreateInterfaceProxyByName static method

Object? tryCreateInterfaceProxyByName(
  1. String bridgedTypeName,
  2. InterpretedInstance instance,
  3. InterpreterVisitor visitor
)

Try to create an interface proxy keyed by the bridged-type name.

Step 3 (1449 plan): bridged-mixin dispatch needs a way to obtain a native shadow for the specific mixin being dispatched, without type-driven inference. The dispatcher knows bridgedMixinName as a string (e.g. 'DiagnosticableTreeMixin') — this helper looks up the factory registered with that exact name and invokes it. The caller is responsible for any subsequent is/as check against the expected native type.

Returns the proxy if a factory is registered, otherwise null.

Implementation

static Object? tryCreateInterfaceProxyByName(
  String bridgedTypeName,
  InterpretedInstance instance,
  InterpreterVisitor visitor,
) {
  final factory = _interfaceProxies[bridgedTypeName];
  if (factory == null) return null;
  // ghissues29: a receiver is kept as the instance's native object.
  if (_receiverProxies.contains(bridgedTypeName)) {
    final kept = instance.nativeProxy;
    if (kept != null) return kept;
    final proxy = factory(visitor, instance);
    if (proxy != null) instance.nativeProxy ??= proxy;
    return instance.nativeProxy ?? proxy;
  }
  return factory(visitor, instance);
}