[Swfdec] Branch 'as' - 16 commits - configure.ac libswfdec/Makefile.am libswfdec/swfdec_as_context.c libswfdec/swfdec_as_frame.c libswfdec/swfdec_as_frame.h libswfdec/swfdec_as_function.c libswfdec/swfdec_as_interpret.c libswfdec/swfdec_as_script_function.c libswfdec/swfdec_as_script_function.h libswfdec/swfdec_as_strings.c libswfdec/swfdec_codec_ffmpeg.c libswfdec/swfdec_js.c libswfdec/swfdec_js.h libswfdec/swfdec_js_sound.c libswfdec/swfdec_js_video.c libswfdec/swfdec_js_xml.c libswfdec/swfdec_player.c libswfdec/swfdec_xml_as.c

Benjamin Otte company at kemper.freedesktop.org
Wed Jun 27 01:37:09 PDT 2007


 configure.ac                          |    2 
 libswfdec/Makefile.am                 |   13 
 libswfdec/swfdec_as_context.c         |    3 
 libswfdec/swfdec_as_frame.c           |   43 +--
 libswfdec/swfdec_as_frame.h           |    7 
 libswfdec/swfdec_as_function.c        |    2 
 libswfdec/swfdec_as_interpret.c       |  103 +++----
 libswfdec/swfdec_as_script_function.c |    6 
 libswfdec/swfdec_as_script_function.h |    7 
 libswfdec/swfdec_as_strings.c         |    5 
 libswfdec/swfdec_codec_ffmpeg.c       |   25 +
 libswfdec/swfdec_js.c                 |  472 ----------------------------------
 libswfdec/swfdec_js.h                 |   74 -----
 libswfdec/swfdec_js_sound.c           |   75 -----
 libswfdec/swfdec_js_video.c           |   92 ++----
 libswfdec/swfdec_js_xml.c             |   87 ------
 libswfdec/swfdec_player.c             |    2 
 libswfdec/swfdec_xml_as.c             |   65 ++++
 18 files changed, 207 insertions(+), 876 deletions(-)

New commits:
diff-tree 6926ffebd79fd8fb3ab853c39f071925fc8066bd (from cdb3324b8d8fd60ea0420de74b89a9edb1528b11)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Jun 27 10:37:06 2007 +0200

    Fix Get/SetProperty to use the right struct layout
    
    My hacks come back and bite me, I need to seriously change that.

