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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/corelib/corelib.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/main.cc
===================================================================
--- runtime/bin/main.cc (revision 28826)
+++ 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)) {
@@ -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);
}
« no previous file with comments | « no previous file | tests/corelib/corelib.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698