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

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

Issue 9630012: Error reporting on File in dart:io (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Style issues 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/dartutils.h ('k') | runtime/bin/directory.h » ('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/dartutils.h" 5 #include "bin/dartutils.h"
6 6
7 #include "bin/file.h" 7 #include "bin/file.h"
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/globals.h" 10 #include "platform/globals.h"
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 int32_t min = 0xc0000000; // -1073741824 271 int32_t min = 0xc0000000; // -1073741824
272 int32_t max = 0x3fffffff; // 1073741823 272 int32_t max = 0x3fffffff; // 1073741823
273 ASSERT(min <= value && value < max); 273 ASSERT(min <= value && value < max);
274 Dart_CObject object; 274 Dart_CObject object;
275 object.type = Dart_CObject::kInt32; 275 object.type = Dart_CObject::kInt32;
276 object.value.as_int32 = value; 276 object.value.as_int32 = value;
277 return Dart_PostCObject(port_id, &object); 277 return Dart_PostCObject(port_id, &object);
278 } 278 }
279 279
280 280
281 Dart_Handle DartUtils::NewDartOSError() {
282 // Extract the current OS error.
283 OSError os_error;
284 return NewDartOSError(&os_error);
285 }
286
287
288 Dart_Handle DartUtils::NewDartOSError(OSError* os_error) {
289 // Create a Dart OSError object with the information retrieved from the OS.
290 Dart_Handle url = Dart_NewString("dart:io");
291 if (Dart_IsError(url)) return url;
292 Dart_Handle lib = Dart_LookupLibrary(url);
293 if (Dart_IsError(lib)) return lib;
294 Dart_Handle cls = Dart_NewString("IOUtils");
295 if (Dart_IsError(cls)) return cls;
296 Dart_Handle method = Dart_NewString("makeOSError");
297 if (Dart_IsError(method)) return method;
298 Dart_Handle args[2];
299 args[0] = Dart_NewString(os_error->message());
300 if (Dart_IsError(args[0])) return args[0];
301 args[1] = Dart_NewInteger(os_error->code());
302 if (Dart_IsError(args[1])) return args[1];
303 Dart_Handle err = Dart_InvokeStatic(lib, cls, method, 2, args);
304 return err;
305 }
306
307
281 // Statically allocated Dart_CObject instances for immutable 308 // Statically allocated Dart_CObject instances for immutable
282 // objects. As these will be used by different threads the use of 309 // objects. As these will be used by different threads the use of
283 // these depends on the fact that the marking internally in the 310 // these depends on the fact that the marking internally in the
284 // Dart_CObject structure is not marking simple value objects. 311 // Dart_CObject structure is not marking simple value objects.
285 Dart_CObject CObject::api_null_ = { Dart_CObject::kNull , { 0 } }; 312 Dart_CObject CObject::api_null_ = { Dart_CObject::kNull , { 0 } };
286 Dart_CObject CObject::api_true_ = { Dart_CObject::kBool , { true } }; 313 Dart_CObject CObject::api_true_ = { Dart_CObject::kBool , { true } };
287 Dart_CObject CObject::api_false_ = { Dart_CObject::kBool, { false } }; 314 Dart_CObject CObject::api_false_ = { Dart_CObject::kBool, { false } };
288 CObject CObject::null_ = CObject(&api_null_); 315 CObject CObject::null_ = CObject(&api_null_);
289 CObject CObject::true_ = CObject(&api_true_); 316 CObject CObject::true_ = CObject(&api_true_);
290 CObject CObject::false_ = CObject(&api_false_); 317 CObject CObject::false_ = CObject(&api_false_);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 return cobject; 398 return cobject;
372 } 399 }
373 400
374 401
375 Dart_CObject* CObject::NewByteArray(int length) { 402 Dart_CObject* CObject::NewByteArray(int length) {
376 Dart_CObject* cobject = New(Dart_CObject::kByteArray, length); 403 Dart_CObject* cobject = New(Dart_CObject::kByteArray, length);
377 cobject->value.as_byte_array.length = length; 404 cobject->value.as_byte_array.length = length;
378 cobject->value.as_byte_array.values = reinterpret_cast<uint8_t*>(cobject + 1); 405 cobject->value.as_byte_array.values = reinterpret_cast<uint8_t*>(cobject + 1);
379 return cobject; 406 return cobject;
380 } 407 }
408
409
410 static int kIllegalArgumentError = 1;
411 static int kOSError = 2;
412
413
414 CObject* CObject::IllegalArgumentError() {
415 CObjectArray* result = new CObjectArray(CObject::NewArray(1));
416 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kIllegalArgumentError)));
417 return result;
418 }
419
420
421 CObject* CObject::NewOSError() {
422 OSError os_error;
423 CObject* error_message =
424 new CObjectString(CObject::NewString(os_error.message()));
425 CObjectArray* result = new CObjectArray(CObject::NewArray(3));
426 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError)));
427 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error.code())));
428 result->SetAt(2, error_message);
429 return result;
430 }
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.h ('k') | runtime/bin/directory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698