diff --git a/libswfdec/swfdec_as_interpret.c b/libswfdec/swfdec_as_interpret.c
index 4f84189..b4bcc4f 100644
--- a/libswfdec/swfdec_as_interpret.c
+++ b/libswfdec/swfdec_as_interpret.c
@@ -448,6 +448,7 @@ swfdec_as_interpret_eval (SwfdecAsContex
 
 /* FIXME: this sucks */
 extern struct {
+  gboolean needs_movie;
   const char * name; /* GC'd */
   void (* get) (SwfdecMovie *movie, SwfdecAsValue *ret);
   void (* set) (SwfdecMovie *movie, const SwfdecAsValue *val);
diff-tree cdb3324b8d8fd60ea0420de74b89a9edb1528b11 (from parents)
Merge: e3b1a4d0c6d2d5104085fdb1d8e14269999de4bd 0d598e6df9d7c2e046935505cee577accc7e0613
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Jun 27 10:31:53 2007 +0200

    Merge branch 'as' of ssh://company@git.freedesktop.org/git/swfdec into as
    
    Conflicts:
    
    	libswfdec/swfdec_as_interpret.c

diff --cc libswfdec/swfdec_as_interpret.c
index 288c47d,e09b09f..4f84189
@@@ -55,8 -74,9 +55,8 @@@
  static void
  swfdec_action_stop (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
  {
-   if (SWFDEC_IS_MOVIE (cx->frame->target))
-     SWFDEC_MOVIE (cx->frame->target)->stopped = TRUE;
 -  SwfdecSpriteMovie *movie = swfdec_action_get_target (cx);
 -  if (movie)
 -    movie->playing = FALSE;
++  if (SWFDEC_IS_SPRITE_MOVIE (cx->frame->target))
++    SWFDEC_SPRITE_MOVIE (cx->frame->target)->playing = FALSE;
    else
      SWFDEC_ERROR ("no movie to stop");
  }
@@@ -64,8 -84,9 +64,8 @@@
  static void
  swfdec_action_play (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
  {
-   if (SWFDEC_IS_MOVIE (cx->frame->target))
-     SWFDEC_MOVIE (cx->frame->target)->stopped = FALSE;
 -  SwfdecSpriteMovie *movie = swfdec_action_get_target (cx);
 -  if (movie)
 -    movie->playing = TRUE;
++  if (SWFDEC_IS_SPRITE_MOVIE (cx->frame->target))
++    SWFDEC_SPRITE_MOVIE (cx->frame->target)->playing = TRUE;
    else
      SWFDEC_ERROR ("no movie to play");
  }
@@@ -73,10 -94,10 +73,10 @@@
  static void
  swfdec_action_next_frame (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
  {
-   if (SWFDEC_IS_MOVIE (cx->frame->target)) {
-     SwfdecMovie *movie = SWFDEC_MOVIE (cx->frame->target);
-     if (movie->frame + 1 < movie->n_frames) {
-       swfdec_movie_goto (movie, movie->frame + 1);
 -  SwfdecSpriteMovie *movie = swfdec_action_get_target (cx);
 -  if (movie) {
++  if (SWFDEC_IS_SPRITE_MOVIE (cx->frame->target)) {
++    SwfdecSpriteMovie *movie = SWFDEC_SPRITE_MOVIE (cx->frame->target);
+     if (movie->frame < movie->n_frames) {
+       swfdec_sprite_movie_goto (movie, movie->frame + 1);
      } else {
        SWFDEC_INFO ("can't execute nextFrame, already at last frame");
      }
@@@ -88,10 -109,10 +88,10 @@@
  static void
  swfdec_action_previous_frame (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
  {
-   if (SWFDEC_IS_MOVIE (cx->frame->target)) {
-     SwfdecMovie *movie = SWFDEC_MOVIE (cx->frame->target);
-     if (movie->frame > 0) {
-       swfdec_movie_goto (movie, movie->frame - 1);
 -  SwfdecSpriteMovie *movie = swfdec_action_get_target (cx);
 -  if (movie) {
++  if (SWFDEC_IS_SPRITE_MOVIE (cx->frame->target)) {
++    SwfdecSpriteMovie *movie = SWFDEC_SPRITE_MOVIE (cx->frame->target);
+     if (movie->frame > 1) {
+       swfdec_sprite_movie_goto (movie, movie->frame - 1);
      } else {
        SWFDEC_INFO ("can't execute previousFrame, already at first frame");
      }
@@@ -110,10 -132,9 +110,10 @@@
      return;
    }
    frame = GUINT16_FROM_LE (*((guint16 *) data));
 -  if (movie) {
 +  if (SWFDEC_IS_SPRITE_MOVIE (cx->frame->target)) {
-     SwfdecMovie *movie = SWFDEC_MOVIE (cx->frame->target);
-     swfdec_movie_goto (movie, frame);
-     movie->stopped = TRUE;
++    SwfdecSpriteMovie *movie = SWFDEC_SPRITE_MOVIE (cx->frame->target);
+     swfdec_sprite_movie_goto (movie, frame + 1);
+     movie->playing = FALSE;
    } else {
      SWFDEC_ERROR ("no movie to goto on");
    }
@@@ -127,13 -150,13 +127,14 @@@
      return;
    }
  
 -  if (movie) {
 +  if (SWFDEC_IS_SPRITE_MOVIE (cx->frame->target)) {
-     SwfdecMovie *movie = SWFDEC_MOVIE (cx->frame->target);
-     int frame = swfdec_sprite_get_frame (SWFDEC_SPRITE_MOVIE (movie)->sprite, (const char *) data);
-     if (frame == -1)
++    SwfdecSpriteMovie *movie = SWFDEC_SPRITE_MOVIE (cx->frame->target);
+     int frame;
+     if (movie->sprite == NULL ||
+ 	(frame = swfdec_sprite_get_frame (movie->sprite, (const char *) data)) == -1)
        return;
-     swfdec_movie_goto (movie, frame);
-     movie->stopped = TRUE;
+     swfdec_sprite_movie_goto (movie, frame + 1);
+     movie->playing = FALSE;
    } else {
      SWFDEC_ERROR ("no movie to goto on");
    }
@@@ -186,15 -211,15 +188,15 @@@
      bias = swfdec_bits_get_u16 (&bits);
    }
    val = swfdec_as_stack_peek (cx->frame->stack, 1);
 -  movie = swfdec_action_get_target (cx);
    /* now set it */
 -  if (movie) {
 +  if (SWFDEC_IS_SPRITE_MOVIE (cx->frame->target)) {
-     SwfdecMovie *movie = SWFDEC_MOVIE (cx->frame->target);
-     int frame = swfdec_value_to_frame (cx, movie, val);
-     if (frame >= 0) {
++    SwfdecSpriteMovie *movie = SWFDEC_SPRITE_MOVIE (cx->frame->target);
+     guint frame = swfdec_value_to_frame (cx, movie, val);
+     if (frame > 0) {
        frame += bias;
-       frame = CLAMP (frame, 0, (int) movie->n_frames - 1);
-       swfdec_movie_goto (movie, frame);
-       movie->stopped = !play;
+       frame = CLAMP (frame, 1, movie->n_frames);
+       swfdec_sprite_movie_goto (movie, frame);
+       movie->playing = play;
      }
    } else {
      SWFDEC_ERROR ("no movie to GotoFrame2 on");
@@@ -274,11 -301,10 +276,11 @@@
      return;
    }
  
-   movie = SWFDEC_MOVIE (cx->frame->target);
++  movie = SWFDEC_SPRITE_MOVIE (cx->frame->target);
    frame = GUINT16_FROM_LE (*((guint16 *) data));
    jump = data[2];
-   if (SWFDEC_MOVIE (movie->swf->movie) == movie) {
-     SwfdecDecoder *dec = movie->swf->decoder;
+   if (SWFDEC_MOVIE (movie)->swf->movie == movie) {
+     SwfdecDecoder *dec = SWFDEC_MOVIE (movie)->swf->decoder;
      loaded = dec->frames_loaded;
      g_assert (loaded <= movie->n_frames);
    } else {
diff-tree e3b1a4d0c6d2d5104085fdb1d8e14269999de4bd (from cbf5b3fcecd54d80669ffe7325344c3fc3168597)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Jun 27 09:29:01 2007 +0200

    hook up Video object code
    
    This should be the last leftover code from 0.4

diff --git a/libswfdec/Makefile.am b/libswfdec/Makefile.am
index f944d94..14e50fb 100644
--- a/libswfdec/Makefile.am
+++ b/libswfdec/Makefile.am
@@ -19,14 +19,6 @@ endif
 
 lib_LTLIBRARIES = libswfdec- at SWFDEC_MAJORMINOR@.la
 
-foofiles = \
-	swfdec_js.c \
-	swfdec_js_global.c \
-	swfdec_js_mouse.c \
-	swfdec_js_movie.c \
-	swfdec_js_sound.c \
-	swfdec_js_video.c
-
 libswfdec_ at SWFDEC_MAJORMINOR@_la_SOURCES = \
 	swfdec_as_array.c \
 	swfdec_as_context.c \
@@ -78,6 +70,7 @@ libswfdec_ at SWFDEC_MAJORMINOR@_la_SOURCES
 	swfdec_html_parser.c \
 	swfdec_image.c \
 	swfdec_interval.c \
+	swfdec_js_video.c \
 	swfdec_listener.c \
 	swfdec_loader.c \
 	swfdec_loadertarget.c \
diff --git a/libswfdec/swfdec_as_strings.c b/libswfdec/swfdec_as_strings.c
index 15d0f69..8fe5c1b 100644
--- a/libswfdec/swfdec_as_strings.c
+++ b/libswfdec/swfdec_as_strings.c
@@ -215,6 +215,9 @@ const char swfdec_as_strings[] = 
   SWFDEC_AS_CONSTANT_STRING ("setBufferTime")
   SWFDEC_AS_CONSTANT_STRING ("load")
   SWFDEC_AS_CONSTANT_STRING ("XML")
+  SWFDEC_AS_CONSTANT_STRING ("Video")
+  SWFDEC_AS_CONSTANT_STRING ("attachVideo")
+  SWFDEC_AS_CONSTANT_STRING ("clear")
   /* add more here */
 ;
 
diff --git a/libswfdec/swfdec_js_video.c b/libswfdec/swfdec_js_video.c
index 946ebf7..76d978b 100644
--- a/libswfdec/swfdec_js_video.c
+++ b/libswfdec/swfdec_js_video.c
@@ -23,78 +23,56 @@
 
 #include "swfdec_video.h"
 #include "swfdec_debug.h"
-#include "swfdec_js.h"
 #include "swfdec_net_stream.h"
 #include "swfdec_player_internal.h"
 
-static JSBool
-swfdec_js_video_attach_video (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static void
+swfdec_video_attach_video (SwfdecAsContext *cx, SwfdecAsObject *obj, guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
 {
+  SwfdecVideoMovie *video = SWFDEC_VIDEO_MOVIE (obj);
   SwfdecNetStream *stream;
-  SwfdecVideoMovie *video;
-
-  video = swfdec_scriptable_from_object (cx, obj, SWFDEC_TYPE_VIDEO_MOVIE);
-  if (video == NULL)
-    return JS_TRUE;
 
-  stream = swfdec_scriptable_from_jsval (cx, argv[0], SWFDEC_TYPE_NET_STREAM);
-  if (stream != NULL) {
-    swfdec_video_movie_set_input (video, &stream->input);
-    return JS_TRUE;
+  if (!SWFDEC_AS_VALUE_IS_OBJECT (&argv[0]) ||
+      !SWFDEC_IS_NET_STREAM (stream = (SwfdecNetStream *) SWFDEC_AS_VALUE_GET_OBJECT (&argv[0]))) {
+    SWFDEC_WARNING ("calling attachVideo without a NetStraem object");
+    swfdec_video_movie_set_input (video, NULL);
+    return;
   }
-  swfdec_video_movie_set_input (video, NULL);
-  return JS_TRUE;
-}
-
-static JSBool
-swfdec_js_video_clear (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
-{
-  SwfdecVideoMovie *video;
-
-  video = swfdec_scriptable_from_object (cx, obj, SWFDEC_TYPE_VIDEO_MOVIE);
-  if (video == NULL)
-    return JS_TRUE;
-
-  swfdec_video_movie_clear (video);
-  return JS_TRUE;
+  swfdec_video_movie_set_input (video, &stream->input);
 }
 
-static JSFunctionSpec video_methods[] = {
-  { "attachVideo",    	swfdec_js_video_attach_video,	1, 0, 0 },
-  { "clear",    	swfdec_js_video_clear,		0, 0, 0 },
-  {0,0,0,0,0}
-};
-
 static void
-swfdec_js_video_finalize (JSContext *cx, JSObject *obj)
+swfdec_video_clear (SwfdecAsContext *cx, SwfdecAsObject *obj, guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
 {
-  SwfdecVideo *video;
-
-  video = JS_GetPrivate (cx, obj);
-  if (video) {
-    SWFDEC_SCRIPTABLE (video)->jsobj = NULL;
-    g_object_unref (video);
-  }
-}
+  SwfdecVideoMovie *video = SWFDEC_VIDEO_MOVIE (obj);
 
-const JSClass video_class = {
-    "Video", JSCLASS_HAS_PRIVATE,
-    JS_PropertyStub,  JS_PropertyStub,  JS_PropertyStub,  JS_PropertyStub,
-    JS_EnumerateStub, JS_ResolveStub,   JS_ConvertStub,   swfdec_js_video_finalize,
-    JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-static JSBool
-swfdec_js_video_new (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
-{
-  return JS_TRUE;
+  swfdec_video_movie_clear (video);
 }
 
 void
-swfdec_js_add_video (SwfdecPlayer *player)
+swfdec_video_movie_init_context (SwfdecPlayer *player, guint version)
 {
-  JS_InitClass (player->jscx, player->jsobj, NULL,
-      &video_class, swfdec_js_video_new, 0, NULL, video_methods,
-      NULL, NULL);
+  SwfdecAsContext *context;
+  SwfdecAsObject *video, *proto;
+  SwfdecAsValue val;
+
+  g_return_if_fail (SWFDEC_IS_PLAYER (player));
+
+  context = SWFDEC_AS_CONTEXT (player);
+  video = SWFDEC_AS_OBJECT (swfdec_as_object_add_function (context->global, 
+      SWFDEC_AS_STR_Video, 0, NULL, 0));
+  if (video == NULL)
+    return;
+  proto = swfdec_as_object_new (context);
+  /* set the right properties on the NetStream object */
+  SWFDEC_AS_VALUE_SET_OBJECT (&val, proto);
+  swfdec_as_object_set_variable (video, SWFDEC_AS_STR_prototype, &val);
+  /* set the right properties on the NetStream.prototype object */
+  SWFDEC_AS_VALUE_SET_OBJECT (&val, video);
+  swfdec_as_object_set_variable (proto, SWFDEC_AS_STR_constructor, &val);
+  swfdec_as_object_add_function (proto, SWFDEC_AS_STR_attachMovie, SWFDEC_TYPE_VIDEO_MOVIE,
+      swfdec_video_attach_video, 1);
+  swfdec_as_object_add_function (proto, SWFDEC_AS_STR_clear, SWFDEC_TYPE_VIDEO_MOVIE,
+      swfdec_video_clear, 0);
 }
 
diff-tree cbf5b3fcecd54d80669ffe7325344c3fc3168597 (from 22dd4563d2051791badd70f034e86b6bf75c75ba)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Jun 27 09:28:26 2007 +0200

    rename variable in copy/paste code

diff --git a/libswfdec/swfdec_xml_as.c b/libswfdec/swfdec_xml_as.c
index 846ec69..8be7ae3 100644
--- a/libswfdec/swfdec_xml_as.c
+++ b/libswfdec/swfdec_xml_as.c
@@ -41,23 +41,23 @@ void
 swfdec_xml_init_context (SwfdecPlayer *player, guint version)
 {
   SwfdecAsContext *context;
-  SwfdecAsObject *stream, *proto;
+  SwfdecAsObject *xml, *proto;
   SwfdecAsValue val;
 
   g_return_if_fail (SWFDEC_IS_PLAYER (player));
 
   context = SWFDEC_AS_CONTEXT (player);
-  stream = SWFDEC_AS_OBJECT (swfdec_as_object_add_function (context->global, 
+  xml = SWFDEC_AS_OBJECT (swfdec_as_object_add_function (context->global, 
       SWFDEC_AS_STR_XML, 0, NULL, 0));
-  if (stream == NULL)
+  if (xml == NULL)
     return;
-  swfdec_as_native_function_set_construct_type (SWFDEC_AS_NATIVE_FUNCTION (stream), SWFDEC_TYPE_XML);
+  swfdec_as_native_function_set_construct_type (SWFDEC_AS_NATIVE_FUNCTION (xml), SWFDEC_TYPE_XML);
   proto = swfdec_as_object_new (context);
   /* set the right properties on the NetStream object */
   SWFDEC_AS_VALUE_SET_OBJECT (&val, proto);
-  swfdec_as_object_set_variable (stream, SWFDEC_AS_STR_prototype, &val);
+  swfdec_as_object_set_variable (xml, SWFDEC_AS_STR_prototype, &val);
   /* set the right properties on the NetStream.prototype object */
-  SWFDEC_AS_VALUE_SET_OBJECT (&val, stream);
+  SWFDEC_AS_VALUE_SET_OBJECT (&val, xml);
   swfdec_as_object_set_variable (proto, SWFDEC_AS_STR_constructor, &val);
   swfdec_as_object_add_function (proto, SWFDEC_AS_STR_load, SWFDEC_TYPE_XML,
       swfdec_xml_do_load, 1);
diff-tree 22dd4563d2051791badd70f034e86b6bf75c75ba (from b591bafc9b65bc077928ed19f19a7a7d0f28c552)
Author: Benjamin Otte <otte at gnome.org>
Date:   Wed Jun 27 09:23:18 2007 +0200

    don't name the XML constructor NetStream

diff --git a/libswfdec/swfdec_as_strings.c b/libswfdec/swfdec_as_strings.c
index 051938e..15d0f69 100644
--- a/libswfdec/swfdec_as_strings.c
+++ b/libswfdec/swfdec_as_strings.c
@@ -214,6 +214,7 @@ const char swfdec_as_strings[] = 
   SWFDEC_AS_CONSTANT_STRING ("seek")
   SWFDEC_AS_CONSTANT_STRING ("setBufferTime")
   SWFDEC_AS_CONSTANT_STRING ("load")
+  SWFDEC_AS_CONSTANT_STRING ("XML")
   /* add more here */
 ;
 
diff --git a/libswfdec/swfdec_xml_as.c b/libswfdec/swfdec_xml_as.c
index 9a94732..846ec69 100644
--- a/libswfdec/swfdec_xml_as.c
+++ b/libswfdec/swfdec_xml_as.c
@@ -48,7 +48,7 @@ swfdec_xml_init_context (SwfdecPlayer *p
 
   context = SWFDEC_AS_CONTEXT (player);
   stream = SWFDEC_AS_OBJECT (swfdec_as_object_add_function (context->global, 
-      SWFDEC_AS_STR_NetStream, 0, NULL, 0));
+      SWFDEC_AS_STR_XML, 0, NULL, 0));
   if (stream == NULL)
     return;
   swfdec_as_native_function_set_construct_type (SWFDEC_AS_NATIVE_FUNCTION (stream), SWFDEC_TYPE_XML);
diff-tree b591bafc9b65bc077928ed19f19a7a7d0f28c552 (from f7040e7c3f3b281d8b48cfd9c6095400c6fe05f2)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jun 26 15:24:21 2007 +0200

    remove swfdec_js.[ch]
    
    All its functions should be implemented elsewhere by now

diff --git a/libswfdec/swfdec_js.c b/libswfdec/swfdec_js.c
deleted file mode 100644
index 48e4b2d..0000000
--- a/libswfdec/swfdec_js.c
+++ /dev/null
@@ -1,472 +0,0 @@
-/* Swfdec
- * Copyright (C) 2006 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
- * Boston, MA  02110-1301  USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-#include <string.h>
-#include <js/jsapi.h>
-#include <js/jscntxt.h> /* for setting tracefp when debugging */
-#include <libswfdec/js/jsfun.h>
-#include <js/jsdbgapi.h> /* for debugging */
-#include <js/jsopcode.h> /* for debugging */
-#include <js/jsscript.h> /* for debugging */
-#include "swfdec_types.h"
-#include "swfdec_player_internal.h"
-#include "swfdec_debug.h"
-#include "swfdec_js.h"
-#include "swfdec_listener.h"
-#include "swfdec_root_movie.h"
-#include "swfdec_swf_decoder.h"
-
-static JSRuntime *swfdec_js_runtime;
-
-/**
- * swfdec_js_init:
- * @runtime_size: desired runtime size of the JavaScript runtime or 0 for default
- *
- * Initializes the Javascript part of swfdec. This function must only be called once.
- **/
-void
-swfdec_js_init (guint runtime_size)
-{
-  g_assert (runtime_size < G_MAXUINT32);
-  if (runtime_size == 0)
-    runtime_size = 8 * 1024 * 1024; /* some default size */
-
-  swfdec_js_runtime = JS_NewRuntime (runtime_size);
-  SWFDEC_INFO ("initialized JS runtime with %u bytes", runtime_size);
-}
-
-static void
-swfdec_js_error_report (JSContext *cx, const char *message, JSErrorReport *report)
-{
-  SWFDEC_ERROR ("JS Error: %s", message);
-  /* FIXME: #ifdef this when not debugging the compiler */
-  //g_assert_not_reached ();
-}
-
-static JSClass global_class = {
-  "global",0,
-  JS_PropertyStub,JS_PropertyStub,JS_PropertyStub,JS_PropertyStub,
-  JS_EnumerateStub,JS_ResolveStub,JS_ConvertStub,JS_FinalizeStub
-};
-
-/**
- * swfdec_js_init_player:
- * @player: a #SwfdecPlayer
- *
- * Initializes @player for Javascript processing.
- **/
-void
-swfdec_js_init_player (SwfdecPlayer *player)
-{
-  player->jscx = JS_NewContext (swfdec_js_runtime, 8192);
-  if (player->jscx == NULL) {
-    SWFDEC_ERROR ("did not get a JS context, trying to live without");
-    return;
-  }
-
-  JS_SetErrorReporter (player->jscx, swfdec_js_error_report);
-  JS_SetContextPrivate(player->jscx, player);
-  player->jsobj = JS_NewObject (player->jscx, &global_class, NULL, NULL);
-  if (player->jsobj == NULL) {
-    SWFDEC_ERROR ("creating the global object failed");
-    swfdec_js_finish_player (player);
-    return;
-  }
-  if (!JS_InitStandardClasses (player->jscx, player->jsobj)) {
-    SWFDEC_ERROR ("initializing JS standard classes failed");
-  }
-  swfdec_js_add_globals (player);
-  swfdec_js_add_mouse (player);
-  swfdec_js_add_movieclip_class (player);
-  swfdec_js_add_color (player);
-  swfdec_js_add_sound (player);
-  swfdec_js_add_video (player);
-  swfdec_js_add_xml (player);
-  swfdec_js_add_connection (player);
-  swfdec_js_add_net_stream (player);
-}
-
-typedef struct _SwfdecJSInterval SwfdecJSInterval;
-extern void swfdec_js_interval_free (SwfdecJSInterval *interval);
-/**
- * swfdec_js_finish_player:
- * @player: a #SwfdecPlayer
- *
- * Shuts down the Javascript processing for @player.
- **/
-void
-swfdec_js_finish_player (SwfdecPlayer *player)
-{
-  swfdec_listener_free (player->mouse_listener);
-  swfdec_listener_free (player->key_listener);
-  while (player->intervals)
-    swfdec_js_interval_free (player->intervals->data);
-  if (player->jscx) {
-    JS_DestroyContext(player->jscx);
-    player->jsobj = NULL;
-    player->jscx = NULL;
-  }
-}
-
-/**
- * swfdec_js_execute_script:
- * @s: a @SwfdecPlayer
- * @movie: a #SwfdecMovie to pass as argument to the script
- * @script: a @JSScript to execute
- * @rval: optional location for the script's return value
- *
- * Executes the given @script for the given @movie. This function is supposed
- * to be the single entry point for running JavaScript code inswide swfdec, so
- * if you want to execute code, please use this function.
- *
- * Returns: TRUE if the script was successfully executed
- **/
-gboolean
-swfdec_js_execute_script (SwfdecPlayer *s, SwfdecMovie *movie, 
-    JSScript *script, jsval *rval)
-{
-  jsval returnval = JSVAL_VOID;
-  JSObject *jsobj;
-  JSBool ret;
-
-  g_return_val_if_fail (s != NULL, FALSE);
-  g_return_val_if_fail (SWFDEC_IS_MOVIE (movie), FALSE);
-  g_return_val_if_fail (script != NULL, FALSE);
-
-  if (rval == NULL)
-    rval = &returnval;
-  if (!(jsobj = swfdec_scriptable_get_object (SWFDEC_SCRIPTABLE (movie))))
-    return FALSE;
-  ret = JS_ExecuteScript (s->jscx, jsobj, script, rval);
-  if (!ret) {
-    SWFDEC_WARNING ("executing script %p for movie %s failed", script, movie->name);
-  }
-
-  if (ret && returnval != JSVAL_VOID) {
-    JSString * str = JS_ValueToString (s->jscx, returnval);
-    if (str)
-      g_print ("%s\n", JS_GetStringBytes (str));
-  }
-  return ret ? TRUE : FALSE;
-}
-
-/**
- * swfdec_js_run:
- * @player: a #SwfdecPlayer
- * @s: JavaScript commands to execute
- * @rval: optional location to store a return value
- *
- * This is a debugging function for injecting script code into the @player.
- * Use it at your own risk.
- *
- * Returns: TRUE if the script was evaluated successfully. 
- **/
-gboolean
-swfdec_js_run (SwfdecPlayer *player, const char *s, jsval *rval)
-{
-  gboolean ret;
-  JSScript *script;
-  
-  g_return_val_if_fail (player != NULL, FALSE);
-  g_return_val_if_fail (s != NULL, FALSE);
-
-  script = JS_CompileScript (player->jscx, player->jsobj, s, strlen (s), "injected-code", 1);
-  if (script == NULL)
-    return FALSE;
-  ret = swfdec_js_execute_script (player, 
-      SWFDEC_MOVIE (player->movies->data), script, rval);
-  JS_DestroyScript (player->jscx, script);
-  return ret;
-}
-
-/**
- * swfdec_value_to_string:
- * @dec: a #JSContext
- * @val: a #jsval
- *
- * Converts the given jsval to its string representation.
- *
- * Returns: the string representation of @val.
- **/
-const char *
-swfdec_js_to_string (JSContext *cx, jsval val)
-{
-  JSString *string;
-  char *ret;
-
-  g_return_val_if_fail (cx != NULL, NULL);
-
-  string = JS_ValueToString (cx, val);
-  if (string == NULL || (ret = JS_GetStringBytes (string)) == NULL)
-    return NULL;
-
-  return ret;
-}
-
-/**
- * swfdec_js_slash_to_dot:
- * @slash_str: a string ion slash notation
- *
- * Converts a string in slash notation to a string in dot notation.
- *
- * Returns: The string converted to dot notation or NULL on failure.
- **/
-char *
-swfdec_js_slash_to_dot (const char *slash_str)
-{
-  const char *cur = slash_str;
-  GString *str = g_string_new ("");
-
-  if (*cur == '/') {
-    g_string_append (str, "_root");
-    if (cur[1] == ':')
-      cur++;
-  } else {
-    goto start;
-  }
-  while (cur && (*cur == '/' || *cur == ':')) {
-    cur++;
-start:
-    if (str->len > 0)
-      g_string_append_c (str, '.');
-    if (cur[0] == '.' && cur[1] == '.') {
-      g_string_append (str, "_parent");
-      cur += 2;
-    } else {
-      char *slash = strchr (cur, '/');
-      if (slash) {
-	g_string_append_len (str, cur, slash - cur);
-	cur = slash;
-      } else {
-	slash = strchr (cur, ':');
-	if (slash) {
-	  g_string_append_len (str, cur, slash - cur);
-	  cur = slash;
-	} else {
-	  g_string_append (str, cur);
-	  cur = NULL;
-	}
-      }
-    }
-    /* cur should now point to the slash */
-  }
-  if (cur) {
-    if (*cur != '\0')
-      goto fail;
-  }
-  SWFDEC_DEBUG ("parsed slash-notated string \"%s\" into dot notation \"%s\"",
-      slash_str, str->str);
-  return g_string_free (str, FALSE);
-
-fail:
-  SWFDEC_WARNING ("failed to parse slash-notated string \"%s\" into dot notation", slash_str);
-  g_string_free (str, TRUE);
-  return NULL;
-}
-
-static JSBool
-swfdec_js_eval_get_property (JSContext *cx, JSObject *obj, 
-    const char *name, guint name_len, jsval *ret)
-{
-  JSAtom *atom;
-  JSObject *pobj;
-  JSProperty *prop;
-
-  atom = js_Atomize (cx, name, name_len, 0);
-  if (!atom)
-    return JS_FALSE;
-  if (obj) {
-    return OBJ_GET_PROPERTY (cx, obj, (jsid) atom, ret);
-  } else {
-    if (cx->fp == NULL || cx->fp->scopeChain == NULL)
-      return JS_FALSE;
-    if (!js_FindProperty (cx, (jsid) atom, &obj, &pobj, &prop))
-      return JS_FALSE;
-    if (!prop)
-      return JS_FALSE;
-    return OBJ_GET_PROPERTY (cx, obj, (jsid) prop->id, ret);
-  }
-}
-
-static JSBool
-swfdec_js_eval_set_property (JSContext *cx, JSObject *obj, 
-    const char *name, guint name_len, jsval *ret)
-{
-  JSAtom *atom;
-
-  atom = js_Atomize (cx, name, name_len, 0);
-  if (!atom)
-    return JS_FALSE;
-  if (obj == NULL) {
-    JSObject *pobj;
-    JSProperty *prop;
-    if (cx->fp == NULL || cx->fp->varobj == NULL)
-      return JS_FALSE;
-    if (!js_FindProperty (cx, (jsid) atom, &obj, &pobj, &prop))
-      return JS_FALSE;
-    if (pobj)
-      obj = pobj;
-    else
-      obj = cx->fp->varobj;
-  }
-  return OBJ_SET_PROPERTY (cx, obj, (jsid) atom, ret);
-}
-
-static gboolean
-swfdec_js_eval_internal (JSContext *cx, JSObject *obj, const char *str,
-        jsval *val, gboolean set)
-{
-  jsval cur;
-  char *work = NULL;
-
-  SWFDEC_LOG ("eval called with \"%s\" on %p", str, obj);
-  if (strchr (str, '/')) {
-    work = swfdec_js_slash_to_dot (str);
-    str = work;
-  }
-  if (obj == NULL && g_str_has_prefix (str, "this")) {
-    str += 4;
-    if (*str == '.')
-      str++;
-    if (cx->fp == NULL)
-      goto out;
-    obj = cx->fp->thisp;
-  }
-  cur = OBJECT_TO_JSVAL (obj);
-  while (str != NULL && *str != '\0') {
-    char *dot = strchr (str, '.');
-    if (!JSVAL_IS_OBJECT (cur))
-      goto out;
-    if (dot) {
-      if (!swfdec_js_eval_get_property (cx, obj, str, dot - str, &cur))
-	goto out;
-      str = dot + 1;
-    } else {
-      if (set) {
-	if (!swfdec_js_eval_set_property (cx, obj, str, strlen (str), val))
-	  goto out;
-      } else {
-	if (!swfdec_js_eval_get_property (cx, obj, str, strlen (str), &cur))
-	  goto out;
-      }
-      goto finish;
-    }
-    obj = JSVAL_TO_OBJECT (cur);
-  }
-  if (obj == NULL) {
-    if (cx->fp == NULL)
-      goto out;
-    g_assert (cx->fp->thisp);
-    cur = OBJECT_TO_JSVAL (cx->fp->thisp);
-  }
-
-finish:
-  g_free (work);
-  *val = cur;
-  return TRUE;
-out:
-  SWFDEC_DEBUG ("error: returning void for %s", str);
-  g_free (work);
-  return FALSE;
-}
-
-/**
- * swfdec_js_eval:
- * @cx: a #JSContext
- * @obj: #JSObject to use as a source for evaluating
- * @str: The string to evaluate
- *
- * This function works like the Actionscript eval function used on @obj.
- * It handles both slash-style and dot-style notation.
- *
- * Returns: the value or JSVAL_VOID if no value was found.
- **/
-jsval
-swfdec_js_eval (JSContext *cx, JSObject *obj, const char *str)
-{
-  jsval ret;
-
-  g_return_val_if_fail (cx != NULL, JSVAL_VOID);
-  g_return_val_if_fail (str != NULL, JSVAL_VOID);
-
-  if (!swfdec_js_eval_internal (cx, obj, str, &ret, FALSE))
-    ret = JSVAL_VOID;
-  return ret;
-}
-
-void
-swfdec_js_eval_set (JSContext *cx, JSObject *obj, const char *str,
-    jsval val)
-{
-  g_return_if_fail (cx != NULL);
-  g_return_if_fail (str != NULL);
-
-  swfdec_js_eval_internal (cx, obj, str, &val, TRUE);
-}
-
-/**
- * swfdec_js_construct_object:
- * @cx: the #JSContext
- * @clasp: class to use for constructing the object
- * @constructor: a jsval possibly referring to a constructor
- * @newp: pointer to variable that will take the created object or NULL on 
- *        failure
- *
- * Constructs a JSObject for the given @constructor, if it really is a
- * constructor. 
- * <note>The object is only constructed, the constructor is not called.
- * You can easily do this with JS_Invoke() later.</note>
- *
- * Returns: %JS_TRUE on success or %JS_FALSE on OOM.
- **/
-JSBool
-swfdec_js_construct_object (JSContext *cx, const JSClass *clasp, 
-    jsval constructor, JSObject **newp)
-{
-  JSObject *object;
-  jsval proto;
-
-  g_return_val_if_fail (newp != NULL, JS_FALSE);
-
-  if (!JSVAL_IS_OBJECT (constructor) || constructor == JSVAL_VOID)
-    goto fail;
-  object = JSVAL_TO_OBJECT (constructor);
-  if (JS_GetClass (object) != &js_FunctionClass)
-    goto fail;
-  if (clasp == NULL)
-    clasp = ((JSFunction *) JS_GetPrivate (cx, object))->clasp;
-  if (!JS_GetProperty (cx, object, "prototype", &proto))
-    return JS_FALSE;
-  if (!JSVAL_IS_OBJECT (proto)) {
-    SWFDEC_ERROR ("prototype is not an object");
-  }
-  object = JS_NewObject (cx, clasp, JSVAL_IS_OBJECT (proto) ? JSVAL_TO_OBJECT (proto) : NULL, NULL);
-  if (object == NULL)
-    return JS_FALSE;
-
-  *newp = object;
-  return JS_TRUE;
-
-fail:
-  *newp = NULL;
-  return JS_TRUE;
-}
diff --git a/libswfdec/swfdec_js.h b/libswfdec/swfdec_js.h
deleted file mode 100644
index 303a90e..0000000
--- a/libswfdec/swfdec_js.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/* Swfdec
- * Copyright (C) 2006 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
- * Boston, MA  02110-1301  USA
- */
-
-#ifndef __SWFDEC_JS_H__
-#define __SWFDEC_JS_H__
-
-#include <libswfdec/swfdec_player.h>
-#include <libswfdec/swfdec_movie.h>
-#include <libswfdec/js/jsapi.h>
-
-G_BEGIN_DECLS
-
-void		swfdec_js_init			(guint			runtime_size);
-void		swfdec_js_init_player		(SwfdecPlayer *		player);
-void		swfdec_js_finish_player		(SwfdecPlayer *		player);
-gboolean	swfdec_js_execute_script	(SwfdecPlayer *		player,
-						 SwfdecMovie *		movie, 
-						 JSScript *		script,
-						 jsval *		rval);
-gboolean	swfdec_js_run			(SwfdecPlayer *		player,
-						 const char *		s,
-						 jsval *		rval);
-
-void		swfdec_js_add_color		(SwfdecPlayer *		player);
-void		swfdec_js_add_connection	(SwfdecPlayer *		player);
-void		swfdec_js_add_globals		(SwfdecPlayer *		player);
-void		swfdec_js_add_mouse		(SwfdecPlayer *		player);
-void		swfdec_js_add_movieclip_class	(SwfdecPlayer *		player);
-void		swfdec_js_add_net_stream	(SwfdecPlayer *		player);
-void		swfdec_js_add_sound		(SwfdecPlayer *		player);
-void		swfdec_js_add_video		(SwfdecPlayer *		player);
-void		swfdec_js_add_xml		(SwfdecPlayer *		player);
-
-void		swfdec_js_movie_create_jsobject	(SwfdecMovie *		movie);
-void		swfdec_js_movie_remove_jsobject	(SwfdecMovie *		movie);
-
-char *		swfdec_js_slash_to_dot		(const char *		slash_str);
-jsval		swfdec_js_eval			(JSContext *		cx,
-						 JSObject *		obj,
-						 const char *		str);
-void		swfdec_js_eval_set    		(JSContext *		cx,
-						 JSObject *		obj,
-						 const char *		str,
-						 jsval			val);
-
-JSBool		swfdec_js_construct_object	(JSContext *		cx,
-						 const JSClass *	clasp,
-						 jsval			constructor,
-						 JSObject **		newp);
-/* support functions */
-const char *	swfdec_js_to_string		(JSContext *		cx,
-						 jsval			val);
-gboolean	swfdec_js_is_movieclip		(JSContext *		cx,
-						 JSObject *		object);
-
-G_END_DECLS
-
-#endif
diff-tree f7040e7c3f3b281d8b48cfd9c6095400c6fe05f2 (from 2a8e3259bd677201c7381d416e7d4fd0c6cfa34e)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jun 26 15:23:36 2007 +0200

    remove old (and useless) file

diff --git a/libswfdec/swfdec_js_sound.c b/libswfdec/swfdec_js_sound.c
deleted file mode 100644
index b9f8d57..0000000
--- a/libswfdec/swfdec_js_sound.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/* Swfdec
- * Copyright (C) 2006 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
- * Boston, MA  02110-1301  USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "swfdec_js.h"
-#include "swfdec_debug.h"
-#include "swfdec_movie.h"
-#include "swfdec_player_internal.h"
-
-static JSBool
-not_implemented (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
-{
-  SWFDEC_WARNING ("FIXME: implement this sound function");
-  return JS_TRUE;
-}
-
-static JSFunctionSpec sound_methods[] = {
-  { "attachSound",	  	not_implemented,	1, 0, 0 },
-  { "getPan",		  	not_implemented,	0, 0, 0 },
-  { "getTransform",	  	not_implemented,	0, 0, 0 },
-  { "getVolume",	  	not_implemented,	0, 0, 0 },
-  { "setPan",		  	not_implemented,	1, 0, 0 },
-  { "setTransform",	  	not_implemented,	1, 0, 0 },
-  { "setVolume",	  	not_implemented,	1, 0, 0 },
-  { "start",		  	not_implemented,	0, 0, 0 },
-  { "stop",		  	not_implemented,	0, 0, 0 },
-  {0,0,0,0,0}
-};
-
-static void
-swfdec_js_sound_finalize (JSContext *cx, JSObject *obj)
-{
-}
-
-static JSClass sound_class = {
-    "Sound", JSCLASS_HAS_PRIVATE,
-    JS_PropertyStub,  JS_PropertyStub,  JS_PropertyStub,  JS_PropertyStub,
-    JS_EnumerateStub, JS_ResolveStub,   JS_ConvertStub,   swfdec_js_sound_finalize,
-    JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-static JSBool
-swfdec_js_sound_new (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
-{
-  *rval = OBJECT_TO_JSVAL (obj);
-  return JS_TRUE;
-}
-
-void
-swfdec_js_add_sound (SwfdecPlayer *player)
-{
-  JS_InitClass (player->jscx, player->jsobj, NULL,
-      &sound_class, swfdec_js_sound_new, 1, NULL, sound_methods,
-      NULL, NULL);
-}
-
diff-tree 2a8e3259bd677201c7381d416e7d4fd0c6cfa34e (from 476ce50c3895f9d136f726ee87e714c5db1db1d3)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jun 26 15:22:04 2007 +0200

    rename swfdec_js_xml.c -> swfdec_xml_as.c

diff --git a/libswfdec/Makefile.am b/libswfdec/Makefile.am
index 87adb81..f944d94 100644
--- a/libswfdec/Makefile.am
+++ b/libswfdec/Makefile.am
@@ -78,7 +78,6 @@ libswfdec_ at SWFDEC_MAJORMINOR@_la_SOURCES
 	swfdec_html_parser.c \
 	swfdec_image.c \
 	swfdec_interval.c \
-	swfdec_js_xml.c \
 	swfdec_listener.c \
 	swfdec_loader.c \
 	swfdec_loadertarget.c \
@@ -110,7 +109,8 @@ libswfdec_ at SWFDEC_MAJORMINOR@_la_SOURCES
 	swfdec_utils.c \
 	swfdec_video.c \
 	swfdec_video_movie.c \
-	swfdec_xml.c
+	swfdec_xml.c \
+	swfdec_xml_as.c
 
 libswfdec_ at SWFDEC_MAJORMINOR@_la_CFLAGS = \
 	$(GLOBAL_CFLAGS) $(CAIRO_CFLAGS) $(GLIB_CFLAGS) $(PANGO_CFLAGS) \
diff --git a/libswfdec/swfdec_js_xml.c b/libswfdec/swfdec_js_xml.c
deleted file mode 100644
index 9a94732..0000000
--- a/libswfdec/swfdec_js_xml.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/* Swfdec
- * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
- * Boston, MA  02110-1301  USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "swfdec_xml.h"
-#include "swfdec_as_native_function.h"
-#include "swfdec_as_object.h"
-#include "swfdec_debug.h"
-#include "swfdec_player_internal.h"
-
-static void
-swfdec_xml_do_load (SwfdecAsContext *cx, SwfdecAsObject *obj, guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
-{
-  SwfdecXml *xml = SWFDEC_XML (obj);
-  const char *url;
-
-  url = swfdec_as_value_to_string (cx, &argv[0]);
-  swfdec_xml_load (xml, url);
-}
-
-void
-swfdec_xml_init_context (SwfdecPlayer *player, guint version)
-{
-  SwfdecAsContext *context;
-  SwfdecAsObject *stream, *proto;
-  SwfdecAsValue val;
-
-  g_return_if_fail (SWFDEC_IS_PLAYER (player));
-
-  context = SWFDEC_AS_CONTEXT (player);
-  stream = SWFDEC_AS_OBJECT (swfdec_as_object_add_function (context->global, 
-      SWFDEC_AS_STR_NetStream, 0, NULL, 0));
-  if (stream == NULL)
-    return;
-  swfdec_as_native_function_set_construct_type (SWFDEC_AS_NATIVE_FUNCTION (stream), SWFDEC_TYPE_XML);
-  proto = swfdec_as_object_new (context);
-  /* set the right properties on the NetStream object */
-  SWFDEC_AS_VALUE_SET_OBJECT (&val, proto);
-  swfdec_as_object_set_variable (stream, SWFDEC_AS_STR_prototype, &val);
-  /* set the right properties on the NetStream.prototype object */
-  SWFDEC_AS_VALUE_SET_OBJECT (&val, stream);
-  swfdec_as_object_set_variable (proto, SWFDEC_AS_STR_constructor, &val);
-  swfdec_as_object_add_function (proto, SWFDEC_AS_STR_load, SWFDEC_TYPE_XML,
-      swfdec_xml_do_load, 1);
-}
-
diff --git a/libswfdec/swfdec_xml_as.c b/libswfdec/swfdec_xml_as.c
new file mode 100644
index 0000000..9a94732
--- /dev/null
+++ b/libswfdec/swfdec_xml_as.c
@@ -0,0 +1,65 @@
+/* Swfdec
+ * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ * Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "swfdec_xml.h"
+#include "swfdec_as_native_function.h"
+#include "swfdec_as_object.h"
+#include "swfdec_debug.h"
+#include "swfdec_player_internal.h"
+
+static void
+swfdec_xml_do_load (SwfdecAsContext *cx, SwfdecAsObject *obj, guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
+{
+  SwfdecXml *xml = SWFDEC_XML (obj);
+  const char *url;
+
+  url = swfdec_as_value_to_string (cx, &argv[0]);
+  swfdec_xml_load (xml, url);
+}
+
+void
+swfdec_xml_init_context (SwfdecPlayer *player, guint version)
+{
+  SwfdecAsContext *context;
+  SwfdecAsObject *stream, *proto;
+  SwfdecAsValue val;
+
+  g_return_if_fail (SWFDEC_IS_PLAYER (player));
+
+  context = SWFDEC_AS_CONTEXT (player);
+  stream = SWFDEC_AS_OBJECT (swfdec_as_object_add_function (context->global, 
+      SWFDEC_AS_STR_NetStream, 0, NULL, 0));
+  if (stream == NULL)
+    return;
+  swfdec_as_native_function_set_construct_type (SWFDEC_AS_NATIVE_FUNCTION (stream), SWFDEC_TYPE_XML);
+  proto = swfdec_as_object_new (context);
+  /* set the right properties on the NetStream object */
+  SWFDEC_AS_VALUE_SET_OBJECT (&val, proto);
+  swfdec_as_object_set_variable (stream, SWFDEC_AS_STR_prototype, &val);
+  /* set the right properties on the NetStream.prototype object */
+  SWFDEC_AS_VALUE_SET_OBJECT (&val, stream);
+  swfdec_as_object_set_variable (proto, SWFDEC_AS_STR_constructor, &val);
+  swfdec_as_object_add_function (proto, SWFDEC_AS_STR_load, SWFDEC_TYPE_XML,
+      swfdec_xml_do_load, 1);
+}
+
diff-tree 476ce50c3895f9d136f726ee87e714c5db1db1d3 (from 9b643ffc75f78d2efd849c431e009255605fedca)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jun 26 15:21:08 2007 +0200

    hook up (almost useless) XML object again

diff --git a/libswfdec/Makefile.am b/libswfdec/Makefile.am
index a28e906..87adb81 100644
--- a/libswfdec/Makefile.am
+++ b/libswfdec/Makefile.am
@@ -25,8 +25,7 @@ foofiles = \
 	swfdec_js_mouse.c \
 	swfdec_js_movie.c \
 	swfdec_js_sound.c \
-	swfdec_js_video.c \
-	swfdec_js_xml.c
+	swfdec_js_video.c
 
 libswfdec_ at SWFDEC_MAJORMINOR@_la_SOURCES = \
 	swfdec_as_array.c \
@@ -79,6 +78,7 @@ libswfdec_ at SWFDEC_MAJORMINOR@_la_SOURCES
 	swfdec_html_parser.c \
 	swfdec_image.c \
 	swfdec_interval.c \
+	swfdec_js_xml.c \
 	swfdec_listener.c \
 	swfdec_loader.c \
 	swfdec_loadertarget.c \
diff --git a/libswfdec/swfdec_as_strings.c b/libswfdec/swfdec_as_strings.c
index 326b858..051938e 100644
--- a/libswfdec/swfdec_as_strings.c
+++ b/libswfdec/swfdec_as_strings.c
@@ -213,6 +213,7 @@ const char swfdec_as_strings[] = 
   SWFDEC_AS_CONSTANT_STRING ("pause")
   SWFDEC_AS_CONSTANT_STRING ("seek")
   SWFDEC_AS_CONSTANT_STRING ("setBufferTime")
+  SWFDEC_AS_CONSTANT_STRING ("load")
   /* add more here */
 ;
 
diff --git a/libswfdec/swfdec_js_xml.c b/libswfdec/swfdec_js_xml.c
index 92da66e..9a94732 100644
--- a/libswfdec/swfdec_js_xml.c
+++ b/libswfdec/swfdec_js_xml.c
@@ -22,66 +22,44 @@
 #endif
 
 #include "swfdec_xml.h"
+#include "swfdec_as_native_function.h"
+#include "swfdec_as_object.h"
 #include "swfdec_debug.h"
-#include "swfdec_js.h"
 #include "swfdec_player_internal.h"
 
-static JSBool
-swfdec_js_xml_load (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+static void
+swfdec_xml_do_load (SwfdecAsContext *cx, SwfdecAsObject *obj, guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
 {
-  SwfdecXml *xml;
+  SwfdecXml *xml = SWFDEC_XML (obj);
   const char *url;
 
-  xml = swfdec_scriptable_from_object (cx, obj, SWFDEC_TYPE_XML);
-  if (xml == NULL)
-    return JS_TRUE;
-  url = swfdec_js_to_string (cx, argv[0]);
-  if (url == NULL)
-    return JS_FALSE;
+  url = swfdec_as_value_to_string (cx, &argv[0]);
   swfdec_xml_load (xml, url);
-  return JS_TRUE;
-}
-
-static JSFunctionSpec xml_methods[] = {
-  { "load",		swfdec_js_xml_load,		1, 0, 0 },
-  {0,0,0,0,0}
-};
-
-static void
-swfdec_js_xml_finalize (JSContext *cx, JSObject *obj)
-{
-  SwfdecXml *conn;
-
-  conn = JS_GetPrivate (cx, obj);
-  if (conn) {
-    SWFDEC_SCRIPTABLE (conn)->jsobj = NULL;
-    g_object_unref (conn);
-  }
-}
-
-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,
-    JSCLASS_NO_OPTIONAL_MEMBERS
-};
-
-static JSBool
-swfdec_js_xml_new (JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
-{
-  SwfdecXml *xml = swfdec_xml_new (JS_GetContextPrivate (cx));
-
-  JS_SetPrivate (cx, obj, xml);
-  SWFDEC_SCRIPTABLE (xml)->jsobj = obj;
-  *rval = OBJECT_TO_JSVAL (obj);
-  return JS_TRUE;
 }
 
 void
-swfdec_js_add_xml (SwfdecPlayer *player)
+swfdec_xml_init_context (SwfdecPlayer *player, guint version)
 {
-  JS_InitClass (player->jscx, player->jsobj, NULL,
-      &xml_class, swfdec_js_xml_new, 0, NULL, xml_methods,
-      NULL, NULL);
+  SwfdecAsContext *context;
+  SwfdecAsObject *stream, *proto;
+  SwfdecAsValue val;
+
+  g_return_if_fail (SWFDEC_IS_PLAYER (player));
+
+  context = SWFDEC_AS_CONTEXT (player);
+  stream = SWFDEC_AS_OBJECT (swfdec_as_object_add_function (context->global, 
+      SWFDEC_AS_STR_NetStream, 0, NULL, 0));
+  if (stream == NULL)
+    return;
+  swfdec_as_native_function_set_construct_type (SWFDEC_AS_NATIVE_FUNCTION (stream), SWFDEC_TYPE_XML);
+  proto = swfdec_as_object_new (context);
+  /* set the right properties on the NetStream object */
+  SWFDEC_AS_VALUE_SET_OBJECT (&val, proto);
+  swfdec_as_object_set_variable (stream, SWFDEC_AS_STR_prototype, &val);
+  /* set the right properties on the NetStream.prototype object */
+  SWFDEC_AS_VALUE_SET_OBJECT (&val, stream);
+  swfdec_as_object_set_variable (proto, SWFDEC_AS_STR_constructor, &val);
+  swfdec_as_object_add_function (proto, SWFDEC_AS_STR_load, SWFDEC_TYPE_XML,
+      swfdec_xml_do_load, 1);
 }
 
diff --git a/libswfdec/swfdec_player.c b/libswfdec/swfdec_player.c
index a83a5e1..aa7de2f 100644
--- a/libswfdec/swfdec_player.c
+++ b/libswfdec/swfdec_player.c
@@ -1070,6 +1070,7 @@ extern void swfdec_movie_color_init_cont
 extern void swfdec_net_connection_init_context (SwfdecPlayer *player, guint version);
 extern void swfdec_net_stream_init_context (SwfdecPlayer *player, guint version);
 extern void swfdec_sprite_movie_init_context (SwfdecPlayer *player, guint version);
+extern void swfdec_xml_init_context (SwfdecPlayer *player, guint version);
 /**
  * swfdec_player_initialize:
  * @player: a #SwfdecPlayer
@@ -1104,6 +1105,7 @@ swfdec_player_initialize (SwfdecPlayer *
     swfdec_movie_color_init_context (player, version);
     swfdec_net_connection_init_context (player, version);
     swfdec_net_stream_init_context (player, version);
+    swfdec_xml_init_context (player, version);
     if (context->state == SWFDEC_AS_CONTEXT_NEW) {
       context->state = SWFDEC_AS_CONTEXT_RUNNING;
       swfdec_as_object_set_constructor (player->roots->data, player->MovieClip, FALSE);
diff-tree 9b643ffc75f78d2efd849c431e009255605fedca (from 22f8918b633320b23bcdca9eef19627674de174a)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jun 26 15:10:35 2007 +0200

    simplify old target handling code

diff --git a/libswfdec/swfdec_as_frame.c b/libswfdec/swfdec_as_frame.c
index e503c7c..c8013a4 100644
--- a/libswfdec/swfdec_as_frame.c
+++ b/libswfdec/swfdec_as_frame.c
@@ -214,15 +214,9 @@ swfdec_as_frame_find_variable (SwfdecAsF
   }
   g_assert (SWFDEC_IS_AS_FRAME (cur));
   /* we've walked the scope chain down. Now look in the special objects. */
-  /* 1) the target set via SetTarget */
-  if (frame->target) {
-    if (swfdec_as_object_get_variable (frame->target, variable, &val))
-      return frame->target;
-  } else {
-    /* The default target is the original object that called into us */
-    if (swfdec_as_object_get_variable (SWFDEC_AS_FRAME (cur)->thisp, variable, &val))
-      return SWFDEC_AS_FRAME (cur)->thisp;
-  }
+  /* 1) the target */
+  if (swfdec_as_object_get_variable (frame->target, variable, &val))
+    return frame->target;
   /* 2) the global object */
   if (swfdec_as_object_get_variable (SWFDEC_AS_OBJECT (frame)->context->global, variable, &val))
     return SWFDEC_AS_OBJECT (frame)->context->global;
@@ -255,14 +249,8 @@ swfdec_as_frame_delete_variable (SwfdecA
   g_assert (SWFDEC_IS_AS_FRAME (cur));
   /* we've walked the scope chain down. Now look in the special objects. */
   /* 1) the target set via SetTarget */
-  if (frame->target) {
-    if (swfdec_as_object_delete_variable (frame->target, variable))
-      return TRUE;
-  } else {
-    /* The default target is the original object that called into us */
-    if (swfdec_as_object_delete_variable (SWFDEC_AS_FRAME (cur)->thisp, variable))
-      return TRUE;
-  }
+  if (swfdec_as_object_delete_variable (frame->target, variable))
+    return TRUE;
   /* 2) the global object */
   return swfdec_as_object_delete_variable (SWFDEC_AS_OBJECT (frame)->context->global, variable);
 }
diff-tree 22f8918b633320b23bcdca9eef19627674de174a (from dc96e46427dd1426221899de210486dbd315cc29)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jun 26 15:08:49 2007 +0200

    fix setting undefined variables
    
    This includes a rework of the target management. Every frame now contains
    a ->target member that is always set to the current target. It also has an
    ->original_target member that remembers the original target, so a SetTarget
    call can correctly reset it.
    The previous notion of ->var_object has been removed.
    
    An ->is_local property has been added. This porperty is used during
    DefineLocal actions to decide wether to set proeprties on the current frame
    or on the target. (FIXME: needs checking that those variables really are set on
    the target)

diff --git a/libswfdec/swfdec_as_context.c b/libswfdec/swfdec_as_context.c
index 4394198..8e06f31 100644
--- a/libswfdec/swfdec_as_context.c
+++ b/libswfdec/swfdec_as_context.c
@@ -474,6 +474,7 @@ start:
     goto start;
   }
   g_assert (frame->script);
+  g_assert (frame->target);
   script = frame->script;
   stack = frame->stack;
   version = SWFDEC_AS_EXTRACT_SCRIPT_VERSION (script->version);
@@ -677,7 +678,7 @@ swfdec_as_context_eval_set_property (Swf
     }
     obj = swfdec_as_frame_find_variable (cx->frame, name);
     if (obj == NULL || obj == cx->global)
-      obj = cx->frame->var_object;
+      obj = cx->frame->target;
   }
   swfdec_as_object_set_variable (obj, name, ret);
 }
diff --git a/libswfdec/swfdec_as_frame.c b/libswfdec/swfdec_as_frame.c
index 1664161..e503c7c 100644
--- a/libswfdec/swfdec_as_frame.c
+++ b/libswfdec/swfdec_as_frame.c
@@ -66,13 +66,10 @@ swfdec_as_frame_mark (SwfdecAsObject *ob
     swfdec_as_object_mark (SWFDEC_AS_OBJECT (frame->next));
   if (frame->scope)
     swfdec_as_object_mark (SWFDEC_AS_OBJECT (frame->scope));
-  if (frame->script) {
-    swfdec_as_object_mark (frame->var_object);
-  }
   if (frame->thisp)
     swfdec_as_object_mark (frame->thisp);
-  if (frame->target)
-    swfdec_as_object_mark (frame->target);
+  swfdec_as_object_mark (frame->target);
+  swfdec_as_object_mark (frame->original_target);
   if (frame->function)
     swfdec_as_object_mark (SWFDEC_AS_OBJECT (frame->function));
   for (i = 0; i < frame->n_registers; i++) {
@@ -124,8 +121,6 @@ swfdec_as_frame_new (SwfdecAsContext *co
   frame->pc = script->buffer->data;
   frame->stack = stack;
   frame->scope = SWFDEC_AS_SCOPE (frame);
-  if (frame->next)
-    frame->var_object = frame->next->var_object;
   frame->n_registers = script->n_registers;
   frame->registers = g_slice_alloc0 (sizeof (SwfdecAsValue) * frame->n_registers);
   if (script->constant_pool) {
@@ -176,8 +171,10 @@ swfdec_as_frame_set_this (SwfdecAsFrame 
   g_return_if_fail (SWFDEC_IS_AS_OBJECT (thisp));
 
   frame->thisp = thisp;
-  if (frame->var_object == NULL)
-    frame->var_object = thisp;
+  if (frame->target == NULL) {
+    frame->target = thisp;
+    frame->original_target = thisp;
+  }
 }
 
 /**
@@ -285,7 +282,11 @@ swfdec_as_frame_set_target (SwfdecAsFram
   g_return_if_fail (SWFDEC_IS_AS_FRAME (frame));
   g_return_if_fail (target == NULL || SWFDEC_IS_AS_OBJECT (target));
 
-  frame->target = target;
+  if (target) {
+    frame->target = target;
+  } else {
+    frame->target = frame->original_target;
+  }
 }
 
 void
diff --git a/libswfdec/swfdec_as_frame.h b/libswfdec/swfdec_as_frame.h
index a790e47..1473fa4 100644
--- a/libswfdec/swfdec_as_frame.h
+++ b/libswfdec/swfdec_as_frame.h
@@ -47,11 +47,12 @@ struct _SwfdecAsFrame {
   const SwfdecAsValue *	argv;		/* arguments */
   /* debugging */
   char *		function_name;	/* name of function */
-  /* normal execution */
+  /* script execution */
   SwfdecScript *	script;		/* script being executed */
   SwfdecAsScope *	scope;		/* first object in scope chain (either this frame or a with object) */
-  SwfdecAsObject *	target;		/* target to use instead of last object in scope chain */
-  SwfdecAsObject *	var_object;	/* new variables go here */
+  SwfdecAsObject *	target;		/* target to use as last object in scope chain or for SetVariable */
+  SwfdecAsObject *	original_target;/* original target (used when resetting target) */
+  gboolean		is_local;	/* TRUE if this frame takes local variables */
   SwfdecAsValue *	registers;	/* the registers */
   guint			n_registers;	/* number of allocated registers */
   SwfdecConstantPool *	constant_pool;	/* constant pool currently in use */
diff --git a/libswfdec/swfdec_as_function.c b/libswfdec/swfdec_as_function.c
index 1f3bc2f..aee6b90 100644
--- a/libswfdec/swfdec_as_function.c
+++ b/libswfdec/swfdec_as_function.c
@@ -89,7 +89,7 @@ swfdec_as_function_call (SwfdecAsFunctio
     return;
   if (thisp)
     swfdec_as_frame_set_this (frame, thisp);
-  frame->var_object = SWFDEC_AS_OBJECT (frame);
+  frame->is_local = TRUE;
   frame->argc = n_args;
   frame->argv = args;
   frame->return_value = return_value;
diff --git a/libswfdec/swfdec_as_interpret.c b/libswfdec/swfdec_as_interpret.c
index 7fc4ae6..288c47d 100644
--- a/libswfdec/swfdec_as_interpret.c
+++ b/libswfdec/swfdec_as_interpret.c
@@ -50,33 +50,13 @@
 #define swfdec_action_has_register(cx, i) \
   ((i) < (cx)->frame->n_registers)
 
-static SwfdecMovie *
-swfdec_action_get_target (SwfdecAsContext *context)
-{
-  SwfdecAsObject *target = context->frame->target;
-
-  if (target == NULL) {
-    SwfdecAsScope *scope = context->frame->scope;
-    while (scope->next)
-      scope = scope->next;
-    g_assert (SWFDEC_IS_AS_FRAME (scope));
-    target = SWFDEC_AS_FRAME (scope)->thisp;
-  }
-  if (!SWFDEC_IS_MOVIE (target)) {
-    SWFDEC_ERROR ("no valid target");
-    return NULL;
-  }
-  return SWFDEC_MOVIE (target);
-}
-
 /*** ALL THE ACTION IS HERE ***/
 
 static void
 swfdec_action_stop (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
 {
-  SwfdecMovie *movie = swfdec_action_get_target (cx);
-  if (movie)
-    movie->stopped = TRUE;
+  if (SWFDEC_IS_MOVIE (cx->frame->target))
+    SWFDEC_MOVIE (cx->frame->target)->stopped = TRUE;
   else
     SWFDEC_ERROR ("no movie to stop");
 }
@@ -84,9 +64,8 @@ swfdec_action_stop (SwfdecAsContext *cx,
 static void
 swfdec_action_play (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
 {
-  SwfdecMovie *movie = swfdec_action_get_target (cx);
-  if (movie)
-    movie->stopped = FALSE;
+  if (SWFDEC_IS_MOVIE (cx->frame->target))
+    SWFDEC_MOVIE (cx->frame->target)->stopped = FALSE;
   else
     SWFDEC_ERROR ("no movie to play");
 }
@@ -94,8 +73,8 @@ swfdec_action_play (SwfdecAsContext *cx,
 static void
 swfdec_action_next_frame (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
 {
-  SwfdecMovie *movie = swfdec_action_get_target (cx);
-  if (movie) {
+  if (SWFDEC_IS_MOVIE (cx->frame->target)) {
+    SwfdecMovie *movie = SWFDEC_MOVIE (cx->frame->target);
     if (movie->frame + 1 < movie->n_frames) {
       swfdec_movie_goto (movie, movie->frame + 1);
     } else {
@@ -109,8 +88,8 @@ swfdec_action_next_frame (SwfdecAsContex
 static void
 swfdec_action_previous_frame (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
 {
-  SwfdecMovie *movie = swfdec_action_get_target (cx);
-  if (movie) {
+  if (SWFDEC_IS_MOVIE (cx->frame->target)) {
+    SwfdecMovie *movie = SWFDEC_MOVIE (cx->frame->target);
     if (movie->frame > 0) {
       swfdec_movie_goto (movie, movie->frame - 1);
     } else {
@@ -124,7 +103,6 @@ swfdec_action_previous_frame (SwfdecAsCo
 static void
 swfdec_action_goto_frame (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
 {
-  SwfdecMovie *movie = swfdec_action_get_target (cx);
   guint frame;
 
   if (len != 2) {
@@ -132,7 +110,8 @@ swfdec_action_goto_frame (SwfdecAsContex
     return;
   }
   frame = GUINT16_FROM_LE (*((guint16 *) data));
-  if (movie) {
+  if (SWFDEC_IS_SPRITE_MOVIE (cx->frame->target)) {
+    SwfdecMovie *movie = SWFDEC_MOVIE (cx->frame->target);
     swfdec_movie_goto (movie, frame);
     movie->stopped = TRUE;
   } else {
@@ -143,14 +122,13 @@ swfdec_action_goto_frame (SwfdecAsContex
 static void
 swfdec_action_goto_label (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
 {
-  SwfdecMovie *movie = swfdec_action_get_target (cx);
-
   if (!memchr (data, 0, len)) {
     SWFDEC_ERROR ("GotoLabel action does not specify a string");
     return;
   }
 
-  if (SWFDEC_IS_SPRITE_MOVIE (movie)) {
+  if (SWFDEC_IS_SPRITE_MOVIE (cx->frame->target)) {
+    SwfdecMovie *movie = SWFDEC_MOVIE (cx->frame->target);
     int frame = swfdec_sprite_get_frame (SWFDEC_SPRITE_MOVIE (movie)->sprite, (const char *) data);
     if (frame == -1)
       return;
@@ -197,7 +175,6 @@ swfdec_action_goto_frame2 (SwfdecAsConte
   guint bias;
   gboolean play;
   SwfdecAsValue *val;
-  SwfdecMovie *movie;
 
   swfdec_bits_init_data (&bits, data, len);
   if (swfdec_bits_getbits (&bits, 6)) {
@@ -209,9 +186,9 @@ swfdec_action_goto_frame2 (SwfdecAsConte
     bias = swfdec_bits_get_u16 (&bits);
   }
   val = swfdec_as_stack_peek (cx->frame->stack, 1);
-  movie = swfdec_action_get_target (cx);
   /* now set it */
-  if (movie) {
+  if (SWFDEC_IS_SPRITE_MOVIE (cx->frame->target)) {
+    SwfdecMovie *movie = SWFDEC_MOVIE (cx->frame->target);
     int frame = swfdec_value_to_frame (cx, movie, val);
     if (frame >= 0) {
       frame += bias;
@@ -252,7 +229,6 @@ static void
 swfdec_action_wait_for_frame2 (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
 {
   jsval val;
-  SwfdecMovie *movie;
 
   if (len != 1) {
     SWFDEC_ERROR ("WaitForFrame2 needs a 1-byte data");
@@ -260,8 +236,8 @@ swfdec_action_wait_for_frame2 (SwfdecAsC
   }
   val = cx->fp->sp[-1];
   cx->fp->sp--;
-  movie = swfdec_action_get_target (cx);
-  if (movie) {
+  if (SWFDEC_IS_SPRITE_MOVIE (cx->frame->target))
+    SwfdecMovie *movie = SWFDEC_MOVIE (cx->frame->target);
     int frame = swfdec_value_to_frame (cx, movie, val);
     guint jump = data[2];
     guint loaded;
@@ -293,12 +269,12 @@ swfdec_action_wait_for_frame (SwfdecAsCo
     SWFDEC_ERROR ("WaitForFrame action length invalid (is %u, should be 3", len);
     return;
   }
-  movie = swfdec_action_get_target (cx);
-  if (movie == NULL) {
+  if (!SWFDEC_IS_SPRITE_MOVIE (cx->frame->target)) {
     SWFDEC_ERROR ("no movie for WaitForFrame");
     return;
   }
 
+  movie = SWFDEC_MOVIE (cx->frame->target);
   frame = GUINT16_FROM_LE (*((guint16 *) data));
   jump = data[2];
   if (SWFDEC_MOVIE (movie->swf->movie) == movie) {
@@ -489,7 +465,7 @@ swfdec_action_get_property (SwfdecAsCont
   val = swfdec_as_stack_peek (cx->frame->stack, 1);
   swfdec_as_interpret_eval (cx, NULL, val);
   if (SWFDEC_AS_VALUE_IS_UNDEFINED (val)) {
-    obj = SWFDEC_AS_OBJECT (swfdec_action_get_target (cx));
+    obj = cx->frame->target;
   } else if (SWFDEC_AS_VALUE_IS_OBJECT (val)) {
     obj = SWFDEC_AS_VALUE_GET_OBJECT (val);
   } else {
@@ -519,7 +495,7 @@ swfdec_action_set_property (SwfdecAsCont
   val = swfdec_as_stack_peek (cx->frame->stack, 3);
   swfdec_as_interpret_eval (cx, NULL, val);
   if (SWFDEC_AS_VALUE_IS_UNDEFINED (val)) {
-    obj = cx->frame->var_object;
+    obj = cx->frame->target;
   } else if (SWFDEC_AS_VALUE_IS_OBJECT (val)) {
     obj = SWFDEC_AS_VALUE_GET_OBJECT (val);
   } else {
@@ -881,7 +857,6 @@ swfdec_action_increment (SwfdecAsContext
 static void
 swfdec_action_get_url (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
 {
-  SwfdecMovie *movie;
   SwfdecBits bits;
   char *url, *target;
 
@@ -897,9 +872,8 @@ swfdec_action_get_url (SwfdecAsContext *
   if (swfdec_bits_left (&bits)) {
     SWFDEC_WARNING ("leftover bytes in GetURL action");
   }
-  movie = swfdec_action_get_target (cx);
-  if (movie)
-    swfdec_movie_load (movie, url, target);
+  if (SWFDEC_IS_MOVIE (cx->frame->target))
+    swfdec_movie_load (SWFDEC_MOVIE (cx->frame->target), url, target);
   else
     SWFDEC_WARNING ("no movie to load");
   g_free (url);
@@ -911,7 +885,6 @@ swfdec_action_get_url2 (SwfdecAsContext 
 {
   const char *target, *url;
   guint method;
-  SwfdecMovie *movie;
 
   if (len != 1) {
     SWFDEC_ERROR ("GetURL2 requires 1 byte of data, not %u", len);
@@ -933,9 +906,8 @@ swfdec_action_get_url2 (SwfdecAsContext 
   if (data[0] & 1) {
     SWFDEC_FIXME ("implement LoadVariables");
   }
-  movie = swfdec_action_get_target (cx);
-  if (movie)
-    swfdec_movie_load (movie, url, target);
+  if (SWFDEC_IS_MOVIE (cx->frame->target))
+    swfdec_movie_load (SWFDEC_MOVIE (cx->frame->target), url, target);
   else
     SWFDEC_WARNING ("no movie to load");
 }
@@ -1289,8 +1261,7 @@ swfdec_action_start_drag (SwfdecAsContex
 
   swfdec_as_stack_ensure_size (stack, 3);
   if (swfdec_as_interpret_eval (cx, NULL, swfdec_as_stack_peek (stack, 1)) == SWFDEC_AS_STR_EMPTY) {
-    SWFDEC_AS_VALUE_SET_OBJECT (swfdec_as_stack_peek (stack, 1), 
-	SWFDEC_AS_OBJECT (swfdec_action_get_target (cx)));
+    SWFDEC_AS_VALUE_SET_OBJECT (swfdec_as_stack_peek (stack, 1), cx->frame->target);
   }
   if (swfdec_as_value_to_number (cx, swfdec_as_stack_peek (stack, 3))) {
     swfdec_as_stack_ensure_size (stack, 7);
@@ -1494,12 +1465,13 @@ swfdec_action_define_function (SwfdecAsC
   }
   /* see function-scope tests */
   if (cx->version > 5) {
-    fun = swfdec_as_script_function_new (frame->scope ? frame->scope : SWFDEC_AS_SCOPE (frame));
+    /* FIXME: or original target? */
+    fun = swfdec_as_script_function_new (frame->scope ? frame->scope : SWFDEC_AS_SCOPE (frame), frame->target);
   } else {
     SwfdecAsScope *scope = frame->scope ? frame->scope : SWFDEC_AS_SCOPE (frame);
     while (scope->next)
       scope = scope->next;
-    fun = swfdec_as_script_function_new (scope);
+    fun = swfdec_as_script_function_new (scope, frame->target);
   }
   if (fun == NULL)
     return;
@@ -1582,7 +1554,7 @@ swfdec_action_define_function (SwfdecAsC
     /* FIXME: really varobj? Not eval or sth like that? */
     function_name = swfdec_as_context_get_string (cx, function_name);
     SWFDEC_AS_VALUE_SET_OBJECT (&funval, SWFDEC_AS_OBJECT (fun));
-    swfdec_as_object_set_variable (frame->var_object, function_name, &funval);
+    swfdec_as_object_set_variable (frame->target, function_name, &funval);
     swfdec_as_object_unroot (SWFDEC_AS_OBJECT (fun));
   }
 
@@ -1673,10 +1645,16 @@ swfdec_action_target_path (SwfdecAsConte
 static void
 swfdec_action_define_local (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
 {
+  SwfdecAsObject *target;
   const char *name;
 
   name = swfdec_as_value_to_string (cx, swfdec_as_stack_peek (cx->frame->stack, 2));
-  swfdec_as_object_set_variable (cx->frame->var_object, name,
+  if (cx->frame->is_local) {
+    target = SWFDEC_AS_OBJECT (cx->frame);
+  } else {
+    target = cx->frame->target;
+  }
+  swfdec_as_object_set_variable (target, name,
       swfdec_as_stack_peek (cx->frame->stack, 1));
   swfdec_as_stack_pop_n (cx->frame->stack, 2);
 }
@@ -1685,10 +1663,16 @@ static void
 swfdec_action_define_local2 (SwfdecAsContext *cx, guint action, const guint8 *data, guint len)
 {
   SwfdecAsValue val = { 0, };
+  SwfdecAsObject *target;
   const char *name;
 
   name = swfdec_as_value_to_string (cx, swfdec_as_stack_pop (cx->frame->stack));
-  swfdec_as_object_set_variable (cx->frame->var_object, name, &val);
+  if (cx->frame->is_local) {
+    target = SWFDEC_AS_OBJECT (cx->frame);
+  } else {
+    target = cx->frame->target;
+  }
+  swfdec_as_object_set_variable (target, name, &val);
 }
 
 static void
diff --git a/libswfdec/swfdec_as_script_function.c b/libswfdec/swfdec_as_script_function.c
index 2144816..3140143 100644
--- a/libswfdec/swfdec_as_script_function.c
+++ b/libswfdec/swfdec_as_script_function.c
@@ -38,6 +38,8 @@ swfdec_as_script_function_call (SwfdecAs
   frame = swfdec_as_frame_new (SWFDEC_AS_OBJECT (function)->context, script->script);
   SWFDEC_AS_SCOPE (frame)->next = script->scope;
   frame->function = function;
+  frame->target = script->target;
+  frame->original_target = script->target;
   return frame;
 }
 
@@ -85,13 +87,14 @@ swfdec_as_script_function_init (SwfdecAs
 }
 
 SwfdecAsFunction *
-swfdec_as_script_function_new (SwfdecAsScope *scope)
+swfdec_as_script_function_new (SwfdecAsScope *scope, SwfdecAsObject *target)
 {
   SwfdecAsValue val;
   SwfdecAsFunction *fun;
   SwfdecAsObject *proto;
 
   g_return_val_if_fail (SWFDEC_IS_AS_SCOPE (scope), NULL);
+  g_return_val_if_fail (SWFDEC_IS_AS_OBJECT (target), NULL);
 
   fun = swfdec_as_function_create (SWFDEC_AS_OBJECT (scope)->context, 
       SWFDEC_TYPE_AS_SCRIPT_FUNCTION, sizeof (SwfdecAsScriptFunction));
@@ -105,6 +108,7 @@ swfdec_as_script_function_new (SwfdecAsS
   SWFDEC_AS_VALUE_SET_OBJECT (&val, proto);
   swfdec_as_object_set_variable (SWFDEC_AS_OBJECT (fun), SWFDEC_AS_STR_prototype, &val);
   SWFDEC_AS_SCRIPT_FUNCTION (fun)->scope = scope;
+  SWFDEC_AS_SCRIPT_FUNCTION (fun)->target = target;
 
   return fun;
 }
diff --git a/libswfdec/swfdec_as_script_function.h b/libswfdec/swfdec_as_script_function.h
index 1034416..9f47919 100644
--- a/libswfdec/swfdec_as_script_function.h
+++ b/libswfdec/swfdec_as_script_function.h
@@ -42,7 +42,8 @@ struct _SwfdecAsScriptFunction {
 
   /* for script script_functions */
   SwfdecScript *	script;		/* script being executed or NULL when native */
-  SwfdecAsScope *	scope;		/* scope this script_function was defined in or NULL */
+  SwfdecAsScope *	scope;		/* scope this script_function was defined in */
+  SwfdecAsObject *	target;		/* target this object was defined in */
 };
 
 struct _SwfdecAsScriptFunctionClass {
@@ -51,8 +52,8 @@ struct _SwfdecAsScriptFunctionClass {
 
 GType			swfdec_as_script_function_get_type	(void);
 
-/* FIXME: verify what scope a script_function gets that is defined inside a With statement */
-SwfdecAsFunction *	swfdec_as_script_function_new		(SwfdecAsScope *	scope);
+SwfdecAsFunction *	swfdec_as_script_function_new		(SwfdecAsScope *	scope,
+								 SwfdecAsObject *	target);
 
 
 G_END_DECLS
diff-tree dc96e46427dd1426221899de210486dbd315cc29 (from parents)
Merge: fad705a672d2685cd5572f1bbe4fa9e17776441f 5cdaada235a5bf34316aa5faa3a3b4fc1d2b515c
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jun 26 13:41:25 2007 +0200

    Merge branch 'master' into as

diff-tree 5cdaada235a5bf34316aa5faa3a3b4fc1d2b515c (from 00d9cad4c135dba8df2cffea271d0ad5935440b1)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jun 26 13:35:15 2007 +0200

    Check for libswscale, too

diff --git a/configure.ac b/configure.ac
index 1766eaf..f366094 100644
--- a/configure.ac
+++ b/configure.ac
@@ -196,7 +196,7 @@ AC_ARG_ENABLE(ffmpeg,
 	enable_ffmpeg="yes")
 
 if test "$enable_ffmpeg" = "yes"; then
-	PKG_CHECK_MODULES(FFMPEG, libavcodec, HAVE_FFMPEG=yes, HAVE_FFMPEG=no)
+	PKG_CHECK_MODULES(FFMPEG, libavcodec libswscale, HAVE_FFMPEG=yes, HAVE_FFMPEG=no)
 	AC_SUBST(FFMPEG_CFLAGS)
 	AC_SUBST(FFMPEG_LIBS)
 	if test "x$HAVE_FFMPEG" = xyes; then
diff-tree 00d9cad4c135dba8df2cffea271d0ad5935440b1 (from 27f2f8fe232d392ddf50e97116724f507cc05a43)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jun 26 13:35:01 2007 +0200

    initialize the struct with 0ed members
    
    Avoids SEGV when assuming the swscaler context is empty.

diff --git a/libswfdec/swfdec_codec_ffmpeg.c b/libswfdec/swfdec_codec_ffmpeg.c
index 8b7463c..c80f117 100644
--- a/libswfdec/swfdec_codec_ffmpeg.c
+++ b/libswfdec/swfdec_codec_ffmpeg.c
@@ -280,7 +280,7 @@ swfdec_video_decoder_ffmpeg_new (SwfdecV
 
   if (ctx == NULL)
     return NULL;
-  codec = g_new (SwfdecVideoDecoderFFMpeg, 1);
+  codec = g_new0 (SwfdecVideoDecoderFFMpeg, 1);
   codec->decoder.decode = swfdec_video_decoder_ffmpeg_decode;
   codec->decoder.free = swfdec_video_decoder_ffmpeg_free;
   codec->ctx = ctx;
diff-tree 27f2f8fe232d392ddf50e97116724f507cc05a43 (from ed66672b6bd13a613aaf875d2f898cc2f16a47b9)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jun 26 12:32:15 2007 +0200

    add support for VP6 to ffmpeg

diff --git a/libswfdec/swfdec_codec_ffmpeg.c b/libswfdec/swfdec_codec_ffmpeg.c
index 5dc8f3c..8b7463c 100644
--- a/libswfdec/swfdec_codec_ffmpeg.c
+++ b/libswfdec/swfdec_codec_ffmpeg.c
@@ -270,6 +270,9 @@ swfdec_video_decoder_ffmpeg_new (SwfdecV
     case SWFDEC_VIDEO_FORMAT_SCREEN:
       id = CODEC_ID_FLASHSV;
       break;
+    case SWFDEC_VIDEO_FORMAT_VP6:
+      id = CODEC_ID_VP6F;
+      break;
     default:
       return NULL;
   }
diff-tree ed66672b6bd13a613aaf875d2f898cc2f16a47b9 (from 8e04b92f5880361d5a34ad4f6674de3c88ad4377)
Author: Benjamin Otte <otte at gnome.org>
Date:   Tue Jun 26 12:29:42 2007 +0200

    update the ffmpeg code to something newer than Debian stable

diff --git a/libswfdec/swfdec_codec_ffmpeg.c b/libswfdec/swfdec_codec_ffmpeg.c
index 8f333e8..5dc8f3c 100644
--- a/libswfdec/swfdec_codec_ffmpeg.c
+++ b/libswfdec/swfdec_codec_ffmpeg.c
@@ -22,6 +22,7 @@
 #endif
 #include <string.h>
 #include <avcodec.h>
+#include <swscale.h>
 
 #include "swfdec_codec_audio.h"
 #include "swfdec_codec_video.h"
@@ -124,7 +125,7 @@ swfdec_audio_decoder_ffmpeg_push (Swfdec
   outbuf = swfdec_buffer_new_and_alloc (AVCODEC_MAX_AUDIO_FRAME_SIZE);
   for (amount = 0; amount < buffer->length; amount += len) {
     
-    len = avcodec_decode_audio (ffmpeg->ctx, (short *) outbuf->data, &out_size, buffer->data + amount, buffer->length - amount);
+    len = avcodec_decode_audio2 (ffmpeg->ctx, (short *) outbuf->data, &out_size, buffer->data + amount, buffer->length - amount);
 
     if (len < 0) {
       SWFDEC_ERROR ("Error %d while decoding", len);
@@ -205,6 +206,7 @@ typedef struct {
   SwfdecVideoDecoder	decoder;
   AVCodecContext *	ctx;		/* out context (d'oh) */
   AVFrame *		frame;		/* the frame we use for decoding */
+  struct SwsContext *	sws;		/* the format conversion */
 } SwfdecVideoDecoderFFMpeg;
 
 SwfdecBuffer *
@@ -221,12 +223,19 @@ swfdec_video_decoder_ffmpeg_decode (Swfd
     SWFDEC_WARNING ("error decoding frame");
     return NULL;
   }
+  if (codec->sws == NULL) {
+    codec->sws = sws_getContext (codec->ctx->width, codec->ctx->height, codec->ctx->pix_fmt,
+	codec->ctx->width, codec->ctx->height, PIX_FMT_RGB32, 0, NULL, NULL, NULL);
+    if (codec->sws == NULL) {
+      SWFDEC_ERROR ("Could not get conversion context");
+      return NULL;
+    }
+  }
   ret = swfdec_buffer_new_and_alloc (codec->ctx->width * codec->ctx->height * 4);
   avpicture_fill (&picture, ret->data, PIX_FMT_RGB32, codec->ctx->width,
       codec->ctx->height);
-  img_convert (&picture, PIX_FMT_RGB32, 
-      (AVPicture *) codec->frame, codec->ctx->pix_fmt,
-      codec->ctx->width, codec->ctx->height);
+  sws_scale (codec->sws, codec->frame->data, codec->frame->linesize, 0, codec->ctx->height,
+      picture.data, picture.linesize);
   *width = codec->ctx->width;
   *height = codec->ctx->height;
   *rowstride = codec->ctx->width * 4;
@@ -238,6 +247,9 @@ swfdec_video_decoder_ffmpeg_free (Swfdec
 {
   SwfdecVideoDecoderFFMpeg *codec = (SwfdecVideoDecoderFFMpeg *) dec;
 
+  if (codec->sws) {
+    sws_freeContext (codec->sws);
+  };
   avcodec_close (codec->ctx);
   av_free (codec->ctx);
   av_free (codec->frame);


More information about the Swfdec mailing list