Chromium Code Reviews| 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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 480 int32_t min = 0xc0000000; // -1073741824 | 480 int32_t min = 0xc0000000; // -1073741824 |
| 481 int32_t max = 0x3fffffff; // 1073741823 | 481 int32_t max = 0x3fffffff; // 1073741823 |
| 482 ASSERT(min <= value && value < max); | 482 ASSERT(min <= value && value < max); |
| 483 Dart_CObject object; | 483 Dart_CObject object; |
| 484 object.type = Dart_CObject::kInt32; | 484 object.type = Dart_CObject::kInt32; |
| 485 object.value.as_int32 = value; | 485 object.value.as_int32 = value; |
| 486 return Dart_PostCObject(port_id, &object); | 486 return Dart_PostCObject(port_id, &object); |
| 487 } | 487 } |
| 488 | 488 |
| 489 | 489 |
| 490 Dart_Handle DartUtils::GetDartClass(const char* library_url, | |
| 491 const char* class_name) { | |
| 492 return Dart_GetClass(Dart_LookupLibrary(Dart_NewString(library_url)), | |
|
Mads Ager (google)
2012/09/28 12:03:56
What is the state of the current Dart API. I forge
Bill Hesse
2012/10/31 16:33:29
The Dart API has been fixed to always return the e
| |
| 493 Dart_NewString(class_name)); | |
| 494 } | |
| 495 | |
| 496 | |
| 490 Dart_Handle DartUtils::NewDartOSError() { | 497 Dart_Handle DartUtils::NewDartOSError() { |
| 491 // Extract the current OS error. | 498 // Extract the current OS error. |
| 492 OSError os_error; | 499 OSError os_error; |
| 493 return NewDartOSError(&os_error); | 500 return NewDartOSError(&os_error); |
| 494 } | 501 } |
| 495 | 502 |
| 496 | 503 |
| 497 Dart_Handle DartUtils::NewDartOSError(OSError* os_error) { | 504 Dart_Handle DartUtils::NewDartOSError(OSError* os_error) { |
| 498 // Create a Dart OSError object with the information retrieved from the OS. | 505 // Create a Dart OSError object with the information retrieved from the OS. |
| 499 Dart_Handle url = Dart_NewString("dart:io"); | 506 Dart_Handle clazz = GetDartClass(kIOLibURL, "OSError"); |
| 500 if (Dart_IsError(url)) return url; | |
| 501 Dart_Handle lib = Dart_LookupLibrary(url); | |
| 502 if (Dart_IsError(lib)) return lib; | |
| 503 Dart_Handle class_name = Dart_NewString("OSError"); | |
| 504 if (Dart_IsError(class_name)) return class_name; | |
| 505 Dart_Handle clazz = Dart_GetClass(lib, class_name); | |
| 506 if (Dart_IsError(clazz)) return clazz; | |
| 507 Dart_Handle args[2]; | 507 Dart_Handle args[2]; |
| 508 args[0] = Dart_NewString(os_error->message()); | 508 args[0] = Dart_NewString(os_error->message()); |
| 509 if (Dart_IsError(args[0])) return args[0]; | |
| 510 args[1] = Dart_NewInteger(os_error->code()); | 509 args[1] = Dart_NewInteger(os_error->code()); |
| 511 if (Dart_IsError(args[1])) return args[1]; | 510 return Dart_New(clazz, Dart_Null(), 2, args); |
| 512 Dart_Handle err = Dart_New(clazz, Dart_Null(), 2, args); | |
| 513 return err; | |
| 514 } | 511 } |
| 515 | 512 |
| 516 | 513 |
| 514 Dart_Handle DartUtils::NewDartExceptionWithMessage(const char* library_url, | |
| 515 const char* exception_name, | |
| 516 const char* message) { | |
| 517 // Create a Dart Exception object with a message. | |
| 518 Dart_Handle clazz = GetDartClass(library_url, exception_name); | |
| 519 Dart_Handle args[1]; | |
| 520 args[0] = Dart_NewString(message); | |
| 521 return Dart_New(clazz, Dart_Null(), 1, args); | |
| 522 } | |
| 523 | |
| 524 | |
| 525 Dart_Handle DartUtils::NewDartIllegalArgumentException(const char* message) { | |
| 526 return NewDartExceptionWithMessage(kCoreLibURL, | |
| 527 "IllegalArgumentException", | |
|
Søren Gjesse
2012/09/28 09:17:31
This is now ArgumentError.
Bill Hesse
2012/10/31 16:33:29
Fixed.
On 2012/09/28 09:17:31, Søren Gjesse wrote
| |
| 528 message); | |
| 529 } | |
| 530 | |
| 531 | |
| 517 void DartUtils::SetOriginalWorkingDirectory() { | 532 void DartUtils::SetOriginalWorkingDirectory() { |
| 518 original_working_directory = Directory::Current(); | 533 original_working_directory = Directory::Current(); |
| 519 } | 534 } |
| 520 | 535 |
| 521 | 536 |
| 522 // Statically allocated Dart_CObject instances for immutable | 537 // Statically allocated Dart_CObject instances for immutable |
| 523 // objects. As these will be used by different threads the use of | 538 // objects. As these will be used by different threads the use of |
| 524 // these depends on the fact that the marking internally in the | 539 // these depends on the fact that the marking internally in the |
| 525 // Dart_CObject structure is not marking simple value objects. | 540 // Dart_CObject structure is not marking simple value objects. |
| 526 Dart_CObject CObject::api_null_ = { Dart_CObject::kNull , { 0 } }; | 541 Dart_CObject CObject::api_null_ = { Dart_CObject::kNull , { 0 } }; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 660 | 675 |
| 661 CObject* CObject::NewOSError(OSError* os_error) { | 676 CObject* CObject::NewOSError(OSError* os_error) { |
| 662 CObject* error_message = | 677 CObject* error_message = |
| 663 new CObjectString(CObject::NewString(os_error->message())); | 678 new CObjectString(CObject::NewString(os_error->message())); |
| 664 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 679 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
| 665 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 680 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
| 666 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 681 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
| 667 result->SetAt(2, error_message); | 682 result->SetAt(2, error_message); |
| 668 return result; | 683 return result; |
| 669 } | 684 } |
| OLD | NEW |