[Swfdec] 7 commits - libswfdec/swfdec_connection.c libswfdec/swfdec_js_connection.c libswfdec/swfdec_js_movie.c libswfdec/swfdec_js_net_stream.c libswfdec/swfdec_js_xml.c libswfdec/swfdec_net_stream.c libswfdec/swfdec_scriptable.c libswfdec/swfdec_scriptable.h libswfdec/swfdec_xml.c

Benjamin Otte company at kemper.freedesktop.org
Thu Mar 1 06:04:00 PST 2007


 libswfdec/swfdec_connection.c    |    4 +
 libswfdec/swfdec_js_connection.c |    2 
 libswfdec/swfdec_js_movie.c      |   89 +++++----------------------------------
 libswfdec/swfdec_js_net_stream.c |   20 ++++++++
 libswfdec/swfdec_js_xml.c        |    2 
 libswfdec/swfdec_net_stream.c    |    4 +
 libswfdec/swfdec_scriptable.c    |   49 ++++++++++++++-------
 libswfdec/swfdec_scriptable.h    |    3 +
 libswfdec/swfdec_xml.c           |    4 +
 9 files changed, 82 insertions(+), 95 deletions(-)

New commits:
diff-tree 7e865ad995f10d135ac60a20d725fb81e5c68372 (from b9a0b866f18fa9329f9e2a4dad82ec59666ded1d)
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Mar 1 15:03:20 2007 +0100

    implement NetStream.play ()

diff --git a/libswfdec/swfdec_js_net_stream.c b/libswfdec/swfdec_js_net_stream.c
index 9f12dd0..ed9c81e 100644
--- a/libswfdec/swfdec_js_net_stream.c
+++ b/libswfdec/swfdec_js_net_stream.c
@@ -27,6 +27,23 @@
 #include "swfdec_player_internal.h"
 
 static JSBool
