[Swfdec-commits] 2 commits - swfdec/swfdec_as_object.c swfdec/swfdec_as_object.h swfdec/swfdec_as_super.c swfdec/swfdec_movie.c swfdec/swfdec_net_stream.c swfdec/swfdec_video_movie.c test/trace
Pekka Lampila
medar at kemper.freedesktop.org
Fri Jul 11 06:11:51 PDT 2008
swfdec/swfdec_as_object.c | 38 ++++++++++++--------
swfdec/swfdec_as_object.h | 3 +
swfdec/swfdec_as_super.c | 9 +++-
swfdec/swfdec_movie.c | 20 ++++++----
swfdec/swfdec_net_stream.c | 59 +++++++++++++++++---------------
swfdec/swfdec_video_movie.c | 55 ++++++++++++++++++-----------
test/trace/Makefile.am | 9 ++++
test/trace/addProperty-with-5.swf |binary
test/trace/addProperty-with-5.swf.trace | 2 +
test/trace/addProperty-with-6.swf |binary
test/trace/addProperty-with-6.swf.trace | 4 ++
test/trace/addProperty-with-7.swf |binary
test/trace/addProperty-with-7.swf.trace | 4 ++
test/trace/addProperty-with-8.swf |binary
test/trace/addProperty-with-8.swf.trace | 4 ++
test/trace/addProperty-with.as | 34 ++++++++++++++++++
16 files changed, 168 insertions(+), 73 deletions(-)
New commits:
commit 00a293ad7bc39152ac655c4ad1449daac80aa017
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Wed Jul 9 14:11:58 2008 +0300
Add a test for addProperty behaviour in scope chain objects
diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am
index 551e263..3958a4c 100644
--- a/test/trace/Makefile.am
+++ b/test/trace/Makefile.am
@@ -84,6 +84,15 @@ EXTRA_DIST = \
addProperty-set-prototypes-7.swf.trace \
addProperty-set-prototypes-8.swf \
addProperty-set-prototypes-8.swf.trace \
+ addProperty-with.as \
+ addProperty-with-5.swf \
+ addProperty-with-5.swf.trace \
+ addProperty-with-6.swf \
+ addProperty-with-6.swf.trace \
+ addProperty-with-7.swf \
+ addProperty-with-7.swf.trace \
+ addProperty-with-8.swf \
+ addProperty-with-8.swf.trace \
and-or-5.swf \
and-or-5.swf.trace \
and-or-6.swf \
diff --git a/test/trace/addProperty-with-5.swf b/test/trace/addProperty-with-5.swf
new file mode 100644
index 0000000..fc0e875
Binary files /dev/null and b/test/trace/addProperty-with-5.swf differ
diff --git a/test/trace/addProperty-with-5.swf.trace b/test/trace/addProperty-with-5.swf.trace
new file mode 100644
index 0000000..0c3efcd
--- /dev/null
+++ b/test/trace/addProperty-with-5.swf.trace
@@ -0,0 +1,2 @@
+Properties with get and set functions in the scope chain
+undefined
diff --git a/test/trace/addProperty-with-6.swf b/test/trace/addProperty-with-6.swf
new file mode 100644
index 0000000..b6b792e
Binary files /dev/null and b/test/trace/addProperty-with-6.swf differ
diff --git a/test/trace/addProperty-with-6.swf.trace b/test/trace/addProperty-with-6.swf.trace
new file mode 100644
index 0000000..c7ece05
--- /dev/null
+++ b/test/trace/addProperty-with-6.swf.trace
@@ -0,0 +1,4 @@
+Properties with get and set functions in the scope chain
+set_a: hello1
+set_b: hello2
+undefined
diff --git a/test/trace/addProperty-with-7.swf b/test/trace/addProperty-with-7.swf
new file mode 100644
index 0000000..fb57a91
Binary files /dev/null and b/test/trace/addProperty-with-7.swf differ
diff --git a/test/trace/addProperty-with-7.swf.trace b/test/trace/addProperty-with-7.swf.trace
new file mode 100644
index 0000000..c7ece05
--- /dev/null
+++ b/test/trace/addProperty-with-7.swf.trace
@@ -0,0 +1,4 @@
+Properties with get and set functions in the scope chain
+set_a: hello1
+set_b: hello2
+undefined
diff --git a/test/trace/addProperty-with-8.swf b/test/trace/addProperty-with-8.swf
new file mode 100644
index 0000000..af8b5f8
Binary files /dev/null and b/test/trace/addProperty-with-8.swf differ
diff --git a/test/trace/addProperty-with-8.swf.trace b/test/trace/addProperty-with-8.swf.trace
new file mode 100644
index 0000000..c7ece05
--- /dev/null
+++ b/test/trace/addProperty-with-8.swf.trace
@@ -0,0 +1,4 @@
+Properties with get and set functions in the scope chain
+set_a: hello1
+set_b: hello2
+undefined
diff --git a/test/trace/addProperty-with.as b/test/trace/addProperty-with.as
new file mode 100644
index 0000000..3889205
--- /dev/null
+++ b/test/trace/addProperty-with.as
@@ -0,0 +1,34 @@
+// makeswf -v 7 -r 15 -o addProperty-with.swf addProperty-with.as
+
+trace ("Properties with get and set functions in the scope chain");
+
+function get_a () { trace ("get_a"); return "a"; };
+function set_a () { trace ("set_a: " + arguments); };
+
+function get_b () { trace ("get_b"); return "b"; };
+function set_b () { trace ("set_b: " + arguments); };
+
+function get_c () { trace ("get_c"); return "c"; };
+
+var a = { b: {}, c: {} };
+a.addProperty ("test", get_a, set_a);
+a.b.__proto__ = {};
+a.b.__proto__.addProperty ("test", get_b, set_b);
+with (a) {
+ test = "hello1";
+ with (b) {
+ test = "hello2";
+ }
+}
+
+a.c.__proto__.addProperty ("test", get_c, null);
+with (a) {
+ with (c) {
+ test = "hello3";
+ }
+}
+ASSetPropFlags (a.c, "__proto__", 0, 7);
+a.c.__proto__ = null;
+trace (a.c.test);
+
+getURL ("FSCommand:quit", "");
commit 05e56fd252d962f2ed7e522aa7091649110fa53b
Author: Pekka Lampila <pekka.lampila at iki.fi>
Date: Wed Jul 9 14:07:13 2008 +0300
Allow object class's get vfunc have NULL as value, and add ignore_pboject
When value == NULL, the steps needed to get the value should be skipped. For
example running the get function for addProperty variables.
ignore_pobject is used to tell that certain variable should be considered to be
part of the original object even if it's in the __proto__. This is the case for properties added with addProperty.
diff --git a/swfdec/swfdec_as_object.c b/swfdec/swfdec_as_object.c
index e6a7862..5e9780f 100644
--- a/swfdec/swfdec_as_object.c
+++ b/swfdec/swfdec_as_object.c
@@ -237,7 +237,8 @@ swfdec_as_object_variable_enabled_in_version (SwfdecAsVariable *var,
static gboolean
swfdec_as_object_do_get (SwfdecAsObject *object, SwfdecAsObject *orig,
- const char *variable, SwfdecAsValue *val, guint *flags)
+ const char *variable, SwfdecAsValue *val, guint *flags,
+ gboolean *ignore_pobject)
{
SwfdecAsVariable *var = swfdec_as_object_hash_lookup (object, variable);
@@ -249,14 +250,19 @@ swfdec_as_object_do_get (SwfdecAsObject *object, SwfdecAsObject *orig,
object->context->version))
return FALSE;
- if (var->get) {
- swfdec_as_function_call (var->get, orig, 0, NULL, val);
- swfdec_as_context_run (object->context);
- *flags = var->flags;
- } else {
- *val = var->value;
- *flags = var->flags;
+ // only run get function, if we are getting the value
+ if (val != NULL) {
+ if (var->get) {
+ swfdec_as_function_call (var->get, orig, 0, NULL, val);
+ swfdec_as_context_run (object->context);
+ } else {
+ *val = var->value;
+ }
}
+
+ *flags = var->flags;
+ *ignore_pobject = var->get != NULL;
+
return TRUE;
}
@@ -933,38 +939,40 @@ swfdec_as_object_get_variable_and_flags (SwfdecAsObject *object,
{
SwfdecAsObjectClass *klass;
guint i;
- SwfdecAsValue tmp_val;
guint tmp_flags;
SwfdecAsObject *tmp_pobject, *cur;
+ gboolean ignore_pobject;
g_return_val_if_fail (SWFDEC_IS_AS_OBJECT (object), FALSE);
g_return_val_if_fail (variable != NULL, FALSE);
- if (value == NULL)
- value = &tmp_val;
if (flags == NULL)
flags = &tmp_flags;
if (pobject == NULL)
pobject = &tmp_pobject;
+ *pobject = object;
cur = object;
for (i = 0; i <= SWFDEC_AS_OBJECT_PROTOTYPE_RECURSION_LIMIT && cur != NULL; i++) {
klass = SWFDEC_AS_OBJECT_GET_CLASS (cur);
- if (klass->get (cur, object, variable, value, flags)) {
- *pobject = cur;
+ if (klass->get (cur, object, variable, value, flags, &ignore_pobject)) {
+ if (!ignore_pobject)
+ *pobject = cur;
return TRUE;
}
cur = swfdec_as_object_get_prototype_internal (cur);
}
if (i > SWFDEC_AS_OBJECT_PROTOTYPE_RECURSION_LIMIT) {
swfdec_as_context_abort (object->context, "Prototype recursion limit exceeded");
- SWFDEC_AS_VALUE_SET_UNDEFINED (value);
+ if (value != NULL)
+ SWFDEC_AS_VALUE_SET_UNDEFINED (value);
*flags = 0;
*pobject = NULL;
return FALSE;
}
//SWFDEC_WARNING ("no such variable %s", variable);
- SWFDEC_AS_VALUE_SET_UNDEFINED (value);
+ if (value != NULL)
+ SWFDEC_AS_VALUE_SET_UNDEFINED (value);
*flags = 0;
*pobject = NULL;
return FALSE;
diff --git a/swfdec/swfdec_as_object.h b/swfdec/swfdec_as_object.h
index cd84e5d..dc68987 100644
--- a/swfdec/swfdec_as_object.h
+++ b/swfdec/swfdec_as_object.h
@@ -81,7 +81,8 @@ struct _SwfdecAsObjectClass {
SwfdecAsObject * orig,
const char * variable,
SwfdecAsValue * val,
- guint * flags);
+ guint * flags,
+ gboolean * ignore_pobject);
/* set the variable - and return it (or NULL on error) */
void (* set) (SwfdecAsObject * object,
const char * variable,
diff --git a/swfdec/swfdec_as_super.c b/swfdec/swfdec_as_super.c
index 9e67b40..2023467 100644
--- a/swfdec/swfdec_as_super.c
+++ b/swfdec/swfdec_as_super.c
@@ -69,7 +69,8 @@ swfdec_as_super_call (SwfdecAsFunction *function)
static gboolean
swfdec_as_super_get (SwfdecAsObject *object, SwfdecAsObject *orig,
- const char *variable, SwfdecAsValue *val, guint *flags)
+ const char *variable, SwfdecAsValue *val, guint *flags,
+ gboolean *ignore_pobject)
{
SwfdecAsSuper *super = SWFDEC_AS_SUPER (object);
SwfdecAsObjectClass *klass;
@@ -84,15 +85,17 @@ swfdec_as_super_get (SwfdecAsObject *object, SwfdecAsObject *orig,
for (i = 0; i <= SWFDEC_AS_OBJECT_PROTOTYPE_RECURSION_LIMIT && cur != NULL; i++) {
klass = SWFDEC_AS_OBJECT_GET_CLASS (cur);
/* FIXME: is the orig pointer correct? */
- if (klass->get (cur, super->object, variable, val, flags))
+ if (klass->get (cur, super->object, variable, val, flags, ignore_pobject))
return TRUE;
/* FIXME: need get_prototype_internal here? */
cur = swfdec_as_object_get_prototype (cur);
}
if (i > SWFDEC_AS_OBJECT_PROTOTYPE_RECURSION_LIMIT)
swfdec_as_context_abort (object->context, "Prototype recursion limit exceeded");
- SWFDEC_AS_VALUE_SET_UNDEFINED (val);
+ if (val != NULL)
+ SWFDEC_AS_VALUE_SET_UNDEFINED (val);
*flags = 0;
+ *ignore_pobject = FALSE;
return FALSE;
}
diff --git a/swfdec/swfdec_movie.c b/swfdec/swfdec_movie.c
index 1ac3f7d..fde8766 100644
--- a/swfdec/swfdec_movie.c
+++ b/swfdec/swfdec_movie.c
@@ -1005,7 +1005,8 @@ swfdec_movie_get_root (SwfdecMovie *movie)
static gboolean
swfdec_movie_get_variable (SwfdecAsObject *object, SwfdecAsObject *orig,
- const char *variable, SwfdecAsValue *val, guint *flags)
+ const char *variable, SwfdecAsValue *val, guint *flags,
+ gboolean *ignore_pobject)
{
SwfdecMovie *movie, *ret;
guint prop_id;
@@ -1016,27 +1017,30 @@ swfdec_movie_get_variable (SwfdecAsObject *object, SwfdecAsObject *orig,
return FALSE;
object = SWFDEC_AS_OBJECT (movie);
- if (SWFDEC_AS_OBJECT_CLASS (swfdec_movie_parent_class)->get (object, orig, variable, val, flags))
+ if (SWFDEC_AS_OBJECT_CLASS (swfdec_movie_parent_class)->get (object, orig, variable, val, flags, ignore_pobject))
return TRUE;
+ *flags = 0;
+ *ignore_pobject = FALSE;
+
/* FIXME: check that this is correct */
if (object->context->version > 5 && variable == SWFDEC_AS_STR__global) {
- SWFDEC_AS_VALUE_SET_OBJECT (val, SWFDEC_AS_OBJECT (movie->resource->sandbox));
- *flags = 0;
+ if (val != NULL)
+ SWFDEC_AS_VALUE_SET_OBJECT (val, SWFDEC_AS_OBJECT (movie->resource->sandbox));
return TRUE;
}
ret = swfdec_movie_get_by_name (movie, variable, FALSE);
if (ret) {
- SWFDEC_AS_VALUE_SET_OBJECT (val, SWFDEC_AS_OBJECT (ret));
- *flags = 0;
+ if (val != NULL)
+ SWFDEC_AS_VALUE_SET_OBJECT (val, SWFDEC_AS_OBJECT (ret));
return TRUE;
}
prop_id = swfdec_movie_property_lookup (variable);
if (prop_id != G_MAXUINT) {
- swfdec_movie_property_get (movie, prop_id, val);
- *flags = 0;
+ if (val != NULL)
+ swfdec_movie_property_get (movie, prop_id, val);
return TRUE;
}
diff --git a/swfdec/swfdec_net_stream.c b/swfdec/swfdec_net_stream.c
index 885b634..40442c8 100644
--- a/swfdec/swfdec_net_stream.c
+++ b/swfdec/swfdec_net_stream.c
@@ -464,47 +464,54 @@ swfdec_net_stream_dispose (GObject *object)
static gboolean
swfdec_net_stream_get_variable (SwfdecAsObject *object, SwfdecAsObject *orig,
- const char *variable, SwfdecAsValue *val, guint *flags)
+ const char *variable, SwfdecAsValue *val, guint *flags,
+ gboolean *ignore_pobject)
{
SwfdecNetStream *stream;
- if (SWFDEC_AS_OBJECT_CLASS (swfdec_net_stream_parent_class)->get (object, orig, variable, val, flags))
+ if (SWFDEC_AS_OBJECT_CLASS (swfdec_net_stream_parent_class)->get (object, orig, variable, val, flags, ignore_pobject))
return TRUE;
+ *flags = 0;
+ *ignore_pobject = FALSE;
+
stream = SWFDEC_NET_STREAM (object);
/* FIXME: need case insensitive comparisons? */
if (variable == SWFDEC_AS_STR_time) {
guint msecs;
- if (stream->flvdecoder == NULL ||
- !swfdec_flv_decoder_get_video_info (stream->flvdecoder, &msecs, NULL)) {
- SWFDEC_AS_VALUE_SET_INT (val, 0);
- } else {
- if (msecs >= stream->current_time)
- msecs = 0;
- else
- msecs = stream->current_time - msecs;
- SWFDEC_AS_VALUE_SET_NUMBER (val, msecs / 1000.);
+ if (val != NULL) {
+ if (stream->flvdecoder == NULL ||
+ !swfdec_flv_decoder_get_video_info (stream->flvdecoder, &msecs, NULL)) {
+ SWFDEC_AS_VALUE_SET_INT (val, 0);
+ } else {
+ if (msecs >= stream->current_time)
+ msecs = 0;
+ else
+ msecs = stream->current_time - msecs;
+ SWFDEC_AS_VALUE_SET_NUMBER (val, msecs / 1000.);
+ }
}
- *flags = 0;
return TRUE;
} else if (variable == SWFDEC_AS_STR_bytesLoaded) {
- if (stream->loader == NULL)
- SWFDEC_AS_VALUE_SET_INT (val, 0);
- else
- SWFDEC_AS_VALUE_SET_NUMBER (val, swfdec_loader_get_loaded (stream->loader));
- *flags = 0;
+ if (val != NULL) {
+ if (stream->loader == NULL)
+ SWFDEC_AS_VALUE_SET_INT (val, 0);
+ else
+ SWFDEC_AS_VALUE_SET_NUMBER (val, swfdec_loader_get_loaded (stream->loader));
+ }
return TRUE;
} else if (variable == SWFDEC_AS_STR_bytesTotal) {
- glong bytes;
- if (stream->loader == NULL) {
- bytes = 0;
- } else {
- bytes = swfdec_loader_get_size (stream->loader);
- if (bytes < 0)
- bytes = swfdec_loader_get_loaded (stream->loader);
+ if (val != NULL) {
+ glong bytes;
+ if (stream->loader == NULL) {
+ bytes = 0;
+ } else {
+ bytes = swfdec_loader_get_size (stream->loader);
+ if (bytes < 0)
+ bytes = swfdec_loader_get_loaded (stream->loader);
+ }
+ SWFDEC_AS_VALUE_SET_NUMBER (val, bytes);
}
- SWFDEC_AS_VALUE_SET_NUMBER (val, bytes);
- *flags = 0;
return TRUE;
} else if (variable == SWFDEC_AS_STR_bufferLength) {
SWFDEC_STUB ("Netstream.bufferLength (get)");
diff --git a/swfdec/swfdec_video_movie.c b/swfdec/swfdec_video_movie.c
index 897aa8c..d7d409b 100644
--- a/swfdec/swfdec_video_movie.c
+++ b/swfdec/swfdec_video_movie.c
@@ -104,43 +104,58 @@ swfdec_video_movie_set_ratio (SwfdecMovie *movie)
static gboolean
swfdec_video_movie_get_variable (SwfdecAsObject *object, SwfdecAsObject *orig,
- const char *variable, SwfdecAsValue *val, guint *flags)
+ const char *variable, SwfdecAsValue *val, guint *flags,
+ gboolean *ignore_pobject)
{
guint version = object->context->version;
SwfdecVideoMovie *video;
+ if (SWFDEC_AS_OBJECT_CLASS (swfdec_video_movie_parent_class)->get (
+ object, orig, variable, val, flags, ignore_pobject))
+ return TRUE;
+
+ *flags = 0;
+ *ignore_pobject = FALSE;
+
video = SWFDEC_VIDEO_MOVIE (object);
if (swfdec_strcmp (version, variable, SWFDEC_AS_STR_width) == 0) {
- guint w;
- if (video->provider) {
- w = swfdec_video_provider_get_width (video->provider);
- } else {
- w = 0;
+ if (val != NULL) {
+ guint w;
+ if (video->provider) {
+ w = swfdec_video_provider_get_width (video->provider);
+ } else {
+ w = 0;
+ }
+ SWFDEC_AS_VALUE_SET_INT (val, w);
}
- SWFDEC_AS_VALUE_SET_INT (val, w);
return TRUE;
} else if (swfdec_strcmp (version, variable, SWFDEC_AS_STR_height) == 0) {
- guint h;
- if (video->provider) {
- h = swfdec_video_provider_get_height (video->provider);
- } else {
- h = 0;
+ if (val != NULL) {
+ guint h;
+ if (video->provider) {
+ h = swfdec_video_provider_get_height (video->provider);
+ } else {
+ h = 0;
+ }
+ SWFDEC_AS_VALUE_SET_INT (val, h);
}
- SWFDEC_AS_VALUE_SET_INT (val, h);
return TRUE;
} else if (swfdec_strcmp (version, variable, SWFDEC_AS_STR_deblocking) == 0) {
- SWFDEC_STUB ("Video.deblocking (get)");
- SWFDEC_AS_VALUE_SET_NUMBER (val, 0);
+ if (val != NULL) {
+ SWFDEC_STUB ("Video.deblocking (get)");
+ SWFDEC_AS_VALUE_SET_NUMBER (val, 0);
+ }
return TRUE;
} else if (swfdec_strcmp (version, variable, SWFDEC_AS_STR_smoothing) == 0) {
- SWFDEC_STUB ("Video.smoothing (get)");
- SWFDEC_AS_VALUE_SET_BOOLEAN (val, FALSE);
+ if (val != NULL) {
+ SWFDEC_STUB ("Video.smoothing (get)");
+ SWFDEC_AS_VALUE_SET_BOOLEAN (val, FALSE);
+ }
return TRUE;
- } else {
- return SWFDEC_AS_OBJECT_CLASS (swfdec_video_movie_parent_class)->get (
- object, orig, variable, val, flags);
}
+
+ return FALSE;
}
static void
More information about the Swfdec-commits
mailing list