Chromium Code Reviews| Index: pkg/http/lib/src/io.dart |
| diff --git a/pkg/http/lib/src/io.dart b/pkg/http/lib/src/io.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d7e0a511962bbdf2885c18bc789d55a0671a6e16 |
| --- /dev/null |
| +++ b/pkg/http/lib/src/io.dart |
| @@ -0,0 +1,41 @@ |
| +// 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.
|
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library http.io; |
| + |
| +@MirrorsUsed(targets: const ['dart.io.HttpClient', 'dart.io.HttpException', |
| + 'dart.io.File']) |
| +import 'dart:mirrors'; |
| + |
| +final _library = _getLibrary(); |
| + |
| +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.
|
| + |
| +final ClassMirror _httpClient = |
| + _library.declarations[const Symbol('HttpClient')]; |
| + |
| +final ClassMirror _httpException = |
| + _library.declarations[const Symbol('HttpException')]; |
| + |
| +final ClassMirror _file = _library.declarations[const Symbol('File')]; |
| + |
| +void assertSupported(String name) { |
| + if (supported) return; |
| + throw new UnsupportedError("$name isn't supported on this platform."); |
| +} |
| + |
| +newHttpClient() => _httpClient.newInstance(const Symbol(''), []).reflectee; |
| + |
| +newFile(String path) => _file.newInstance(const Symbol(''), [path]).reflectee; |
| + |
| +bool isHttpException(error) => reflect(error).type.isSubtypeOf(_httpException); |
| + |
| +LibraryMirror _getLibrary() { |
| + try { |
| + return currentMirrorSystem().findLibrary(const Symbol('dart.io')); |
| + } catch (_) { |
| + // TODO(nweiz): narrow the catch clause when issue 18532 is fixed. |
| + return null; |
| + } |
| +} |