| 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_debugger_api.h" | 10 #include "include/dart_debugger_api.h" |
| (...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 result = Dart_StringToCString(result, &script_source); | 803 result = Dart_StringToCString(result, &script_source); |
| 804 if (Dart_IsError(result)) { | 804 if (Dart_IsError(result)) { |
| 805 return result; | 805 return result; |
| 806 } | 806 } |
| 807 Log::Print("%s\n", script_source); | 807 Log::Print("%s\n", script_source); |
| 808 } | 808 } |
| 809 return Dart_True(); | 809 return Dart_True(); |
| 810 } | 810 } |
| 811 | 811 |
| 812 | 812 |
| 813 static const char* ServiceRequestError(const char* message) { |
| 814 TextBuffer buffer(128); |
| 815 buffer.Printf("{\"type\":\"Error\",\"text\":\"%s\"", message); |
| 816 return buffer.Steal(); |
| 817 } |
| 818 |
| 819 |
| 820 static const char* ServiceRequestError(Dart_Handle error) { |
| 821 TextBuffer buffer(128); |
| 822 buffer.Printf("{\"type\":\"Error\",\"text\":\"Internal error %s\"", |
| 823 Dart_GetError(error)); |
| 824 return buffer.Steal(); |
| 825 } |
| 826 |
| 827 |
| 828 class DartScope { |
| 829 public: |
| 830 DartScope() { Dart_EnterScope(); } |
| 831 ~DartScope() { Dart_ExitScope(); } |
| 832 }; |
| 833 |
| 834 |
| 835 static const char* ServiceRequestHandler( |
| 836 const char* name, |
| 837 const char** arguments, |
| 838 intptr_t num_arguments, |
| 839 const char** option_keys, |
| 840 const char** option_values, |
| 841 intptr_t num_options, |
| 842 void* user_data) { |
| 843 DartScope scope; |
| 844 const char* kSockets = "sockets"; |
| 845 if (num_arguments == 2 && |
| 846 strncmp(arguments[1], kSockets, strlen(kSockets)) == 0) { |
| 847 Dart_Handle dart_io_str = Dart_NewStringFromCString("dart:io"); |
| 848 if (Dart_IsError(dart_io_str)) return ServiceRequestError(dart_io_str); |
| 849 Dart_Handle io_lib = Dart_LookupLibrary(dart_io_str); |
| 850 if (Dart_IsError(io_lib)) return ServiceRequestError(io_lib); |
| 851 Dart_Handle handler_function_name = |
| 852 Dart_NewStringFromCString("_socketsStats"); |
| 853 if (Dart_IsError(handler_function_name)) { |
| 854 return ServiceRequestError(handler_function_name); |
| 855 } |
| 856 Dart_Handle result = Dart_Invoke(io_lib, handler_function_name, 0, NULL); |
| 857 if (Dart_IsError(result)) return ServiceRequestError(result); |
| 858 const char *json; |
| 859 result = Dart_StringToCString(result, &json); |
| 860 if (Dart_IsError(result)) return ServiceRequestError(result); |
| 861 return strdup(json); |
| 862 } else { |
| 863 return ServiceRequestError("Unrecognized path"); |
| 864 } |
| 865 } |
| 866 |
| 867 |
| 813 void main(int argc, char** argv) { | 868 void main(int argc, char** argv) { |
| 814 char* script_name; | 869 char* script_name; |
| 815 CommandLineOptions vm_options(argc); | 870 CommandLineOptions vm_options(argc); |
| 816 CommandLineOptions dart_options(argc); | 871 CommandLineOptions dart_options(argc); |
| 817 bool print_flags_seen = false; | 872 bool print_flags_seen = false; |
| 818 bool verbose_debug_seen = false; | 873 bool verbose_debug_seen = false; |
| 819 | 874 |
| 820 // Perform platform specific initialization. | 875 // Perform platform specific initialization. |
| 821 if (!Platform::Initialize()) { | 876 if (!Platform::Initialize()) { |
| 822 Log::PrintErr("Initialization failed\n"); | 877 Log::PrintErr("Initialization failed\n"); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 EventHandler::Start(); | 942 EventHandler::Start(); |
| 888 | 943 |
| 889 // Start the VM service isolate, if necessary. | 944 // Start the VM service isolate, if necessary. |
| 890 if (start_vm_service) { | 945 if (start_vm_service) { |
| 891 ASSERT(vm_service_server_port >= 0); | 946 ASSERT(vm_service_server_port >= 0); |
| 892 bool r = VmService::Start(vm_service_server_port); | 947 bool r = VmService::Start(vm_service_server_port); |
| 893 if (!r) { | 948 if (!r) { |
| 894 Log::PrintErr("Could not start VM Service isolate %s\n", | 949 Log::PrintErr("Could not start VM Service isolate %s\n", |
| 895 VmService::GetErrorMessage()); | 950 VmService::GetErrorMessage()); |
| 896 } | 951 } |
| 952 Dart_RegisterIsolateServiceRequestCallback( |
| 953 "io", &ServiceRequestHandler, NULL); |
| 897 } | 954 } |
| 898 | 955 |
| 899 // Call CreateIsolateAndSetup which creates an isolate and loads up | 956 // Call CreateIsolateAndSetup which creates an isolate and loads up |
| 900 // the specified application script. | 957 // the specified application script. |
| 901 char* error = NULL; | 958 char* error = NULL; |
| 902 bool is_compile_error = false; | 959 bool is_compile_error = false; |
| 903 char* isolate_name = BuildIsolateName(script_name, "main"); | 960 char* isolate_name = BuildIsolateName(script_name, "main"); |
| 904 IsolateData* isolate_data = new IsolateData(script_name); | 961 IsolateData* isolate_data = new IsolateData(script_name); |
| 905 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, | 962 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, |
| 906 "main", | 963 "main", |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 exit(Process::GlobalExitCode()); | 1095 exit(Process::GlobalExitCode()); |
| 1039 } | 1096 } |
| 1040 | 1097 |
| 1041 } // namespace bin | 1098 } // namespace bin |
| 1042 } // namespace dart | 1099 } // namespace dart |
| 1043 | 1100 |
| 1044 int main(int argc, char** argv) { | 1101 int main(int argc, char** argv) { |
| 1045 dart::bin::main(argc, argv); | 1102 dart::bin::main(argc, argv); |
| 1046 UNREACHABLE(); | 1103 UNREACHABLE(); |
| 1047 } | 1104 } |
| OLD | NEW |