Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Unified Diff: pkg/unittest/lib/src/core_matchers.dart

Issue 12226131: Work around dart2js' broken implementation of runtimeType. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/unittest/lib/src/core_matchers.dart
===================================================================
--- pkg/unittest/lib/src/core_matchers.dart (revision 18404)
+++ pkg/unittest/lib/src/core_matchers.dart (working copy)
@@ -173,20 +173,22 @@
}
} else {
reason = new StringDescription();
- var includeTypes = expected.runtimeType != actual.runtimeType;
+ var eType = typeName(expected);
+ var aType = typeName(actual);
+ var includeTypes = eType != aType;
// If we have recursed, show the expected value too; if not,
// expect() will show it for us. As expect will not show type
// mismatches at the top level we handle those here too.
if (includeTypes || depth > 1) {
reason.add('expected ');
if (includeTypes) {
- reason.add(expected.runtimeType.toString()).add(':');
+ reason.add(eType).add(':');
}
reason.addDescriptionOf(expected).add(' but ');
}
reason.add('was ');
if (includeTypes) {
- reason.add(actual.runtimeType.toString()).add(':');
+ reason.add(aType).add(':');
}
reason.addDescriptionOf(actual);
}
@@ -197,6 +199,17 @@
return reason;
}
+ String typeName(x) {
+ // dart2js blows up on some objects (e.g. window.navigator).
+ // So we play safe here.
Siggi Cherem (dart-lang) 2013/02/12 23:09:17 please file a bug and add a reference here, I'm pr
+ try {
+ if (x == null) return "null";
+ return x.runtimeType.toString();
+ } catch (e) {
+ return "Unknown";
+ }
+ }
+
String _match(expected, actual) {
Description reason = _recursiveMatch(expected, actual, '', 0);
return reason == null ? null : reason.toString();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698