| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Dart_Cleanup(); |
| 112 | 112 |
| 113 DebuggerConnectionHandler::StopHandler(); | 113 DebuggerConnectionHandler::StopHandler(); |
| 114 EventHandler::Stop(); | 114 // TODO(zra): Stop the EventHandler once thread shutdown is enabled. |
| 115 // EventHandler::Stop(); |
| 115 exit(exit_code); | 116 exit(exit_code); |
| 116 } | 117 } |
| 117 | 118 |
| 118 | 119 |
| 119 // The environment provided through the command line using -D options. | 120 // The environment provided through the command line using -D options. |
| 120 static dart::HashMap* environment = NULL; | 121 static dart::HashMap* environment = NULL; |
| 121 | 122 |
| 122 static bool IsValidFlag(const char* name, | 123 static bool IsValidFlag(const char* name, |
| 123 const char* prefix, | 124 const char* prefix, |
| 124 intptr_t prefix_length) { | 125 intptr_t prefix_length) { |
| (...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 if (!Dart_Initialize(vm_isolate_snapshot_buffer, NULL, | 1039 if (!Dart_Initialize(vm_isolate_snapshot_buffer, NULL, |
| 1039 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, | 1040 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, |
| 1040 DartUtils::OpenFile, | 1041 DartUtils::OpenFile, |
| 1041 DartUtils::ReadFile, | 1042 DartUtils::ReadFile, |
| 1042 DartUtils::WriteFile, | 1043 DartUtils::WriteFile, |
| 1043 DartUtils::CloseFile, | 1044 DartUtils::CloseFile, |
| 1044 DartUtils::EntropySource)) { | 1045 DartUtils::EntropySource)) { |
| 1045 fprintf(stderr, "%s", "VM initialization failed\n"); | 1046 fprintf(stderr, "%s", "VM initialization failed\n"); |
| 1046 fflush(stderr); | 1047 fflush(stderr); |
| 1047 DebuggerConnectionHandler::StopHandler(); | 1048 DebuggerConnectionHandler::StopHandler(); |
| 1048 EventHandler::Stop(); | 1049 // TODO(zra): Stop the EventHandler once thread shutdown is enabled. |
| 1050 // EventHandler::Stop(); |
| 1049 exit(kErrorExitCode); | 1051 exit(kErrorExitCode); |
| 1050 } | 1052 } |
| 1051 | 1053 |
| 1052 Dart_RegisterIsolateServiceRequestCallback( | 1054 Dart_RegisterIsolateServiceRequestCallback( |
| 1053 "getIO", &ServiceGetIOHandler, NULL); | 1055 "getIO", &ServiceGetIOHandler, NULL); |
| 1054 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, | 1056 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, |
| 1055 &ServiceStreamCancelCallback); | 1057 &ServiceStreamCancelCallback); |
| 1056 | 1058 |
| 1057 // Call CreateIsolateAndSetup which creates an isolate and loads up | 1059 // Call CreateIsolateAndSetup which creates an isolate and loads up |
| 1058 // the specified application script. | 1060 // the specified application script. |
| 1059 char* error = NULL; | 1061 char* error = NULL; |
| 1060 int exit_code = 0; | 1062 int exit_code = 0; |
| 1061 char* isolate_name = BuildIsolateName(script_name, "main"); | 1063 char* isolate_name = BuildIsolateName(script_name, "main"); |
| 1062 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, | 1064 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, |
| 1063 "main", | 1065 "main", |
| 1064 commandline_package_root, | 1066 commandline_package_root, |
| 1065 commandline_packages_file, | 1067 commandline_packages_file, |
| 1066 NULL, | 1068 NULL, |
| 1067 &error, | 1069 &error, |
| 1068 &exit_code); | 1070 &exit_code); |
| 1069 if (isolate == NULL) { | 1071 if (isolate == NULL) { |
| 1070 Log::PrintErr("%s\n", error); | 1072 Log::PrintErr("%s\n", error); |
| 1071 free(error); | 1073 free(error); |
| 1072 delete [] isolate_name; | 1074 delete [] isolate_name; |
| 1073 DebuggerConnectionHandler::StopHandler(); | 1075 DebuggerConnectionHandler::StopHandler(); |
| 1074 EventHandler::Stop(); | 1076 // TODO(zra): Stop the EventHandler once thread shutdown is enabled. |
| 1077 // EventHandler::Stop(); |
| 1075 exit((exit_code != 0) ? exit_code : kErrorExitCode); | 1078 exit((exit_code != 0) ? exit_code : kErrorExitCode); |
| 1076 } | 1079 } |
| 1077 delete [] isolate_name; | 1080 delete [] isolate_name; |
| 1078 | 1081 |
| 1079 Dart_EnterIsolate(isolate); | 1082 Dart_EnterIsolate(isolate); |
| 1080 ASSERT(isolate == Dart_CurrentIsolate()); | 1083 ASSERT(isolate == Dart_CurrentIsolate()); |
| 1081 ASSERT(isolate != NULL); | 1084 ASSERT(isolate != NULL); |
| 1082 Dart_Handle result; | 1085 Dart_Handle result; |
| 1083 | 1086 |
| 1084 Dart_EnterScope(); | 1087 Dart_EnterScope(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 | 1174 |
| 1172 Dart_ExitScope(); | 1175 Dart_ExitScope(); |
| 1173 // Shutdown the isolate. | 1176 // Shutdown the isolate. |
| 1174 Dart_ShutdownIsolate(); | 1177 Dart_ShutdownIsolate(); |
| 1175 // Terminate process exit-code handler. | 1178 // Terminate process exit-code handler. |
| 1176 Process::TerminateExitCodeHandler(); | 1179 Process::TerminateExitCodeHandler(); |
| 1177 | 1180 |
| 1178 Dart_Cleanup(); | 1181 Dart_Cleanup(); |
| 1179 | 1182 |
| 1180 DebuggerConnectionHandler::StopHandler(); | 1183 DebuggerConnectionHandler::StopHandler(); |
| 1181 EventHandler::Stop(); | 1184 // TODO(zra): Stop the EventHandler once thread shutdown is enabled. |
| 1185 // EventHandler::Stop(); |
| 1182 | 1186 |
| 1183 // Free copied argument strings if converted. | 1187 // Free copied argument strings if converted. |
| 1184 if (argv_converted) { | 1188 if (argv_converted) { |
| 1185 for (int i = 0; i < argc; i++) free(argv[i]); | 1189 for (int i = 0; i < argc; i++) free(argv[i]); |
| 1186 } | 1190 } |
| 1187 | 1191 |
| 1188 // Free environment if any. | 1192 // Free environment if any. |
| 1189 if (environment != NULL) { | 1193 if (environment != NULL) { |
| 1190 for (HashMap::Entry* p = environment->Start(); | 1194 for (HashMap::Entry* p = environment->Start(); |
| 1191 p != NULL; | 1195 p != NULL; |
| 1192 p = environment->Next(p)) { | 1196 p = environment->Next(p)) { |
| 1193 free(p->key); | 1197 free(p->key); |
| 1194 free(p->value); | 1198 free(p->value); |
| 1195 } | 1199 } |
| 1196 delete environment; | 1200 delete environment; |
| 1197 } | 1201 } |
| 1198 | 1202 |
| 1199 exit(Process::GlobalExitCode()); | 1203 exit(Process::GlobalExitCode()); |
| 1200 } | 1204 } |
| 1201 | 1205 |
| 1202 } // namespace bin | 1206 } // namespace bin |
| 1203 } // namespace dart | 1207 } // namespace dart |
| 1204 | 1208 |
| 1205 int main(int argc, char** argv) { | 1209 int main(int argc, char** argv) { |
| 1206 dart::bin::main(argc, argv); | 1210 dart::bin::main(argc, argv); |
| 1207 UNREACHABLE(); | 1211 UNREACHABLE(); |
| 1208 } | 1212 } |
| OLD | NEW |