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

Unified Diff: lib/compiler/implementation/lib/js_helper.dart

Issue 10908142: Add runtimeType() to Object which returns canonicalized instances of Type. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address more comments. Created 8 years, 3 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
Index: lib/compiler/implementation/lib/js_helper.dart
diff --git a/lib/compiler/implementation/lib/js_helper.dart b/lib/compiler/implementation/lib/js_helper.dart
index e03c863bab5200f3b6476b4458b39775c83c6337..429f12dee4ec4f1cb7f9f2f0edf988d4073b68cf 100644
--- a/lib/compiler/implementation/lib/js_helper.dart
+++ b/lib/compiler/implementation/lib/js_helper.dart
@@ -1324,3 +1324,23 @@ void throwNoSuchMethod(obj, name, arguments) {
void throwCyclicInit(String staticName) {
throw new RuntimeError("Cyclic initialization for static $staticName");
}
+
+class TypeImpl implements Type {
+ final String typeName;
+ TypeImpl(this.typeName);
+ toString() => typeName;
+}
+
+Type getOrCreateCachedRuntimeType(String key) {
+ Type runtimeType = JS('Object', @'$.runtimeTypeCache[#]', key);
ngeoffray 2012/09/17 15:31:14 'Object' -> 'Type'
ngeoffray 2012/09/17 15:31:14 Please use JS_CURRENT_ISOLATE() instead of $.
karlklose 2012/09/19 06:40:45 Done.
karlklose 2012/09/19 06:40:45 Done.
+ if (runtimeType == null) {
+ runtimeType = new TypeImpl(key);
+ JS('void', @'$.runtimeTypeCache[#] = #', key, runtimeType);
ngeoffray 2012/09/17 15:31:14 ditto
karlklose 2012/09/19 06:40:45 Done.
+ }
+ return runtimeType;
+}
+
+String getRuntimeTypeString(var object) {
+ var typeInfo = JS('Object', @'#.builtin$typeInfo', object);
+ return JS('String', @'#.runtimeType', typeInfo);
+}

Powered by Google App Engine
This is Rietveld 408576698