| 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 // These must match the constants in runtime/bin/dartutils.h class CObject. | 8 // These must match the constants in runtime/bin/dartutils.h class CObject. |
| 9 const int _SUCCESS_RESPONSE = 0; | 9 const int _SUCCESS_RESPONSE = 0; |
| 10 const int _ILLEGAL_ARGUMENT_RESPONSE = 1; | 10 const int _ILLEGAL_ARGUMENT_RESPONSE = 1; |
| 11 const int _OSERROR_RESPONSE = 2; | 11 const int _OSERROR_RESPONSE = 2; |
| 12 const int _FILE_CLOSED_RESPONSE = 3; | 12 const int _FILE_CLOSED_RESPONSE = 3; |
| 13 | 13 |
| 14 const int _ERROR_RESPONSE_ERROR_TYPE = 0; | 14 const int _ERROR_RESPONSE_ERROR_TYPE = 0; |
| 15 const int _OSERROR_RESPONSE_ERROR_CODE = 1; | 15 const int _OSERROR_RESPONSE_ERROR_CODE = 1; |
| 16 const int _OSERROR_RESPONSE_MESSAGE = 2; | 16 const int _OSERROR_RESPONSE_MESSAGE = 2; |
| 17 | 17 |
| 18 // Functions used to receive exceptions from native ports. | 18 // Functions used to receive exceptions from native ports. |
| 19 bool _isErrorResponse(response) { | 19 bool _isErrorResponse(response) { |
| 20 return response is List && response[0] != _SUCCESS_RESPONSE; | 20 return response is List && response[0] != _SUCCESS_RESPONSE; |
| 21 } | 21 } |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * Returns an Exception or an Error | 24 * Returns an Exception or an Error |
| 25 */ | 25 */ |
| 26 _exceptionFromResponse(response, String message) { | 26 _exceptionFromResponse(response, String message, String path) { |
| 27 assert(_isErrorResponse(response)); | 27 assert(_isErrorResponse(response)); |
| 28 switch (response[_ERROR_RESPONSE_ERROR_TYPE]) { | 28 switch (response[_ERROR_RESPONSE_ERROR_TYPE]) { |
| 29 case _ILLEGAL_ARGUMENT_RESPONSE: | 29 case _ILLEGAL_ARGUMENT_RESPONSE: |
| 30 return new ArgumentError(); | 30 return new ArgumentError(); |
| 31 case _OSERROR_RESPONSE: | 31 case _OSERROR_RESPONSE: |
| 32 var err = new OSError(response[_OSERROR_RESPONSE_MESSAGE], | 32 var err = new OSError(response[_OSERROR_RESPONSE_MESSAGE], |
| 33 response[_OSERROR_RESPONSE_ERROR_CODE]); | 33 response[_OSERROR_RESPONSE_ERROR_CODE]); |
| 34 return new FileException(message, err); | 34 return new FileException(message, path, err); |
| 35 case _FILE_CLOSED_RESPONSE: | 35 case _FILE_CLOSED_RESPONSE: |
| 36 return new FileException("File closed"); | 36 return new FileException("File closed", path); |
| 37 default: | 37 default: |
| 38 return new Exception("Unknown error"); | 38 return new Exception("Unknown error"); |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * Base class for all IO related exceptions. | 43 * Base class for all IO related exceptions. |
| 44 */ | 44 */ |
| 45 abstract class IOException implements Exception { | 45 abstract class IOException implements Exception { |
| 46 String toString() => "IOException"; | 46 String toString() => "IOException"; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 class _BufferUtils { | 158 class _BufferUtils { |
| 159 // Check if a List is a builtin VM List type. Returns true | 159 // Check if a List is a builtin VM List type. Returns true |
| 160 // if the List is a builtin VM List type and false if it is | 160 // if the List is a builtin VM List type and false if it is |
| 161 // a user defined List type. | 161 // a user defined List type. |
| 162 external static bool _isBuiltinList(List buffer); | 162 external static bool _isBuiltinList(List buffer); |
| 163 } | 163 } |
| 164 | 164 |
| 165 class _IOCrypto { | 165 class _IOCrypto { |
| 166 external static Uint8List getRandomBytes(int count); | 166 external static Uint8List getRandomBytes(int count); |
| 167 } | 167 } |
| OLD | NEW |