| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of dart.core; | 5 part of dart.core; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * An [Expando] allows adding new properties to objects. | 8 * An [Expando] allows adding new properties to objects. |
| 9 * | 9 * |
| 10 * Does not work on numbers, strings, booleans or null. | 10 * Does not work on numbers, strings, booleans or null. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 */ | 64 */ |
| 65 void operator[]=(Object object, T value) { | 65 void operator[]=(Object object, T value) { |
| 66 var values = Primitives.getProperty(object, _EXPANDO_PROPERTY_NAME); | 66 var values = Primitives.getProperty(object, _EXPANDO_PROPERTY_NAME); |
| 67 if (values == null) { | 67 if (values == null) { |
| 68 values = new Object(); | 68 values = new Object(); |
| 69 Primitives.setProperty(object, _EXPANDO_PROPERTY_NAME, values); | 69 Primitives.setProperty(object, _EXPANDO_PROPERTY_NAME, values); |
| 70 } | 70 } |
| 71 Primitives.setProperty(values, _getKey(), value); | 71 Primitives.setProperty(values, _getKey(), value); |
| 72 } | 72 } |
| 73 | 73 |
| 74 String _getKey() { |
| 75 String key = Primitives.getProperty(this, _KEY_PROPERTY_NAME); |
| 76 if (key == null) { |
| 77 key = "expando\$key\$${_keyCount++}"; |
| 78 Primitives.setProperty(this, _KEY_PROPERTY_NAME, key); |
| 79 } |
| 80 return key; |
| 81 } |
| 82 |
| 83 static const String _KEY_PROPERTY_NAME = 'expando\$key'; |
| 84 |
| 85 static const String _EXPANDO_PROPERTY_NAME = 'expando\$values'; |
| 86 |
| 87 static int _keyCount = 0; |
| 88 |
| 74 } | 89 } |
| OLD | NEW |