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

Unified Diff: sdk/lib/io/common.dart

Issue 14907002: dart:io | Implement asynchronous versions of FileSystemEntity methods. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add implementation of FileSystemEntity.type, and refactor error handling. Created 7 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 | « sdk/lib/_internal/compiler/implementation/lib/io_patch.dart ('k') | sdk/lib/io/directory_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/common.dart
diff --git a/sdk/lib/io/common.dart b/sdk/lib/io/common.dart
index 9350ad68308d76336d96e31ba3264f62cd4e3c07..022e84b340825f3a47f8890eab9fd6c6d43faff3 100644
--- a/sdk/lib/io/common.dart
+++ b/sdk/lib/io/common.dart
@@ -14,6 +14,30 @@ const int _ERROR_RESPONSE_ERROR_TYPE = 0;
const int _OSERROR_RESPONSE_ERROR_CODE = 1;
const int _OSERROR_RESPONSE_MESSAGE = 2;
+// Functions used to receive exceptions from native ports.
+bool _isErrorResponse(response) {
+ return response is List && response[0] != _SUCCESS_RESPONSE;
+}
+
+/**
+ * Returns an Exception or an Error
+ */
+_exceptionFromResponse(response, String message) {
+ assert(_isErrorResponse(response));
+ switch (response[_ERROR_RESPONSE_ERROR_TYPE]) {
+ case _ILLEGAL_ARGUMENT_RESPONSE:
+ return new ArgumentError();
+ case _OSERROR_RESPONSE:
+ var err = new OSError(response[_OSERROR_RESPONSE_MESSAGE],
+ response[_OSERROR_RESPONSE_ERROR_CODE]);
+ return new FileIOException(message, err);
+ case _FILE_CLOSED_RESPONSE:
+ return new FileIOException("File closed");
+ default:
+ return new Exception("Unknown error");
+ }
+}
+
/**
* An [OSError] object holds information about an error from the
* operating system.
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/lib/io_patch.dart ('k') | sdk/lib/io/directory_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698