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

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

Issue 24508004: Fix VM exit code in some cases. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 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 | no next file » | 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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 return native_name; 400 return native_name;
401 } 401 }
402 402
403 return Dart_SetField(runtime_options_type, native_name, dart_arguments); 403 return Dart_SetField(runtime_options_type, native_name, dart_arguments);
404 } 404 }
405 405
406 406
407 #define CHECK_RESULT(result) \ 407 #define CHECK_RESULT(result) \
408 if (Dart_IsError(result)) { \ 408 if (Dart_IsError(result)) { \
409 *error = strdup(Dart_GetError(result)); \ 409 *error = strdup(Dart_GetError(result)); \
410 *is_compile_error = Dart_IsCompilationError(result); \
410 Dart_ExitScope(); \ 411 Dart_ExitScope(); \
411 Dart_ShutdownIsolate(); \ 412 Dart_ShutdownIsolate(); \
412 return NULL; \ 413 return NULL; \
413 } \ 414 } \
414 415
415 416
416 // Returns true on success, false on failure. 417 // Returns true on success, false on failure.
417 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, 418 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
418 const char* main, 419 const char* main,
419 void* data, 420 void* data,
420 char** error) { 421 char** error,
422 bool* is_compile_error) {
421 Dart_Isolate isolate = 423 Dart_Isolate isolate =
422 Dart_CreateIsolate(script_uri, main, snapshot_buffer, data, error); 424 Dart_CreateIsolate(script_uri, main, snapshot_buffer, data, error);
423 if (isolate == NULL) { 425 if (isolate == NULL) {
424 return NULL; 426 return NULL;
425 } 427 }
426 428
427 Dart_EnterScope(); 429 Dart_EnterScope();
428 430
429 if (snapshot_buffer != NULL) { 431 if (snapshot_buffer != NULL) {
430 // Setup the native resolver as the snapshot does not carry it. 432 // Setup the native resolver as the snapshot does not carry it.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 return NULL; 498 return NULL;
497 } 499 }
498 500
499 return isolate; 501 return isolate;
500 } 502 }
501 503
502 504
503 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, 505 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri,
504 const char* main, 506 const char* main,
505 void* data, char** error) { 507 void* data, char** error) {
508 bool is_compile_error = false;
506 return CreateIsolateAndSetupHelper(script_uri, 509 return CreateIsolateAndSetupHelper(script_uri,
507 main, 510 main,
508 new IsolateData(), 511 new IsolateData(),
509 error); 512 error,
513 &is_compile_error);
510 } 514 }
511 515
512 516
513 static void PrintVersion() { 517 static void PrintVersion() {
514 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); 518 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString());
515 } 519 }
516 520
517 521
518 static void PrintUsage() { 522 static void PrintUsage() {
519 Log::PrintErr( 523 Log::PrintErr(
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 bool r = VmService::Start(vm_service_server_port); 762 bool r = VmService::Start(vm_service_server_port);
759 if (!r) { 763 if (!r) {
760 Log::PrintErr("Could not start VM Service isolate %s", 764 Log::PrintErr("Could not start VM Service isolate %s",
761 VmService::GetErrorMessage()); 765 VmService::GetErrorMessage());
762 } 766 }
763 } 767 }
764 768
765 // Call CreateIsolateAndSetup which creates an isolate and loads up 769 // Call CreateIsolateAndSetup which creates an isolate and loads up
766 // the specified application script. 770 // the specified application script.
767 char* error = NULL; 771 char* error = NULL;
772 bool is_compile_error = false;
768 char* isolate_name = BuildIsolateName(script_name, "main"); 773 char* isolate_name = BuildIsolateName(script_name, "main");
769 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, 774 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name,
770 "main", 775 "main",
771 new IsolateData(), 776 new IsolateData(),
772 &error); 777 &error,
778 &is_compile_error);
773 if (isolate == NULL) { 779 if (isolate == NULL) {
774 Log::PrintErr("%s\n", error); 780 Log::PrintErr("%s\n", error);
775 free(error); 781 free(error);
776 delete [] isolate_name; 782 delete [] isolate_name;
777 return kErrorExitCode; // Indicates we encountered an error. 783 return is_compile_error ? kCompilationErrorExitCode : kErrorExitCode;
778 } 784 }
779 delete [] isolate_name; 785 delete [] isolate_name;
780 786
781 Dart_EnterIsolate(isolate); 787 Dart_EnterIsolate(isolate);
782 ASSERT(isolate == Dart_CurrentIsolate()); 788 ASSERT(isolate == Dart_CurrentIsolate());
783 ASSERT(isolate != NULL); 789 ASSERT(isolate != NULL);
784 Dart_Handle result; 790 Dart_Handle result;
785 791
786 Dart_EnterScope(); 792 Dart_EnterScope();
787 793
788 if (generate_script_snapshot) { 794 if (generate_script_snapshot) {
789 // First create a snapshot. 795 // First create a snapshot.
790 Dart_Handle result; 796 Dart_Handle result;
791 uint8_t* buffer = NULL; 797 uint8_t* buffer = NULL;
792 intptr_t size = 0; 798 intptr_t size = 0;
793 result = Dart_CreateScriptSnapshot(&buffer, &size); 799 result = Dart_CreateScriptSnapshot(&buffer, &size);
794 if (Dart_IsError(result)) { 800 if (Dart_IsError(result)) {
795 Log::PrintErr("%s\n", Dart_GetError(result)); 801 Log::PrintErr("%s\n", Dart_GetError(result));
796 Dart_ExitScope(); 802 Dart_ExitScope();
797 Dart_ShutdownIsolate(); 803 Dart_ShutdownIsolate();
798 return kErrorExitCode; // Indicates we encountered an error. 804 return DartErrorExit(result);
799 } 805 }
800 806
801 // Write the magic number to indicate file is a script snapshot. 807 // Write the magic number to indicate file is a script snapshot.
802 DartUtils::WriteMagicNumber(snapshot_file); 808 DartUtils::WriteMagicNumber(snapshot_file);
803 809
804 // Now write the snapshot out to specified file. 810 // Now write the snapshot out to specified file.
805 bool bytes_written = snapshot_file->WriteFully(buffer, size); 811 bool bytes_written = snapshot_file->WriteFully(buffer, size);
806 ASSERT(bytes_written); 812 ASSERT(bytes_written);
807 delete snapshot_file; 813 delete snapshot_file;
808 } else { 814 } else {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 882
877 return Process::GlobalExitCode(); 883 return Process::GlobalExitCode();
878 } 884 }
879 885
880 } // namespace bin 886 } // namespace bin
881 } // namespace dart 887 } // namespace dart
882 888
883 int main(int argc, char** argv) { 889 int main(int argc, char** argv) {
884 return dart::bin::main(argc, argv); 890 return dart::bin::main(argc, argv);
885 } 891 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698