Chromium Code Reviews| Index: runtime/bin/dartutils.cc |
| diff --git a/runtime/bin/dartutils.cc b/runtime/bin/dartutils.cc |
| index 57dfbc59d080b472224bb2ef144feb8b19ff95c2..0084a2669b7a9cbb7b0ec220c25245eafd8f1120 100644 |
| --- a/runtime/bin/dartutils.cc |
| +++ b/runtime/bin/dartutils.cc |
| @@ -483,6 +483,13 @@ bool DartUtils::PostInt32(Dart_Port port_id, int32_t value) { |
| } |
| +Dart_Handle DartUtils::GetDartClass(const char* library_url, |
| + const char* class_name) { |
| + return Dart_GetClass(Dart_LookupLibrary(Dart_NewString(library_url)), |
|
Søren Gjesse
2012/11/01 11:49:11
Does this work correctly with error handles if the
Bill Hesse
2012/11/11 22:34:34
Yes. All the functions return an error handle if
|
| + Dart_NewString(class_name)); |
| +} |
| + |
| + |
| Dart_Handle DartUtils::NewDartOSError() { |
| // Extract the current OS error. |
| OSError os_error; |
| @@ -492,21 +499,29 @@ Dart_Handle DartUtils::NewDartOSError() { |
| Dart_Handle DartUtils::NewDartOSError(OSError* os_error) { |
| // Create a Dart OSError object with the information retrieved from the OS. |
| - Dart_Handle url = Dart_NewString("dart:io"); |
| - if (Dart_IsError(url)) return url; |
| - Dart_Handle lib = Dart_LookupLibrary(url); |
| - if (Dart_IsError(lib)) return lib; |
| - Dart_Handle class_name = Dart_NewString("OSError"); |
| - if (Dart_IsError(class_name)) return class_name; |
| - Dart_Handle clazz = Dart_GetClass(lib, class_name); |
| - if (Dart_IsError(clazz)) return clazz; |
| + Dart_Handle clazz = GetDartClass(kIOLibURL, "OSError"); |
| Dart_Handle args[2]; |
| args[0] = Dart_NewString(os_error->message()); |
| - if (Dart_IsError(args[0])) return args[0]; |
| args[1] = Dart_NewInteger(os_error->code()); |
| - if (Dart_IsError(args[1])) return args[1]; |
| - Dart_Handle err = Dart_New(clazz, Dart_Null(), 2, args); |
| - return err; |
| + return Dart_New(clazz, Dart_Null(), 2, args); |
| +} |
| + |
| + |
| +Dart_Handle DartUtils::NewDartExceptionWithMessage(const char* library_url, |
| + const char* exception_name, |
| + const char* message) { |
| + // Create a Dart Exception object with a message. |
| + Dart_Handle clazz = GetDartClass(library_url, exception_name); |
| + Dart_Handle args[1]; |
| + args[0] = Dart_NewString(message); |
| + return Dart_New(clazz, Dart_Null(), 1, args); |
| +} |
| + |
| + |
| +Dart_Handle DartUtils::NewDartArgumentError(const char* message) { |
| + return NewDartExceptionWithMessage(kCoreLibURL, |
| + "ArgumentError", |
| + message); |
| } |