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

Side by Side Diff: sdk/lib/_internal/lib/js_mirrors.dart

Issue 246833003: Revert "Remove unmodifiable map wrappers that could instead use UnmodifiableMapView." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/mirrors/util.dart ('k') | sdk/lib/core/uri.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library dart._js_mirrors; 5 library dart._js_mirrors;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'dart:collection' show 9 import 'dart:collection' show
10 UnmodifiableListView, 10 UnmodifiableListView;
11 UnmodifiableMapView;
12 11
13 import 'dart:mirrors'; 12 import 'dart:mirrors';
14 13
15 import 'dart:_foreign_helper' show 14 import 'dart:_foreign_helper' show
16 JS, 15 JS,
17 JS_CURRENT_ISOLATE, 16 JS_CURRENT_ISOLATE,
18 JS_CURRENT_ISOLATE_CONTEXT, 17 JS_CURRENT_ISOLATE_CONTEXT,
19 JS_GET_NAME; 18 JS_GET_NAME;
20 19
21 import 'dart:_internal' as _symbol_dev; 20 import 'dart:_internal' as _symbol_dev;
(...skipping 2807 matching lines...) Expand 10 before | Expand all | Expand 10 after
2829 case MISSING_CONSTRUCTOR: 2828 case MISSING_CONSTRUCTOR:
2830 return 2829 return
2831 "NoSuchMethodError: No constructor named '${n(_name)}' in class" 2830 "NoSuchMethodError: No constructor named '${n(_name)}' in class"
2832 " '${n(_cls.qualifiedName)}'."; 2831 " '${n(_cls.qualifiedName)}'.";
2833 default: 2832 default:
2834 return 'NoSuchMethodError'; 2833 return 'NoSuchMethodError';
2835 } 2834 }
2836 } 2835 }
2837 } 2836 }
2838 2837
2838 // Copied from package "unmodifiable_collection".
2839 // TODO(14314): Move to dart:collection.
2840 class UnmodifiableMapView<K, V> implements Map<K, V> {
2841 Map<K, V> _source;
2842 UnmodifiableMapView(Map<K, V> source) : _source = source;
2843
2844 static void _throw() {
2845 throw new UnsupportedError("Cannot modify an unmodifiable Map");
2846 }
2847
2848 int get length => _source.length;
2849
2850 bool get isEmpty => _source.isEmpty;
2851
2852 bool get isNotEmpty => _source.isNotEmpty;
2853
2854 V operator [](K key) => _source[key];
2855
2856 bool containsKey(K key) => _source.containsKey(key);
2857
2858 bool containsValue(V value) => _source.containsValue(value);
2859
2860 void forEach(void f(K key, V value)) => _source.forEach(f);
2861
2862 Iterable<K> get keys => _source.keys;
2863
2864 Iterable<V> get values => _source.values;
2865
2866 void operator []=(K key, V value) => _throw();
2867
2868 V putIfAbsent(K key, V ifAbsent()) { _throw(); }
2869
2870 void addAll(Map<K, V> other) => _throw();
2871
2872 V remove(K key) { _throw(); }
2873
2874 void clear() => _throw();
2875 }
2876
2839 Symbol getSymbol(String name, LibraryMirror library) { 2877 Symbol getSymbol(String name, LibraryMirror library) {
2840 if (_isPublicSymbol(name)) { 2878 if (_isPublicSymbol(name)) {
2841 return new _symbol_dev.Symbol.validated(name); 2879 return new _symbol_dev.Symbol.validated(name);
2842 } 2880 }
2843 if (library == null) { 2881 if (library == null) {
2844 throw new ArgumentError( 2882 throw new ArgumentError(
2845 "Library required for private symbol name: $name"); 2883 "Library required for private symbol name: $name");
2846 } 2884 }
2847 if (!_symbol_dev.Symbol.isValidSymbol(name)) { 2885 if (!_symbol_dev.Symbol.isValidSymbol(name)) {
2848 throw new ArgumentError("Not a valid symbol name: $name"); 2886 throw new ArgumentError("Not a valid symbol name: $name");
2849 } 2887 }
2850 throw new UnimplementedError( 2888 throw new UnimplementedError(
2851 "MirrorSystem.getSymbol not implemented for private names"); 2889 "MirrorSystem.getSymbol not implemented for private names");
2852 } 2890 }
2853 2891
2854 bool _isPublicSymbol(String name) { 2892 bool _isPublicSymbol(String name) {
2855 // A symbol is public if it doesn't start with '_' and it doesn't 2893 // A symbol is public if it doesn't start with '_' and it doesn't
2856 // have a part (following a '.') that starts with '_'. 2894 // have a part (following a '.') that starts with '_'.
2857 const int UNDERSCORE = 0x5f; 2895 const int UNDERSCORE = 0x5f;
2858 if (name.isEmpty) return true; 2896 if (name.isEmpty) return true;
2859 int index = -1; 2897 int index = -1;
2860 do { 2898 do {
2861 if (name.codeUnitAt(index + 1) == UNDERSCORE) return false; 2899 if (name.codeUnitAt(index + 1) == UNDERSCORE) return false;
2862 index = name.indexOf('.', index + 1); 2900 index = name.indexOf('.', index + 1);
2863 } while (index >= 0 && index + 1 < name.length); 2901 } while (index >= 0 && index + 1 < name.length);
2864 return true; 2902 return true;
2865 } 2903 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/mirrors/util.dart ('k') | sdk/lib/core/uri.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698