Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: runtime/bin/main.cc

Issue 867113003: Revert r43217, r43215, r43208, r43207, and r43202. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/io_impl_sources.gypi ('k') | runtime/bin/platform.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 // available here in the case of script snapshot loading. 582 // available here in the case of script snapshot loading.
583 Dart_Handle builtin_lib = 583 Dart_Handle builtin_lib =
584 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); 584 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
585 CHECK_RESULT(builtin_lib); 585 CHECK_RESULT(builtin_lib);
586 586
587 // Prepare for script loading by setting up the 'print' and 'timer' 587 // Prepare for script loading by setting up the 'print' and 'timer'
588 // closures and setting up 'package root' for URI resolution. 588 // closures and setting up 'package root' for URI resolution.
589 result = DartUtils::PrepareForScriptLoading(package_root, builtin_lib); 589 result = DartUtils::PrepareForScriptLoading(package_root, builtin_lib);
590 CHECK_RESULT(result); 590 CHECK_RESULT(result);
591 591
592
593 if (Dart_IsServiceIsolate(isolate)) {
594 // If this is the service isolate, load embedder specific bits and return.
595 if (!VmService::Setup(vm_service_server_ip, vm_service_server_port)) {
596 *error = strdup(VmService::GetErrorMessage());
597 return NULL;
598 }
599 Dart_ExitScope();
600 Dart_ExitIsolate();
601 return isolate;
602 }
603
604 // Load the script.
605 result = DartUtils::LoadScript(script_uri, builtin_lib); 592 result = DartUtils::LoadScript(script_uri, builtin_lib);
606 CHECK_RESULT(result); 593 CHECK_RESULT(result);
607 594
608 // Run event-loop and wait for script loading to complete. 595 // Run event-loop and wait for script loading to complete.
609 result = Dart_RunLoop(); 596 result = Dart_RunLoop();
610 CHECK_RESULT(result); 597 CHECK_RESULT(result);
611 598
612 Platform::SetPackageRoot(package_root); 599 Platform::SetPackageRoot(package_root);
613 600 Dart_Handle io_lib_url = DartUtils::NewString(DartUtils::kIOLibURL);
614 DartUtils::SetupIOLibrary(script_uri); 601 CHECK_RESULT(io_lib_url);
602 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url);
603 CHECK_RESULT(io_lib);
604 Dart_Handle platform_type = DartUtils::GetDartType(DartUtils::kIOLibURL,
605 "_Platform");
606 CHECK_RESULT(platform_type);
607 Dart_Handle script_name = DartUtils::NewString("_nativeScript");
608 CHECK_RESULT(script_name);
609 Dart_Handle dart_script = DartUtils::NewString(script_uri);
610 CHECK_RESULT(dart_script);
611 Dart_Handle set_script_name =
612 Dart_SetField(platform_type, script_name, dart_script);
613 CHECK_RESULT(set_script_name);
615 614
616 // Make the isolate runnable so that it is ready to handle messages. 615 // Make the isolate runnable so that it is ready to handle messages.
617 Dart_ExitScope(); 616 Dart_ExitScope();
618 Dart_ExitIsolate(); 617 Dart_ExitIsolate();
619 bool retval = Dart_IsolateMakeRunnable(isolate); 618 bool retval = Dart_IsolateMakeRunnable(isolate);
620 if (!retval) { 619 if (!retval) {
621 *error = strdup("Invalid isolate state - Unable to make it runnable"); 620 *error = strdup("Invalid isolate state - Unable to make it runnable");
622 Dart_EnterIsolate(isolate); 621 Dart_EnterIsolate(isolate);
623 Dart_ShutdownIsolate(); 622 Dart_ShutdownIsolate();
624 return NULL; 623 return NULL;
(...skipping 15 matching lines...) Expand all
640 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate"); 639 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate");
641 return NULL; 640 return NULL;
642 } 641 }
643 script_uri = parent_isolate_data->script_url; 642 script_uri = parent_isolate_data->script_url;
644 if (script_uri == NULL) { 643 if (script_uri == NULL) {
645 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate"); 644 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate");
646 return NULL; 645 return NULL;
647 } 646 }
648 } 647 }
649 if (package_root == NULL) { 648 if (package_root == NULL) {
650 if (parent_isolate_data != NULL) { 649 package_root = parent_isolate_data->package_root;
651 package_root = parent_isolate_data->package_root;
652 } else {
653 package_root = ".";
654 }
655 } 650 }
656 return CreateIsolateAndSetupHelper(script_uri, 651 return CreateIsolateAndSetupHelper(script_uri,
657 main, 652 main,
658 package_root, 653 package_root,
659 error, 654 error,
660 &is_compile_error); 655 &is_compile_error);
661 } 656 }
662 657
663 658
659 #define CHECK_RESULT(result) \
660 if (Dart_IsError(result)) { \
661 *error = strdup(Dart_GetError(result)); \
662 Dart_ExitScope(); \
663 Dart_ShutdownIsolate(); \
664 return NULL; \
665 } \
666
667 static Dart_Isolate CreateServiceIsolate(void* data, char** error) {
668 const char* script_uri = DartUtils::kVMServiceLibURL;
669 IsolateData* isolate_data = new IsolateData(script_uri, NULL);
670 Dart_Isolate isolate =
671 Dart_CreateIsolate(script_uri, "main", snapshot_buffer, isolate_data,
672 error);
673 if (isolate == NULL) {
674 return NULL;
675 }
676 Dart_EnterScope();
677 if (snapshot_buffer != NULL) {
678 // Setup the native resolver as the snapshot does not carry it.
679 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
680 Builtin::SetNativeResolver(Builtin::kIOLibrary);
681 }
682 // Set up the library tag handler for this isolate.
683 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler);
684 CHECK_RESULT(result);
685 result = Dart_SetEnvironmentCallback(EnvironmentCallback);
686 CHECK_RESULT(result);
687 // Prepare builtin and its dependent libraries for use to resolve URIs.
688 Dart_Handle builtin_lib =
689 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
690 CHECK_RESULT(builtin_lib);
691 // Prepare for script loading by setting up the 'print' and 'timer'
692 // closures and setting up 'package root' for URI resolution.
693 result = DartUtils::PrepareForScriptLoading(NULL, builtin_lib);
694 CHECK_RESULT(result);
695
696 Dart_ExitScope();
697 Dart_ExitIsolate();
698 return isolate;
699 }
700
701 #undef CHECK_RESULT
702
664 static void PrintVersion() { 703 static void PrintVersion() {
665 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); 704 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString());
666 } 705 }
667 706
668 707
669 static void PrintUsage() { 708 static void PrintUsage() {
670 Log::PrintErr( 709 Log::PrintErr(
671 "Usage: dart [<vm-flags>] <dart-script-file> [<dart-options>]\n" 710 "Usage: dart [<vm-flags>] <dart-script-file> [<dart-options>]\n"
672 "\n" 711 "\n"
673 "Executes the Dart script passed as <dart-script-file>.\n" 712 "Executes the Dart script passed as <dart-script-file>.\n"
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 973
935 if (!DartUtils::SetOriginalWorkingDirectory()) { 974 if (!DartUtils::SetOriginalWorkingDirectory()) {
936 OSError err; 975 OSError err;
937 fprintf(stderr, "Error determining current directory: %s\n", err.message()); 976 fprintf(stderr, "Error determining current directory: %s\n", err.message());
938 fflush(stderr); 977 fflush(stderr);
939 exit(kErrorExitCode); 978 exit(kErrorExitCode);
940 } 979 }
941 980
942 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); 981 Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
943 982
944 // Start event handler.
945 EventHandler::Start();
946
947 // Initialize the Dart VM. 983 // Initialize the Dart VM.
948 if (!Dart_Initialize(CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, 984 if (!Dart_Initialize(CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate,
949 DartUtils::OpenFile, 985 DartUtils::OpenFile,
950 DartUtils::ReadFile, 986 DartUtils::ReadFile,
951 DartUtils::WriteFile, 987 DartUtils::WriteFile,
952 DartUtils::CloseFile, 988 DartUtils::CloseFile,
953 DartUtils::EntropySource)) { 989 DartUtils::EntropySource,
990 CreateServiceIsolate)) {
954 fprintf(stderr, "%s", "VM initialization failed\n"); 991 fprintf(stderr, "%s", "VM initialization failed\n");
955 fflush(stderr); 992 fflush(stderr);
956 exit(kErrorExitCode); 993 exit(kErrorExitCode);
957 } 994 }
958 995
959 996 // Start event handler.
997 EventHandler::Start();
960 998
961 // Start the debugger wire protocol handler if necessary. 999 // Start the debugger wire protocol handler if necessary.
962 if (start_debugger) { 1000 if (start_debugger) {
963 ASSERT(debug_port >= 0); 1001 ASSERT(debug_port >= 0);
964 bool print_msg = verbose_debug_seen || (debug_port == 0); 1002 bool print_msg = verbose_debug_seen || (debug_port == 0);
965 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); 1003 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port);
966 if (print_msg) { 1004 if (print_msg) {
967 Log::Print("Debugger listening on port %d\n", debug_port); 1005 Log::Print("Debugger listening on port %d\n", debug_port);
968 } 1006 }
969 } else {
970 DebuggerConnectionHandler::InitForVmService();
971 } 1007 }
972 1008
973 Dart_RegisterIsolateServiceRequestCallback( 1009 ASSERT(Dart_CurrentIsolate() == NULL);
1010 // Start the VM service isolate, if necessary.
1011 if (start_vm_service) {
1012 if (!start_debugger) {
1013 DebuggerConnectionHandler::InitForVmService();
1014 }
1015 bool r = VmService::Start(vm_service_server_ip, vm_service_server_port);
1016 if (!r) {
1017 Log::PrintErr("Could not start VM Service isolate %s\n",
1018 VmService::GetErrorMessage());
1019 }
1020 Dart_RegisterIsolateServiceRequestCallback(
974 "io", &ServiceRequestHandler, NULL); 1021 "io", &ServiceRequestHandler, NULL);
1022 }
1023 ASSERT(Dart_CurrentIsolate() == NULL);
975 1024
976 // Call CreateIsolateAndSetup which creates an isolate and loads up 1025 // Call CreateIsolateAndSetup which creates an isolate and loads up
977 // the specified application script. 1026 // the specified application script.
978 char* error = NULL; 1027 char* error = NULL;
979 bool is_compile_error = false; 1028 bool is_compile_error = false;
980 char* isolate_name = BuildIsolateName(script_name, "main"); 1029 char* isolate_name = BuildIsolateName(script_name, "main");
981 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, 1030 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name,
982 "main", 1031 "main",
983 commandline_package_root, 1032 commandline_package_root,
984 &error, 1033 &error,
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 exit(Process::GlobalExitCode()); 1160 exit(Process::GlobalExitCode());
1112 } 1161 }
1113 1162
1114 } // namespace bin 1163 } // namespace bin
1115 } // namespace dart 1164 } // namespace dart
1116 1165
1117 int main(int argc, char** argv) { 1166 int main(int argc, char** argv) {
1118 dart::bin::main(argc, argv); 1167 dart::bin::main(argc, argv);
1119 UNREACHABLE(); 1168 UNREACHABLE();
1120 } 1169 }
OLDNEW
« no previous file with comments | « runtime/bin/io_impl_sources.gypi ('k') | runtime/bin/platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698