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

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

Issue 214723002: Remove unmodifiable map wrappers that could instead use UnmodifiableMapView. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix missing import, increment mirror function count. 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;
11 12
12 import 'dart:mirrors'; 13 import 'dart:mirrors';
13 14
14 import 'dart:_foreign_helper' show 15 import 'dart:_foreign_helper' show
15 JS, 16 JS,
16 JS_CURRENT_ISOLATE, 17 JS_CURRENT_ISOLATE,
17 JS_CURRENT_ISOLATE_CONTEXT, 18 JS_CURRENT_ISOLATE_CONTEXT,
18 JS_GET_NAME; 19 JS_GET_NAME;
19 20
20 import 'dart:_internal' as _symbol_dev; 21 import 'dart:_internal' as _symbol_dev;
(...skipping 2807 matching lines...) Expand 10 before | Expand all | Expand 10 after
2828 case MISSING_CONSTRUCTOR: 2829 case MISSING_CONSTRUCTOR:
2829 return 2830 return
2830 "NoSuchMethodError: No constructor named '${n(_name)}' in class" 2831 "NoSuchMethodError: No constructor named '${n(_name)}' in class"
2831 " '${n(_cls.qualifiedName)}'."; 2832 " '${n(_cls.qualifiedName)}'.";
2832 default: 2833 default:
2833 return 'NoSuchMethodError'; 2834 return 'NoSuchMethodError';
2834 } 2835 }
2835 } 2836 }
2836 } 2837 }
2837 2838
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
2877 Symbol getSymbol(String name, LibraryMirror library) { 2839 Symbol getSymbol(String name, LibraryMirror library) {
2878 if (_isPublicSymbol(name)) { 2840 if (_isPublicSymbol(name)) {
2879 return new _symbol_dev.Symbol.validated(name); 2841 return new _symbol_dev.Symbol.validated(name);
2880 } 2842 }
2881 if (library == null) { 2843 if (library == null) {
2882 throw new ArgumentError( 2844 throw new ArgumentError(
2883 "Library required for private symbol name: $name"); 2845 "Library required for private symbol name: $name");
2884 } 2846 }
2885 if (!_symbol_dev.Symbol.isValidSymbol(name)) { 2847 if (!_symbol_dev.Symbol.isValidSymbol(name)) {
2886 throw new ArgumentError("Not a valid symbol name: $name"); 2848 throw new ArgumentError("Not a valid symbol name: $name");
2887 } 2849 }
2888 throw new UnimplementedError( 2850 throw new UnimplementedError(
2889 "MirrorSystem.getSymbol not implemented for private names"); 2851 "MirrorSystem.getSymbol not implemented for private names");
2890 } 2852 }
2891 2853
2892 bool _isPublicSymbol(String name) { 2854 bool _isPublicSymbol(String name) {
2893 // A symbol is public if it doesn't start with '_' and it doesn't 2855 // A symbol is public if it doesn't start with '_' and it doesn't
2894 // have a part (following a '.') that starts with '_'. 2856 // have a part (following a '.') that starts with '_'.
2895 const int UNDERSCORE = 0x5f; 2857 const int UNDERSCORE = 0x5f;
2896 if (name.isEmpty) return true; 2858 if (name.isEmpty) return true;
2897 int index = -1; 2859 int index = -1;
2898 do { 2860 do {
2899 if (name.codeUnitAt(index + 1) == UNDERSCORE) return false; 2861 if (name.codeUnitAt(index + 1) == UNDERSCORE) return false;
2900 index = name.indexOf('.', index + 1); 2862 index = name.indexOf('.', index + 1);
2901 } while (index >= 0 && index + 1 < name.length); 2863 } while (index >= 0 && index + 1 < name.length);
2902 return true; 2864 return true;
2903 } 2865 }
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