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

Side by Side Diff: runtime/bin/file.cc

Issue 9657001: Start using Dart_PropagateError in the runtime/bin directory. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 | « runtime/bin/eventhandler.cc ('k') | runtime/bin/gen_snapshot.cc » ('j') | no next file with comments »
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 #include "bin/file.h" 5 #include "bin/file.h"
6 6
7 #include "bin/builtin.h" 7 #include "bin/builtin.h"
8 #include "bin/dartutils.h" 8 #include "bin/dartutils.h"
9 #include "bin/thread.h" 9 #include "bin/thread.h"
10 10
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 File* file = reinterpret_cast<File*>(value); 172 File* file = reinterpret_cast<File*>(value);
173 if (file != NULL) { 173 if (file != NULL) {
174 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); 174 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1);
175 ASSERT(Dart_IsList(buffer_obj)); 175 ASSERT(Dart_IsList(buffer_obj));
176 int64_t offset = 176 int64_t offset =
177 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); 177 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2));
178 int64_t length = 178 int64_t length =
179 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); 179 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3));
180 intptr_t array_len = 0; 180 intptr_t array_len = 0;
181 Dart_Handle result = Dart_ListLength(buffer_obj, &array_len); 181 Dart_Handle result = Dart_ListLength(buffer_obj, &array_len);
182 ASSERT(!Dart_IsError(result)); 182 if (Dart_IsError(result)) {
183 Dart_PropagateError(result);
184 }
183 ASSERT((offset + length) <= array_len); 185 ASSERT((offset + length) <= array_len);
184 uint8_t* buffer = new uint8_t[length]; 186 uint8_t* buffer = new uint8_t[length];
185 int total_bytes_read = 187 int total_bytes_read =
186 file->Read(reinterpret_cast<void*>(buffer), length); 188 file->Read(reinterpret_cast<void*>(buffer), length);
187 /* 189 /*
188 * Reading 0 indicates end of file. 190 * Reading 0 indicates end of file.
189 */ 191 */
190 if (total_bytes_read >= 0) { 192 if (total_bytes_read >= 0) {
191 result = 193 result =
192 Dart_ListSetAsBytes(buffer_obj, offset, buffer, total_bytes_read); 194 Dart_ListSetAsBytes(buffer_obj, offset, buffer, total_bytes_read);
193 if (!Dart_IsError(result)) { 195 if (Dart_IsError(result)) {
194 return_value = total_bytes_read; 196 delete[] buffer;
197 Dart_PropagateError(result);
195 } 198 }
199 return_value = total_bytes_read;
196 } 200 }
197 delete[] buffer; 201 delete[] buffer;
198 } 202 }
199 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); 203 Dart_SetReturnValue(args, Dart_NewInteger(return_value));
200 Dart_ExitScope(); 204 Dart_ExitScope();
201 } 205 }
202 206
203 207
204 void FUNCTION_NAME(File_WriteList)(Dart_NativeArguments args) { 208 void FUNCTION_NAME(File_WriteList)(Dart_NativeArguments args) {
205 Dart_EnterScope(); 209 Dart_EnterScope();
206 intptr_t return_value = -1; 210 intptr_t return_value = -1;
207 intptr_t value = 211 intptr_t value =
208 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); 212 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0));
209 File* file = reinterpret_cast<File*>(value); 213 File* file = reinterpret_cast<File*>(value);
210 if (file != NULL) { 214 if (file != NULL) {
211 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); 215 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1);
212 ASSERT(Dart_IsList(buffer_obj)); 216 ASSERT(Dart_IsList(buffer_obj));
213 int64_t offset = 217 int64_t offset =
214 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); 218 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2));
215 int64_t length = 219 int64_t length =
216 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); 220 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3));
217 intptr_t buffer_len = 0; 221 intptr_t buffer_len = 0;
218 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); 222 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len);
219 ASSERT(!Dart_IsError(result)); 223 if (Dart_IsError(result)) {
224 Dart_PropagateError(result);
225 }
220 ASSERT((offset + length) <= buffer_len); 226 ASSERT((offset + length) <= buffer_len);
221 uint8_t* buffer = new uint8_t[length]; 227 uint8_t* buffer = new uint8_t[length];
222 result = Dart_ListGetAsBytes(buffer_obj, offset, buffer, length); 228 result = Dart_ListGetAsBytes(buffer_obj, offset, buffer, length);
223 ASSERT(!Dart_IsError(result)); 229 if (Dart_IsError(result)) {
230 delete[] buffer;
231 Dart_PropagateError(result);
232 }
224 int total_bytes_written = 233 int total_bytes_written =
225 file->Write(reinterpret_cast<void*>(buffer), length); 234 file->Write(reinterpret_cast<void*>(buffer), length);
226 if (total_bytes_written >= 0) { 235 if (total_bytes_written >= 0) {
227 return_value = total_bytes_written; 236 return_value = total_bytes_written;
228 } 237 }
229 delete[] buffer; 238 delete[] buffer;
230 } 239 }
231 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); 240 Dart_SetReturnValue(args, Dart_NewInteger(return_value));
232 Dart_ExitScope(); 241 Dart_ExitScope();
233 } 242 }
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 Dart_EnterScope(); 768 Dart_EnterScope();
760 Dart_SetReturnValue(args, Dart_Null()); 769 Dart_SetReturnValue(args, Dart_Null());
761 Dart_Port service_port = File::GetServicePort(); 770 Dart_Port service_port = File::GetServicePort();
762 if (service_port != kIllegalPort) { 771 if (service_port != kIllegalPort) {
763 // Return a send port for the service port. 772 // Return a send port for the service port.
764 Dart_Handle send_port = Dart_NewSendPort(service_port); 773 Dart_Handle send_port = Dart_NewSendPort(service_port);
765 Dart_SetReturnValue(args, send_port); 774 Dart_SetReturnValue(args, send_port);
766 } 775 }
767 Dart_ExitScope(); 776 Dart_ExitScope();
768 } 777 }
OLDNEW
« no previous file with comments | « runtime/bin/eventhandler.cc ('k') | runtime/bin/gen_snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698