Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 856 Dart_GetError(result)); | 856 Dart_GetError(result)); |
| 857 } | 857 } |
| 858 } | 858 } |
| 859 if (has_print_script) { | 859 if (has_print_script) { |
| 860 result = GenerateScriptSource(); | 860 result = GenerateScriptSource(); |
| 861 if (Dart_IsError(result)) { | 861 if (Dart_IsError(result)) { |
| 862 return DartErrorExit(result); | 862 return DartErrorExit(result); |
| 863 } | 863 } |
| 864 } else { | 864 } else { |
| 865 // Lookup and invoke the top level main function. | 865 // Lookup and invoke the top level main function. |
| 866 Dart_Handle main_args[1]; | 866 // The top-level function may accept up to two arguments: |
| 867 // main(List<String> args, var message). | |
| 868 // However most commonly it either accepts one (the args list) or | |
| 869 // none. | |
| 870 // If the message is optional, main(args, [message]), it is invoked with | |
| 871 // one argument only. | |
| 872 Dart_Handle main_args[2]; | |
| 867 main_args[0] = CreateRuntimeOptions(&dart_options); | 873 main_args[0] = CreateRuntimeOptions(&dart_options); |
| 874 main_args[1] = Dart_Null(); | |
| 875 // 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
| |
| 868 result = Dart_Invoke(library, DartUtils::NewString("main"), 1, main_args); | 876 result = Dart_Invoke(library, DartUtils::NewString("main"), 1, main_args); |
| 869 // TODO(iposva): Return a special error type for mismatched argument | 877 // TODO(iposva): Return a special error type for mismatched argument |
| 870 // counts from Dart_Invoke to avoid the string comparison. | 878 // counts from Dart_Invoke to avoid the string comparison. |
| 871 const char* expected_error = "Dart_Invoke: wrong argument count for " | 879 const char* expected_error = "Dart_Invoke: wrong argument count for " |
| 872 "function 'main': 1 passed, 0 expected."; | 880 "function 'main': "; |
| 881 intptr_t length = strlen(expected_error); | |
| 873 if (Dart_IsError(result) && | 882 if (Dart_IsError(result) && |
| 874 strcmp(expected_error, Dart_GetError(result)) == 0) { | 883 strncmp(expected_error, Dart_GetError(result), length) == 0) { |
| 875 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); | 884 // 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.
| |
| 885 result = | |
| 886 Dart_Invoke(library, DartUtils::NewString("main"), 2, main_args); | |
| 887 if (Dart_IsError(result) && | |
| 888 strncmp(expected_error, Dart_GetError(result), length) == 0) { | |
| 889 // Finally try with 0 arguments. | |
| 890 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); | |
| 891 } | |
| 876 } | 892 } |
| 877 if (Dart_IsError(result)) { | 893 if (Dart_IsError(result)) { |
| 878 return DartErrorExit(result); | 894 return DartErrorExit(result); |
| 879 } | 895 } |
| 880 | 896 |
| 881 // Keep handling messages until the last active receive port is closed. | 897 // Keep handling messages until the last active receive port is closed. |
| 882 result = Dart_RunLoop(); | 898 result = Dart_RunLoop(); |
| 883 if (Dart_IsError(result)) { | 899 if (Dart_IsError(result)) { |
| 884 return DartErrorExit(result); | 900 return DartErrorExit(result); |
| 885 } | 901 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 901 | 917 |
| 902 return Process::GlobalExitCode(); | 918 return Process::GlobalExitCode(); |
| 903 } | 919 } |
| 904 | 920 |
| 905 } // namespace bin | 921 } // namespace bin |
| 906 } // namespace dart | 922 } // namespace dart |
| 907 | 923 |
| 908 int main(int argc, char** argv) { | 924 int main(int argc, char** argv) { |
| 909 return dart::bin::main(argc, argv); | 925 return dart::bin::main(argc, argv); |
| 910 } | 926 } |
| OLD | NEW |