Pekka Lampila
2007-Nov-15 16:25 UTC
[Swfdec] 5 commits - configure.ac libswfdec/swfdec_as_frame.c libswfdec/swfdec_as_frame_internal.h libswfdec/swfdec_as_function.c libswfdec/swfdec_as_interpret.c libswfdec/swfdec_as_strings.c test/trace
configure.ac | 12 +- libswfdec/swfdec_as_frame.c | 14 +++ libswfdec/swfdec_as_frame_internal.h | 3 libswfdec/swfdec_as_function.c | 12 ++ libswfdec/swfdec_as_interpret.c | 1 libswfdec/swfdec_as_strings.c | 2 test/trace/Makefile.am | 9 ++ test/trace/arguments-5.swf |binary test/trace/arguments-5.swf.trace | 63 ++++++++++++++ test/trace/arguments-6.swf |binary test/trace/arguments-6.swf.trace | 115 ++++++++++++++++++++++++++ test/trace/arguments-7.swf |binary test/trace/arguments-7.swf.trace | 115 ++++++++++++++++++++++++++ test/trace/arguments-8.swf |binary test/trace/arguments-8.swf.trace | 115 ++++++++++++++++++++++++++ test/trace/arguments.as | 150 +++++++++++++++++++++++++++++++++++ 16 files changed, 605 insertions(+), 6 deletions(-) New commits: commit 59fc3ad219854c539528044c8aeaf60dde8c9633 Author: Pekka Lampila <pekka.lampila at iki.fi> Date: Thu Nov 15 18:19:59 2007 +0200 Add a test for arguments caller and callee diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am index 78f38a4..1a9640a 100644 --- a/test/trace/Makefile.am +++ b/test/trace/Makefile.am @@ -83,6 +83,15 @@ EXTRA_DIST = \ and-or-6.swf.trace \ and-or-7.swf \ and-or-7.swf.trace \ + arguments.as \ + arguments-5.swf \ + arguments-5.swf.trace \ + arguments-6.swf \ + arguments-6.swf.trace \ + arguments-7.swf \ + arguments-7.swf.trace \ + arguments-8.swf \ + arguments-8.swf.trace \ array.swf \ array.swf.trace \ array-new.as \ diff --git a/test/trace/arguments-5.swf b/test/trace/arguments-5.swf new file mode 100644 index 0000000..3c8b5c0 Binary files /dev/null and b/test/trace/arguments-5.swf differ diff --git a/test/trace/arguments-5.swf.trace b/test/trace/arguments-5.swf.trace new file mode 100644 index 0000000..ea28be3 --- /dev/null +++ b/test/trace/arguments-5.swf.trace @@ -0,0 +1,63 @@ +Global: +arguments: +caller: +callee: + +Calling from outside of function + +CallFunction +arguments: +caller: null +callee: + +CallMethod +arguments: +caller: null +callee: + +Call: + +Apply: + +New: +arguments: +caller: null +callee: + +Sort: +arguments: a, +caller: null +callee: + +Calling from inside a function + +Check + +CallFunction +arguments: +caller: +callee: + +CallMethod +arguments: +caller: +callee: + +Call: + +Apply: + +New: +arguments: +caller: +callee: + +Sort: +arguments: a, +caller: +callee: + +Timeout: +arguments: +caller: null +callee: diff --git a/test/trace/arguments-6.swf b/test/trace/arguments-6.swf new file mode 100644 index 0000000..bff66b5 Binary files /dev/null and b/test/trace/arguments-6.swf differ diff --git a/test/trace/arguments-6.swf.trace b/test/trace/arguments-6.swf.trace new file mode 100644 index 0000000..3f766da --- /dev/null +++ b/test/trace/arguments-6.swf.trace @@ -0,0 +1,115 @@ +Global: +arguments: +caller: +callee: + +Calling from outside of function + +CallFunction +arguments: +caller: null +callee: func + +CallMethod +arguments: +caller: null +callee: func + +Call: +arguments: +caller: null +callee: func + +Apply: +arguments: +caller: null +callee: func + +New: +arguments: +caller: null +callee: func + +Sort: +arguments: a, +caller: null +callee: func + +Prop set: +arguments: 2 +caller: null +callee: prop_set + +Prop get: +arguments: +caller: null +callee: prop_get + +Watcher: +arguments: watched,true,false, +caller: null +callee: watcher + +Broadcast: +arguments: +caller: null +callee: broadcast + +Calling from inside a function + +Check + +CallFunction +arguments: +caller: check +callee: func + +CallMethod +arguments: +caller: check +callee: func + +Call: +arguments: +caller: check +callee: func + +Apply: +arguments: +caller: check +callee: func + +New: +arguments: +caller: check +callee: func + +Sort: +arguments: a, +caller: check +callee: func + +Prop set: +arguments: 2 +caller: check +callee: prop_set + +Prop get: +arguments: +caller: check +callee: prop_get + +Watcher: +arguments: watched,,false, +caller: check +callee: watcher + +Broadcast: +arguments: +caller: check +callee: broadcast + +Timeout: +arguments: +caller: null +callee: timeout diff --git a/test/trace/arguments-7.swf b/test/trace/arguments-7.swf new file mode 100644 index 0000000..42fbf87 Binary files /dev/null and b/test/trace/arguments-7.swf differ diff --git a/test/trace/arguments-7.swf.trace b/test/trace/arguments-7.swf.trace new file mode 100644 index 0000000..e681495 --- /dev/null +++ b/test/trace/arguments-7.swf.trace @@ -0,0 +1,115 @@ +Global: +arguments: undefined +caller: undefined +callee: undefined + +Calling from outside of function + +CallFunction +arguments: +caller: null +callee: func + +CallMethod +arguments: +caller: null +callee: func + +Call: +arguments: +caller: null +callee: func + +Apply: +arguments: +caller: null +callee: func + +New: +arguments: +caller: null +callee: func + +Sort: +arguments: a,undefined +caller: null +callee: func + +Prop set: +arguments: 2 +caller: null +callee: prop_set + +Prop get: +arguments: +caller: null +callee: prop_get + +Watcher: +arguments: watched,true,false,undefined +caller: null +callee: watcher + +Broadcast: +arguments: +caller: null +callee: broadcast + +Calling from inside a function + +Check + +CallFunction +arguments: +caller: check +callee: func + +CallMethod +arguments: +caller: check +callee: func + +Call: +arguments: +caller: check +callee: func + +Apply: +arguments: +caller: check +callee: func + +New: +arguments: +caller: check +callee: func + +Sort: +arguments: a,undefined +caller: check +callee: func + +Prop set: +arguments: 2 +caller: check +callee: prop_set + +Prop get: +arguments: +caller: check +callee: prop_get + +Watcher: +arguments: watched,undefined,false,undefined +caller: check +callee: watcher + +Broadcast: +arguments: +caller: check +callee: broadcast + +Timeout: +arguments: +caller: null +callee: timeout diff --git a/test/trace/arguments-8.swf b/test/trace/arguments-8.swf new file mode 100644 index 0000000..3dc3637 Binary files /dev/null and b/test/trace/arguments-8.swf differ diff --git a/test/trace/arguments-8.swf.trace b/test/trace/arguments-8.swf.trace new file mode 100644 index 0000000..e681495 --- /dev/null +++ b/test/trace/arguments-8.swf.trace @@ -0,0 +1,115 @@ +Global: +arguments: undefined +caller: undefined +callee: undefined + +Calling from outside of function + +CallFunction +arguments: +caller: null +callee: func + +CallMethod +arguments: +caller: null +callee: func + +Call: +arguments: +caller: null +callee: func + +Apply: +arguments: +caller: null +callee: func + +New: +arguments: +caller: null +callee: func + +Sort: +arguments: a,undefined +caller: null +callee: func + +Prop set: +arguments: 2 +caller: null +callee: prop_set + +Prop get: +arguments: +caller: null +callee: prop_get + +Watcher: +arguments: watched,true,false,undefined +caller: null +callee: watcher + +Broadcast: +arguments: +caller: null +callee: broadcast + +Calling from inside a function + +Check + +CallFunction +arguments: +caller: check +callee: func + +CallMethod +arguments: +caller: check +callee: func + +Call: +arguments: +caller: check +callee: func + +Apply: +arguments: +caller: check +callee: func + +New: +arguments: +caller: check +callee: func + +Sort: +arguments: a,undefined +caller: check +callee: func + +Prop set: +arguments: 2 +caller: check +callee: prop_set + +Prop get: +arguments: +caller: check +callee: prop_get + +Watcher: +arguments: watched,undefined,false,undefined +caller: check +callee: watcher + +Broadcast: +arguments: +caller: check +callee: broadcast + +Timeout: +arguments: +caller: null +callee: timeout diff --git a/test/trace/arguments.as b/test/trace/arguments.as new file mode 100644 index 0000000..479013e --- /dev/null +++ b/test/trace/arguments.as @@ -0,0 +1,150 @@ +// makeswf -v 7 -r 1 -o test-7.swf test.as + +trace ("Global:"); +trace ("arguments: " + arguments); +trace ("caller: " + arguments.caller); +trace ("callee: " + arguments.callee); + +function func () { + trace ("arguments: " + arguments); + trace ("caller: " + arguments.caller); + trace ("callee: " + arguments.callee); +} +func.toString = function () { return "func"; }; + +function prop_get () { + trace (""); + trace ("Prop get:"); + trace ("arguments: " + arguments); + trace ("caller: " + arguments.caller); + trace ("callee: " + arguments.callee); +} +prop_get.toString = function () { return "prop_get"; }; + +function prop_set () { + trace (""); + trace ("Prop set:"); + trace ("arguments: " + arguments); + trace ("caller: " + arguments.caller); + trace ("callee: " + arguments.callee); +} +prop_set.toString = function () { return "prop_set"; }; + +function watcher () { + trace (""); + trace ("Watcher:"); + trace ("arguments: " + arguments); + trace ("caller: " + arguments.caller); + trace ("callee: " + arguments.callee); +} +watcher.toString = function () { return "watcher"; }; + +var o = {}; +o.func = func; +o.addProperty ("prop", prop_get, prop_set); +o.watched = true; +o.watch ("watched", watcher); + +var emitter = new Object (); +AsBroadcaster.initialize (emitter); +emitter._listeners.push (new Object ()); +emitter._listeners[0].broadcast = function () { + trace (""); + trace ("Broadcast:"); + trace ("arguments: " + arguments); + trace ("caller: " + arguments.caller); + trace ("callee: " + arguments.callee); +}; +emitter._listeners[0].broadcast.toString = function () { return "broadcast"; }; + +function timeout () { + trace (""); + trace ("Timeout:"); + trace ("arguments: " + arguments); + trace ("caller: " + arguments.caller); + trace ("callee: " + arguments.callee); + + loadMovie ("FSCommand:quit", ""); +} +timeout.toString = function () { return "timeout"; }; + +trace (""); +trace ("Calling from outside of function"); + +trace (""); +trace ("CallFunction"); +func (); + +trace (""); +trace ("CallMethod"); +o.func (); + +trace (""); +trace ("Call:"); +func.call (); + +trace (""); +trace ("Apply:"); +func.apply (); + +trace (""); +trace ("New:"); +var a = new func (); + +trace (""); +trace ("Sort:"); +a = new Array (2); +a[0] = "a"; +a.sort (func); + +o.prop = 2; +a = o.prop; + +o.watched = false; + +emitter.broadcastMessage ("broadcast"); + +function check () { + trace (""); + trace ("CallFunction"); + func (); + + trace (""); + trace ("CallMethod"); + o.func (); + + trace (""); + trace ("Call:"); + func.call (); + + trace (""); + trace ("Apply:"); + func.apply (); + + trace (""); + trace ("New:"); + var a = new func (); + + trace (""); + trace ("Sort:"); + a = new Array (2); + a[0] = "a"; + a.sort (func); + + o.prop = 2; + a = o.prop; + + o.watched = false; + + emitter.broadcastMessage ("broadcast"); + + setTimeout (timeout, 0); +} +check.toString = function () { return "check"; }; + +trace (""); +trace ("Calling from inside a function"); + +trace (""); +trace ("Check"); +check (); commit 25f366a8e7bbc45c0925d78c98457345ec0dd027 Author: Pekka Lampila <pekka.lampila at iki.fi> Date: Thu Nov 15 18:16:57 2007 +0200 Implement arguments.caller diff --git a/libswfdec/swfdec_as_frame.c b/libswfdec/swfdec_as_frame.c index 0fb7a04..26287bc 100644 --- a/libswfdec/swfdec_as_frame.c +++ b/libswfdec/swfdec_as_frame.c @@ -696,6 +696,13 @@ swfdec_as_frame_preload (SwfdecAsFrame *frame) swfdec_as_array_push (SWFDEC_AS_ARRAY (args), cur); } + if (frame->caller != NULL) { + SWFDEC_AS_VALUE_SET_OBJECT (&val, SWFDEC_AS_OBJECT (frame->caller)); + } else { + SWFDEC_AS_VALUE_SET_NULL (&val); + } + swfdec_as_object_set_variable (args, SWFDEC_AS_STR_caller, &val); + if (frame->callee != NULL) { SWFDEC_AS_VALUE_SET_OBJECT (&val, SWFDEC_AS_OBJECT (frame->callee)); } else { diff --git a/libswfdec/swfdec_as_frame_internal.h b/libswfdec/swfdec_as_frame_internal.h index 59cdc5a..7c4f3ac 100644 --- a/libswfdec/swfdec_as_frame_internal.h +++ b/libswfdec/swfdec_as_frame_internal.h @@ -40,7 +40,9 @@ struct _SwfdecAsFrame { guint argc; /* number of arguments */ const SwfdecAsValue * argv; /* arguments or %NULL if taken from stack */ SwfdecSecurity * security; /* security for this frame or %NULL if not allowed to call */ + SwfdecAsFunction * caller; /* the function that made the call or %NULL */ SwfdecAsFunction * callee; /* the function being called or %NULL */ + gboolean update_caller; /* whether callee should be used as a caller for called functions */ /* debugging */ const char * function_name; /* name of function */ /* script execution */ diff --git a/libswfdec/swfdec_as_function.c b/libswfdec/swfdec_as_function.c index c6b0f65..0f0d3b5 100644 --- a/libswfdec/swfdec_as_function.c +++ b/libswfdec/swfdec_as_function.c @@ -105,16 +105,24 @@ swfdec_as_function_call_no_preload (SwfdecAsFunction *function, { SwfdecAsContext *context; SwfdecAsFrame *frame; + SwfdecAsFunction *caller; SwfdecAsFunctionClass *klass; g_return_val_if_fail (SWFDEC_IS_AS_FUNCTION (function), NULL); g_return_val_if_fail (thisp == NULL || SWFDEC_IS_AS_OBJECT (thisp), NULL); - context = SWFDEC_AS_OBJECT (function)->context; /* just to be sure... */ if (return_value) SWFDEC_AS_VALUE_SET_UNDEFINED (return_value); + context = SWFDEC_AS_OBJECT (function)->context; + if (context->frame != NULL) { + caller = (context->frame->update_caller ? context->frame->callee : + context->frame->caller); + } else { + caller = NULL; + } + klass = SWFDEC_AS_FUNCTION_GET_CLASS (function); g_assert (klass->call); frame = klass->call (function); @@ -130,6 +138,7 @@ swfdec_as_function_call_no_preload (SwfdecAsFunction *function, swfdec_as_frame_set_this (frame, swfdec_as_object_resolve (thisp)); } frame->is_local = TRUE; + frame->caller = caller; frame->callee = function; frame->argc = n_args; frame->argv = args; diff --git a/libswfdec/swfdec_as_interpret.c b/libswfdec/swfdec_as_interpret.c index 7d6686f..ab6b41c 100644 --- a/libswfdec/swfdec_as_interpret.c +++ b/libswfdec/swfdec_as_interpret.c @@ -865,6 +865,7 @@ swfdec_action_call_function (SwfdecAsContext *cx, guint action, const guint8 *da frame = swfdec_action_call (cx, n_args); if (frame) { swfdec_as_frame_preload (frame); + frame->update_caller = TRUE; } else { SWFDEC_WARNING ("no function named %s", name); } diff --git a/libswfdec/swfdec_as_strings.c b/libswfdec/swfdec_as_strings.c index acf1a33..e294a03 100644 --- a/libswfdec/swfdec_as_strings.c +++ b/libswfdec/swfdec_as_strings.c @@ -433,5 +433,6 @@ const char swfdec_as_strings[] SWFDEC_AS_CONSTANT_STRING ("IllegalRequest") SWFDEC_AS_CONSTANT_STRING ("LoadNeverCompleted") SWFDEC_AS_CONSTANT_STRING ("callee") + SWFDEC_AS_CONSTANT_STRING ("caller") /* add more here */ ; commit 2bf52c7c12c4194778a673e26a9a74ffea3a0b5b Author: Pekka Lampila <pekka.lampila at iki.fi> Date: Thu Nov 15 16:11:26 2007 +0200 Require glib 2.14 for vivified and 2.12 for everything else diff --git a/configure.ac b/configure.ac index c9c5d43..924aa4d 100644 --- a/configure.ac +++ b/configure.ac @@ -72,7 +72,7 @@ AC_ARG_WITH(pkg-config-path, dnl Check for essential libraries first: dnl =================================== -GLIB_VER=2.10 +GLIB_VER=2.12 PKG_CHECK_MODULES(GLIB, glib-2.0 >= $GLIB_VER gobject-2.0 >= $GLIB_VER gthread-2.0 >= $GLIB_VER, HAVE_GLIB=yes, HAVE_GLIB=no) if test "$HAVE_GLIB" = "no"; then @@ -287,11 +287,12 @@ AC_ARG_ENABLE(vivified, if test "$enable_vivi" = "yes"; then MING_REQUIRED=0.4.0.beta5 VIVI_GTK_REQUIRED=2.11.6 - PKG_CHECK_MODULES(VIVI, libming >= $MING_REQUIRED gmodule-export-2.0 gtk+-2.0 >= $VIVI_GTK_REQUIRED, HAVE_VIVI=yes, HAVE_VIVI=no) + VIVI_GLIB_REQUIRED=2.14 + PKG_CHECK_MODULES(VIVI, libming >= $MING_REQUIRED gmodule-export-2.0 gtk+-2.0 >= $VIVI_GTK_REQUIRED glib-2.0 >= $VIVI_GLIB_REQUIRED, HAVE_VIVI=yes, HAVE_VIVI=no) if test "x$HAVE_VIVI" = xyes; then AC_DEFINE(HAVE_VIVI, 1, [Define if Vivified is enabled]) else - AC_MSG_ERROR([Vivified requirements not met. You need libming >= $MING_REQUIRED and Gtk+ >= $VIVI_GTK_REQUIRED.]) + AC_MSG_ERROR([Vivified requirements not met. You need libming >= $MING_REQUIRED, glib >= $VIVI_GLIB_REQUIRED and Gtk+ >= $VIVI_GTK_REQUIRED.]) fi else AC_MSG_NOTICE([Vivified was not enabled.]) commit 8bbc396cd2c337506839b6a2af6d72639042a486 Author: Pekka Lampila <pekka.lampila at iki.fi> Date: Thu Nov 15 15:30:49 2007 +0200 Require at least pangocairo 1.16 We might even need 1.18, not sure diff --git a/configure.ac b/configure.ac index 96ffeed..c9c5d43 100644 --- a/configure.ac +++ b/configure.ac @@ -87,9 +87,10 @@ AC_SUBST(GLIB_GENMARSHAL) GLIB_MKENUMS=glib-mkenums AC_SUBST(GLIB_MKENUMS) -PKG_CHECK_MODULES(PANGO, pangocairo, HAVE_PANGO=yes, HAVE_PANGO=no) +PANGO_VER=1.16 +PKG_CHECK_MODULES(PANGO, pangocairo >= $PANGO_VER, HAVE_PANGO=yes, HAVE_PANGO=no) if test "$HAVE_PANGO" = "no"; then - AC_MSG_ERROR([pangocairo is required to build swfdec]) + AC_MSG_ERROR([pangocairo >= $PANGO_VER is required to build swfdec]) fi AC_SUBST(PANGO_LIBS) AC_SUBST(PANGO_CFLAGS) commit b9f4dbed6c21f1d79d1da825b9e293cabdeb763d Author: Pekka Lampila <pekka.lampila at iki.fi> Date: Thu Nov 15 10:49:08 2007 +0200 Implement arguments.callee diff --git a/libswfdec/swfdec_as_frame.c b/libswfdec/swfdec_as_frame.c index 77f4c3a..0fb7a04 100644 --- a/libswfdec/swfdec_as_frame.c +++ b/libswfdec/swfdec_as_frame.c @@ -695,6 +695,13 @@ swfdec_as_frame_preload (SwfdecAsFrame *frame) cur = swfdec_as_stack_iterator_next (&iter)) { swfdec_as_array_push (SWFDEC_AS_ARRAY (args), cur); } + + if (frame->callee != NULL) { + SWFDEC_AS_VALUE_SET_OBJECT (&val, SWFDEC_AS_OBJECT (frame->callee)); + } else { + SWFDEC_AS_VALUE_SET_NULL (&val); + } + swfdec_as_object_set_variable (args, SWFDEC_AS_STR_callee, &val); } else { /* silence gcc */ args = NULL; diff --git a/libswfdec/swfdec_as_frame_internal.h b/libswfdec/swfdec_as_frame_internal.h index d50a9ce..59cdc5a 100644 --- a/libswfdec/swfdec_as_frame_internal.h +++ b/libswfdec/swfdec_as_frame_internal.h @@ -40,6 +40,7 @@ struct _SwfdecAsFrame { guint argc; /* number of arguments */ const SwfdecAsValue * argv; /* arguments or %NULL if taken from stack */ SwfdecSecurity * security; /* security for this frame or %NULL if not allowed to call */ + SwfdecAsFunction * callee; /* the function being called or %NULL */ /* debugging */ const char * function_name; /* name of function */ /* script execution */ diff --git a/libswfdec/swfdec_as_function.c b/libswfdec/swfdec_as_function.c index c64df5e..c6b0f65 100644 --- a/libswfdec/swfdec_as_function.c +++ b/libswfdec/swfdec_as_function.c @@ -130,6 +130,7 @@ swfdec_as_function_call_no_preload (SwfdecAsFunction *function, swfdec_as_frame_set_this (frame, swfdec_as_object_resolve (thisp)); } frame->is_local = TRUE; + frame->callee = function; frame->argc = n_args; frame->argv = args; frame->return_value = return_value; diff --git a/libswfdec/swfdec_as_strings.c b/libswfdec/swfdec_as_strings.c index 2879324..acf1a33 100644 --- a/libswfdec/swfdec_as_strings.c +++ b/libswfdec/swfdec_as_strings.c @@ -432,5 +432,6 @@ const char swfdec_as_strings[] SWFDEC_AS_CONSTANT_STRING ("URLNotFound") SWFDEC_AS_CONSTANT_STRING ("IllegalRequest") SWFDEC_AS_CONSTANT_STRING ("LoadNeverCompleted") + SWFDEC_AS_CONSTANT_STRING ("callee") /* add more here */ ;