Chromium Code Reviews| Index: runtime/bin/main.cc |
| diff --git a/runtime/bin/main.cc b/runtime/bin/main.cc |
| index 76c00626bbf200657ca9a997ac7ee7affcbb0911..e814ca3113ab2ef9943231d60dce0afebe5bff5d 100644 |
| --- a/runtime/bin/main.cc |
| +++ b/runtime/bin/main.cc |
| @@ -863,16 +863,32 @@ int main(int argc, char** argv) { |
| } |
| } else { |
| // Lookup and invoke the top level main function. |
| - Dart_Handle main_args[1]; |
| + // The top-level function may accept up to two arguments: |
| + // main(List<String> args, var message). |
| + // However most commonly it either accepts one (the args list) or |
| + // none. |
| + // If the message is optional, main(args, [message]), it is invoked with |
| + // one argument only. |
| + Dart_Handle main_args[2]; |
| main_args[0] = CreateRuntimeOptions(&dart_options); |
| + main_args[1] = Dart_Null(); |
| + // First try with 1 argument. |
|
Lasse Reichstein Nielsen
2013/10/25 09:42:49
Could we inspect the function to see its signature
floitsch
2013/10/25 13:11:01
It will be fixed. The TODO below is from Ivan. Thi
|
| 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."; |
| + "function 'main': "; |
| + intptr_t length = strlen(expected_error); |
| if (Dart_IsError(result) && |
| - strcmp(expected_error, Dart_GetError(result)) == 0) { |
| - result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); |
| + strncmp(expected_error, Dart_GetError(result), length) == 0) { |
| + // Try with two arguments. |
|
Lasse Reichstein Nielsen
2013/10/25 09:42:49
Say why we try two before zero.
We really want to
floitsch
2013/10/25 13:11:01
See comment above.
|
| + result = |
| + Dart_Invoke(library, DartUtils::NewString("main"), 2, main_args); |
| + if (Dart_IsError(result) && |
| + strncmp(expected_error, Dart_GetError(result), length) == 0) { |
| + // Finally try with 0 arguments. |
| + result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); |
| + } |
| } |
| if (Dart_IsError(result)) { |
| return DartErrorExit(result); |