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

Side by Side Diff: sdk/lib/io/platform_impl.dart

Issue 1974043002: Revert "Fix remaining strong-mode warnings and errors in dart:io." (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
« no previous file with comments | « sdk/lib/io/link.dart ('k') | sdk/lib/io/secure_socket.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) 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 dart.io; 5 part of dart.io;
6 6
7 class _Platform { 7 class _Platform {
8 external static int _numberOfProcessors(); 8 external static int _numberOfProcessors();
9 external static String _pathSeparator(); 9 external static String _pathSeparator();
10 external static String _operatingSystem(); 10 external static String _operatingSystem();
(...skipping 21 matching lines...) Expand all
32 external static String _packageConfig(); 32 external static String _packageConfig();
33 external static String _version(); 33 external static String _version();
34 34
35 static String executable = _executable(); 35 static String executable = _executable();
36 static String resolvedExecutable = _resolvedExecutable(); 36 static String resolvedExecutable = _resolvedExecutable();
37 static String packageRoot = _packageRoot(); 37 static String packageRoot = _packageRoot();
38 static String packageConfig = _packageConfig(); 38 static String packageConfig = _packageConfig();
39 39
40 // Cache the OS environemnt. This can be an OSError instance if 40 // Cache the OS environemnt. This can be an OSError instance if
41 // retrieving the environment failed. 41 // retrieving the environment failed.
42 static var/*OSError|Map<String,String>*/ _environmentCache; 42 static var _environmentCache;
43 43
44 static int get numberOfProcessors => _numberOfProcessors(); 44 static int get numberOfProcessors => _numberOfProcessors();
45 static String get pathSeparator => _pathSeparator(); 45 static String get pathSeparator => _pathSeparator();
46 static String get operatingSystem => _operatingSystem(); 46 static String get operatingSystem => _operatingSystem();
47 static Uri script; 47 static Uri script;
48 48
49 static String get localHostname { 49 static String get localHostname {
50 var result = _localHostname(); 50 var result = _localHostname();
51 if (result is OSError) { 51 if (result is OSError) {
52 throw result; 52 throw result;
53 } else { 53 } else {
54 return result; 54 return result;
55 } 55 }
56 } 56 }
57 57
58 static List<String> get executableArguments => _executableArguments(); 58 static List<String> get executableArguments => _executableArguments();
59 59
60 static Map<String, String> get environment { 60 static Map<String, String> get environment {
61 if (_environmentCache == null) { 61 if (_environmentCache == null) {
62 var env = _environment(); 62 var env = _environment();
63 if (env is !OSError) { 63 if (env is !OSError) {
64 var isWindows = operatingSystem == 'windows'; 64 var isWindows = operatingSystem == 'windows';
65 var result = isWindows 65 var result = isWindows ? new _CaseInsensitiveStringMap() : new Map();
66 ? new _CaseInsensitiveStringMap<String>()
67 : new Map<String, String>();
68 for (var str in env) { 66 for (var str in env) {
69 // The Strings returned by [_environment()] are expected to be 67 // The Strings returned by [_environment()] are expected to be
70 // valid environment entries, but exceptions have been seen 68 // valid environment entries, but exceptions have been seen
71 // (e.g., an entry of just '=' has been seen on OS/X). 69 // (e.g., an entry of just '=' has been seen on OS/X).
72 // Invalid entries (lines without a '=' or with an empty name) 70 // Invalid entries (lines without a '=' or with an empty name)
73 // are discarded. 71 // are discarded.
74 var equalsIndex = str.indexOf('='); 72 var equalsIndex = str.indexOf('=');
75 if (equalsIndex > 0) { 73 if (equalsIndex > 0) {
76 result[str.substring(0, equalsIndex)] = 74 result[str.substring(0, equalsIndex)] =
77 str.substring(equalsIndex + 1); 75 str.substring(equalsIndex + 1);
78 } 76 }
79 } 77 }
80 _environmentCache = new UnmodifiableMapView<String, String>(result); 78 _environmentCache = new UnmodifiableMapView<String, String>(result);
81 } else { 79 } else {
82 _environmentCache = env; 80 _environmentCache = env;
83 } 81 }
84 } 82 }
85 83
86 if (_environmentCache is OSError) { 84 if (_environmentCache is OSError) {
87 throw _environmentCache; 85 throw _environmentCache;
88 } else { 86 } else {
89 return _environmentCache as Object/*=Map<String, String>*/; 87 return _environmentCache;
90 } 88 }
91 } 89 }
92 90
93 static String get version => _version(); 91 static String get version => _version();
94 } 92 }
95 93
96 // Environment variables are case-insensitive on Windows. In order 94 // Environment variables are case-insensitive on Windows. In order
97 // to reflect that we use a case-insensitive string map on Windows. 95 // to reflect that we use a case-insensitive string map on Windows.
98 class _CaseInsensitiveStringMap<V> implements Map<String, V> { 96 class _CaseInsensitiveStringMap<V> implements Map<String, V> {
99 final Map<String, V> _map = new Map<String, V>(); 97 final Map<String, V> _map = new Map<String, V>();
100 98
101 bool containsKey(Object key) => 99 bool containsKey(Object key) =>
102 key is String && _map.containsKey(key.toUpperCase()); 100 key is String && _map.containsKey(key.toUpperCase());
103 bool containsValue(Object value) => _map.containsValue(value); 101 bool containsValue(Object value) => _map.containsValue(value);
104 V operator [](Object key) => key is String ? _map[key.toUpperCase()] : null; 102 V operator [](Object key) => key is String ? _map[key.toUpperCase()] : null;
105 void operator []=(String key, V value) { 103 void operator []=(String key, V value) {
106 _map[key.toUpperCase()] = value; 104 _map[key.toUpperCase()] = value;
107 } 105 }
108 V putIfAbsent(String key, V ifAbsent()) { 106 V putIfAbsent(String key, V ifAbsent()) {
109 return _map.putIfAbsent(key.toUpperCase(), ifAbsent); 107 return _map.putIfAbsent(key.toUpperCase(), ifAbsent);
110 } 108 }
111 void addAll(Map<String, V> other) { 109 void addAll(Map other) {
112 other.forEach((key, value) => this[key.toUpperCase()] = value); 110 other.forEach((key, value) => this[key.toUpperCase()] = value);
113 } 111 }
114 V remove(Object key) => key is String ? _map.remove(key.toUpperCase()) : null; 112 V remove(Object key) => key is String ? _map.remove(key.toUpperCase()) : null;
115 void clear() { _map.clear(); } 113 void clear() { _map.clear(); }
116 void forEach(void f(String key, V value)) { _map.forEach(f); } 114 void forEach(void f(String key, V value)) { _map.forEach(f); }
117 Iterable<String> get keys => _map.keys; 115 Iterable<String> get keys => _map.keys;
118 Iterable<V> get values => _map.values; 116 Iterable<V> get values => _map.values;
119 int get length => _map.length; 117 int get length => _map.length;
120 bool get isEmpty => _map.isEmpty; 118 bool get isEmpty => _map.isEmpty;
121 bool get isNotEmpty => _map.isNotEmpty; 119 bool get isNotEmpty => _map.isNotEmpty;
122 String toString() => _map.toString(); 120 String toString() => _map.toString();
123 } 121 }
OLDNEW
« no previous file with comments | « sdk/lib/io/link.dart ('k') | sdk/lib/io/secure_socket.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698