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

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

Issue 13813018: Changelist to land https://codereview.chromium.org/13452007/ for Siva. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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 | « no previous file | runtime/include/dart_api.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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 420
421 return Dart_SetField(runtime_options_class, native_name, dart_arguments); 421 return Dart_SetField(runtime_options_class, native_name, dart_arguments);
422 } 422 }
423 423
424 424
425 #define CHECK_RESULT(result) \ 425 #define CHECK_RESULT(result) \
426 if (Dart_IsError(result)) { \ 426 if (Dart_IsError(result)) { \
427 *error = strdup(Dart_GetError(result)); \ 427 *error = strdup(Dart_GetError(result)); \
428 Dart_ExitScope(); \ 428 Dart_ExitScope(); \
429 Dart_ShutdownIsolate(); \ 429 Dart_ShutdownIsolate(); \
430 return false; \ 430 return NULL; \
431 } \ 431 } \
432 432
433 433
434 // Returns true on success, false on failure. 434 // Returns true on success, false on failure.
435 static bool CreateIsolateAndSetupHelper(const char* script_uri, 435 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
436 const char* main, 436 const char* main,
437 void* data, 437 void* data,
438 char** error) { 438 char** error) {
439 Dart_Isolate isolate = 439 Dart_Isolate isolate =
440 Dart_CreateIsolate(script_uri, main, snapshot_buffer, data, error); 440 Dart_CreateIsolate(script_uri, main, snapshot_buffer, data, error);
441 if (isolate == NULL) { 441 if (isolate == NULL) {
442 return false; 442 return NULL;
443 } 443 }
444 444
445 Dart_EnterScope(); 445 Dart_EnterScope();
446 446
447 if (snapshot_buffer != NULL) { 447 if (snapshot_buffer != NULL) {
448 // Setup the native resolver as the snapshot does not carry it. 448 // Setup the native resolver as the snapshot does not carry it.
449 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); 449 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary);
450 Builtin::SetNativeResolver(Builtin::kIOLibrary); 450 Builtin::SetNativeResolver(Builtin::kIOLibrary);
451 } 451 }
452 452
(...skipping 21 matching lines...) Expand all
474 Dart_Handle library = DartUtils::LoadScript(script_uri, builtin_lib); 474 Dart_Handle library = DartUtils::LoadScript(script_uri, builtin_lib);
475 CHECK_RESULT(library); 475 CHECK_RESULT(library);
476 if (!Dart_IsLibrary(library)) { 476 if (!Dart_IsLibrary(library)) {
477 char errbuf[256]; 477 char errbuf[256];
478 snprintf(errbuf, sizeof(errbuf), 478 snprintf(errbuf, sizeof(errbuf),
479 "Expected a library when loading script: %s", 479 "Expected a library when loading script: %s",
480 script_uri); 480 script_uri);
481 *error = strdup(errbuf); 481 *error = strdup(errbuf);
482 Dart_ExitScope(); 482 Dart_ExitScope();
483 Dart_ShutdownIsolate(); 483 Dart_ShutdownIsolate();
484 return false; 484 return NULL;
485 } 485 }
486
487 // Make the isolate runnable so that it is ready to handle messages.
486 Dart_ExitScope(); 488 Dart_ExitScope();
489 Dart_ExitIsolate();
490 bool retval = Dart_IsolateMakeRunnable(isolate);
491 if (!retval) {
492 *error = strdup("Invalid isolate state - Unable to make it runnable");
493 Dart_EnterIsolate(isolate);
494 Dart_ShutdownIsolate();
495 return NULL;
496 }
497
487 VmStats::AddIsolate(reinterpret_cast<IsolateData*>(data), isolate); 498 VmStats::AddIsolate(reinterpret_cast<IsolateData*>(data), isolate);
488 return true; 499 return isolate;
489 } 500 }
490 501
491 502
492 static bool CreateIsolateAndSetup(const char* script_uri, 503 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri,
493 const char* main, 504 const char* main,
494 void* data, char** error) { 505 void* data, char** error) {
495 return CreateIsolateAndSetupHelper(script_uri, 506 return CreateIsolateAndSetupHelper(script_uri,
496 main, 507 main,
497 new IsolateData(), 508 new IsolateData(),
498 error); 509 error);
499 } 510 }
500 511
501 512
502 static void PrintVersion() { 513 static void PrintVersion() {
503 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); 514 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString());
504 } 515 }
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); 748 DebuggerConnectionHandler::StartHandler(debug_ip, debug_port);
738 if (verbose_debug_seen) { 749 if (verbose_debug_seen) {
739 Log::Print("Debugger initialized\n"); 750 Log::Print("Debugger initialized\n");
740 } 751 }
741 } 752 }
742 753
743 // Call CreateIsolateAndSetup which creates an isolate and loads up 754 // Call CreateIsolateAndSetup which creates an isolate and loads up
744 // the specified application script. 755 // the specified application script.
745 char* error = NULL; 756 char* error = NULL;
746 char* isolate_name = BuildIsolateName(script_name, "main"); 757 char* isolate_name = BuildIsolateName(script_name, "main");
747 if (!CreateIsolateAndSetupHelper(script_name, 758 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name,
748 "main", 759 "main",
749 new IsolateData(), 760 new IsolateData(),
750 &error)) { 761 &error);
762 if (isolate == NULL) {
751 Log::PrintErr("%s\n", error); 763 Log::PrintErr("%s\n", error);
752 free(error); 764 free(error);
753 delete [] isolate_name; 765 delete [] isolate_name;
754 return kErrorExitCode; // Indicates we encountered an error. 766 return kErrorExitCode; // Indicates we encountered an error.
755 } 767 }
756 delete [] isolate_name; 768 delete [] isolate_name;
757 769
758 Dart_Isolate isolate = Dart_CurrentIsolate(); 770 Dart_EnterIsolate(isolate);
771 ASSERT(isolate == Dart_CurrentIsolate());
759 ASSERT(isolate != NULL); 772 ASSERT(isolate != NULL);
760 Dart_Handle result; 773 Dart_Handle result;
761 774
762 Dart_EnterScope(); 775 Dart_EnterScope();
763 776
764 if (vmstats_port >= 0) { 777 if (vmstats_port >= 0) {
765 VmStats::Start(vmstats_port, vmstats_root); 778 VmStats::Start(vmstats_port, vmstats_root);
766 } 779 }
767 780
768 if (generate_script_snapshot) { 781 if (generate_script_snapshot) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 Dart_ShutdownIsolate(); 854 Dart_ShutdownIsolate();
842 // Terminate process exit-code handler. 855 // Terminate process exit-code handler.
843 Process::TerminateExitCodeHandler(); 856 Process::TerminateExitCodeHandler();
844 // Free copied argument strings if converted. 857 // Free copied argument strings if converted.
845 if (argv_converted) { 858 if (argv_converted) {
846 for (int i = 0; i < argc; i++) free(argv[i]); 859 for (int i = 0; i < argc; i++) free(argv[i]);
847 } 860 }
848 861
849 return Process::GlobalExitCode(); 862 return Process::GlobalExitCode();
850 } 863 }
OLDNEW
« no previous file with comments | « no previous file | runtime/include/dart_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698