OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
Bob Nystrom
2014/05/01 18:30:12
Doc comments on the public stuff in here.
nweiz
2014/05/01 19:34:54
Done.
| |
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. | |
4 | |
5 library http.io; | |
6 | |
7 @MirrorsUsed(targets: const ['dart.io.HttpClient', 'dart.io.HttpException', | |
8 'dart.io.File']) | |
9 import 'dart:mirrors'; | |
10 | |
11 final _library = _getLibrary(); | |
12 | |
13 bool get supported => _library != null; | |
Bob Nystrom
2014/05/01 18:30:12
Nit, but how about putting all of the private fiel
nweiz
2014/05/01 19:34:54
Done.
| |
14 | |
15 final ClassMirror _httpClient = | |
16 _library.declarations[const Symbol('HttpClient')]; | |
17 | |
18 final ClassMirror _httpException = | |
19 _library.declarations[const Symbol('HttpException')]; | |
20 | |
21 final ClassMirror _file = _library.declarations[const Symbol('File')]; | |
22 | |
23 void assertSupported(String name) { | |
24 if (supported) return; | |
25 throw new UnsupportedError("$name isn't supported on this platform."); | |
26 } | |
27 | |
28 newHttpClient() => _httpClient.newInstance(const Symbol(''), []).reflectee; | |
29 | |
30 newFile(String path) => _file.newInstance(const Symbol(''), [path]).reflectee; | |
31 | |
32 bool isHttpException(error) => reflect(error).type.isSubtypeOf(_httpException); | |
33 | |
34 LibraryMirror _getLibrary() { | |
35 try { | |
36 return currentMirrorSystem().findLibrary(const Symbol('dart.io')); | |
37 } catch (_) { | |
38 // TODO(nweiz): narrow the catch clause when issue 18532 is fixed. | |
39 return null; | |
40 } | |
41 } | |
OLD | NEW |