Chromium Code Reviews| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 // and listen for a debugger to connect. | 47 // and listen for a debugger to connect. |
| 48 static bool start_debugger = false; | 48 static bool start_debugger = false; |
| 49 static const char* debug_ip = NULL; | 49 static const char* debug_ip = NULL; |
| 50 static int debug_port = -1; | 50 static int debug_port = -1; |
| 51 static const char* DEFAULT_DEBUG_IP = "127.0.0.1"; | 51 static const char* DEFAULT_DEBUG_IP = "127.0.0.1"; |
| 52 static const int DEFAULT_DEBUG_PORT = 5858; | 52 static const int DEFAULT_DEBUG_PORT = 5858; |
| 53 | 53 |
| 54 // Value of the --package-root flag. | 54 // Value of the --package-root flag. |
| 55 // (This pointer points into an argv buffer and does not need to be | 55 // (This pointer points into an argv buffer and does not need to be |
| 56 // free'd.) | 56 // free'd.) |
| 57 static const char* package_root = NULL; | 57 static const char* commandline_package_root = NULL; |
| 58 | 58 |
| 59 | 59 |
| 60 // Global flag that is used to indicate that we want to compile all the | 60 // Global flag that is used to indicate that we want to compile all the |
| 61 // dart functions and not run anything. | 61 // dart functions and not run anything. |
| 62 static bool has_compile_all = false; | 62 static bool has_compile_all = false; |
| 63 | 63 |
| 64 // Global flag that is used to indicate that we want to print the source code | 64 // Global flag that is used to indicate that we want to print the source code |
| 65 // for script that is being run. | 65 // for script that is being run. |
| 66 static bool has_print_script = false; | 66 static bool has_print_script = false; |
| 67 | 67 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 return true; | 129 return true; |
| 130 } | 130 } |
| 131 | 131 |
| 132 | 132 |
| 133 static bool ProcessPackageRootOption(const char* arg, | 133 static bool ProcessPackageRootOption(const char* arg, |
| 134 CommandLineOptions* vm_options) { | 134 CommandLineOptions* vm_options) { |
| 135 ASSERT(arg != NULL); | 135 ASSERT(arg != NULL); |
| 136 if (*arg == '\0' || *arg == '-') { | 136 if (*arg == '\0' || *arg == '-') { |
| 137 return false; | 137 return false; |
| 138 } | 138 } |
| 139 package_root = arg; | 139 commandline_package_root = arg; |
| 140 return true; | 140 return true; |
| 141 } | 141 } |
| 142 | 142 |
| 143 | 143 |
| 144 static void* GetHashmapKeyFromString(char* key) { | 144 static void* GetHashmapKeyFromString(char* key) { |
| 145 return reinterpret_cast<void*>(key); | 145 return reinterpret_cast<void*>(key); |
| 146 } | 146 } |
| 147 | 147 |
| 148 | 148 |
| 149 static bool ExtractPortAndIP(const char *option_value, | 149 static bool ExtractPortAndIP(const char *option_value, |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 547 *error = strdup(Dart_GetError(result)); \ | 547 *error = strdup(Dart_GetError(result)); \ |
| 548 *is_compile_error = Dart_IsCompilationError(result); \ | 548 *is_compile_error = Dart_IsCompilationError(result); \ |
| 549 Dart_ExitScope(); \ | 549 Dart_ExitScope(); \ |
| 550 Dart_ShutdownIsolate(); \ | 550 Dart_ShutdownIsolate(); \ |
| 551 return NULL; \ | 551 return NULL; \ |
| 552 } \ | 552 } \ |
| 553 | 553 |
| 554 // Returns true on success, false on failure. | 554 // Returns true on success, false on failure. |
| 555 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, | 555 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, |
| 556 const char* main, | 556 const char* main, |
| 557 void* data, | 557 void* data, |
|
Ivan Posva
2014/09/08 05:46:35
The data parameter should be typed as IsolateData*
Anders Johnsen
2014/09/09 06:45:43
Done.
| |
| 558 char** error, | 558 char** error, |
| 559 bool* is_compile_error) { | 559 bool* is_compile_error) { |
| 560 Dart_Isolate isolate = | 560 Dart_Isolate isolate = |
| 561 Dart_CreateIsolate(script_uri, main, snapshot_buffer, data, error); | 561 Dart_CreateIsolate(script_uri, main, snapshot_buffer, data, error); |
| 562 if (isolate == NULL) { | 562 if (isolate == NULL) { |
| 563 return NULL; | 563 return NULL; |
| 564 } | 564 } |
| 565 | 565 |
| 566 Dart_EnterScope(); | 566 Dart_EnterScope(); |
| 567 | 567 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 580 | 580 |
| 581 // Load the specified application script into the newly created isolate. | 581 // Load the specified application script into the newly created isolate. |
| 582 | 582 |
| 583 // Prepare builtin and its dependent libraries for use to resolve URIs. | 583 // Prepare builtin and its dependent libraries for use to resolve URIs. |
| 584 // The builtin library is part of the core snapshot and would already be | 584 // The builtin library is part of the core snapshot and would already be |
| 585 // available here in the case of script snapshot loading. | 585 // available here in the case of script snapshot loading. |
| 586 Dart_Handle builtin_lib = | 586 Dart_Handle builtin_lib = |
| 587 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 587 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 588 CHECK_RESULT(builtin_lib); | 588 CHECK_RESULT(builtin_lib); |
| 589 | 589 |
| 590 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(data); | |
|
Ivan Posva
2014/09/08 05:46:35
Unneeded.
Anders Johnsen
2014/09/09 06:45:43
Done.
| |
| 591 ASSERT(isolate_data != NULL); | |
| 592 ASSERT(isolate_data->script_url != NULL); | |
| 593 const char* package_root = isolate_data->package_root; | |
| 594 | |
| 590 // Prepare for script loading by setting up the 'print' and 'timer' | 595 // Prepare for script loading by setting up the 'print' and 'timer' |
| 591 // closures and setting up 'package root' for URI resolution. | 596 // closures and setting up 'package root' for URI resolution. |
| 592 result = DartUtils::PrepareForScriptLoading(package_root, builtin_lib); | 597 result = DartUtils::PrepareForScriptLoading(package_root, builtin_lib); |
| 593 CHECK_RESULT(result); | 598 CHECK_RESULT(result); |
| 594 | 599 |
| 595 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(data); | |
| 596 ASSERT(isolate_data != NULL); | |
| 597 ASSERT(isolate_data->script_url != NULL); | |
| 598 result = DartUtils::LoadScript(isolate_data->script_url, builtin_lib); | 600 result = DartUtils::LoadScript(isolate_data->script_url, builtin_lib); |
| 599 CHECK_RESULT(result); | 601 CHECK_RESULT(result); |
| 600 | 602 |
| 601 // Run event-loop and wait for script loading to complete. | 603 // Run event-loop and wait for script loading to complete. |
| 602 result = Dart_RunLoop(); | 604 result = Dart_RunLoop(); |
| 603 CHECK_RESULT(result); | 605 CHECK_RESULT(result); |
| 604 | 606 |
| 605 Platform::SetPackageRoot(package_root); | 607 Platform::SetPackageRoot(package_root); |
| 606 Dart_Handle io_lib_url = DartUtils::NewString(DartUtils::kIOLibURL); | 608 Dart_Handle io_lib_url = DartUtils::NewString(DartUtils::kIOLibURL); |
| 607 CHECK_RESULT(io_lib_url); | 609 CHECK_RESULT(io_lib_url); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 629 return NULL; | 631 return NULL; |
| 630 } | 632 } |
| 631 | 633 |
| 632 return isolate; | 634 return isolate; |
| 633 } | 635 } |
| 634 | 636 |
| 635 #undef CHECK_RESULT | 637 #undef CHECK_RESULT |
| 636 | 638 |
| 637 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, | 639 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, |
| 638 const char* main, | 640 const char* main, |
| 641 const char* package_root, | |
| 639 void* data, char** error) { | 642 void* data, char** error) { |
| 643 IsolateData* parent_isolate_data = reinterpret_cast<IsolateData*>(data); | |
| 640 bool is_compile_error = false; | 644 bool is_compile_error = false; |
| 641 if (script_uri == NULL) { | 645 if (script_uri == NULL) { |
| 642 if (data == NULL) { | 646 if (data == NULL) { |
| 643 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate"); | 647 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate"); |
| 644 return NULL; | 648 return NULL; |
| 645 } | 649 } |
| 646 IsolateData* parent_isolate_data = reinterpret_cast<IsolateData*>(data); | |
| 647 script_uri = parent_isolate_data->script_url; | 650 script_uri = parent_isolate_data->script_url; |
| 648 if (script_uri == NULL) { | 651 if (script_uri == NULL) { |
| 649 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate"); | 652 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate"); |
| 650 return NULL; | 653 return NULL; |
| 651 } | 654 } |
| 652 } | 655 } |
| 653 IsolateData* isolate_data = new IsolateData(script_uri); | 656 if (package_root == NULL) { |
| 657 package_root = parent_isolate_data->package_root; | |
| 658 } | |
| 659 IsolateData* isolate_data = new IsolateData(script_uri, package_root); | |
| 654 return CreateIsolateAndSetupHelper(script_uri, | 660 return CreateIsolateAndSetupHelper(script_uri, |
| 655 main, | 661 main, |
| 656 isolate_data, | 662 isolate_data, |
|
turnidge
2014/09/08 19:47:00
You are treating script_uri and package_root assym
Anders Johnsen
2014/09/09 06:45:43
It would needed to be passed both places (like scr
| |
| 657 error, | 663 error, |
| 658 &is_compile_error); | 664 &is_compile_error); |
| 659 } | 665 } |
| 660 | 666 |
| 661 | 667 |
| 662 #define CHECK_RESULT(result) \ | 668 #define CHECK_RESULT(result) \ |
| 663 if (Dart_IsError(result)) { \ | 669 if (Dart_IsError(result)) { \ |
| 664 *error = strdup(Dart_GetError(result)); \ | 670 *error = strdup(Dart_GetError(result)); \ |
| 665 Dart_ExitScope(); \ | 671 Dart_ExitScope(); \ |
| 666 Dart_ShutdownIsolate(); \ | 672 Dart_ShutdownIsolate(); \ |
| 667 return NULL; \ | 673 return NULL; \ |
| 668 } \ | 674 } \ |
| 669 | 675 |
| 670 static Dart_Isolate CreateServiceIsolate(void* data, char** error) { | 676 static Dart_Isolate CreateServiceIsolate(void* data, char** error) { |
| 671 const char* script_uri = DartUtils::kVMServiceLibURL; | 677 const char* script_uri = DartUtils::kVMServiceLibURL; |
| 672 IsolateData* isolate_data = new IsolateData(script_uri); | 678 IsolateData* isolate_data = new IsolateData(script_uri, NULL); |
| 673 Dart_Isolate isolate = | 679 Dart_Isolate isolate = |
| 674 Dart_CreateIsolate(script_uri, "main", snapshot_buffer, isolate_data, | 680 Dart_CreateIsolate(script_uri, "main", snapshot_buffer, isolate_data, |
| 675 error); | 681 error); |
| 676 if (isolate == NULL) { | 682 if (isolate == NULL) { |
| 677 return NULL; | 683 return NULL; |
| 678 } | 684 } |
| 679 Dart_EnterScope(); | 685 Dart_EnterScope(); |
| 680 if (snapshot_buffer != NULL) { | 686 if (snapshot_buffer != NULL) { |
| 681 // Setup the native resolver as the snapshot does not carry it. | 687 // Setup the native resolver as the snapshot does not carry it. |
| 682 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); | 688 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
| 683 Builtin::SetNativeResolver(Builtin::kIOLibrary); | 689 Builtin::SetNativeResolver(Builtin::kIOLibrary); |
| 684 } | 690 } |
| 685 // Set up the library tag handler for this isolate. | 691 // Set up the library tag handler for this isolate. |
| 686 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); | 692 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); |
| 687 CHECK_RESULT(result); | 693 CHECK_RESULT(result); |
| 688 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 694 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
| 689 CHECK_RESULT(result); | 695 CHECK_RESULT(result); |
| 690 // Prepare builtin and its dependent libraries for use to resolve URIs. | 696 // Prepare builtin and its dependent libraries for use to resolve URIs. |
| 691 Dart_Handle builtin_lib = | 697 Dart_Handle builtin_lib = |
| 692 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 698 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 693 CHECK_RESULT(builtin_lib); | 699 CHECK_RESULT(builtin_lib); |
| 694 // Prepare for script loading by setting up the 'print' and 'timer' | 700 // Prepare for script loading by setting up the 'print' and 'timer' |
| 695 // closures and setting up 'package root' for URI resolution. | 701 // closures and setting up 'package root' for URI resolution. |
| 696 result = DartUtils::PrepareForScriptLoading(package_root, builtin_lib); | 702 result = DartUtils::PrepareForScriptLoading(commandline_package_root, |
| 703 builtin_lib); | |
|
Ivan Posva
2014/09/08 05:46:35
I would expect the service isolate to not expect a
Anders Johnsen
2014/09/09 06:45:43
Will pass 'NULL' then.
| |
| 697 CHECK_RESULT(result); | 704 CHECK_RESULT(result); |
| 698 Platform::SetPackageRoot(package_root); | 705 Platform::SetPackageRoot(commandline_package_root); |
| 699 Dart_Handle io_lib_url = DartUtils::NewString(DartUtils::kIOLibURL); | 706 Dart_Handle io_lib_url = DartUtils::NewString(DartUtils::kIOLibURL); |
| 700 CHECK_RESULT(io_lib_url); | 707 CHECK_RESULT(io_lib_url); |
| 701 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url); | 708 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url); |
| 702 CHECK_RESULT(io_lib); | 709 CHECK_RESULT(io_lib); |
| 703 Dart_Handle platform_type = DartUtils::GetDartType(DartUtils::kIOLibURL, | 710 Dart_Handle platform_type = DartUtils::GetDartType(DartUtils::kIOLibURL, |
| 704 "_Platform"); | 711 "_Platform"); |
| 705 CHECK_RESULT(platform_type); | 712 CHECK_RESULT(platform_type); |
| 706 Dart_Handle script_name = DartUtils::NewString("_nativeScript"); | 713 Dart_Handle script_name = DartUtils::NewString("_nativeScript"); |
| 707 CHECK_RESULT(script_name); | 714 CHECK_RESULT(script_name); |
| 708 Dart_Handle dart_script = DartUtils::NewString(script_uri); | 715 Dart_Handle dart_script = DartUtils::NewString(script_uri); |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1037 Dart_RegisterIsolateServiceRequestCallback( | 1044 Dart_RegisterIsolateServiceRequestCallback( |
| 1038 "io", &ServiceRequestHandler, NULL); | 1045 "io", &ServiceRequestHandler, NULL); |
| 1039 } | 1046 } |
| 1040 ASSERT(Dart_CurrentIsolate() == NULL); | 1047 ASSERT(Dart_CurrentIsolate() == NULL); |
| 1041 | 1048 |
| 1042 // Call CreateIsolateAndSetup which creates an isolate and loads up | 1049 // Call CreateIsolateAndSetup which creates an isolate and loads up |
| 1043 // the specified application script. | 1050 // the specified application script. |
| 1044 char* error = NULL; | 1051 char* error = NULL; |
| 1045 bool is_compile_error = false; | 1052 bool is_compile_error = false; |
| 1046 char* isolate_name = BuildIsolateName(script_name, "main"); | 1053 char* isolate_name = BuildIsolateName(script_name, "main"); |
| 1047 IsolateData* isolate_data = new IsolateData(script_name); | 1054 IsolateData* isolate_data = new IsolateData(script_name, |
| 1055 commandline_package_root); | |
| 1048 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, | 1056 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, |
| 1049 "main", | 1057 "main", |
| 1050 isolate_data, | 1058 isolate_data, |
| 1051 &error, | 1059 &error, |
| 1052 &is_compile_error); | 1060 &is_compile_error); |
| 1053 if (isolate == NULL) { | 1061 if (isolate == NULL) { |
| 1054 Log::PrintErr("%s\n", error); | 1062 Log::PrintErr("%s\n", error); |
| 1055 free(error); | 1063 free(error); |
| 1056 delete [] isolate_name; | 1064 delete [] isolate_name; |
| 1057 exit(is_compile_error ? kCompilationErrorExitCode : kErrorExitCode); | 1065 exit(is_compile_error ? kCompilationErrorExitCode : kErrorExitCode); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1169 exit(Process::GlobalExitCode()); | 1177 exit(Process::GlobalExitCode()); |
| 1170 } | 1178 } |
| 1171 | 1179 |
| 1172 } // namespace bin | 1180 } // namespace bin |
| 1173 } // namespace dart | 1181 } // namespace dart |
| 1174 | 1182 |
| 1175 int main(int argc, char** argv) { | 1183 int main(int argc, char** argv) { |
| 1176 dart::bin::main(argc, argv); | 1184 dart::bin::main(argc, argv); |
| 1177 UNREACHABLE(); | 1185 UNREACHABLE(); |
| 1178 } | 1186 } |
| OLD | NEW |