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

Side by Side Diff: tool/input_sdk/private/constant_map.dart

Issue 1112403004: SDK fixes (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Formatting fix Created 5 years, 7 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 unified diff | Download patch
OLDNEW
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 _js_helper; 5 part of _js_helper;
6 6
7 abstract class ConstantMap<K, V> implements Map<K, V> { 7 abstract class ConstantMap<K, V> implements Map<K, V> {
8 const ConstantMap._(); 8 const ConstantMap._();
9 9
10 bool get isEmpty => length == 0; 10 bool get isEmpty => length == 0;
11 11
12 bool get isNotEmpty => !isEmpty; 12 bool get isNotEmpty => !isEmpty;
13 13
14 String toString() => Maps.mapToString(this); 14 String toString() => Maps.mapToString(this);
15 15
16 _throwUnmodifiable() { 16 _throwUnmodifiable() {
17 throw new UnsupportedError("Cannot modify unmodifiable Map"); 17 throw new UnsupportedError("Cannot modify unmodifiable Map");
18 } 18 }
19 void operator []=(K key, V val) => _throwUnmodifiable(); 19 void operator []=(K key, V val) => _throwUnmodifiable();
20 V putIfAbsent(K key, V ifAbsent()) => _throwUnmodifiable(); 20 V putIfAbsent(K key, V ifAbsent()) => _throwUnmodifiable();
21 V remove(K key) => _throwUnmodifiable(); 21 V remove(Object key) => _throwUnmodifiable();
22 void clear() => _throwUnmodifiable(); 22 void clear() => _throwUnmodifiable();
23 void addAll(Map<K, V> other) => _throwUnmodifiable(); 23 void addAll(Map<K, V> other) => _throwUnmodifiable();
24 } 24 }
25 25
26 class ConstantStringMap<K, V> extends ConstantMap<K, V> 26 class ConstantStringMap<K, V> extends ConstantMap<K, V>
27 implements _symbol_dev.EfficientLength { 27 implements _symbol_dev.EfficientLength {
28 28
29 // This constructor is not used. The instantiation is shortcut by the 29 // This constructor is not used. The instantiation is shortcut by the
30 // compiler. It is here to make the uninitialized final fields legal. 30 // compiler. It is here to make the uninitialized final fields legal.
31 const ConstantStringMap._(this.length, this._jsObject, this._keys) 31 const ConstantStringMap._(this.length, this._jsObject, this._keys)
32 : super._(); 32 : super._();
33 33
34 final int length; 34 final int length;
35 // A constant map is backed by a JavaScript object. 35 // A constant map is backed by a JavaScript object.
36 final _jsObject; 36 final _jsObject;
37 final List<K> _keys; 37 final List<K> _keys;
38 38
39 bool containsValue(V needle) { 39 bool containsValue(Object needle) {
40 return values.any((V value) => value == needle); 40 return values.any((V value) => value == needle);
41 } 41 }
42 42
43 bool containsKey(Object key) { 43 bool containsKey(Object key) {
44 if (key is! String) return false; 44 if (key is! String) return false;
45 if ('__proto__' == key) return false; 45 if ('__proto__' == key) return false;
46 return jsHasOwnProperty(_jsObject, key); 46 return jsHasOwnProperty(_jsObject, key);
47 } 47 }
48 48
49 V operator [](Object key) { 49 V operator [](Object key) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // [_jsData] holds a key-value pair list. 109 // [_jsData] holds a key-value pair list.
110 final _jsData; 110 final _jsData;
111 111
112 // We cannot create the backing map on creation since hashCode interceptors 112 // We cannot create the backing map on creation since hashCode interceptors
113 // have not been defined when constants are created. 113 // have not been defined when constants are created.
114 Map<K, V> _getMap() { 114 Map<K, V> _getMap() {
115 if (JS('bool', r'!this.$map')) { 115 if (JS('bool', r'!this.$map')) {
116 Map backingMap = new LinkedHashMap<K, V>(); 116 Map backingMap = new LinkedHashMap<K, V>();
117 JS('', r'this.$map = #', fillLiteralMap(_jsData, backingMap)); 117 JS('', r'this.$map = #', fillLiteralMap(_jsData, backingMap));
118 } 118 }
119 return JS('Map', r'this.$map'); 119 return JS('Map<K, V>', r'this.$map');
120 } 120 }
121 121
122 bool containsValue(V needle) { 122 bool containsValue(Object needle) {
123 return _getMap().containsValue(needle); 123 return _getMap().containsValue(needle);
124 } 124 }
125 125
126 bool containsKey(Object key) { 126 bool containsKey(Object key) {
127 return _getMap().containsKey(key); 127 return _getMap().containsKey(key);
128 } 128 }
129 129
130 V operator [](Object key) { 130 V operator [](Object key) {
131 return _getMap()[key]; 131 return _getMap()[key];
132 } 132 }
133 133
134 void forEach(void f(K key, V value)) { 134 void forEach(void f(K key, V value)) {
135 _getMap().forEach(f); 135 _getMap().forEach(f);
136 } 136 }
137 137
138 Iterable<K> get keys { 138 Iterable<K> get keys {
139 return _getMap().keys; 139 return _getMap().keys;
140 } 140 }
141 141
142 Iterable<V> get values { 142 Iterable<V> get values {
143 return _getMap().values; 143 return _getMap().values;
144 } 144 }
145 145
146 int get length => _getMap().length; 146 int get length => _getMap().length;
147 } 147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698