+swfdec_js_net_stream_play (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+{
+  SwfdecNetStream *stream;
+  const char *url;
+
+  stream = swfdec_scriptable_from_object (cx, obj, SWFDEC_TYPE_NET_STREAM);
+  if (stream == NULL)
+    return JS_TRUE;
+  url = swfdec_js_to_string (cx, argv[0]);
+  if (url == NULL)
+    return JS_FALSE;
+  swfdec_net_stream_set_url (stream, url);
+  swfdec_net_stream_set_playing (stream, TRUE);
+  return JS_TRUE;
+}
+
+static JSBool
 swfdec_js_net_stream_to_string (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 {
   JSString *string;
@@ -40,6 +57,7 @@ swfdec_js_net_stream_to_string (JSContex
 }
 
 static JSFunctionSpec net_stream_methods[] = {
+  { "play",		swfdec_js_net_stream_play,	1, 0, 0 },
   { "toString",		swfdec_js_net_stream_to_string,	0, 0, 0 },
   {0,0,0,0,0}
 };
diff-tree b9a0b866f18fa9329f9e2a4dad82ec59666ded1d (from 83559ae030079a2fd2b2372bc0b4a692f8d41795)
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Mar 1 15:02:35 2007 +0100

    mark properties from attached movies DontDelete and ReadOnly

diff --git a/libswfdec/swfdec_js_movie.c b/libswfdec/swfdec_js_movie.c
index 61baaee..dcf119d 100644
--- a/libswfdec/swfdec_js_movie.c
+++ b/libswfdec/swfdec_js_movie.c
@@ -1124,6 +1124,7 @@ swfdec_js_movie_add_property (SwfdecMovi
   jsval val;
   JSObject *jsobj;
   JSContext *cx;
+  JSBool found = JS_FALSE;
 
   jsobj = swfdec_scriptable_get_object (script);
   val = OBJECT_TO_JSVAL (jsobj);
@@ -1138,7 +1139,11 @@ swfdec_js_movie_add_property (SwfdecMovi
     jsobj = SWFDEC_ROOT_MOVIE (movie)->player->jsobj;
     SWFDEC_LOG ("setting %s as property for _global", movie->name);
   }
-  JS_SetProperty (cx, jsobj, movie->name, &val);
+  if (!JS_SetProperty (cx, jsobj, movie->name, &val) ||
+      !JS_SetPropertyAttributes (cx, jsobj, movie->name, JSPROP_READONLY | JSPROP_PERMANENT, &found) ||
+      found != JS_TRUE) {
+    SWFDEC_ERROR ("could not set property %s correctly", movie->name);
+  }
 }
 
 void
@@ -1147,6 +1152,7 @@ swfdec_js_movie_remove_property (SwfdecM
   SwfdecScriptable *script = SWFDEC_SCRIPTABLE (movie);
   JSObject *jsobj;
   JSContext *cx;
+  JSBool found = JS_FALSE;
 
   if (script->jsobj == NULL)
     return;
@@ -1161,6 +1167,10 @@ swfdec_js_movie_remove_property (SwfdecM
   }
 
   SWFDEC_LOG ("removing %s as property", movie->name);
-  JS_DeleteProperty (cx, jsobj, movie->name);
+  if (!JS_SetPropertyAttributes (cx, jsobj, movie->name, JSPROP_READONLY | JSPROP_PERMANENT, &found) ||
+      found != JS_TRUE ||
+      !JS_DeleteProperty (cx, jsobj, movie->name)) {
+    SWFDEC_ERROR ("could not remove property %s correctly", movie->name);
+  }
 }
 
diff-tree 83559ae030079a2fd2b2372bc0b4a692f8d41795 (from b7e6159a4eba0d9d58d828073d99d10fe81d67ed)
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Mar 1 14:48:39 2007 +0100

    remove if 0'ed code that lay dormant since 0.3

diff --git a/libswfdec/swfdec_js_movie.c b/libswfdec/swfdec_js_movie.c
index 2296078..61baaee 100644
--- a/libswfdec/swfdec_js_movie.c
+++ b/libswfdec/swfdec_js_movie.c
@@ -1096,81 +1096,6 @@ static JSPropertySpec movieclip_props[] 
   {NULL}
 };
 
-#if 0
-JSObject *
-movieclip_find (SwfdecActionContext *context,
-    SwfdecMovie *movie)
-{
-  GList *g;
-  struct mc_list_entry *listentry;
-
-  for (g = g_list_first (context->movielist); g; g = g_list_next (g)) {
-    listentry = (struct mc_list_entry *)g->data;
-
-    if (listentry->movie == movie)
-      return listentry->mc;
-  }
-
-  return NULL;
-}
-
-static void
-swfdec_native_ASSetPropFlags (SwfdecActionContext *context, int num_args,
-  ActionVal *_this)
-{
-  ActionVal *a;
-  ActionVal *b;
-  ActionVal *c;
-  ActionVal *d;
-  int allowFalse = 0;
-  int flags;
-
-  a = stack_pop (context); /* obj */
-  action_val_convert_to_object (a);
-  b = stack_pop (context); /* property list */
-  c = stack_pop (context); /* flags */
-  action_val_convert_to_number (c);
-  if (num_args >= 4) {
-    d = stack_pop (context); /* allowFalse */
-    action_val_convert_to_boolean (d);
-    allowFalse = d->number;
-    action_val_free (d);
-  }
-
-  flags = (int)c->number & 0x7;
-  /* The flags appear to be 0x1 for DontEnum, 0x2 for DontDelete, and 0x4 for
-   * DontWrite, though the tables I found on the web are poorly written.
-   */
-
-  if (ACTIONVAL_IS_NULL(b)) {
-    GList *g;
-
-    SWFDEC_DEBUG("%d args", num_args);
-
-    for (g = g_list_first (a->obj->properties); g; g = g_list_next (g)) {
-      ScriptObjectProperty *prop = g->data;
-      if (allowFalse) {
-        prop->flags = flags;
-      } else {
-        prop->flags |= flags;
-      }
-    }
-  } else {
-    action_val_convert_to_string (b);
-    SWFDEC_WARNING("ASSetPropFlags not implemented (properties %s, flags 0x%x)",
-      b->string, (int)c->number);
-  }
-
-  action_val_free (a);
-  action_val_free (b);
-  action_val_free (c);
-
-  a = action_val_new ();
-  a->type = ACTIONVAL_TYPE_UNDEF;
-  stack_push (context, a);
-}
-#endif
-
 static JSBool
 swfdec_js_movieclip_new (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
 {
diff-tree b7e6159a4eba0d9d58d828073d99d10fe81d67ed (from c093bc3060a499d2f2552b614498ab20e3b22dc9)
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Mar 1 14:37:26 2007 +0100

    add swfdec_scriptable_from_object

diff --git a/libswfdec/swfdec_scriptable.c b/libswfdec/swfdec_scriptable.c
index f70db42..6554666 100644
--- a/libswfdec/swfdec_scriptable.c
+++ b/libswfdec/swfdec_scriptable.c
@@ -124,6 +124,35 @@ swfdec_scriptable_get_object (SwfdecScri
 }
 
 /**
+ * swfdec_scriptable_from_object:
+ * @cx: a #JSContext
+ * @object: the JSObject to convert (NULL is a valid value)
+ * @type: type of the object to get.
+ *
+ * Converts the given @object to a #SwfdecScriptable, if it represents one.
+ * The object must be of @type, otherwise %NULL will be returned.
+ *
+ * Returns: the scriptable represented by @object or NULL if it does not 
+ *          reference a @scriptable
+ **/
+gpointer
+swfdec_scriptable_from_object (JSContext *cx, JSObject *object, GType type)
+{
+  SwfdecScriptableClass *klass;
+
+  g_return_val_if_fail (g_type_is_a (type, SWFDEC_TYPE_SCRIPTABLE), NULL);
+
+  if (object == NULL)
+    return NULL;
+  klass = g_type_class_peek (type);
+  if (klass == NULL)
+    return NULL; /* class doesn't exist -> no object of this type exists */
+  if (!JS_InstanceOf (cx, object, klass->jsclass, NULL))
+    return NULL;
+  return JS_GetPrivate (cx, object);
+}
+
+/**
  * swfdec_scriptable_from_jsval:
  * @cx: a #JSContext
  * @val: the jsval to convert
@@ -138,22 +167,14 @@ swfdec_scriptable_get_object (SwfdecScri
 gpointer
 swfdec_scriptable_from_jsval (JSContext *cx, jsval val, GType type)
 {
-  SwfdecScriptableClass *klass;
   JSObject *object;
 
   g_return_val_if_fail (g_type_is_a (type, SWFDEC_TYPE_SCRIPTABLE), NULL);
 
   if (!JSVAL_IS_OBJECT (val))
     return NULL;
-  if (JSVAL_IS_NULL (val))
-    return NULL;
   object = JSVAL_TO_OBJECT (val);
-  klass = g_type_class_peek (type);
-  if (klass == NULL)
-    return NULL; /* class doesn't exist -> no object of this type exists */
-  if (!JS_InstanceOf (cx, object, klass->jsclass, NULL))
-    return NULL;
-  return JS_GetPrivate (cx, object);
+  return swfdec_scriptable_from_object (cx, object, type);
 }
 
 /**
diff --git a/libswfdec/swfdec_scriptable.h b/libswfdec/swfdec_scriptable.h
index 0f57f11..a197d8f 100644
--- a/libswfdec/swfdec_scriptable.h
+++ b/libswfdec/swfdec_scriptable.h
@@ -60,6 +60,9 @@ JSObject *		swfdec_scriptable_get_object
 gpointer		swfdec_scriptable_from_jsval	(JSContext *		cx,
 							 jsval			val,
 							 GType			type);
+gpointer		swfdec_scriptable_from_object	(JSContext *		cx,
+							 JSObject *		object,
+							 GType			type);
 
 void			swfdec_scriptable_set_variables	(SwfdecScriptable *	script,
 							 const char *		variables);
diff-tree c093bc3060a499d2f2552b614498ab20e3b22dc9 (from parents)
Merge: 3e757b2781984c01f99384dd12e729b2a4c9c2c8 c87585512fddb167171f7762b4a87598e0b0447d
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Mar 1 13:20:29 2007 +0100

    Merge branch 'master' of ssh://company@git.freedesktop.org/git/swfdec

diff-tree 3e757b2781984c01f99384dd12e729b2a4c9c2c8 (from 40f546c66744e4e6deedcce714ffc344ef5afd1a)
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Mar 1 13:20:09 2007 +0100

    register the classes with the objects for NetConnection, NetStream and XML

diff --git a/libswfdec/swfdec_connection.c b/libswfdec/swfdec_connection.c
index 8e423df..464affb 100644
--- a/libswfdec/swfdec_connection.c
+++ b/libswfdec/swfdec_connection.c
@@ -42,12 +42,16 @@ swfdec_connection_dispose (GObject *obje
   G_OBJECT_CLASS (swfdec_connection_parent_class)->dispose (object);
 }
 
+extern const JSClass connection_class;
 static void
 swfdec_connection_class_init (SwfdecConnectionClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  SwfdecScriptableClass *scriptable_class = SWFDEC_SCRIPTABLE_CLASS (klass);
 
   object_class->dispose = swfdec_connection_dispose;
+
+  scriptable_class->jsclass = &connection_class;
 }
 
 static void
diff --git a/libswfdec/swfdec_js_connection.c b/libswfdec/swfdec_js_connection.c
index 1ff1032..1568e64 100644
--- a/libswfdec/swfdec_js_connection.c
+++ b/libswfdec/swfdec_js_connection.c
@@ -81,7 +81,7 @@ swfdec_js_connection_finalize (JSContext
   }
 }
 
-static JSClass connection_class = {
+const JSClass connection_class = {
     "NetConnection", JSCLASS_HAS_PRIVATE,
     JS_PropertyStub,  JS_PropertyStub,  JS_PropertyStub,  JS_PropertyStub,
     JS_EnumerateStub, JS_ResolveStub,   JS_ConvertStub,   swfdec_js_connection_finalize,
diff --git a/libswfdec/swfdec_js_net_stream.c b/libswfdec/swfdec_js_net_stream.c
index 7b53cfb..9f12dd0 100644
--- a/libswfdec/swfdec_js_net_stream.c
+++ b/libswfdec/swfdec_js_net_stream.c
@@ -56,7 +56,7 @@ swfdec_js_net_stream_finalize (JSContext
   }
 }
 
-static JSClass net_stream_class = {
+const JSClass net_stream_class = {
     "NetStream", JSCLASS_HAS_PRIVATE,
     JS_PropertyStub,  JS_PropertyStub,  JS_PropertyStub,  JS_PropertyStub,
     JS_EnumerateStub, JS_ResolveStub,   JS_ConvertStub,   swfdec_js_net_stream_finalize,
diff --git a/libswfdec/swfdec_js_xml.c b/libswfdec/swfdec_js_xml.c
index d6d0df5..e2cdecf 100644
--- a/libswfdec/swfdec_js_xml.c
+++ b/libswfdec/swfdec_js_xml.c
@@ -73,7 +73,7 @@ swfdec_js_xml_finalize (JSContext *cx, J
   }
 }
 
-static JSClass xml_class = {
+const JSClass xml_class = {
     "XML", JSCLASS_HAS_PRIVATE,
     JS_PropertyStub,  JS_PropertyStub,  JS_PropertyStub,  JS_PropertyStub,
     JS_EnumerateStub, JS_ResolveStub,   JS_ConvertStub,   swfdec_js_xml_finalize,
diff --git a/libswfdec/swfdec_net_stream.c b/libswfdec/swfdec_net_stream.c
index 3fb4937..b6f15e8 100644
--- a/libswfdec/swfdec_net_stream.c
+++ b/libswfdec/swfdec_net_stream.c
@@ -222,12 +222,16 @@ swfdec_net_stream_dispose (GObject *obje
   G_OBJECT_CLASS (swfdec_net_stream_parent_class)->dispose (object);
 }
 
+extern const JSClass net_stream_class;
 static void
 swfdec_net_stream_class_init (SwfdecNetStreamClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  SwfdecScriptableClass *scriptable_class = SWFDEC_SCRIPTABLE_CLASS (klass);
 
   object_class->dispose = swfdec_net_stream_dispose;
+
+  scriptable_class->jsclass = &net_stream_class;
 }
 
 static void
diff --git a/libswfdec/swfdec_xml.c b/libswfdec/swfdec_xml.c
index 1f05c7d..b5cbf26 100644
--- a/libswfdec/swfdec_xml.c
+++ b/libswfdec/swfdec_xml.c
@@ -141,12 +141,16 @@ swfdec_xml_dispose (GObject *object)
   G_OBJECT_CLASS (swfdec_xml_parent_class)->dispose (object);
 }
 
+extern const JSClass xml_class;
 static void
 swfdec_xml_class_init (SwfdecXmlClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  SwfdecScriptableClass *scriptable_class = SWFDEC_SCRIPTABLE_CLASS (klass);
 
   object_class->dispose = swfdec_xml_dispose;
+
+  scriptable_class->jsclass = &xml_class;
 }
 
 static void
diff-tree 40f546c66744e4e6deedcce714ffc344ef5afd1a (from 66e63dc1d746e5b3d5bffd3b780a028aa6b995be)
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Mar 1 13:18:51 2007 +0100

    fix swfdec_scriptable_set_variables again
    
    The last "fix" made the last property not being set

diff --git a/libswfdec/swfdec_scriptable.c b/libswfdec/swfdec_scriptable.c
index 772a7de..f70db42 100644
--- a/libswfdec/swfdec_scriptable.c
+++ b/libswfdec/swfdec_scriptable.c
@@ -174,8 +174,6 @@ swfdec_scriptable_set_variables (SwfdecS
   g_return_if_fail (variables != NULL);
 
   SWFDEC_DEBUG ("setting variables on %p: %s", script, variables);
-  if (*variables == '\0')
-    return;
   object = swfdec_scriptable_get_object (script);
   while (TRUE) {
     char *name, *value;
@@ -186,15 +184,12 @@ swfdec_scriptable_set_variables (SwfdecS
       SWFDEC_WARNING ("variables invalid at \"%s\"", variables);
       break;
     }
-    if (*variables == '\0') {
-      break;
-    } else if (*variables != '&') {
+    if (*variables != '\0' && *variables != '&') {
       SWFDEC_WARNING ("variables not delimited with & at \"%s\"", variables);
       g_free (name);
       g_free (value);
       break;
     }
-    variables++;
     string = JS_NewStringCopyZ (script->jscx, value);
     if (string == NULL) {
       g_free (name);
@@ -212,6 +207,9 @@ swfdec_scriptable_set_variables (SwfdecS
     SWFDEC_DEBUG ("Set variable \"%s\" to \"%s\"", name, value);
     g_free (name);
     g_free (value);
+    if (*variables == '\0')
+      break;
+    variables++;
   }
 }
 


More information about the Swfdec mailing list