@@ -75,6 +75,30 @@ static const char* vm_service_server_ip = DEFAULT_VM_SERVICE_SERVER_IP;
75
75
// being allocated.
76
76
static int vm_service_server_port = -1 ;
77
77
78
+
79
+ // Exit code indicating an API error.
80
+ static const int kApiErrorExitCode = 253 ;
81
+ // Exit code indicating a compilation error.
82
+ static const int kCompilationErrorExitCode = 254 ;
83
+ // Exit code indicating an unhandled error that is not a compilation error.
84
+ static const int kErrorExitCode = 255 ;
85
+
86
+ static void ErrorExit (int exit_code, const char * format, ...) {
87
+ va_list arguments;
88
+ va_start (arguments, format);
89
+ Log::VPrintErr (format, arguments);
90
+ va_end (arguments);
91
+ fflush (stderr);
92
+
93
+ Dart_ExitScope ();
94
+ Dart_ShutdownIsolate ();
95
+
96
+ Dart_Cleanup ();
97
+
98
+ exit (exit_code);
99
+ }
100
+
101
+
78
102
// The environment provided through the command line using -D options.
79
103
static dart::HashMap* environment = NULL ;
80
104
@@ -540,7 +564,8 @@ static Dart_Handle EnvironmentCallback(Dart_Handle name) {
540
564
#define CHECK_RESULT (result ) \
541
565
if (Dart_IsError(result)) { \
542
566
*error = strdup (Dart_GetError (result)); \
543
- *is_compile_error = Dart_IsCompilationError (result); \
567
+ *exit_code = Dart_IsCompilationError (result) ? kCompilationErrorExitCode : \
568
+ (Dart_IsApiError (result) ? kApiErrorExitCode : kErrorExitCode ); \
544
569
Dart_ExitScope (); \
545
570
Dart_ShutdownIsolate (); \
546
571
return NULL ; \
@@ -552,7 +577,7 @@ static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
552
577
const char * main,
553
578
const char * package_root,
554
579
char ** error,
555
- bool * is_compile_error ) {
580
+ int * exit_code ) {
556
581
ASSERT (script_uri != NULL );
557
582
IsolateData* isolate_data = new IsolateData (script_uri, package_root);
558
583
Dart_Isolate isolate = NULL ;
@@ -640,7 +665,7 @@ static Dart_Isolate CreateIsolateAndSetup(const char* script_uri,
640
665
const char * package_root,
641
666
void * data, char ** error) {
642
667
IsolateData* parent_isolate_data = reinterpret_cast <IsolateData*>(data);
643
- bool is_compile_error = false ;
668
+ int exit_code = 0 ;
644
669
if (script_uri == NULL ) {
645
670
if (data == NULL ) {
646
671
*error = strdup (" Invalid 'callback_data' - Unable to spawn new isolate" );
@@ -663,7 +688,7 @@ static Dart_Isolate CreateIsolateAndSetup(const char* script_uri,
663
688
main,
664
689
package_root,
665
690
error,
666
- &is_compile_error );
691
+ &exit_code );
667
692
}
668
693
669
694
@@ -765,29 +790,6 @@ char* BuildIsolateName(const char* script_name,
765
790
return buffer;
766
791
}
767
792
768
-
769
- // Exit code indicating a compilation error.
770
- static const int kCompilationErrorExitCode = 254 ;
771
-
772
- // Exit code indicating an unhandled error that is not a compilation error.
773
- static const int kErrorExitCode = 255 ;
774
-
775
- static void ErrorExit (int exit_code, const char * format, ...) {
776
- va_list arguments;
777
- va_start (arguments, format);
778
- Log::VPrintErr (format, arguments);
779
- va_end (arguments);
780
- fflush (stderr);
781
-
782
- Dart_ExitScope ();
783
- Dart_ShutdownIsolate ();
784
-
785
- Dart_Cleanup ();
786
-
787
- exit (exit_code);
788
- }
789
-
790
-
791
793
static void DartExitOnError (Dart_Handle error) {
792
794
if (!Dart_IsError (error)) {
793
795
return ;
@@ -982,18 +984,18 @@ void main(int argc, char** argv) {
982
984
// Call CreateIsolateAndSetup which creates an isolate and loads up
983
985
// the specified application script.
984
986
char * error = NULL ;
985
- bool is_compile_error = false ;
987
+ int exit_code = 0 ;
986
988
char * isolate_name = BuildIsolateName (script_name, " main" );
987
989
Dart_Isolate isolate = CreateIsolateAndSetupHelper (script_name,
988
990
" main" ,
989
991
commandline_package_root,
990
992
&error,
991
- &is_compile_error );
993
+ &exit_code );
992
994
if (isolate == NULL ) {
993
995
Log::PrintErr (" %s\n " , error);
994
996
free (error);
995
997
delete [] isolate_name;
996
- exit (is_compile_error ? kCompilationErrorExitCode : kErrorExitCode );
998
+ exit ((exit_code != 0 ) ? exit_code : kErrorExitCode );
997
999
}
998
1000
delete [] isolate_name;
999
1001
0 commit comments