define method
Implementation
void define(String name, Object? value, {String? sourceUri}) {
if (_values.containsKey(name) ||
_bridgedClasses.containsKey(name) ||
_bridgedEnums.containsKey(name)) {
// SCE25: a top-level function or variable bridged by TWO packages under
// one name used to take this branch, log a warning nobody reads in a
// normal run, and silently bind the bare name to whichever registered
// last. The class path has rejected that arbitrary pick since tcca19;
// this is the same rule on the namespace that lacked it.
//
// Only a cross-package collision qualifies. A script redefining its own
// variable, or an embedder re-registering without a source URI, keeps the
// legacy overwrite — an error whose remedy does not exist is worse than
// the pick it replaces, which is the rule [_markAmbiguousBridgeName]
// already applies for classes.
final prior = _values[name];
if (sourceUri != null && _values.containsKey(name)) {
if (_markAmbiguousBridgeName(name, prior, value, sourceUri)) return;
} else {
Logger.warn(
"Redefining variable or colliding with bridged type: $name",
);
}
}
if (sourceUri != null) _bridgeSourceUrisOrNew[name] = sourceUri;
_values[name] = value;
}