Benjamin Otte
2007-Mar-21 04:50 UTC
[Swfdec] 3 commits - libswfdec/swfdec_js_net_stream.c libswfdec/swfdec_script.c test/trace
libswfdec/swfdec_js_net_stream.c | 42 +++++++++++++++++++++++- libswfdec/swfdec_script.c | 2 - test/trace/Makefile.am | 3 + test/trace/registerclass-previous.c | 49 ++++++++++++++++++++++++++++ test/trace/registerclass-previous.swf |binary test/trace/registerclass-previous.swf.trace | 3 + 6 files changed, 97 insertions(+), 2 deletions(-) New commits: diff-tree b12efb820117b62a7150d13359499678e7dcf31d (from fbd556ee977d205de43503fc43b47edb40bb07d1) Author: Benjamin Otte <otte@gnome.org> Date: Wed Mar 21 12:50:06 2007 +0100 add a test to confirm that registerClass does not effect previous instances diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am index 32583ec..3a7fd4c 100644 --- a/test/trace/Makefile.am +++ b/test/trace/Makefile.am @@ -145,6 +145,9 @@ EXTRA_DIST = \ preload.swf.trace \ prototypes.swf \ prototypes.swf.trace \ + registerclass-previous.c \ + registerclass-previous.swf \ + registerclass-previous.swf.trace \ registerclass-properties.swf \ registerclass-properties.swf.trace \ rotation-5.swf \ diff --git a/test/trace/registerclass-previous.c b/test/trace/registerclass-previous.c new file mode 100644 index 0000000..1ff084c --- /dev/null +++ b/test/trace/registerclass-previous.c @@ -0,0 +1,49 @@ +/* gcc `pkg-config --libs --cflags libming` registerclass-previous.c -o registerclass-previous && ./registerclass-previous + */ + +#include <ming.h> + +int +main (int argc, char **argv) +{ + SWFMovie movie; + SWFMovieClip clip; + SWFDisplayItem item; + + if (Ming_init ()) + return 1; + Ming_useSWFVersion (7); + + movie = newSWFMovie(); + SWFMovie_setRate (movie, 1); + SWFMovie_setDimension (movie, 200, 150); + + clip = newSWFMovieClip (); + SWFMovie_addExport (movie, (SWFBlock) clip, "export"); + item = SWFMovie_add (movie, (SWFBlock) clip); + SWFDisplayItem_setName (item, "m"); + SWFMovie_add (movie, (SWFBlock) compileSWFActionCode ("" + "trace (\"Check that registerClass does not influence previously created instances\");" + "fun = function () {" + " trace (this + \": Constructor\");" + "};" + "fun.prototype = new Object ();" + "fun.prototype.foo = function () {" + " trace (\"foo called on \" + this);" + "};" + "Object.registerClass (\"export\", fun);" + "m.foo ();" + "")); + SWFMovie_nextFrame (movie); + + item = SWFMovie_add (movie, (SWFBlock) clip); + SWFDisplayItem_setName (item, "m2"); + SWFMovie_add (movie, (SWFBlock) compileSWFActionCode ("" + "m.foo ();" + "m2.foo ();" + "stop ();" + "")); + + SWFMovie_save (movie, "registerclass-previous.swf"); + return 0; +} diff --git a/test/trace/registerclass-previous.swf b/test/trace/registerclass-previous.swf new file mode 100644 index 0000000..c8c5475 Binary files /dev/null and b/test/trace/registerclass-previous.swf differ diff --git a/test/trace/registerclass-previous.swf.trace b/test/trace/registerclass-previous.swf.trace new file mode 100644 index 0000000..bdedf43 --- /dev/null +++ b/test/trace/registerclass-previous.swf.trace @@ -0,0 +1,3 @@ +Check that registerClass does not influence previously created instances +_level0.m2: Constructor +foo called on _level0.m2 diff-tree fbd556ee977d205de43503fc43b47edb40bb07d1 (from 9d7d1f6a72cfcbcc94184d350ca0932ca675ba07) Author: Benjamin Otte <otte@gnome.org> Date: Wed Mar 21 12:06:22 2007 +0100 implement NetStream::bytesLoaded and NetStream::bytesTotal diff --git a/libswfdec/swfdec_js_net_stream.c b/libswfdec/swfdec_js_net_stream.c index 2b91bfb..a977ea8 100644 --- a/libswfdec/swfdec_js_net_stream.c +++ b/libswfdec/swfdec_js_net_stream.c @@ -110,8 +110,48 @@ swfdec_js_net_stream_time (JSContext *cx return JS_NewNumberValue (cx, msecs / 1000., vp); } +static JSBool +swfdec_js_net_stream_bytes_loaded (JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + SwfdecNetStream *stream; + + stream = swfdec_scriptable_from_object (cx, obj, SWFDEC_TYPE_NET_STREAM); + if (stream == NULL) + return JS_TRUE; + + if (stream->loader == NULL) { + *vp = INT_TO_JSVAL (0); + return JS_TRUE; + } + + return JS_NewNumberValue (cx, swfdec_loader_get_loaded (stream->loader), vp); +} + +static JSBool +swfdec_js_net_stream_bytes_total (JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + SwfdecNetStream *stream; + gulong bytes; + + stream = swfdec_scriptable_from_object (cx, obj, SWFDEC_TYPE_NET_STREAM); + if (stream == NULL) + return JS_TRUE; + + if (stream->loader == NULL) { + *vp = INT_TO_JSVAL (0); + return JS_TRUE; + } + bytes = swfdec_loader_get_size (stream->loader); + if (bytes == 0) + bytes = swfdec_loader_get_loaded (stream->loader); + + return JS_NewNumberValue (cx, bytes, vp); +} + static JSPropertySpec net_stream_props[] = { - { "time", -1, JSPROP_PERMANENT|JSPROP_READONLY, swfdec_js_net_stream_time, NULL }, + { "bytesLoaded", -1, JSPROP_PERMANENT|JSPROP_READONLY, swfdec_js_net_stream_bytes_loaded, NULL }, + { "bytesTotal", -1, JSPROP_PERMANENT|JSPROP_READONLY, swfdec_js_net_stream_bytes_total, NULL }, + { "time", -1, JSPROP_PERMANENT|JSPROP_READONLY, swfdec_js_net_stream_time, NULL }, { NULL } }; diff-tree 9d7d1f6a72cfcbcc94184d350ca0932ca675ba07 (from badb4883c0eff1236bf7698b759b04355fa9999c) Author: Benjamin Otte <otte@gnome.org> Date: Wed Mar 21 11:44:44 2007 +0100 make named functions set varobj, not scopeChain diff --git a/libswfdec/swfdec_script.c b/libswfdec/swfdec_script.c index 4853d3c..06915d0 100644 --- a/libswfdec/swfdec_script.c +++ b/libswfdec/swfdec_script.c @@ -1795,7 +1795,7 @@ swfdec_action_define_function (JSContext *cx->fp->sp++ = OBJECT_TO_JSVAL (fun->object); } else { jsval val = OBJECT_TO_JSVAL (fun->object); - if (!JS_SetProperty (cx, cx->fp->scopeChain, function_name, &val)) + if (!JS_SetProperty (cx, cx->fp->varobj, function_name, &val)) return JS_FALSE; }