Chromium Code Reviews| 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 // This class has no constructor. This is on purpose since the instantiation | 5 // This class has no constructor. This is on purpose since the instantiation |
| 6 // is shortcut by the compiler. | 6 // is shortcut by the compiler. |
| 7 class ConstantMap<V> implements Map<String, V> { | 7 class ConstantMap<V> implements Map<String, V> { |
| 8 final int length; | 8 final int length; |
| 9 // A constant map is backed by a JavaScript object. | 9 // A constant map is backed by a JavaScript object. |
| 10 final _jsObject; | 10 final _jsObject; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 Collection<V> getValues() { | 33 Collection<V> getValues() { |
| 34 List<V> result = <V>[]; | 34 List<V> result = <V>[]; |
| 35 _keys.forEach((String key) => result.add(this[key])); | 35 _keys.forEach((String key) => result.add(this[key])); |
| 36 return result; | 36 return result; |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool isEmpty() => length == 0; | 39 bool isEmpty() => length == 0; |
| 40 | 40 |
| 41 String toString() => Maps.mapToString(this); | 41 String toString() => Maps.mapToString(this); |
| 42 | 42 |
| 43 _throwImmutable() { | 43 _throwUnmodifiable() { |
| 44 throw const IllegalAccessException(); | 44 throw new StateError("Cannot modify unmodifable Map"); |
|
floitsch
2012/10/23 12:50:32
unmodifiable
Lasse Reichstein Nielsen
2012/10/24 12:32:15
Done.
| |
| 45 } | 45 } |
| 46 void operator []=(String key, V val) => _throwImmutable(); | 46 void operator []=(String key, V val) => _throwUnmodifiable(); |
| 47 V putIfAbsent(String key, V ifAbsent()) => _throwImmutable(); | 47 V putIfAbsent(String key, V ifAbsent()) => _throwUnmodifiable(); |
| 48 V remove(String key) => _throwImmutable(); | 48 V remove(String key) => _throwUnmodifiable(); |
| 49 void clear() => _throwImmutable(); | 49 void clear() => _throwUnmodifiable(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 // This class has no constructor. This is on purpose since the instantiation | 52 // This class has no constructor. This is on purpose since the instantiation |
| 53 // is shortcut by the compiler. | 53 // is shortcut by the compiler. |
| 54 class ConstantProtoMap<V> extends ConstantMap<V> { | 54 class ConstantProtoMap<V> extends ConstantMap<V> { |
| 55 final V _protoValue; | 55 final V _protoValue; |
| 56 | 56 |
| 57 bool containsKey(String key) { | 57 bool containsKey(String key) { |
| 58 if (key == '__proto__') return true; | 58 if (key == '__proto__') return true; |
| 59 return super.containsKey(key); | 59 return super.containsKey(key); |
| 60 } | 60 } |
| 61 | 61 |
| 62 V operator [](String key) { | 62 V operator [](String key) { |
| 63 if (key == '__proto__') return _protoValue; | 63 if (key == '__proto__') return _protoValue; |
| 64 return super[key]; | 64 return super[key]; |
| 65 } | 65 } |
| 66 } | 66 } |
| OLD | NEW |