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

Side by Side Diff: runtime/bin/common.dart

Issue 11023003: Clean up file implementation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/bin/directory_impl.dart » ('j') | runtime/bin/file_impl.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Constants used when working with native ports.
6 const int _SUCCESS_RESPONSE = 0;
7 const int _ILLEGAL_ARGUMENT_RESPONSE = 1;
8 const int _OSERROR_RESPONSE = 2;
9 const int _FILE_CLOSED_RESPONSE = 3;
10
11 const int _ERROR_RESPONSE_ERROR_TYPE = 0;
12 const int _OSERROR_RESPONSE_ERROR_CODE = 1;
13 const int _OSERROR_RESPONSE_MESSAGE = 2;
14
5 /** 15 /**
6 * An [OSError] object holds information about an error from the 16 * An [OSError] object holds information about an error from the
7 * operating system. 17 * operating system.
8 */ 18 */
9 class OSError { 19 class OSError {
10 /** Constant used to indicate that no OS error code is available. */ 20 /** Constant used to indicate that no OS error code is available. */
11 static const int noErrorCode = -1; 21 static const int noErrorCode = -1;
12 22
13 /** Creates an OSError object from a message and an errorCode. */ 23 /** Creates an OSError object from a message and an errorCode. */
14 const OSError([String this.message = "", int this.errorCode = noErrorCode]); 24 const OSError([String this.message = "", int this.errorCode = noErrorCode]);
(...skipping 29 matching lines...) Expand all
44 final int errorCode; 54 final int errorCode;
45 } 55 }
46 56
47 57
48 // Check if a List is a builtin VM List type. Returns true 58 // Check if a List is a builtin VM List type. Returns true
49 // if the List is a builtin VM List type and false if it is 59 // if the List is a builtin VM List type and false if it is
50 // a user defined List type. 60 // a user defined List type.
51 bool _isBuiltinList(List buffer) native "Common_IsBuiltinList"; 61 bool _isBuiltinList(List buffer) native "Common_IsBuiltinList";
52 62
53 63
64 // Object for holding a buffer and an offset.
65 class _BufferAndOffset {
66 _BufferAndOffset(List this.buffer, int this.offset);
67 List buffer;
68 int offset;
69 }
70
71
54 // Ensure that the input List can be serialized through a native port. 72 // Ensure that the input List can be serialized through a native port.
55 // Only builtin Lists can be serialized through. If user-defined Lists 73 // Only builtin Lists can be serialized through. If user-defined Lists
56 // get here, the contents is copied to a Uint8List. This has the added 74 // get here, the contents is copied to a Uint8List. This has the added
57 // benefit that it is faster to access from the C code as well. 75 // benefit that it is faster to access from the C code as well.
58 List _ensureFastAndSerializableBuffer( 76 _BufferAndOffset _ensureFastAndSerializableBuffer(
59 List buffer, int offset, int bytes) { 77 List buffer, int offset, int bytes) {
60 List outBuffer;
61 int outOffset = offset;
62 if (buffer is Uint8List || _isBuiltinList(buffer)) { 78 if (buffer is Uint8List || _isBuiltinList(buffer)) {
63 outBuffer = buffer; 79 return new _BufferAndOffset(buffer, offset);
64 } else { 80 }
65 outBuffer = new Uint8List(bytes); 81 var newBuffer = new Uint8List(bytes);
66 outOffset = 0; 82 int j = offset;
67 int j = offset; 83 for (int i = 0; i < bytes; i++) {
68 for (int i = 0; i < bytes; i++) { 84 int value = buffer[j];
69 int value = buffer[j]; 85 if (value is! int) {
70 if (value is! int) { 86 throw new FileIOException("List element is not an integer at index $j");
71 throw new FileIOException(
72 "List element is not an integer at index $j");
73 }
74 outBuffer[i] = value;
75 j++;
76 } 87 }
88 newBuffer[i] = value;
89 j++;
77 } 90 }
78 return [outBuffer, outOffset]; 91 return new _BufferAndOffset(newBuffer, 0);
79 } 92 }
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/directory_impl.dart » ('j') | runtime/bin/file_impl.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698