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 <stdlib.h> | 5 #include <stdlib.h> |
6 #include <string.h> | 6 #include <string.h> |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
10 #include "include/dart_tools_api.h" | 10 #include "include/dart_tools_api.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 static void ErrorExit(int exit_code, const char* format, ...) { | 101 static void ErrorExit(int exit_code, const char* format, ...) { |
102 va_list arguments; | 102 va_list arguments; |
103 va_start(arguments, format); | 103 va_start(arguments, format); |
104 Log::VPrintErr(format, arguments); | 104 Log::VPrintErr(format, arguments); |
105 va_end(arguments); | 105 va_end(arguments); |
106 fflush(stderr); | 106 fflush(stderr); |
107 | 107 |
108 Dart_ExitScope(); | 108 Dart_ExitScope(); |
109 Dart_ShutdownIsolate(); | 109 Dart_ShutdownIsolate(); |
110 | 110 |
111 Dart_Cleanup(); | 111 // Terminate process exit-code handler. |
| 112 Process::TerminateExitCodeHandler(); |
| 113 |
| 114 char* error = Dart_Cleanup(); |
| 115 if (error != NULL) { |
| 116 Log::PrintErr("VM cleanup failed: %s\n", error); |
| 117 free(error); |
| 118 } |
112 | 119 |
113 exit(exit_code); | 120 exit(exit_code); |
114 } | 121 } |
115 | 122 |
116 | 123 |
117 // The environment provided through the command line using -D options. | 124 // The environment provided through the command line using -D options. |
118 static dart::HashMap* environment = NULL; | 125 static dart::HashMap* environment = NULL; |
119 | 126 |
120 static bool IsValidFlag(const char* name, | 127 static bool IsValidFlag(const char* name, |
121 const char* prefix, | 128 const char* prefix, |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 Dart_Isolate isolate = NULL; | 624 Dart_Isolate isolate = NULL; |
618 | 625 |
619 isolate = Dart_CreateIsolate(script_uri, | 626 isolate = Dart_CreateIsolate(script_uri, |
620 main, | 627 main, |
621 isolate_snapshot_buffer, | 628 isolate_snapshot_buffer, |
622 flags, | 629 flags, |
623 isolate_data, | 630 isolate_data, |
624 error); | 631 error); |
625 | 632 |
626 if (isolate == NULL) { | 633 if (isolate == NULL) { |
| 634 delete isolate_data; |
627 return NULL; | 635 return NULL; |
628 } | 636 } |
629 | 637 |
630 Dart_EnterScope(); | 638 Dart_EnterScope(); |
631 | 639 |
632 if (isolate_snapshot_buffer != NULL) { | 640 if (isolate_snapshot_buffer != NULL) { |
633 // Setup the native resolver as the snapshot does not carry it. | 641 // Setup the native resolver as the snapshot does not carry it. |
634 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); | 642 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
635 Builtin::SetNativeResolver(Builtin::kIOLibrary); | 643 Builtin::SetNativeResolver(Builtin::kIOLibrary); |
636 } | 644 } |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 bool print_msg = verbose_debug_seen || (debug_port == 0); | 1020 bool print_msg = verbose_debug_seen || (debug_port == 0); |
1013 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); | 1021 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); |
1014 if (print_msg) { | 1022 if (print_msg) { |
1015 Log::Print("Debugger listening on port %d\n", debug_port); | 1023 Log::Print("Debugger listening on port %d\n", debug_port); |
1016 } | 1024 } |
1017 } else { | 1025 } else { |
1018 DebuggerConnectionHandler::InitForVmService(); | 1026 DebuggerConnectionHandler::InitForVmService(); |
1019 } | 1027 } |
1020 | 1028 |
1021 // Initialize the Dart VM. | 1029 // Initialize the Dart VM. |
1022 if (!Dart_Initialize(vm_isolate_snapshot_buffer, | 1030 char* error = Dart_Initialize(vm_isolate_snapshot_buffer, |
1023 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, | 1031 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, |
1024 DartUtils::OpenFile, | 1032 DartUtils::OpenFile, |
1025 DartUtils::ReadFile, | 1033 DartUtils::ReadFile, |
1026 DartUtils::WriteFile, | 1034 DartUtils::WriteFile, |
1027 DartUtils::CloseFile, | 1035 DartUtils::CloseFile, |
1028 DartUtils::EntropySource)) { | 1036 DartUtils::EntropySource); |
1029 fprintf(stderr, "%s", "VM initialization failed\n"); | 1037 if (error != NULL) { |
| 1038 fprintf(stderr, "VM initialization failed: %s\n", error); |
1030 fflush(stderr); | 1039 fflush(stderr); |
| 1040 free(error); |
1031 exit(kErrorExitCode); | 1041 exit(kErrorExitCode); |
1032 } | 1042 } |
1033 | 1043 |
1034 Dart_RegisterIsolateServiceRequestCallback( | 1044 Dart_RegisterIsolateServiceRequestCallback( |
1035 "getIO", &ServiceGetIOHandler, NULL); | 1045 "getIO", &ServiceGetIOHandler, NULL); |
1036 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, | 1046 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, |
1037 &ServiceStreamCancelCallback); | 1047 &ServiceStreamCancelCallback); |
1038 | 1048 |
1039 // Call CreateIsolateAndSetup which creates an isolate and loads up | 1049 // Call CreateIsolateAndSetup which creates an isolate and loads up |
1040 // the specified application script. | 1050 // the specified application script. |
1041 char* error = NULL; | |
1042 int exit_code = 0; | 1051 int exit_code = 0; |
1043 char* isolate_name = BuildIsolateName(script_name, "main"); | 1052 char* isolate_name = BuildIsolateName(script_name, "main"); |
1044 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, | 1053 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, |
1045 "main", | 1054 "main", |
1046 commandline_package_root, | 1055 commandline_package_root, |
1047 commandline_packages_file, | 1056 commandline_packages_file, |
1048 NULL, | 1057 NULL, |
1049 &error, | 1058 &error, |
1050 &exit_code); | 1059 &exit_code); |
1051 if (isolate == NULL) { | 1060 if (isolate == NULL) { |
1052 Log::PrintErr("%s\n", error); | 1061 Log::PrintErr("%s\n", error); |
1053 free(error); | 1062 free(error); |
| 1063 error = NULL; |
1054 delete [] isolate_name; | 1064 delete [] isolate_name; |
| 1065 Process::TerminateExitCodeHandler(); |
| 1066 error = Dart_Cleanup(); |
| 1067 if (error != NULL) { |
| 1068 Log::PrintErr("VM cleanup failed: %s\n", error); |
| 1069 free(error); |
| 1070 } |
1055 exit((exit_code != 0) ? exit_code : kErrorExitCode); | 1071 exit((exit_code != 0) ? exit_code : kErrorExitCode); |
1056 } | 1072 } |
1057 delete [] isolate_name; | 1073 delete [] isolate_name; |
1058 | 1074 |
1059 Dart_EnterIsolate(isolate); | 1075 Dart_EnterIsolate(isolate); |
1060 ASSERT(isolate == Dart_CurrentIsolate()); | 1076 ASSERT(isolate == Dart_CurrentIsolate()); |
1061 ASSERT(isolate != NULL); | 1077 ASSERT(isolate != NULL); |
1062 Dart_Handle result; | 1078 Dart_Handle result; |
1063 | 1079 |
1064 Dart_EnterScope(); | 1080 Dart_EnterScope(); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 result = Dart_RunLoop(); | 1164 result = Dart_RunLoop(); |
1149 DartExitOnError(result); | 1165 DartExitOnError(result); |
1150 } | 1166 } |
1151 | 1167 |
1152 Dart_ExitScope(); | 1168 Dart_ExitScope(); |
1153 // Shutdown the isolate. | 1169 // Shutdown the isolate. |
1154 Dart_ShutdownIsolate(); | 1170 Dart_ShutdownIsolate(); |
1155 // Terminate process exit-code handler. | 1171 // Terminate process exit-code handler. |
1156 Process::TerminateExitCodeHandler(); | 1172 Process::TerminateExitCodeHandler(); |
1157 | 1173 |
1158 Dart_Cleanup(); | 1174 error = Dart_Cleanup(); |
| 1175 if (error != NULL) { |
| 1176 Log::PrintErr("VM cleanup failed: %s\n", error); |
| 1177 free(error); |
| 1178 } |
1159 | 1179 |
1160 // Free copied argument strings if converted. | 1180 // Free copied argument strings if converted. |
1161 if (argv_converted) { | 1181 if (argv_converted) { |
1162 for (int i = 0; i < argc; i++) free(argv[i]); | 1182 for (int i = 0; i < argc; i++) free(argv[i]); |
1163 } | 1183 } |
1164 | 1184 |
1165 // Free environment if any. | 1185 // Free environment if any. |
1166 if (environment != NULL) { | 1186 if (environment != NULL) { |
1167 for (HashMap::Entry* p = environment->Start(); | 1187 for (HashMap::Entry* p = environment->Start(); |
1168 p != NULL; | 1188 p != NULL; |
1169 p = environment->Next(p)) { | 1189 p = environment->Next(p)) { |
1170 free(p->key); | 1190 free(p->key); |
1171 free(p->value); | 1191 free(p->value); |
1172 } | 1192 } |
1173 delete environment; | 1193 delete environment; |
1174 } | 1194 } |
1175 | 1195 |
1176 exit(Process::GlobalExitCode()); | 1196 exit(Process::GlobalExitCode()); |
1177 } | 1197 } |
1178 | 1198 |
1179 } // namespace bin | 1199 } // namespace bin |
1180 } // namespace dart | 1200 } // namespace dart |
1181 | 1201 |
1182 int main(int argc, char** argv) { | 1202 int main(int argc, char** argv) { |
1183 dart::bin::main(argc, argv); | 1203 dart::bin::main(argc, argv); |
1184 UNREACHABLE(); | 1204 UNREACHABLE(); |
1185 } | 1205 } |
OLD | NEW |