registerBridgedClassLazy method

void registerBridgedClassLazy(
  1. String name,
  2. Type nativeType,
  3. BridgedClass thunk(),
  4. String library, {
  5. String? sourceUri,
})

Step #17 — registers a bridged class via a deferred factory thunk.

The BridgedClass is built (member maps + adapter closures) only when the class is first resolved by name or native type, so a script that touches N of M registered classes materializes ≈N objects rather than M. The single memoized build point is LibraryClass.bridgedClass.

Implementation

void registerBridgedClassLazy(
  String name,
  Type nativeType,
  BridgedClass Function() thunk,
  String library, {
  String? sourceUri,
}) {
  final libClass = LibraryClass.lazy(name, nativeType, thunk, sourceUri: sourceUri);
  (_bridgedClasses[library] ??= {})[name] = libClass;
  _bridgedDefLookupByType.putThunk(nativeType, thunk);
  // Step 7: dual-write into the process-global pool (see registerBridgedEnum).
  final bundle = _bundleFor();
  (bundle.bridgedClasses[library] ??= {})[name] = libClass;
  bundle.bridgedDefLookupByType.putThunk(nativeType, thunk);
}