OLD | NEW |
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 // Constants used when working with native ports. | 7 // Constants used when working with native ports. |
8 const int _SUCCESS_RESPONSE = 0; | 8 const int _SUCCESS_RESPONSE = 0; |
9 const int _ILLEGAL_ARGUMENT_RESPONSE = 1; | 9 const int _ILLEGAL_ARGUMENT_RESPONSE = 1; |
10 const int _OSERROR_RESPONSE = 2; | 10 const int _OSERROR_RESPONSE = 2; |
11 const int _FILE_CLOSED_RESPONSE = 3; | 11 const int _FILE_CLOSED_RESPONSE = 3; |
12 | 12 |
13 const int _ERROR_RESPONSE_ERROR_TYPE = 0; | 13 const int _ERROR_RESPONSE_ERROR_TYPE = 0; |
14 const int _OSERROR_RESPONSE_ERROR_CODE = 1; | 14 const int _OSERROR_RESPONSE_ERROR_CODE = 1; |
15 const int _OSERROR_RESPONSE_MESSAGE = 2; | 15 const int _OSERROR_RESPONSE_MESSAGE = 2; |
16 | 16 |
| 17 // Functions used to receive exceptions from native ports. |
| 18 bool _isErrorResponse(response) { |
| 19 return response is List && response[0] != _SUCCESS_RESPONSE; |
| 20 } |
| 21 |
| 22 /** |
| 23 * Returns an Exception or an Error |
| 24 */ |
| 25 _exceptionFromResponse(response, String message) { |
| 26 assert(_isErrorResponse(response)); |
| 27 switch (response[_ERROR_RESPONSE_ERROR_TYPE]) { |
| 28 case _ILLEGAL_ARGUMENT_RESPONSE: |
| 29 return new ArgumentError(); |
| 30 case _OSERROR_RESPONSE: |
| 31 var err = new OSError(response[_OSERROR_RESPONSE_MESSAGE], |
| 32 response[_OSERROR_RESPONSE_ERROR_CODE]); |
| 33 return new FileIOException(message, err); |
| 34 case _FILE_CLOSED_RESPONSE: |
| 35 return new FileIOException("File closed"); |
| 36 default: |
| 37 return new Exception("Unknown error"); |
| 38 } |
| 39 } |
| 40 |
17 /** | 41 /** |
18 * An [OSError] object holds information about an error from the | 42 * An [OSError] object holds information about an error from the |
19 * operating system. | 43 * operating system. |
20 */ | 44 */ |
21 class OSError implements Error { | 45 class OSError implements Error { |
22 /** Constant used to indicate that no OS error code is available. */ | 46 /** Constant used to indicate that no OS error code is available. */ |
23 static const int noErrorCode = -1; | 47 static const int noErrorCode = -1; |
24 | 48 |
25 /** Creates an OSError object from a message and an errorCode. */ | 49 /** Creates an OSError object from a message and an errorCode. */ |
26 const OSError([String this.message = "", int this.errorCode = noErrorCode]); | 50 const OSError([String this.message = "", int this.errorCode = noErrorCode]); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 class _BufferUtils { | 128 class _BufferUtils { |
105 // Check if a List is a builtin VM List type. Returns true | 129 // Check if a List is a builtin VM List type. Returns true |
106 // if the List is a builtin VM List type and false if it is | 130 // if the List is a builtin VM List type and false if it is |
107 // a user defined List type. | 131 // a user defined List type. |
108 external static bool _isBuiltinList(List buffer); | 132 external static bool _isBuiltinList(List buffer); |
109 } | 133 } |
110 | 134 |
111 class _IOCrypto { | 135 class _IOCrypto { |
112 external static Uint8List getRandomBytes(int count); | 136 external static Uint8List getRandomBytes(int count); |
113 } | 137 } |
OLD | NEW |