[Swfdec] 2 commits - libswfdec/swfdec_script.c test/trace

Benjamin Otte company at kemper.freedesktop.org
Mon Mar 12 08:18:03 PDT 2007


 libswfdec/swfdec_script.c           |   46 ++++++++++++++++++++++++++++++++----
 test/trace/Makefile.am              |    5 +++
 test/trace/extends-simple.swf       |binary
 test/trace/extends-simple.swf.trace |    5 +++
 test/trace/extends-super.swf        |binary
 test/trace/extends-super.swf.trace  |    9 +++++++
 6 files changed, 60 insertions(+), 5 deletions(-)

New commits:
diff-tree a4707072b71463188e6fa49a397f893fc9ad5b89 (from abde74daded99c21e3992f8171f2748f8aef8ba6)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Mar 12 16:18:17 2007 +0100

    Add 2 new tests for ActionExtends

diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am
index 7b65208..1994892 100644
--- a/test/trace/Makefile.am
+++ b/test/trace/Makefile.am
@@ -57,7 +57,12 @@ EXTRA_DIST = \
 	empty-stack.as \
 	empty-stack.swf \
 	empty-stack.swf.trace \
+	event-order.swf \
 	event-order.swf.trace \
+	extends-simple.swf \
+	extends-simple.swf.trace \
+	extends-super.swf \
+	extends-super.swf.trace \
 	function1.swf \
 	function1.swf.trace \
 	function2.swf \
diff --git a/test/trace/extends-simple.swf b/test/trace/extends-simple.swf
new file mode 100755
index 0000000..96b8edc
Binary files /dev/null and b/test/trace/extends-simple.swf differ
diff --git a/test/trace/extends-simple.swf.trace b/test/trace/extends-simple.swf.trace
new file mode 100755
index 0000000..1c7149e
--- /dev/null
+++ b/test/trace/extends-simple.swf.trace
@@ -0,0 +1,5 @@
+Check simple inheritance
+constructed a Simple
+constructed a Sub
+called Sub.trace
+called Simple.trace
diff --git a/test/trace/extends-super.swf b/test/trace/extends-super.swf
new file mode 100755
index 0000000..de49a32
Binary files /dev/null and b/test/trace/extends-super.swf differ
diff --git a/test/trace/extends-super.swf.trace b/test/trace/extends-super.swf.trace
new file mode 100755
index 0000000..53ab226
--- /dev/null
+++ b/test/trace/extends-super.swf.trace
@@ -0,0 +1,9 @@
+Check how super works
+it's me
+constructed a Sub
+called Sub.trace
+called Simple.trace
+it's me
+constructed a Sub
+called Sub.trace
+it's me
diff-tree abde74daded99c21e3992f8171f2748f8aef8ba6 (from 03fccd9bc1924e4e128d1d0d6454a867991fd623)
Author: Benjamin Otte <otte at gnome.org>
Date:   Mon Mar 12 16:17:01 2007 +0100

    implement ActionExtends
    
    also includes:
    - implement preloading super
    - make CallMethod treat the method name being undefined as empty string

diff --git a/libswfdec/swfdec_script.c b/libswfdec/swfdec_script.c
index 4b17af1..ac4921c 100644
--- a/libswfdec/swfdec_script.c
+++ b/libswfdec/swfdec_script.c
@@ -719,9 +719,13 @@ swfdec_action_call_method (JSContext *cx
   
   if (!swfdec_script_ensure_stack (cx, 3))
     return JS_FALSE;
-  s = swfdec_js_to_string (cx, fp->sp[-1]);
-  if (s == NULL)
-    return JS_FALSE;
+  if (fp->sp[-1] == JSVAL_VOID) {
+    s = "";
+  } else {
+    s = swfdec_js_to_string (cx, fp->sp[-1]);
+    if (s == NULL)
+      return JS_FALSE;
+  }
   if (!JS_ValueToECMAUint32 (cx, fp->sp[-3], &n_args))
     return JS_FALSE;
   
@@ -1979,6 +1983,33 @@ swfdec_action_get_time (JSContext *cx, g
   return JS_TRUE;
 }
 
+static JSBool
+swfdec_action_extends (JSContext *cx, guint action, const guint8 *data, guint len)
+{
+  jsval superclass, subclass, proto;
+  JSObject *prototype;
+
+  superclass = cx->fp->sp[-1];
+  subclass = cx->fp->sp[-2];
+  cx->fp->sp -= 2;
+  if (!JSVAL_IS_OBJECT (superclass) || superclass == JSVAL_NULL ||
+      !JSVAL_IS_OBJECT (subclass) || subclass == JSVAL_NULL) {
+    SWFDEC_ERROR ("superclass or subclass aren't objects");
+    return JS_TRUE;
+  }
+  if (!JS_GetProperty (cx, JSVAL_TO_OBJECT (superclass), "prototype", &proto) ||
+      !JSVAL_IS_OBJECT (proto))
+    return JS_FALSE;
+  prototype = JS_NewObject (cx, NULL, JSVAL_TO_OBJECT (proto), NULL);
+  if (prototype == NULL)
+    return JS_FALSE;
+  proto = OBJECT_TO_JSVAL (prototype);
+  if (!JS_SetProperty (cx, prototype, "__constructor__", &superclass) ||
+      !JS_SetProperty (cx, JSVAL_TO_OBJECT (subclass), "prototype", &proto))
+    return JS_FALSE;
+  return JS_TRUE;
+}
+
 /*** PRINT FUNCTIONS ***/
 
 static char *
@@ -2365,7 +2396,7 @@ static const SwfdecActionSpec actions[25
   [0x67] = { "Greater", NULL, 2, 1, { NULL, NULL, NULL, swfdec_action_new_comparison_6, swfdec_action_new_comparison_7 } },
   [0x68] = { "StringGreater", NULL },
   /* version 7 */
-  [0x69] = { "Extends", NULL },
+  [0x69] = { "Extends", NULL, 2, 0, { NULL, NULL, NULL, NULL, swfdec_action_extends } },
 
   /* version 3 */
   [0x81] = { "GotoFrame", swfdec_action_print_goto_frame, 0, 0, { swfdec_action_goto_frame, swfdec_action_goto_frame, swfdec_action_goto_frame, swfdec_action_goto_frame, swfdec_action_goto_frame } },
@@ -2627,7 +2658,12 @@ swfdec_script_interpret (SwfdecScript *s
       fp->flags |= JS_BIT (JSFRAME_OVERRIDE_SHIFT);
     }
     if (script->flags & SWFDEC_SCRIPT_PRELOAD_SUPER) {
-      SWFDEC_ERROR ("preloading super isn't implemented");
+      if (!JS_GetProperty (cx, JS_GetPrototype (cx, fp->thisp), 
+	  fp->flags & JSINVOKE_CONSTRUCT ? "__constructor__" : "__proto__", 
+	  &fp->vars[preload_reg++])) {
+	ok = JS_FALSE;
+	goto out;
+      }
     }
     if (script->flags & SWFDEC_SCRIPT_PRELOAD_ROOT) {
       JSAtom *atom;


More information about the Swfdec mailing list