propagateBridgeTypesTo method

void propagateBridgeTypesTo(
  1. Environment target
)

Propagates every bridge registered in this environment's type lookup to target for native-object resolution.

Use case: stdlib modules (dart:math, dart:io, …) live in isolated per-stdlib environments to avoid lexical name collisions, but their native types (e.g. _Random) must still be discoverable from globalEnvironment.toBridgedInstance when a script passes a native instance through an interpreted function. Calling stdlibEnv.propagateBridgeTypesTo(globalEnvironment) after registration mirrors the type→bridge mapping without leaking the lexical name Random into globalEnvironment.

Mirror of tom_d4rt Environment.propagateBridgeTypesTo.

Implementation

void propagateBridgeTypesTo(Environment target) {
  if (identical(target, this)) return;
  var added = false;
  for (final entry in _bridgedClassesLookupByType.entries) {
    target._bridgedClassesLookupByTypeOrNew.putIfAbsent(entry.key, () {
      added = true;
      return entry.value;
    });
  }
  if (added) target._invalidateResolutionCache();
}