[Swfdec] 4 commits - libswfdec/swfdec_as_context.c libswfdec/swfdec_as_interpret.c libswfdec/swfdec_as_object.c libswfdec/swfdec_as_object.h test/trace
Pekka Lampila
medar at kemper.freedesktop.org
Fri Aug 17 13:00:01 PDT 2007
libswfdec/swfdec_as_context.c | 22 ++++------
libswfdec/swfdec_as_interpret.c | 4 +
libswfdec/swfdec_as_object.c | 21 +++++++--
libswfdec/swfdec_as_object.h | 4 -
test/trace/propflags-5.swf |binary
test/trace/propflags-5.swf.trace | 3 +
test/trace/propflags-6.swf |binary
test/trace/propflags-6.swf.trace | 3 +
test/trace/propflags-7.swf |binary
test/trace/propflags-7.swf.trace | 3 +
test/trace/propflags.as | 83 +++++++++++++++++++++++++++++++++++++++
11 files changed, 121 insertions(+), 22 deletions(-)
New commits:
diff-tree 8ea0acbb24b2faaa135c7ca793483b818c5621b9 (from bd0bd75bc96be5c3be3a5cb3aa4c3bb26ac0a3c2)
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Fri Aug 17 22:52:50 2007 +0300
Fix propflags test case by sorting the traced arrays.
diff --git a/test/trace/propflags-5.swf b/test/trace/propflags-5.swf
index b26242b..644c5ac 100644
Binary files a/test/trace/propflags-5.swf and b/test/trace/propflags-5.swf differ
diff --git a/test/trace/propflags-5.swf.trace b/test/trace/propflags-5.swf.trace
index 7026d1f..eeaa55a 100644
--- a/test/trace/propflags-5.swf.trace
+++ b/test/trace/propflags-5.swf.trace
@@ -1,3 +1,3 @@
-Hidden: 7,5,3,1,__constructor__,constructor,__proto__
-Constant: 7,6,5,4
+Hidden: 1,3,5,7,__constructor__,__proto__,constructor
+Constant: 4,5,6,7
Permanent:
diff --git a/test/trace/propflags-6.swf b/test/trace/propflags-6.swf
index 93c2e52..2af13d8 100644
Binary files a/test/trace/propflags-6.swf and b/test/trace/propflags-6.swf differ
diff --git a/test/trace/propflags-6.swf.trace b/test/trace/propflags-6.swf.trace
index a7eb732..8d59d4e 100644
--- a/test/trace/propflags-6.swf.trace
+++ b/test/trace/propflags-6.swf.trace
@@ -1,3 +1,3 @@
-Hidden: 7,5,3,1,__constructor__,constructor,__proto__
-Constant: 7,6,5,4
-Permanent: 7,6,3,2,__proto__
+Hidden: 1,3,5,7,__constructor__,__proto__,constructor
+Constant: 4,5,6,7
+Permanent: 2,3,6,7,__proto__
diff --git a/test/trace/propflags-7.swf b/test/trace/propflags-7.swf
index 9903ec0..9ae55c5 100644
Binary files a/test/trace/propflags-7.swf and b/test/trace/propflags-7.swf differ
diff --git a/test/trace/propflags-7.swf.trace b/test/trace/propflags-7.swf.trace
index 614873e..74b639d 100644
--- a/test/trace/propflags-7.swf.trace
+++ b/test/trace/propflags-7.swf.trace
@@ -1,3 +1,3 @@
-Hidden: 7,5,3,1,__constructor__,__proto__
-Constant: 7,6,5,4
-Permanent: 7,6,3,2,__proto__
+Hidden: 1,3,5,7,__constructor__,__proto__
+Constant: 4,5,6,7
+Permanent: 2,3,6,7,__proto__
diff --git a/test/trace/propflags.as b/test/trace/propflags.as
index 25ab56b..34ce251 100644
--- a/test/trace/propflags.as
+++ b/test/trace/propflags.as
@@ -19,7 +19,7 @@ function hidden_properties (obj)
}
ASSetPropFlags (obj, hidden, 1, 0);
- return hidden;
+ return hidden.sort ();
}
// loses flags from the properties that are not permanent
@@ -44,7 +44,7 @@ function permanent_properties (obj)
ASSetPropFlags (obj, hidden, 1, 0);
ASSetPropFlags (obj, constant, 3, 0);
- return permanent;
+ return permanent.sort ();
}
function constant_properties (obj)
@@ -67,7 +67,7 @@ function constant_properties (obj)
ASSetPropFlags (obj, hidden, 1, 0);
- return constant;
+ return constant.sort ();
}
var obj = new Object ();
diff-tree bd0bd75bc96be5c3be3a5cb3aa4c3bb26ac0a3c2 (from a37dad992ab5fe037d4ef153d6a80ee0327262d9)
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Fri Aug 17 21:55:16 2007 +0300
Set __proto__ and __constructor__ properties flags
diff --git a/libswfdec/swfdec_as_object.c b/libswfdec/swfdec_as_object.c
index 46c590d..a5e4b08 100644
--- a/libswfdec/swfdec_as_object.c
+++ b/libswfdec/swfdec_as_object.c
@@ -942,7 +942,8 @@ swfdec_as_object_create (SwfdecAsFunctio
* object.__proto__ = construct.prototype; ]|
**/
void
-swfdec_as_object_set_constructor (SwfdecAsObject *object, SwfdecAsObject *construct, gboolean scripted)
+swfdec_as_object_set_constructor (SwfdecAsObject *object,
+ SwfdecAsObject *construct, gboolean scripted)
{
SwfdecAsValue val;
SwfdecAsObject *proto;
@@ -950,7 +951,8 @@ swfdec_as_object_set_constructor (Swfdec
g_return_if_fail (SWFDEC_IS_AS_OBJECT (object));
g_return_if_fail (SWFDEC_IS_AS_OBJECT (construct));
- swfdec_as_object_get_variable (SWFDEC_AS_OBJECT (construct), SWFDEC_AS_STR_prototype, &val);
+ swfdec_as_object_get_variable (SWFDEC_AS_OBJECT (construct),
+ SWFDEC_AS_STR_prototype, &val);
if (SWFDEC_AS_VALUE_IS_OBJECT (&val)) {
proto = SWFDEC_AS_VALUE_GET_OBJECT (&val);
} else {
@@ -959,8 +961,15 @@ swfdec_as_object_set_constructor (Swfdec
}
SWFDEC_AS_VALUE_SET_OBJECT (&val, proto);
swfdec_as_object_set_variable (object, SWFDEC_AS_STR___proto__, &val);
+ swfdec_as_object_set_variable_flags (object, SWFDEC_AS_STR___proto__,
+ SWFDEC_AS_VARIABLE_HIDDEN | SWFDEC_AS_VARIABLE_PERMANENT);
SWFDEC_AS_VALUE_SET_OBJECT (&val, construct);
- swfdec_as_object_set_variable (object, scripted ? SWFDEC_AS_STR_constructor : SWFDEC_AS_STR___constructor__, &val);
+ swfdec_as_object_set_variable (object,
+ scripted ? SWFDEC_AS_STR_constructor : SWFDEC_AS_STR___constructor__,
+ &val);
+ swfdec_as_object_set_variable_flags (object,
+ scripted ? SWFDEC_AS_STR_constructor : SWFDEC_AS_STR___constructor__,
+ SWFDEC_AS_VARIABLE_HIDDEN);
}
/**
diff-tree a37dad992ab5fe037d4ef153d6a80ee0327262d9 (from 87b80853e78f8281e206db513eb9471b192fffaf)
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Fri Aug 17 21:52:19 2007 +0300
Fix ASSetProbFlags function.
diff --git a/libswfdec/swfdec_as_context.c b/libswfdec/swfdec_as_context.c
index 49ec05e..d0017d0 100644
--- a/libswfdec/swfdec_as_context.c
+++ b/libswfdec/swfdec_as_context.c
@@ -1004,21 +1004,18 @@ swfdec_as_context_eval_set (SwfdecAsCont
/*** AS CODE ***/
static void
-swfdec_as_context_ASSetPropFlags_set_one_flag (SwfdecAsObject *object, const char *s, guint *flags)
+swfdec_as_context_ASSetPropFlags_set_one_flag (SwfdecAsObject *object,
+ const char *s, guint *flags)
{
guint real;
- /* first set all relevant flags */
- real = flags[0] & flags[1];
- swfdec_as_object_set_variable_flags (object, s, real);
- /* then unset all relevant flags */
- real = ~flags[0] & flags[1];
- swfdec_as_object_unset_variable_flags (object, s, real);
+ swfdec_as_object_unset_variable_flags (object, s, flags[1]);
+ swfdec_as_object_set_variable_flags (object, s, flags[0]);
}
static gboolean
-swfdec_as_context_ASSetPropFlags_foreach (SwfdecAsObject *object, const char *s,
- SwfdecAsValue *val, guint cur_flags, gpointer data)
+swfdec_as_context_ASSetPropFlags_foreach (SwfdecAsObject *object,
+ const char *s, SwfdecAsValue *val, guint cur_flags, gpointer data)
{
guint *flags = data;
@@ -1047,16 +1044,15 @@ swfdec_as_context_ASSetPropFlags (Swfdec
flags[1] = (argc > 3) ? swfdec_as_value_to_integer (cx, &argv[3]) : -1;
if (SWFDEC_AS_VALUE_IS_NULL (&argv[1])) {
swfdec_as_object_foreach (obj, swfdec_as_context_ASSetPropFlags_foreach, flags);
- } else if (SWFDEC_AS_VALUE_IS_STRING (&argv[1])) {
- char **split = g_strsplit (SWFDEC_AS_VALUE_GET_STRING (&argv[1]), ",", -1);
+ } else {
+ char **split =
+ g_strsplit (swfdec_as_value_to_string (cx, &argv[1]), ",", -1);
guint i;
for (i = 0; split[i]; i++) {
swfdec_as_context_ASSetPropFlags_set_one_flag (obj,
swfdec_as_context_get_string (cx, split[i]), flags);
}
g_strfreev (split);
- } else {
- SWFDEC_FIXME ("ASSetPropFlags for non-null properties not implemented yet");
}
}
diff-tree 87b80853e78f8281e206db513eb9471b192fffaf (from afdf9987d560b315469d8747f56916dcd3235ecb)
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Fri Aug 17 16:42:12 2007 +0300
Add test case for propflags. Rename couple of SwfdecAsVariableFlags.
SWFDEC_AS_VARIABLE_NO_ENUM is now SWFDEC_AS_VARIABLE_HIDDEN and
SWFDEC_AS_VARIABLE_READONLY is now SWFDEC_AS_VARIABLE_CONSTANT
diff --git a/libswfdec/swfdec_as_interpret.c b/libswfdec/swfdec_as_interpret.c
index 47e62d5..f9a2cc2 100644
--- a/libswfdec/swfdec_as_interpret.c
+++ b/libswfdec/swfdec_as_interpret.c
@@ -1870,6 +1870,8 @@ swfdec_action_extends (SwfdecAsContext *
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_VALUE_SET_OBJECT (&proto, prototype);
swfdec_as_object_set_variable (SWFDEC_AS_VALUE_GET_OBJECT (subclass),
SWFDEC_AS_STR_prototype, &proto);
@@ -1883,7 +1885,7 @@ swfdec_action_do_enumerate (SwfdecAsObje
{
SwfdecAsContext *cx = cxp;
- if (flags & SWFDEC_AS_VARIABLE_DONT_ENUM)
+ if (flags & SWFDEC_AS_VARIABLE_HIDDEN)
return TRUE;
swfdec_as_stack_ensure_free (cx, 1);
SWFDEC_AS_VALUE_SET_STRING (swfdec_as_stack_push (cx), variable);
diff --git a/libswfdec/swfdec_as_object.c b/libswfdec/swfdec_as_object.c
index b5dcd25..46c590d 100644
--- a/libswfdec/swfdec_as_object.c
+++ b/libswfdec/swfdec_as_object.c
@@ -245,7 +245,7 @@ swfdec_as_object_do_set (SwfdecAsObject
if (var == NULL)
return;
}
- if (var->flags & SWFDEC_AS_VARIABLE_READONLY)
+ if (var->flags & SWFDEC_AS_VARIABLE_CONSTANT)
return;
if (var->get) {
if (var->set) {
@@ -773,7 +773,7 @@ swfdec_as_object_add_function (SwfdecAsO
SWFDEC_AS_VALUE_SET_OBJECT (&val, SWFDEC_AS_OBJECT (function));
/* FIXME: I'd like to make sure no such property exists yet */
swfdec_as_object_set_variable (object, name, &val);
- swfdec_as_object_set_variable_flags (object, name, SWFDEC_AS_VARIABLE_DONT_ENUM);
+ swfdec_as_object_set_variable_flags (object, name, SWFDEC_AS_VARIABLE_HIDDEN);
return function;
}
@@ -993,7 +993,7 @@ swfdec_as_object_add_variable (SwfdecAsO
var->set = set;
var->flags = 0;
if (set == NULL)
- var->flags |= SWFDEC_AS_VARIABLE_READONLY;
+ var->flags |= SWFDEC_AS_VARIABLE_CONSTANT;
}
/*** AS CODE ***/
diff --git a/libswfdec/swfdec_as_object.h b/libswfdec/swfdec_as_object.h
index 265c6cb..55bfc05 100644
--- a/libswfdec/swfdec_as_object.h
+++ b/libswfdec/swfdec_as_object.h
@@ -27,9 +27,9 @@ G_BEGIN_DECLS
/* NB: matches ASSetPropFlags */
typedef enum {
- SWFDEC_AS_VARIABLE_DONT_ENUM = (1 << 0),
+ SWFDEC_AS_VARIABLE_HIDDEN = (1 << 0),
SWFDEC_AS_VARIABLE_PERMANENT = (1 << 1),
- SWFDEC_AS_VARIABLE_READONLY = (1 << 2),
+ SWFDEC_AS_VARIABLE_CONSTANT = (1 << 2),
SWFDEC_AS_VARIABLE_FLASH6_UP = (1 << 7)
} SwfdecAsVariableFlag;
diff --git a/test/trace/propflags-5.swf b/test/trace/propflags-5.swf
new file mode 100644
index 0000000..b26242b
Binary files /dev/null and b/test/trace/propflags-5.swf differ
diff --git a/test/trace/propflags-5.swf.trace b/test/trace/propflags-5.swf.trace
new file mode 100644
index 0000000..7026d1f
--- /dev/null
+++ b/test/trace/propflags-5.swf.trace
@@ -0,0 +1,3 @@
+Hidden: 7,5,3,1,__constructor__,constructor,__proto__
+Constant: 7,6,5,4
+Permanent:
diff --git a/test/trace/propflags-6.swf b/test/trace/propflags-6.swf
new file mode 100644
index 0000000..93c2e52
Binary files /dev/null and b/test/trace/propflags-6.swf differ
diff --git a/test/trace/propflags-6.swf.trace b/test/trace/propflags-6.swf.trace
new file mode 100644
index 0000000..a7eb732
--- /dev/null
+++ b/test/trace/propflags-6.swf.trace
@@ -0,0 +1,3 @@
+Hidden: 7,5,3,1,__constructor__,constructor,__proto__
+Constant: 7,6,5,4
+Permanent: 7,6,3,2,__proto__
diff --git a/test/trace/propflags-7.swf b/test/trace/propflags-7.swf
new file mode 100644
index 0000000..9903ec0
Binary files /dev/null and b/test/trace/propflags-7.swf differ
diff --git a/test/trace/propflags-7.swf.trace b/test/trace/propflags-7.swf.trace
new file mode 100644
index 0000000..614873e
--- /dev/null
+++ b/test/trace/propflags-7.swf.trace
@@ -0,0 +1,3 @@
+Hidden: 7,5,3,1,__constructor__,__proto__
+Constant: 7,6,5,4
+Permanent: 7,6,3,2,__proto__
diff --git a/test/trace/propflags.as b/test/trace/propflags.as
new file mode 100644
index 0000000..25ab56b
--- /dev/null
+++ b/test/trace/propflags.as
@@ -0,0 +1,83 @@
+// makeswf -v 7 -r 1 -o test-7.swf test.as
+
+function hidden_properties (obj)
+{
+ normal = new Array ();
+ for (prop in obj) {
+ normal.push (prop);
+ }
+
+ hidden = new Array ();
+ ASSetPropFlags (obj, null, 0, 1);
+ for (prop in obj) {
+ for (i = 0; i < normal.length; i++) {
+ if (normal[i] == prop)
+ break;
+ }
+ if (i == normal.length)
+ hidden.push (prop);
+ }
+ ASSetPropFlags (obj, hidden, 1, 0);
+
+ return hidden;
+}
+
+// loses flags from the properties that are not permanent
+function permanent_properties (obj)
+{
+ hidden = hidden_properties (obj);
+ constant = constant_properties (obj);
+
+ ASSetPropFlags (obj, hidden, 0, 1);
+
+ permanent = new Array();
+ for (var prop in obj) {
+ var old = obj[prop];
+ delete obj[prop];
+ if (obj.hasOwnProperty (prop)) {
+ permanent.push (prop);
+ } else {
+ obj[prop] = old;
+ }
+ }
+
+ ASSetPropFlags (obj, hidden, 1, 0);
+ ASSetPropFlags (obj, constant, 3, 0);
+
+ return permanent;
+}
+
+function constant_properties (obj)
+{
+ hidden = hidden_properties (obj);
+
+ ASSetPropFlags (obj, hidden, 0, 1);
+
+ constant = new Array();
+ for (var prop in obj) {
+ var old = obj[prop];
+ var val = "hello " + obj[prop];
+ obj[prop] = val;
+ if (obj[prop] != val) {
+ constant.push (prop);
+ } else {
+ obj[prop] = old;
+ }
+ }
+
+ ASSetPropFlags (obj, hidden, 1, 0);
+
+ return constant;
+}
+
+var obj = new Object ();
+obj[0] = 0;
+for (var i = 1; i <= 7; i++) {
+ obj[i] = i;
+ ASSetPropFlags (obj, i, i, 0);
+}
+trace ("Hidden: " + hidden_properties (obj));
+trace ("Constant: " + constant_properties (obj));
+trace ("Permanent: " + permanent_properties (obj));
+
+loadMovie ("FSCommand:quit", "");
More information about the Swfdec
mailing list