summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@gnome.org>2008-11-18 12:05:19 +0100
committerBenjamin Otte <otte@gnome.org>2008-11-18 12:05:19 +0100
commit2ea5b413acf2637097ec8312f1ae6ea797003ee4 (patch)
tree1e82aa379bd62a14a7e57a271ba59e5c945a6ad8
parentbb5ece1032c5bb6db72e76e7b8f9e9040c7f1885 (diff)
add swfdec_as_object_enumerate()
This functionality seems to be used more often, so make it a nice function
-rw-r--r--swfdec/swfdec_as_interpret.c27
-rw-r--r--swfdec/swfdec_as_object.c50
-rw-r--r--swfdec/swfdec_as_object.h1
3 files changed, 53 insertions, 25 deletions
diff --git a/swfdec/swfdec_as_interpret.c b/swfdec/swfdec_as_interpret.c
index ca33a9dc..525d824b 100644
--- a/swfdec/swfdec_as_interpret.c
+++ b/swfdec/swfdec_as_interpret.c
@@ -2384,36 +2384,13 @@ fail:
swfdec_as_stack_pop_n (cx, 2);
}
-static gboolean
-swfdec_action_enumerate_foreach (SwfdecAsObject *object, const char *variable,
- SwfdecAsValue *value, guint flags, gpointer listp)
-{
- GSList **list = listp;
-
- if (flags & SWFDEC_AS_VARIABLE_HIDDEN)
- return TRUE;
-
- *list = g_slist_remove (*list, variable);
- *list = g_slist_prepend (*list, (gpointer) variable);
- return TRUE;
-}
-
static void
swfdec_action_do_enumerate (SwfdecAsContext *cx, SwfdecAsObject *object)
{
guint i;
- GSList *walk, *list = NULL;
+ GSList *walk, *list;
- for (i = 0; i < 256 && object; i++) {
- swfdec_as_object_foreach (object, swfdec_action_enumerate_foreach, &list);
- object = swfdec_as_object_get_prototype (object);
- }
- if (i == 256) {
- swfdec_as_context_abort (cx, "Prototype recursion limit exceeded");
- g_slist_free (list);
- return;
- }
- list = g_slist_reverse (list);
+ list = swfdec_as_object_enumerate (object);
i = 0;
for (walk = list; walk; walk = walk->next) {
/* 8 is an arbitrary value */
diff --git a/swfdec/swfdec_as_object.c b/swfdec/swfdec_as_object.c
index 6e9ab928..8ea79fc3 100644
--- a/swfdec/swfdec_as_object.c
+++ b/swfdec/swfdec_as_object.c
@@ -1149,6 +1149,56 @@ swfdec_as_object_foreach (SwfdecAsObject *object, SwfdecAsVariableForeach func,
/*** SIMPLIFICATIONS ***/
+static gboolean
+swfdec_as_object_enumerate_foreach (SwfdecAsObject *object, const char *variable,
+ SwfdecAsValue *value, guint flags, gpointer listp)
+{
+ GSList **list = listp;
+
+ if (flags & SWFDEC_AS_VARIABLE_HIDDEN)
+ return TRUE;
+
+ *list = g_slist_remove (*list, variable);
+ *list = g_slist_prepend (*list, (gpointer) variable);
+ return TRUE;
+}
+
+/**
+ * swfdec_as_object_enumerate:
+ * @object: the object to enumerate
+ *
+ * Enumerates all non-hidden properties of a given object and its prototypes
+ * and returns their names as garbage-collected strings in a list. This
+ * function is a special case of swfdec_as_object_foreach().
+ *
+ * Returns: a GSList of all properties of the object. You need to
+ * g_slist_free() the list after use.
+ **/
+GSList *
+swfdec_as_object_enumerate (SwfdecAsObject *object)
+{
+ guint i;
+ GSList *list = NULL;
+
+ for (i = 0; i < SWFDEC_AS_OBJECT_PROTOTYPE_RECURSION_LIMIT && object; i++) {
+ swfdec_as_object_foreach (object, swfdec_as_object_enumerate_foreach, &list);
+ object = swfdec_as_object_get_prototype (object);
+ }
+ if (i == 256) {
+ swfdec_as_context_abort (object->context, "Prototype recursion limit exceeded");
+ g_slist_free (list);
+ return NULL;
+ }
+#if 0
+ list = g_slist_reverse (list);
+#else
+ /* we force an alphabetical order into the list for now. This is wrong,
+ * but at least ensures reproducability */
+ list = g_slist_sort (list, (GCompareFunc) strcmp);
+#endif
+ return list;
+}
+
static void
swfdec_as_object_do_nothing (SwfdecAsContext *cx, SwfdecAsObject *object,
guint argc, SwfdecAsValue *argv, SwfdecAsValue *retval)
diff --git a/swfdec/swfdec_as_object.h b/swfdec/swfdec_as_object.h
index f1acba9e..95f42ac8 100644
--- a/swfdec/swfdec_as_object.h
+++ b/swfdec/swfdec_as_object.h
@@ -126,6 +126,7 @@ void swfdec_as_object_unset_variable_flags
gboolean swfdec_as_object_foreach (SwfdecAsObject * object,
SwfdecAsVariableForeach func,
gpointer data);
+GSList * swfdec_as_object_enumerate (SwfdecAsObject * object);
SwfdecAsFunction *swfdec_as_object_add_function (SwfdecAsObject * object,
const char * name,