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

Unified Diff: pkg/http/lib/src/io.dart

Issue 261763002: Rip out the last dart:io dependency from pkg/http. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/http/lib/src/client.dart ('k') | pkg/http/lib/src/io_client.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..1730706331f41b112334f40876e13c4e1b787d6b
--- /dev/null
+++ b/pkg/http/lib/src/io.dart
@@ -0,0 +1,54 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// 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';
+
+/// Whether `dart:io` is supported on this platform.
+bool get supported => _library != null;
+
+/// The `dart:io` library mirror, or `null` if it couldn't be loaded.
+final _library = _getLibrary();
+
+/// The `dart:io` HttpClient class mirror.
+final ClassMirror _httpClient =
+ _library.declarations[const Symbol('HttpClient')];
+
+/// The `dart:io` HttpException class mirror.
+final ClassMirror _httpException =
+ _library.declarations[const Symbol('HttpException')];
+
+/// The `dart:io` File class mirror.
+final ClassMirror _file = _library.declarations[const Symbol('File')];
+
+/// Asserts that the [name]d `dart:io` feature is supported on this platform.
+///
+/// If `dart:io` doesn't work on this platform, this throws an
+/// [UnsupportedError].
+void assertSupported(String name) {
+ if (supported) return;
+ throw new UnsupportedError("$name isn't supported on this platform.");
+}
+
+/// Creates a new `dart:io` HttpClient instance.
+newHttpClient() => _httpClient.newInstance(const Symbol(''), []).reflectee;
+
+/// Creates a new `dart:io` File instance with the given [path].
+newFile(String path) => _file.newInstance(const Symbol(''), [path]).reflectee;
+
+/// Returns whether [error] is a `dart:io` HttpException.
+bool isHttpException(error) => reflect(error).type.isSubtypeOf(_httpException);
+
+/// Tries to load `dart:io` and returns `null` if it fails.
+LibraryMirror _getLibrary() {
+ try {
+ return currentMirrorSystem().findLibrary(const Symbol('dart.io'));
+ } catch (_) {
+ // TODO(nweiz): narrow the catch clause when issue 18532 is fixed.
+ return null;
+ }
+}
« no previous file with comments | « pkg/http/lib/src/client.dart ('k') | pkg/http/lib/src/io_client.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698