Benjamin Otte
2007-Aug-20 09:01 UTC
[Swfdec] 5 commits - libswfdec/swfdec_as_interpret.c libswfdec/swfdec_as_object.c libswfdec/swfdec_as_types.c libswfdec/swfdec_movie.c test/trace
libswfdec/swfdec_as_interpret.c | 9 -- libswfdec/swfdec_as_object.c | 33 +++++++-- libswfdec/swfdec_as_types.c | 5 + libswfdec/swfdec_movie.c | 2 test/trace/Makefile.am | 9 ++ test/trace/construct-properties-5.swf |binary test/trace/construct-properties-5.swf.trace | 93 ++++++++++++++++++++++++++++ test/trace/construct-properties-6.swf |binary test/trace/construct-properties-6.swf.trace | 93 ++++++++++++++++++++++++++++ test/trace/construct-properties-7.swf |binary test/trace/construct-properties-7.swf.trace | 93 ++++++++++++++++++++++++++++ test/trace/construct-properties-8.swf |binary test/trace/construct-properties-8.swf.trace | 93 ++++++++++++++++++++++++++++ test/trace/construct-properties.as | 36 ++++++++++ 14 files changed, 451 insertions(+), 15 deletions(-) New commits: diff-tree c7b91a2f93c264e6c06adabe1b4fcd97fb590c50 (from 919d9074df7d913998bc38edf3423f12eccdd4b8) Author: Benjamin Otte <otte at gnome.org> Date: Mon Aug 20 11:01:19 2007 +0200 add test for __constructor__ and constructor properties diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am index 3f7219f..800954c 100644 --- a/test/trace/Makefile.am +++ b/test/trace/Makefile.am @@ -230,6 +230,15 @@ EXTRA_DIST = \ comparisons-6.swf.trace \ comparisons-7.swf \ comparisons-7.swf.trace \ + construct-properties.as \ + construct-properties-5.swf \ + construct-properties-5.swf.trace \ + construct-properties-6.swf \ + construct-properties-6.swf.trace \ + construct-properties-7.swf \ + construct-properties-7.swf.trace \ + construct-properties-8.swf \ + construct-properties-8.swf.trace \ constructor-prototype.swf \ constructor-prototype.swf.trace \ countdown.swf \ diff --git a/test/trace/construct-properties-5.swf b/test/trace/construct-properties-5.swf new file mode 100644 index 0000000..2eff81e Binary files /dev/null and b/test/trace/construct-properties-5.swf differ diff --git a/test/trace/construct-properties-5.swf.trace b/test/trace/construct-properties-5.swf.trace new file mode 100644 index 0000000..a4aaf4b --- /dev/null +++ b/test/trace/construct-properties-5.swf.trace @@ -0,0 +1,93 @@ +Check initial properties of script-constructed objects +>>> new Object () +[type Function] +undefined +undefined +undefined +[object Object] +undefined +>>> {} +[type Function] +undefined +undefined +undefined +[object Object] +undefined +>>> [] +[type Function] +undefined +undefined +undefined + +undefined +>>> +[type Function] +undefined +undefined +undefined +[object Object] +undefined +>>> new Foo () +[type Function] +undefined +undefined +undefined +[object Object] +undefined +>>> +[type Function] +undefined +undefined +undefined +[object Object] +undefined +>>> new this.Foo () +[type Function] +undefined +undefined +undefined +[object Object] +undefined +undefined +>>> +[type Function] +undefined +undefined +undefined +undefined +undefined +>>> new Foo () - without prototype +[type Function] +undefined +undefined +undefined +undefined +undefined +>>> +[type Function] +undefined +undefined +undefined +undefined +undefined +>>> new this.Foo () - without prototype +[type Function] +undefined +undefined +undefined +undefined +undefined +>>> 42 +[type Function] +undefined +undefined +undefined +[type Object] +undefined +>>> true +[type Function] +undefined +undefined +undefined +[type Object] +undefined diff --git a/test/trace/construct-properties-6.swf b/test/trace/construct-properties-6.swf new file mode 100644 index 0000000..f6cf779 Binary files /dev/null and b/test/trace/construct-properties-6.swf differ diff --git a/test/trace/construct-properties-6.swf.trace b/test/trace/construct-properties-6.swf.trace new file mode 100644 index 0000000..90d5425 --- /dev/null +++ b/test/trace/construct-properties-6.swf.trace @@ -0,0 +1,93 @@ +Check initial properties of script-constructed objects +>>> new Object () +[type Function] +true +[type Function] +true +[object Object] +true +>>> {} +[type Function] +true +undefined +false +[object Object] +true +>>> [] +[type Function] +true +undefined +false + +true +>>> +[type Function] +true +[type Function] +true +[object Object] +true +>>> new Foo () +[type Function] +true +[type Function] +true +[object Object] +true +>>> +[type Function] +true +[type Function] +true +[object Object] +true +>>> new this.Foo () +[type Function] +true +[type Function] +true +[object Object] +true +undefined +>>> +[type Function] +undefined +[type Function] +undefined +undefined +undefined +>>> new Foo () - without prototype +[type Function] +undefined +[type Function] +undefined +undefined +undefined +>>> +[type Function] +undefined +[type Function] +undefined +undefined +undefined +>>> new this.Foo () - without prototype +[type Function] +true +[type Function] +true +undefined +false +>>> 42 +[type Function] +true +[type Function] +true +[type Object] +true +>>> true +[type Function] +true +[type Function] +true +[type Object] +true diff --git a/test/trace/construct-properties-7.swf b/test/trace/construct-properties-7.swf new file mode 100644 index 0000000..263bfb1 Binary files /dev/null and b/test/trace/construct-properties-7.swf differ diff --git a/test/trace/construct-properties-7.swf.trace b/test/trace/construct-properties-7.swf.trace new file mode 100644 index 0000000..0063c74 --- /dev/null +++ b/test/trace/construct-properties-7.swf.trace @@ -0,0 +1,93 @@ +Check initial properties of script-constructed objects +>>> new Object () +[type Function] +false +[type Function] +true +[object Object] +true +>>> {} +[type Function] +true +undefined +false +[object Object] +true +>>> [] +[type Function] +true +undefined +false + +true +>>> +[type Function] +false +[type Function] +true +[object Object] +true +>>> new Foo () +[type Function] +false +[type Function] +true +[object Object] +true +>>> +[type Function] +false +[type Function] +true +[object Object] +true +>>> new this.Foo () +[type Function] +false +[type Function] +true +[object Object] +true +undefined +>>> +undefined +undefined +[type Function] +undefined +undefined +undefined +>>> new Foo () - without prototype +undefined +undefined +[type Function] +undefined +undefined +undefined +>>> +undefined +undefined +[type Function] +undefined +undefined +undefined +>>> new this.Foo () - without prototype +undefined +false +[type Function] +true +undefined +false +>>> 42 +[type Function] +false +[type Function] +true +[type Object] +true +>>> true +[type Function] +false +[type Function] +true +[type Object] +true diff --git a/test/trace/construct-properties-8.swf b/test/trace/construct-properties-8.swf new file mode 100644 index 0000000..5f685c9 Binary files /dev/null and b/test/trace/construct-properties-8.swf differ diff --git a/test/trace/construct-properties-8.swf.trace b/test/trace/construct-properties-8.swf.trace new file mode 100644 index 0000000..0063c74 --- /dev/null +++ b/test/trace/construct-properties-8.swf.trace @@ -0,0 +1,93 @@ +Check initial properties of script-constructed objects +>>> new Object () +[type Function] +false +[type Function] +true +[object Object] +true +>>> {} +[type Function] +true +undefined +false +[object Object] +true +>>> [] +[type Function] +true +undefined +false + +true +>>> +[type Function] +false +[type Function] +true +[object Object] +true +>>> new Foo () +[type Function] +false +[type Function] +true +[object Object] +true +>>> +[type Function] +false +[type Function] +true +[object Object] +true +>>> new this.Foo () +[type Function] +false +[type Function] +true +[object Object] +true +undefined +>>> +undefined +undefined +[type Function] +undefined +undefined +undefined +>>> new Foo () - without prototype +undefined +undefined +[type Function] +undefined +undefined +undefined +>>> +undefined +undefined +[type Function] +undefined +undefined +undefined +>>> new this.Foo () - without prototype +undefined +false +[type Function] +true +undefined +false +>>> 42 +[type Function] +false +[type Function] +true +[type Object] +true +>>> true +[type Function] +false +[type Function] +true +[type Object] +true diff --git a/test/trace/construct-properties.as b/test/trace/construct-properties.as new file mode 100644 index 0000000..990952f --- /dev/null +++ b/test/trace/construct-properties.as @@ -0,0 +1,36 @@ +// makeswf -v 7 -s 200x150 -r 1 -o construct-properties.swf construct-properties.as + +trace ("Check initial properties of script-constructed objects"); + +function check (o, desc) +{ + trace (">>> " + desc); + trace (o.constructor); + trace (o.hasOwnProperty ("constructor")); + trace (o.__constructor__); + trace (o.hasOwnProperty ("__constructor__")); + trace (o.__proto__); + trace (o.hasOwnProperty ("__proto__")); +}; + +check (new Object (), "new Object ()"); +check ({}, "{}"); +check ([], "[]"); +Foo = function () { + check (this, ""); +}; +check (new Foo (), "new Foo ()"); +check (new this.Foo (), "new this.Foo ()"); +ASSetPropFlags (Foo, "prototype", 0, 7); +delete Foo.prototype; +trace (Foo.prototype); +x = new Foo (); +check (x, "new Foo () - without prototype"); +Foo.__proto__ = null; +x = new Foo (); +x.hasOwnProperty = Object.prototype.hasOwnProperty; +check (x, "new this.Foo () - without prototype"); +check (42, "42"); +check (true, "true"); + +loadMovie ("FSCommand:quit", ""); diff-tree 919d9074df7d913998bc38edf3423f12eccdd4b8 (from 4701b184371267c89a81413b410cae921df9027f) Author: Benjamin Otte <otte at gnome.org> Date: Mon Aug 20 11:00:12 2007 +0200 rework init code to set constructor and __constructor__ properties correctly diff --git a/libswfdec/swfdec_as_object.c b/libswfdec/swfdec_as_object.c index 0bb7209..749b0d7 100644 --- a/libswfdec/swfdec_as_object.c +++ b/libswfdec/swfdec_as_object.c @@ -882,6 +882,7 @@ void swfdec_as_object_create (SwfdecAsFunction *fun, guint n_args, const SwfdecAsValue *args) { + SwfdecAsValue val; SwfdecAsObject *new; SwfdecAsContext *context; SwfdecAsFunction *cur; @@ -919,11 +920,27 @@ swfdec_as_object_create (SwfdecAsFunctio type = SWFDEC_TYPE_AS_OBJECT; size = sizeof (SwfdecAsObject); } - if (!swfdec_as_context_use_mem (context, size)) - return; - new = g_object_new (type, NULL); - swfdec_as_object_add (new, context, size); - swfdec_as_object_set_constructor (new, SWFDEC_AS_OBJECT (fun)); + if (swfdec_as_context_use_mem (context, size)) { + new = g_object_new (type, NULL); + swfdec_as_object_add (new, context, size); + /* set initial variables */ + if (swfdec_as_object_get_variable (SWFDEC_AS_OBJECT (fun), SWFDEC_AS_STR_prototype, &val)) { + swfdec_as_object_set_variable_and_flags (new, SWFDEC_AS_STR___proto__, + &val, SWFDEC_AS_VARIABLE_HIDDEN | SWFDEC_AS_VARIABLE_PERMANENT); + } + SWFDEC_AS_VALUE_SET_OBJECT (&val, SWFDEC_AS_OBJECT (fun)); + if (context->version < 7) { + swfdec_as_object_set_variable_and_flags (new, SWFDEC_AS_STR_constructor, + &val, SWFDEC_AS_VARIABLE_HIDDEN); + } + if (context->version <= 5) + SWFDEC_AS_VALUE_SET_UNDEFINED (&val); + swfdec_as_object_set_variable_and_flags (new, SWFDEC_AS_STR___constructor__, + &val, SWFDEC_AS_VARIABLE_HIDDEN); + } else { + /* need to do this, since we must push something to the frame stack */ + new = NULL; + } swfdec_as_function_call (fun, new, n_args, args, NULL); context->frame->construct = TRUE; } @@ -937,7 +954,7 @@ swfdec_as_object_create (SwfdecAsFunctio * variables set automatically, but for objects you created yourself, you want * to call this function. This is essentially the same as the following script * code: - * |[ object.__constructor__ = construct; + * |[ object.constructor = construct; * object.__proto__ = construct.prototype; ]| **/ void @@ -1083,6 +1100,8 @@ swfdec_as_object_init_context (SwfdecAsC } /* now, set our own */ swfdec_as_object_set_variable (object, SWFDEC_AS_STR_prototype, &val); + SWFDEC_AS_VALUE_SET_OBJECT (&val, object); + swfdec_as_object_set_variable (proto, SWFDEC_AS_STR_constructor, &val); if (version > 5) { swfdec_as_object_add_function (proto, SWFDEC_AS_STR_addProperty, diff --git a/libswfdec/swfdec_movie.c b/libswfdec/swfdec_movie.c index 0ddb8ff..243dabc 100644 --- a/libswfdec/swfdec_movie.c +++ b/libswfdec/swfdec_movie.c @@ -377,7 +377,7 @@ swfdec_movie_run_construct (SwfdecMovie player = SWFDEC_PLAYER (SWFDEC_AS_OBJECT (movie)->context); g_queue_remove (player->construct_queue, movie); swfdec_movie_execute_script (movie, SWFDEC_EVENT_CONSTRUCT); - swfdec_as_object_call (SWFDEC_AS_OBJECT (movie), SWFDEC_AS_STR___constructor__, 0, NULL, NULL); + swfdec_as_object_call (SWFDEC_AS_OBJECT (movie), SWFDEC_AS_STR_constructor, 0, NULL, NULL); } void diff-tree 4701b184371267c89a81413b410cae921df9027f (from 3aa1d8b9d0bbf5897fdf678f845312476bb16a0d) Author: Benjamin Otte <otte at gnome.org> Date: Mon Aug 20 10:59:19 2007 +0200 functions in Flash > 5 print "[type Function]", too diff --git a/libswfdec/swfdec_as_types.c b/libswfdec/swfdec_as_types.c index 8d69fbb..11b11f2 100644 --- a/libswfdec/swfdec_as_types.c +++ b/libswfdec/swfdec_as_types.c @@ -31,6 +31,7 @@ #include "swfdec_as_number.h" #include "swfdec_as_stack.h" #include "swfdec_as_strings.h" +#include "swfdec_as_super.h" #include "swfdec_debug.h" #include "swfdec_movie.h" @@ -378,7 +379,9 @@ swfdec_as_value_to_string (SwfdecAsConte swfdec_as_object_call (object, SWFDEC_AS_STR_toString, 0, NULL, &ret); if (SWFDEC_AS_VALUE_IS_STRING (&ret)) return SWFDEC_AS_VALUE_GET_STRING (&ret); - else if (context->version <= 5 && SWFDEC_IS_AS_FUNCTION (SWFDEC_AS_VALUE_GET_OBJECT (value))) + else if (SWFDEC_IS_AS_SUPER (SWFDEC_AS_VALUE_GET_OBJECT (value))) + return SWFDEC_AS_STR__type_Object_; + else if (SWFDEC_IS_AS_FUNCTION (SWFDEC_AS_VALUE_GET_OBJECT (value))) return SWFDEC_AS_STR__type_Function_; else return SWFDEC_AS_STR__type_Object_; diff-tree 3aa1d8b9d0bbf5897fdf678f845312476bb16a0d (from 13378254ef972458c30937ac80dd8fb056358239) Author: Benjamin Otte <otte at gnome.org> Date: Mon Aug 20 10:58:34 2007 +0200 fix ActionExtends code It now creates an empty object and sets properties on it instead resetting properties on a default object diff --git a/libswfdec/swfdec_as_interpret.c b/libswfdec/swfdec_as_interpret.c index 3b7c01f..72cf447 100644 --- a/libswfdec/swfdec_as_interpret.c +++ b/libswfdec/swfdec_as_interpret.c @@ -1865,16 +1865,13 @@ swfdec_action_extends (SwfdecAsContext * goto fail; } super = SWFDEC_AS_VALUE_GET_OBJECT (superclass); - prototype = swfdec_as_object_new (cx); + prototype = swfdec_as_object_new_empty (cx); if (prototype == NULL) return; swfdec_as_object_get_variable (super, SWFDEC_AS_STR_prototype, &proto); swfdec_as_object_set_variable (prototype, SWFDEC_AS_STR___proto__, &proto); - swfdec_as_object_delete_variable (prototype, SWFDEC_AS_STR_constructor); - swfdec_as_object_set_variable (prototype, SWFDEC_AS_STR___constructor__, - superclass); - swfdec_as_object_set_variable_flags (prototype, SWFDEC_AS_STR___constructor__, - SWFDEC_AS_VARIABLE_HIDDEN); + swfdec_as_object_set_variable_and_flags (prototype, SWFDEC_AS_STR___constructor__, + superclass, SWFDEC_AS_VARIABLE_HIDDEN); SWFDEC_AS_VALUE_SET_OBJECT (&proto, prototype); swfdec_as_object_set_variable (SWFDEC_AS_VALUE_GET_OBJECT (subclass), SWFDEC_AS_STR_prototype, &proto); diff-tree 13378254ef972458c30937ac80dd8fb056358239 (from 1ce09b255198bdb2908cbc251e07bee76998e6a1) Author: Benjamin Otte <otte at gnome.org> Date: Mon Aug 20 09:51:27 2007 +0200 native objects have "constructor" set, not "__constructor__" diff --git a/libswfdec/swfdec_as_object.c b/libswfdec/swfdec_as_object.c index bfe02f5..0bb7209 100644 --- a/libswfdec/swfdec_as_object.c +++ b/libswfdec/swfdec_as_object.c @@ -961,7 +961,7 @@ swfdec_as_object_set_constructor (Swfdec swfdec_as_object_set_variable_and_flags (object, SWFDEC_AS_STR___proto__, &val, SWFDEC_AS_VARIABLE_HIDDEN | SWFDEC_AS_VARIABLE_PERMANENT); SWFDEC_AS_VALUE_SET_OBJECT (&val, construct); - swfdec_as_object_set_variable_and_flags (object, SWFDEC_AS_STR___constructor__, + swfdec_as_object_set_variable_and_flags (object, SWFDEC_AS_STR_constructor, &val, SWFDEC_AS_VARIABLE_HIDDEN); }