mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 08:44:27 +00:00
[vm/testing] Improve il_matchers obfuscation support
Recognize "Instance of C" string and handle it in special way: apply renaming to class name (C) only. Fixes https://github.com/dart-lang/sdk/issues/53512 TEST=vm/dart/comparison_canonicalization_il_test in obfuscate configuration Fixed: 53512 Cq-Include-Trybots: luci.dart.try:vm-aot-obfuscate-linux-release-x64-try Change-Id: I3fa31ab52aef01417d523a075913a0971158be72 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/326062 Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Slava Egorov <vegorov@google.com>
This commit is contained in:
parent
74bdcded45
commit
98d9a31dbc
1 changed files with 22 additions and 11 deletions
|
@ -191,29 +191,40 @@ class _BoundMatcher implements Matcher {
|
|||
|
||||
/// Matcher which matches a specified value [v].
|
||||
class _EqualsMatcher implements Matcher {
|
||||
final dynamic v;
|
||||
final dynamic expected;
|
||||
|
||||
_EqualsMatcher(this.v);
|
||||
_EqualsMatcher(this.expected);
|
||||
|
||||
@override
|
||||
MatchStatus match(Env e, v) {
|
||||
if (this.v == v) {
|
||||
MatchStatus match(Env e, got) {
|
||||
if (expected == got) {
|
||||
return MatchStatus.matched;
|
||||
}
|
||||
|
||||
// Some instructions refer to obfuscated names, try to rename
|
||||
// the expectation and try again.
|
||||
if (this.v is String && v is String && e.rename(this.v) == v) {
|
||||
return MatchStatus.matched;
|
||||
// the expectation and try again. For strings of form "Instance of C"
|
||||
// apply renaming to class name part only.
|
||||
if (expected is String && got is String) {
|
||||
const instanceOfPrefix = "Instance of ";
|
||||
|
||||
final String renamed;
|
||||
if (expected.startsWith(instanceOfPrefix)) {
|
||||
final className = expected.substring(instanceOfPrefix.length);
|
||||
renamed = instanceOfPrefix + e.rename(className);
|
||||
} else {
|
||||
renamed = e.rename(expected);
|
||||
}
|
||||
|
||||
if (renamed == got) {
|
||||
return MatchStatus.matched;
|
||||
}
|
||||
}
|
||||
|
||||
return this.v == v
|
||||
? MatchStatus.matched
|
||||
: MatchStatus.fail('expected ${this.v} got $v');
|
||||
return MatchStatus.fail('expected $expected got $got');
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => '$v';
|
||||
String toString() => '$expected';
|
||||
}
|
||||
|
||||
/// Matcher which matches the value which is equivalent to the binding
|
||||
|
|
Loading…
Reference in a new issue