[gjs] util: Add a flag to gjs_parse_args to allow JS to pass ignored arguments
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] util: Add a flag to gjs_parse_args to allow JS to pass ignored arguments
- Date: Fri, 3 Feb 2012 03:27:44 +0000 (UTC)
commit 4ea658f9e7366dc8e7c803fe9453a284133bb71a
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Fri Jan 27 18:06:17 2012 -0500
util: Add a flag to gjs_parse_args to allow JS to pass ignored arguments
Because param_new_internal parses arguments in two steps, we need to make
it OK for JS to pass more arguments than the totla amount
gjs/jsapi-util.c | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/gjs/jsapi-util.c b/gjs/jsapi-util.c
index c495e20..326325a 100644
--- a/gjs/jsapi-util.c
+++ b/gjs/jsapi-util.c
@@ -1380,6 +1380,9 @@ gjs_value_to_int64 (JSContext *context,
* u: A number, converted into a C "guint32"
* o: A JavaScript object, as a "JSObject *"
*
+ * If the first character in the format string is a '!', then JS is allowed
+ * to pass extra arguments that are ignored, to the function.
+ *
* The '|' character introduces optional arguments. All format specifiers
* after a '|' when not specified, do not cause any changes in the C
* value location.
@@ -1399,6 +1402,7 @@ gjs_parse_args (JSContext *context,
guint n_unwind = 0;
#define MAX_UNWIND_STRINGS 16
gpointer unwind_strings[MAX_UNWIND_STRINGS];
+ gboolean ignore_trailing_args = FALSE;
guint n_required;
guint n_total;
guint consumed_args;
@@ -1407,6 +1411,11 @@ gjs_parse_args (JSContext *context,
va_start (args, argv);
+ if (*format == '!') {
+ ignore_trailing_args = TRUE;
+ format++;
+ }
+
/* Check for optional argument specifier */
fmt_iter = strchr (format, '|');
if (fmt_iter) {
@@ -1419,7 +1428,7 @@ gjs_parse_args (JSContext *context,
n_required = n_total = strlen (format);
}
- if (argc < n_required || argc > n_total) {
+ if (argc < n_required || (argc > n_total && !ignore_trailing_args)) {
if (n_required == n_total) {
gjs_throw(context, "Error invoking %s: Expected %d arguments, got %d", function_name,
n_required, argc);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]