| Index: runtime/bin/main.cc
 | 
| ===================================================================
 | 
| --- runtime/bin/main.cc	(revision 43502)
 | 
| +++ runtime/bin/main.cc	(working copy)
 | 
| @@ -75,6 +75,30 @@
 | 
|  // being allocated.
 | 
|  static int vm_service_server_port = -1;
 | 
|  
 | 
| +
 | 
| +// Exit code indicating an API error.
 | 
| +static const int kApiErrorExitCode = 253;
 | 
| +// Exit code indicating a compilation error.
 | 
| +static const int kCompilationErrorExitCode = 254;
 | 
| +// Exit code indicating an unhandled error that is not a compilation error.
 | 
| +static const int kErrorExitCode = 255;
 | 
| +
 | 
| +static void ErrorExit(int exit_code, const char* format, ...) {
 | 
| +  va_list arguments;
 | 
| +  va_start(arguments, format);
 | 
| +  Log::VPrintErr(format, arguments);
 | 
| +  va_end(arguments);
 | 
| +  fflush(stderr);
 | 
| +
 | 
| +  Dart_ExitScope();
 | 
| +  Dart_ShutdownIsolate();
 | 
| +
 | 
| +  Dart_Cleanup();
 | 
| +
 | 
| +  exit(exit_code);
 | 
| +}
 | 
| +
 | 
| +
 | 
|  // The environment provided through the command line using -D options.
 | 
|  static dart::HashMap* environment = NULL;
 | 
|  
 | 
| @@ -540,7 +564,8 @@
 | 
|  #define CHECK_RESULT(result)                                                   \
 | 
|    if (Dart_IsError(result)) {                                                  \
 | 
|      *error = strdup(Dart_GetError(result));                                    \
 | 
| -    *is_compile_error = Dart_IsCompilationError(result);                       \
 | 
| +    *exit_code = Dart_IsCompilationError(result) ? kCompilationErrorExitCode : \
 | 
| +        (Dart_IsApiError(result) ? kApiErrorExitCode : kErrorExitCode);        \
 | 
|      Dart_ExitScope();                                                          \
 | 
|      Dart_ShutdownIsolate();                                                    \
 | 
|      return NULL;                                                               \
 | 
| @@ -552,7 +577,7 @@
 | 
|                                                  const char* main,
 | 
|                                                  const char* package_root,
 | 
|                                                  char** error,
 | 
| -                                                bool* is_compile_error) {
 | 
| +                                                int* exit_code) {
 | 
|    ASSERT(script_uri != NULL);
 | 
|    IsolateData* isolate_data = new IsolateData(script_uri, package_root);
 | 
|    Dart_Isolate isolate = NULL;
 | 
| @@ -640,7 +665,7 @@
 | 
|                                            const char* package_root,
 | 
|                                            void* data, char** error) {
 | 
|    IsolateData* parent_isolate_data = reinterpret_cast<IsolateData*>(data);
 | 
| -  bool is_compile_error = false;
 | 
| +  int exit_code = 0;
 | 
|    if (script_uri == NULL) {
 | 
|      if (data == NULL) {
 | 
|        *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate");
 | 
| @@ -663,7 +688,7 @@
 | 
|                                       main,
 | 
|                                       package_root,
 | 
|                                       error,
 | 
| -                                     &is_compile_error);
 | 
| +                                     &exit_code);
 | 
|  }
 | 
|  
 | 
|  
 | 
| @@ -765,29 +790,6 @@
 | 
|    return buffer;
 | 
|  }
 | 
|  
 | 
| -
 | 
| -// Exit code indicating a compilation error.
 | 
| -static const int kCompilationErrorExitCode = 254;
 | 
| -
 | 
| -// Exit code indicating an unhandled error that is not a compilation error.
 | 
| -static const int kErrorExitCode = 255;
 | 
| -
 | 
| -static void ErrorExit(int exit_code, const char* format, ...) {
 | 
| -  va_list arguments;
 | 
| -  va_start(arguments, format);
 | 
| -  Log::VPrintErr(format, arguments);
 | 
| -  va_end(arguments);
 | 
| -  fflush(stderr);
 | 
| -
 | 
| -  Dart_ExitScope();
 | 
| -  Dart_ShutdownIsolate();
 | 
| -
 | 
| -  Dart_Cleanup();
 | 
| -
 | 
| -  exit(exit_code);
 | 
| -}
 | 
| -
 | 
| -
 | 
|  static void DartExitOnError(Dart_Handle error) {
 | 
|    if (!Dart_IsError(error)) {
 | 
|      return;
 | 
| @@ -982,18 +984,18 @@
 | 
|    // Call CreateIsolateAndSetup which creates an isolate and loads up
 | 
|    // the specified application script.
 | 
|    char* error = NULL;
 | 
| -  bool is_compile_error = false;
 | 
| +  int exit_code = 0;
 | 
|    char* isolate_name = BuildIsolateName(script_name, "main");
 | 
|    Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name,
 | 
|                                                       "main",
 | 
|                                                       commandline_package_root,
 | 
|                                                       &error,
 | 
| -                                                     &is_compile_error);
 | 
| +                                                     &exit_code);
 | 
|    if (isolate == NULL) {
 | 
|      Log::PrintErr("%s\n", error);
 | 
|      free(error);
 | 
|      delete [] isolate_name;
 | 
| -    exit(is_compile_error ? kCompilationErrorExitCode : kErrorExitCode);
 | 
| +    exit((exit_code != 0) ? exit_code : kErrorExitCode);
 | 
|    }
 | 
|    delete [] isolate_name;
 | 
|  
 | 
| 
 |