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 #include "bin/dartutils.h" | 5 #include "bin/dartutils.h" |
6 | 6 |
7 #include "bin/extensions.h" | 7 #include "bin/extensions.h" |
8 #include "bin/directory.h" | 8 #include "bin/directory.h" |
9 #include "bin/file.h" | 9 #include "bin/file.h" |
10 #include "include/dart_api.h" | 10 #include "include/dart_api.h" |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 int32_t min = 0xc0000000; // -1073741824 | 476 int32_t min = 0xc0000000; // -1073741824 |
477 int32_t max = 0x3fffffff; // 1073741823 | 477 int32_t max = 0x3fffffff; // 1073741823 |
478 ASSERT(min <= value && value < max); | 478 ASSERT(min <= value && value < max); |
479 Dart_CObject object; | 479 Dart_CObject object; |
480 object.type = Dart_CObject::kInt32; | 480 object.type = Dart_CObject::kInt32; |
481 object.value.as_int32 = value; | 481 object.value.as_int32 = value; |
482 return Dart_PostCObject(port_id, &object); | 482 return Dart_PostCObject(port_id, &object); |
483 } | 483 } |
484 | 484 |
485 | 485 |
486 Dart_Handle DartUtils::GetDartClass(const char* library_url, | |
487 const char* class_name) { | |
488 return Dart_GetClass(Dart_LookupLibrary(Dart_NewString(library_url)), | |
489 Dart_NewString(class_name)); | |
490 } | |
491 | |
492 | |
486 Dart_Handle DartUtils::NewDartOSError() { | 493 Dart_Handle DartUtils::NewDartOSError() { |
487 // Extract the current OS error. | 494 // Extract the current OS error. |
488 OSError os_error; | 495 OSError os_error; |
489 return NewDartOSError(&os_error); | 496 return NewDartOSError(&os_error); |
490 } | 497 } |
491 | 498 |
492 | 499 |
493 Dart_Handle DartUtils::NewDartOSError(OSError* os_error) { | 500 Dart_Handle DartUtils::NewDartOSError(OSError* os_error) { |
494 // Create a Dart OSError object with the information retrieved from the OS. | 501 // Create a Dart OSError object with the information retrieved from the OS. |
495 Dart_Handle url = Dart_NewString("dart:io"); | 502 Dart_Handle clazz = GetDartClass(kIOLibURL, "OSError"); |
496 if (Dart_IsError(url)) return url; | |
497 Dart_Handle lib = Dart_LookupLibrary(url); | |
498 if (Dart_IsError(lib)) return lib; | |
499 Dart_Handle class_name = Dart_NewString("OSError"); | |
500 if (Dart_IsError(class_name)) return class_name; | |
501 Dart_Handle clazz = Dart_GetClass(lib, class_name); | |
502 if (Dart_IsError(clazz)) return clazz; | |
503 Dart_Handle args[2]; | 503 Dart_Handle args[2]; |
504 args[0] = Dart_NewString(os_error->message()); | 504 args[0] = Dart_NewString(os_error->message()); |
505 if (Dart_IsError(args[0])) return args[0]; | |
506 args[1] = Dart_NewInteger(os_error->code()); | 505 args[1] = Dart_NewInteger(os_error->code()); |
507 if (Dart_IsError(args[1])) return args[1]; | 506 return Dart_New(clazz, Dart_Null(), 2, args); |
508 Dart_Handle err = Dart_New(clazz, Dart_Null(), 2, args); | |
509 return err; | |
510 } | 507 } |
511 | 508 |
512 | 509 |
510 Dart_Handle DartUtils::NewDartExceptionWithMessage(const char* library_url, | |
511 const char* exception_name, | |
512 const char* message) { | |
513 // Create a Dart Exception object with a message. | |
514 Dart_Handle clazz = GetDartClass(library_url, exception_name); | |
515 Dart_Handle args[1]; | |
516 args[0] = Dart_NewString(message); | |
517 return Dart_New(clazz, Dart_Null(), 1, args); | |
518 } | |
519 | |
520 | |
521 Dart_Handle DartUtils::NewDartIllegalArgumentException(const char* message) { | |
Bill Hesse
2012/10/31 16:33:29
Changed to ArgumentError.
| |
522 return NewDartExceptionWithMessage(kCoreLibURL, | |
523 "IllegalArgumentException", | |
524 message); | |
525 } | |
526 | |
527 | |
513 void DartUtils::SetOriginalWorkingDirectory() { | 528 void DartUtils::SetOriginalWorkingDirectory() { |
514 original_working_directory = Directory::Current(); | 529 original_working_directory = Directory::Current(); |
515 } | 530 } |
516 | 531 |
517 | 532 |
518 // Statically allocated Dart_CObject instances for immutable | 533 // Statically allocated Dart_CObject instances for immutable |
519 // objects. As these will be used by different threads the use of | 534 // objects. As these will be used by different threads the use of |
520 // these depends on the fact that the marking internally in the | 535 // these depends on the fact that the marking internally in the |
521 // Dart_CObject structure is not marking simple value objects. | 536 // Dart_CObject structure is not marking simple value objects. |
522 Dart_CObject CObject::api_null_ = { Dart_CObject::kNull , { 0 } }; | 537 Dart_CObject CObject::api_null_ = { Dart_CObject::kNull , { 0 } }; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
656 | 671 |
657 CObject* CObject::NewOSError(OSError* os_error) { | 672 CObject* CObject::NewOSError(OSError* os_error) { |
658 CObject* error_message = | 673 CObject* error_message = |
659 new CObjectString(CObject::NewString(os_error->message())); | 674 new CObjectString(CObject::NewString(os_error->message())); |
660 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 675 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
661 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 676 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
662 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 677 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
663 result->SetAt(2, error_message); | 678 result->SetAt(2, error_message); |
664 return result; | 679 return result; |
665 } | 680 } |
OLD | NEW |