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