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

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

Issue 125103004: Move service into VM (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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
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 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 Dart_GetType(io_lib, platform_class_name, 0, NULL); 535 Dart_GetType(io_lib, platform_class_name, 0, NULL);
536 CHECK_RESULT(platform_type); 536 CHECK_RESULT(platform_type);
537 Dart_Handle script_name_name = DartUtils::NewString("_nativeScript"); 537 Dart_Handle script_name_name = DartUtils::NewString("_nativeScript");
538 CHECK_RESULT(script_name_name); 538 CHECK_RESULT(script_name_name);
539 Dart_Handle dart_script = DartUtils::NewString(script_uri); 539 Dart_Handle dart_script = DartUtils::NewString(script_uri);
540 CHECK_RESULT(dart_script); 540 CHECK_RESULT(dart_script);
541 Dart_Handle set_script_name = 541 Dart_Handle set_script_name =
542 Dart_SetField(platform_type, script_name_name, dart_script); 542 Dart_SetField(platform_type, script_name_name, dart_script);
543 CHECK_RESULT(set_script_name); 543 CHECK_RESULT(set_script_name);
544 544
545 VmService::SendIsolateStartupMessage(); 545 Dart_RegisterWithService();
546 546
547 // Make the isolate runnable so that it is ready to handle messages. 547 // Make the isolate runnable so that it is ready to handle messages.
548 Dart_ExitScope(); 548 Dart_ExitScope();
549 Dart_ExitIsolate(); 549 Dart_ExitIsolate();
550 bool retval = Dart_IsolateMakeRunnable(isolate); 550 bool retval = Dart_IsolateMakeRunnable(isolate);
551 if (!retval) { 551 if (!retval) {
552 *error = strdup("Invalid isolate state - Unable to make it runnable"); 552 *error = strdup("Invalid isolate state - Unable to make it runnable");
553 Dart_EnterIsolate(isolate); 553 Dart_EnterIsolate(isolate);
554 Dart_ShutdownIsolate(); 554 Dart_ShutdownIsolate();
555 return NULL; 555 return NULL;
(...skipping 21 matching lines...) Expand all
577 } 577 }
578 IsolateData* isolate_data = new IsolateData(script_uri); 578 IsolateData* isolate_data = new IsolateData(script_uri);
579 return CreateIsolateAndSetupHelper(script_uri, 579 return CreateIsolateAndSetupHelper(script_uri,
580 main, 580 main,
581 isolate_data, 581 isolate_data,
582 error, 582 error,
583 &is_compile_error); 583 &is_compile_error);
584 } 584 }
585 585
586 586
587 static Dart_Isolate CreateServiceIsolate(void* data, char** error) {
588 const char* script_uri = "dart:vmservice";
siva 2014/01/10 00:01:54 You could add a DartUtils::kVMServiceLibURL value
Cutch 2014/01/10 21:01:42 Done.
589 bool is_compile_error_ = false;
590 bool *is_compile_error = &is_compile_error_;
siva 2014/01/10 00:01:54 I don't see the variables is_compile_error and is_
Cutch 2014/01/10 21:01:42 They are used in the CHECK_RESULT macro. I've adde
591 IsolateData* isolate_data = new IsolateData(script_uri);
592 Dart_Isolate isolate =
593 Dart_CreateIsolate(script_uri, "main", snapshot_buffer, isolate_data,
594 error);
595 if (isolate == NULL) {
596 return NULL;
597 }
598 Dart_EnterScope();
599 if (snapshot_buffer != NULL) {
600 // Setup the native resolver as the snapshot does not carry it.
601 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
602 Builtin::SetNativeResolver(Builtin::kIOLibrary);
603 }
604 // Set up the library tag handler for this isolate.
605 Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler);
606 CHECK_RESULT(result);
607 result = Dart_SetEnvironmentCallback(EnvironmentCallback);
608 CHECK_RESULT(result);
609 // Prepare builtin and its dependent libraries for use to resolve URIs.
610 Dart_Handle builtin_lib =
611 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary);
612 CHECK_RESULT(builtin_lib);
613 // Prepare for script loading by setting up the 'print' and 'timer'
614 // closures and setting up 'package root' for URI resolution.
615 result = DartUtils::PrepareForScriptLoading(package_root, builtin_lib);
616 CHECK_RESULT(result);
617 Platform::SetPackageRoot(package_root);
618 Dart_Handle io_lib_url = DartUtils::NewString("dart:io");
siva 2014/01/10 00:01:54 DartUtils::kIOLibURL instead of "dart:io"
Cutch 2014/01/10 21:01:42 Done here and elsewhere.
619 CHECK_RESULT(io_lib_url);
620 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url);
621 CHECK_RESULT(io_lib);
622 Dart_Handle platform_class_name = DartUtils::NewString("Platform");
623 CHECK_RESULT(platform_class_name);
624 Dart_Handle platform_type =
625 Dart_GetType(io_lib, platform_class_name, 0, NULL);
siva 2014/01/10 00:01:54 You could use Dart_Handle platform_type = DartUtil
Cutch 2014/01/10 21:01:42 Done here and elsewhere.
626 CHECK_RESULT(platform_type);
627 Dart_Handle script_name_name = DartUtils::NewString("_nativeScript");
siva 2014/01/10 00:01:54 Why does the variable have to be called script_nam
Cutch 2014/01/10 21:01:42 Done here and elsewhere.
628 CHECK_RESULT(script_name_name);
629 Dart_Handle dart_script = DartUtils::NewString(script_uri);
630 CHECK_RESULT(dart_script);
631 Dart_Handle set_script_name =
632 Dart_SetField(platform_type, script_name_name, dart_script);
633 CHECK_RESULT(set_script_name);
634 Dart_ExitScope();
635 Dart_ExitIsolate();
636 return isolate;
637 }
638
639
587 static void PrintVersion() { 640 static void PrintVersion() {
588 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); 641 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString());
589 } 642 }
590 643
591 644
592 static void PrintUsage() { 645 static void PrintUsage() {
593 Log::PrintErr( 646 Log::PrintErr(
594 "Usage: dart [<vm-flags>] <dart-script-file> [<dart-options>]\n" 647 "Usage: dart [<vm-flags>] <dart-script-file> [<dart-options>]\n"
595 "\n" 648 "\n"
596 "Executes the Dart script passed as <dart-script-file>.\n" 649 "Executes the Dart script passed as <dart-script-file>.\n"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 if (!Dart_IsError(error)) { 762 if (!Dart_IsError(error)) {
710 return; 763 return;
711 } 764 }
712 const int exit_code = Dart_IsCompilationError(error) ? 765 const int exit_code = Dart_IsCompilationError(error) ?
713 kCompilationErrorExitCode : kErrorExitCode; 766 kCompilationErrorExitCode : kErrorExitCode;
714 ErrorExit(exit_code, "%s\n", Dart_GetError(error)); 767 ErrorExit(exit_code, "%s\n", Dart_GetError(error));
715 } 768 }
716 769
717 770
718 static void ShutdownIsolate(void* callback_data) { 771 static void ShutdownIsolate(void* callback_data) {
719 VmService::VmServiceShutdownCallback(callback_data); 772 Dart_UnregisterFromService();
720 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data); 773 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data);
721 delete isolate_data; 774 delete isolate_data;
722 } 775 }
723 776
724 777
725 static Dart_Handle GenerateScriptSource() { 778 static Dart_Handle GenerateScriptSource() {
726 Dart_Handle library_url = Dart_LibraryUrl(Dart_RootLibrary()); 779 Dart_Handle library_url = Dart_LibraryUrl(Dart_RootLibrary());
727 if (Dart_IsError(library_url)) { 780 if (Dart_IsError(library_url)) {
728 return library_url; 781 return library_url;
729 } 782 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 } 858 }
806 859
807 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); 860 Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
808 861
809 // Initialize the Dart VM. 862 // Initialize the Dart VM.
810 if (!Dart_Initialize(CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, 863 if (!Dart_Initialize(CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate,
811 DartUtils::OpenFile, 864 DartUtils::OpenFile,
812 DartUtils::ReadFile, 865 DartUtils::ReadFile,
813 DartUtils::WriteFile, 866 DartUtils::WriteFile,
814 DartUtils::CloseFile, 867 DartUtils::CloseFile,
815 DartUtils::EntropySource)) { 868 DartUtils::EntropySource,
869 CreateServiceIsolate)) {
816 fprintf(stderr, "%s", "VM initialization failed\n"); 870 fprintf(stderr, "%s", "VM initialization failed\n");
817 fflush(stderr); 871 fflush(stderr);
818 exit(kErrorExitCode); 872 exit(kErrorExitCode);
819 } 873 }
820 874
821 // Start the debugger wire protocol handler if necessary. 875 // Start the debugger wire protocol handler if necessary.
822 if (start_debugger) { 876 if (start_debugger) {
823 ASSERT(debug_port >= 0); 877 ASSERT(debug_port >= 0);
824 bool print_msg = verbose_debug_seen || (debug_port == 0); 878 bool print_msg = verbose_debug_seen || (debug_port == 0);
825 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); 879 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 exit(Process::GlobalExitCode()); 1039 exit(Process::GlobalExitCode());
986 } 1040 }
987 1041
988 } // namespace bin 1042 } // namespace bin
989 } // namespace dart 1043 } // namespace dart
990 1044
991 int main(int argc, char** argv) { 1045 int main(int argc, char** argv) {
992 dart::bin::main(argc, argv); 1046 dart::bin::main(argc, argv);
993 UNREACHABLE(); 1047 UNREACHABLE();
994 } 1048 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698