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

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

Issue 10534089: Add experimental expando support. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix comment and merge. Created 8 years, 6 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/mock.dart
diff --git a/lib/compiler/implementation/lib/mock.dart b/lib/compiler/implementation/lib/mock.dart
index 7950f9d2df380d525e558aae2b1b8c0c1bcfdc1e..89e26be7fe34929bedd1de454fa3c135ea42d88c 100644
--- a/lib/compiler/implementation/lib/mock.dart
+++ b/lib/compiler/implementation/lib/mock.dart
@@ -48,3 +48,43 @@ class _InternalByteArray {
void exit(int exitCode) {
throw new UnsupportedOperationException("exit($exitCode)");
}
+
+class _Expando<T> implements Expando<T> {
+
+ final String name;
+
+ const _Expando([this.name]);
+
+ T operator[](Object object) {
+ var values = Primitives.getProperty(object, EXPANDO_PROPERTY_NAME);
+ return (values === null) ? null : Primitives.getProperty(values, _getKey());
+ }
+
+ void operator[]=(Object object, T value) {
+ var values = Primitives.getProperty(object, EXPANDO_PROPERTY_NAME);
+ if (values === null) {
+ values = new Object();
+ Primitives.setProperty(object, EXPANDO_PROPERTY_NAME, values);
+ }
+ Primitives.setProperty(values, _getKey(), value);
+ }
+
+ String toString() {
+ String key = _getKey();
+ return (name === null) ? "Expando:${key}" : "Expando:${name}@${key}";
+ }
+
+ String _getKey() {
+ String key = Primitives.getProperty(this, KEY_PROPERTY_NAME);
+ if (key === null) {
+ key = "expando\$key\$${keyCount++}";
+ Primitives.setProperty(this, KEY_PROPERTY_NAME, key);
+ }
+ return key;
+ }
+
+ static final String KEY_PROPERTY_NAME = 'expando\$key';
+ static final String EXPANDO_PROPERTY_NAME = 'expando\$values';
+ static int keyCount = 0;
+
+}

Powered by Google App Engine
This is Rietveld 408576698