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

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

Issue 27073005: - Add the ability to pass the command line options as an argument to main. (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 | tests/corelib/main_test.dart » ('j') | tests/corelib/main_test.dart » ('J')
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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 // Parse out options to be passed to dart main. 353 // Parse out options to be passed to dart main.
354 while (i < argc) { 354 while (i < argc) {
355 dart_options->AddArgument(argv[i]); 355 dart_options->AddArgument(argv[i]);
356 i++; 356 i++;
357 } 357 }
358 358
359 return 0; 359 return 0;
360 } 360 }
361 361
362 362
363 static Dart_Handle SetupRuntimeOptions(CommandLineOptions* options, 363 static Dart_Handle CreateRuntimeOptions(CommandLineOptions* options) {
364 const char* script_name) {
365 int options_count = options->count(); 364 int options_count = options->count();
366 Dart_Handle dart_arguments = Dart_NewList(options_count); 365 Dart_Handle dart_arguments = Dart_NewList(options_count);
367 if (Dart_IsError(dart_arguments)) { 366 if (Dart_IsError(dart_arguments)) {
368 return dart_arguments; 367 return dart_arguments;
369 } 368 }
370 for (int i = 0; i < options_count; i++) { 369 for (int i = 0; i < options_count; i++) {
371 Dart_Handle argument_value = 370 Dart_Handle argument_value =
372 DartUtils::NewString(options->GetArgument(i)); 371 DartUtils::NewString(options->GetArgument(i));
Anders Johnsen 2013/10/17 09:52:30 Unintentional change?
Ivan Posva 2013/10/17 21:39:02 Indentation messup. Thanks!
373 if (Dart_IsError(argument_value)) { 372 if (Dart_IsError(argument_value)) {
374 return argument_value; 373 return argument_value;
375 } 374 }
376 Dart_Handle result = Dart_ListSetAt(dart_arguments, i, argument_value); 375 Dart_Handle result = Dart_ListSetAt(dart_arguments, i, argument_value);
377 if (Dart_IsError(result)) { 376 if (Dart_IsError(result)) {
378 return result; 377 return result;
379 } 378 }
380 } 379 }
380 return dart_arguments;
381 }
382
383
384 static Dart_Handle SetupRuntimeOptions(CommandLineOptions* options) {
385 Dart_Handle dart_arguments = CreateRuntimeOptions(options);
386 if (Dart_IsError(dart_arguments)) {
387 return dart_arguments;
388 }
381 Dart_Handle io_lib_url = DartUtils::NewString("dart:io"); 389 Dart_Handle io_lib_url = DartUtils::NewString("dart:io");
382 if (Dart_IsError(io_lib_url)) { 390 if (Dart_IsError(io_lib_url)) {
383 return io_lib_url; 391 return io_lib_url;
384 } 392 }
385 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url); 393 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url);
386 if (Dart_IsError(io_lib)) { 394 if (Dart_IsError(io_lib)) {
387 return io_lib; 395 return io_lib;
388 } 396 }
389 Dart_Handle runtime_options_class_name = DartUtils::NewString("_OptionsImpl"); 397 Dart_Handle runtime_options_class_name = DartUtils::NewString("_OptionsImpl");
390 if (Dart_IsError(runtime_options_class_name)) { 398 if (Dart_IsError(runtime_options_class_name)) {
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 } 828 }
821 829
822 if (has_check_function_fingerprints) { 830 if (has_check_function_fingerprints) {
823 result = Dart_CheckFunctionFingerprints(); 831 result = Dart_CheckFunctionFingerprints();
824 if (Dart_IsError(result)) { 832 if (Dart_IsError(result)) {
825 return DartErrorExit(result); 833 return DartErrorExit(result);
826 } 834 }
827 } 835 }
828 836
829 // Create a dart options object that can be accessed from dart code. 837 // Create a dart options object that can be accessed from dart code.
830 Dart_Handle options_result = 838 Dart_Handle options_result = SetupRuntimeOptions(&dart_options);
831 SetupRuntimeOptions(&dart_options, script_name);
832 if (Dart_IsError(options_result)) { 839 if (Dart_IsError(options_result)) {
833 return DartErrorExit(options_result); 840 return DartErrorExit(options_result);
834 } 841 }
835 // Lookup the library of the root script. 842 // Lookup the library of the root script.
836 Dart_Handle library = Dart_RootLibrary(); 843 Dart_Handle library = Dart_RootLibrary();
837 if (Dart_IsNull(library)) { 844 if (Dart_IsNull(library)) {
838 return ErrorExit(kErrorExitCode, 845 return ErrorExit(kErrorExitCode,
839 "Unable to find root library for '%s'\n", 846 "Unable to find root library for '%s'\n",
840 script_name); 847 script_name);
841 } 848 }
842 // Set debug breakpoint if specified on the command line. 849 // Set debug breakpoint if specified on the command line.
843 if (breakpoint_at != NULL) { 850 if (breakpoint_at != NULL) {
844 result = SetBreakpoint(breakpoint_at, library); 851 result = SetBreakpoint(breakpoint_at, library);
845 if (Dart_IsError(result)) { 852 if (Dart_IsError(result)) {
846 return ErrorExit(kErrorExitCode, 853 return ErrorExit(kErrorExitCode,
847 "Error setting breakpoint at '%s': %s\n", 854 "Error setting breakpoint at '%s': %s\n",
848 breakpoint_at, 855 breakpoint_at,
849 Dart_GetError(result)); 856 Dart_GetError(result));
850 } 857 }
851 } 858 }
852 if (has_print_script) { 859 if (has_print_script) {
853 result = GenerateScriptSource(); 860 result = GenerateScriptSource();
854 if (Dart_IsError(result)) { 861 if (Dart_IsError(result)) {
855 return DartErrorExit(result); 862 return DartErrorExit(result);
856 } 863 }
857 } else { 864 } else {
858 // Lookup and invoke the top level main function. 865 // Lookup and invoke the top level main function.
859 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); 866 Dart_Handle main_args[1];
867 main_args[0] = CreateRuntimeOptions(&dart_options);
868 result = Dart_Invoke(library, DartUtils::NewString("main"), 1, main_args);
869 // TODO(iposva): Return a special error type for mismatched argument
870 // counts from Dart_Invoke to avoid the string comparison.
871 const char* expected_error = "Dart_Invoke: wrong argument count for "
872 "function 'main': 1 passed, 0 expected.";
873 if (Dart_IsError(result) &&
874 strcmp(expected_error, Dart_GetError(result)) == 0) {
875 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL);
876 }
860 if (Dart_IsError(result)) { 877 if (Dart_IsError(result)) {
861 return DartErrorExit(result); 878 return DartErrorExit(result);
862 } 879 }
863 880
864 // Keep handling messages until the last active receive port is closed. 881 // Keep handling messages until the last active receive port is closed.
865 result = Dart_RunLoop(); 882 result = Dart_RunLoop();
866 if (Dart_IsError(result)) { 883 if (Dart_IsError(result)) {
867 return DartErrorExit(result); 884 return DartErrorExit(result);
868 } 885 }
869 } 886 }
(...skipping 14 matching lines...) Expand all
884 901
885 return Process::GlobalExitCode(); 902 return Process::GlobalExitCode();
886 } 903 }
887 904
888 } // namespace bin 905 } // namespace bin
889 } // namespace dart 906 } // namespace dart
890 907
891 int main(int argc, char** argv) { 908 int main(int argc, char** argv) {
892 return dart::bin::main(argc, argv); 909 return dart::bin::main(argc, argv);
893 } 910 }
OLDNEW
« no previous file with comments | « no previous file | tests/corelib/main_test.dart » ('j') | tests/corelib/main_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698