operator == method
Honour user-defined == so that interpreted instances compare correctly
inside native Dart collections (e.g. Set<Cell>, Map<Cell, …>).
Dispatches through the active interpreter visitor when the script has
declared an == operator on this class or any of its interpreted
ancestors. When no override exists, or no visitor is active (e.g. the
instance escaped d4rt's execution context), we fall back to native
identity equality. Mirror of tom_d4rt InterpretedInstance.==.
Implementation
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
final eq = klass.findOperator('==');
if (eq == null) return false;
final visitor = D4.activeVisitor;
if (visitor == null) return false;
final id = identityHashCode(this);
if (!_equalsInProgress.add(id)) {
return false;
}
Object? result;
try {
result = eq.bind(this).call(visitor, <Object?>[other], const {});
} on ReturnException catch (e) {
result = e.value;
} catch (_) {
return false;
} finally {
_equalsInProgress.remove(id);
}
return result == true;
}