Chromium Code Reviews| Index: runtime/bin/main.cc |
| =================================================================== |
| --- runtime/bin/main.cc (revision 28687) |
| +++ runtime/bin/main.cc (working copy) |
| @@ -360,8 +360,7 @@ |
| } |
| -static Dart_Handle SetupRuntimeOptions(CommandLineOptions* options, |
| - const char* script_name) { |
| +static Dart_Handle CreateRuntimeOptions(CommandLineOptions* options) { |
| int options_count = options->count(); |
| Dart_Handle dart_arguments = Dart_NewList(options_count); |
| if (Dart_IsError(dart_arguments)) { |
| @@ -369,7 +368,7 @@ |
| } |
| for (int i = 0; i < options_count; i++) { |
| Dart_Handle argument_value = |
| - DartUtils::NewString(options->GetArgument(i)); |
| + 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!
|
| if (Dart_IsError(argument_value)) { |
| return argument_value; |
| } |
| @@ -378,6 +377,15 @@ |
| return result; |
| } |
| } |
| + return dart_arguments; |
| +} |
| + |
| + |
| +static Dart_Handle SetupRuntimeOptions(CommandLineOptions* options) { |
| + Dart_Handle dart_arguments = CreateRuntimeOptions(options); |
| + if (Dart_IsError(dart_arguments)) { |
| + return dart_arguments; |
| + } |
| Dart_Handle io_lib_url = DartUtils::NewString("dart:io"); |
| if (Dart_IsError(io_lib_url)) { |
| return io_lib_url; |
| @@ -827,8 +835,7 @@ |
| } |
| // Create a dart options object that can be accessed from dart code. |
| - Dart_Handle options_result = |
| - SetupRuntimeOptions(&dart_options, script_name); |
| + Dart_Handle options_result = SetupRuntimeOptions(&dart_options); |
| if (Dart_IsError(options_result)) { |
| return DartErrorExit(options_result); |
| } |
| @@ -856,7 +863,17 @@ |
| } |
| } else { |
| // Lookup and invoke the top level main function. |
| - result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); |
| + Dart_Handle main_args[1]; |
| + main_args[0] = CreateRuntimeOptions(&dart_options); |
| + result = Dart_Invoke(library, DartUtils::NewString("main"), 1, main_args); |
| + // TODO(iposva): Return a special error type for mismatched argument |
| + // counts from Dart_Invoke to avoid the string comparison. |
| + const char* expected_error = "Dart_Invoke: wrong argument count for " |
| + "function 'main': 1 passed, 0 expected."; |
| + if (Dart_IsError(result) && |
| + strcmp(expected_error, Dart_GetError(result)) == 0) { |
| + result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); |
| + } |
| if (Dart_IsError(result)) { |
| return DartErrorExit(result); |
| } |