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

Side by Side Diff: lib/compiler/implementation/lib/constant_map.dart

Issue 11267018: Make getKeys, getValues getters (keys, values). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update status files with co19 issue number. Created 8 years, 1 month 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 | Annotate | Revision Log
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 // 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;
11 final List<String> _keys; 11 final List<String> _keys;
12 12
13 bool containsValue(V needle) { 13 bool containsValue(V needle) {
14 return getValues().some((V value) => value == needle); 14 return values.some((V value) => value == needle);
15 } 15 }
16 16
17 bool containsKey(String key) { 17 bool containsKey(String key) {
18 if (key == '__proto__') return false; 18 if (key == '__proto__') return false;
19 return jsHasOwnProperty(_jsObject, key); 19 return jsHasOwnProperty(_jsObject, key);
20 } 20 }
21 21
22 V operator [](String key) { 22 V operator [](String key) {
23 if (!containsKey(key)) return null; 23 if (!containsKey(key)) return null;
24 return jsPropertyAccess(_jsObject, key); 24 return jsPropertyAccess(_jsObject, key);
25 } 25 }
26 26
27 void forEach(void f(String key, V value)) { 27 void forEach(void f(String key, V value)) {
28 _keys.forEach((String key) => f(key, this[key])); 28 _keys.forEach((String key) => f(key, this[key]));
29 } 29 }
30 30
31 Collection<String> getKeys() => _keys; 31 Collection<String> get keys => _keys;
32 32
33 Collection<V> getValues() { 33 Collection<V> get values {
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 get isEmpty => length == 0; 39 bool get isEmpty => length == 0;
40 40
41 String toString() => Maps.mapToString(this); 41 String toString() => Maps.mapToString(this);
42 42
43 _throwUnmodifiable() { 43 _throwUnmodifiable() {
(...skipping 13 matching lines...) Expand all
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 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/js_backend/backend.dart ('k') | lib/compiler/implementation/lib/isolate_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698