CVSROOT: /sources/gnash Module name: gnash Changes by: Sandro Santilli <strk> 07/09/12 16:17:05
Modified files: . : ChangeLog server/asobj : AsBroadcaster.cpp testsuite/actionscript.all: AsBroadcaster.as Log message: * server/asobj/AsBroadcaster.cpp: add support for passing arguments for broadcasted message handlers. * testsuite/actionscript.all/AsBroadcaster.as: add tests for arguments passed to broadcasted messages. CVSWeb URLs: http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.4294&r2=1.4295 http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/AsBroadcaster.cpp?cvsroot=gnash&r1=1.2&r2=1.3 http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/AsBroadcaster.as?cvsroot=gnash&r1=1.3&r2=1.4 Patches: Index: ChangeLog =================================================================== RCS file: /sources/gnash/gnash/ChangeLog,v retrieving revision 1.4294 retrieving revision 1.4295 diff -u -b -r1.4294 -r1.4295 --- ChangeLog 12 Sep 2007 15:21:42 -0000 1.4294 +++ ChangeLog 12 Sep 2007 16:17:04 -0000 1.4295 @@ -1,5 +1,12 @@ 2007-09-12 Sandro Santilli <[EMAIL PROTECTED]> + * server/asobj/AsBroadcaster.cpp: add support for passing arguments + for broadcasted message handlers. + * testsuite/actionscript.all/AsBroadcaster.as: add tests for arguments + passed to broadcasted messages. + +2007-09-12 Sandro Santilli <[EMAIL PROTECTED]> + * server/as_function.{cpp,h}: make 'prototype' a proper property, change getPrototype() to return by intrusive_ptr. * server/sprite_instance.cpp: update call to getPrototype(). Index: server/asobj/AsBroadcaster.cpp =================================================================== RCS file: /sources/gnash/gnash/server/asobj/AsBroadcaster.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -b -r1.2 -r1.3 --- server/asobj/AsBroadcaster.cpp 11 Sep 2007 17:41:11 -0000 1.2 +++ server/asobj/AsBroadcaster.cpp 12 Sep 2007 16:17:04 -0000 1.3 @@ -28,6 +28,7 @@ #include "builtin_function.h" #include "VM.h" // for getPlayerVersion() #include "Object.h" // for getObjectInterface +#include "action.h" // for call_method #include <boost/algorithm/string/case_conv.hpp> // for PROPNAME @@ -41,7 +42,7 @@ /// of the current VM std::string _eventName; - /// Environment to use for marhalling and functions invokation + /// Environment to use for marshalling and functions invokation as_environment& _env; // These two will be needed for consistency checking @@ -51,6 +52,8 @@ /// Number of event dispatches unsigned int _dispatched; + const fn_call& _fn; + public: /// @param eName name of event, will be converted to lowercase if needed @@ -58,11 +61,12 @@ /// @param env Environment to use for marhalling and functions invocation. /// Note that visit() will push values on it ! /// - BroadcasterVisitor(const std::string& eName, as_environment& env) + BroadcasterVisitor(const fn_call& fn) : - _eventName(PROPNAME(eName)), - _env(env), - _dispatched(0) + _eventName(PROPNAME(fn.arg(0).to_string())), + _env(fn.env()), + _dispatched(0), + _fn(fn) { } @@ -72,11 +76,21 @@ boost::intrusive_ptr<as_object> o = v.to_object(); if ( ! o ) return; + as_value method; + o->get_member(_eventName, &method); + + if ( method.is_function() ) + { + #ifndef NDEBUG size_t oldStackSize = _env.stack_size(); #endif - /*as_value ret =*/ o->callMethod(_eventName, _env); + call_method(method, &_env, o.get(), _fn.nargs-1, _fn.offset()-1); + assert ( _env.stack_size() == oldStackSize ); + + } + ++_dispatched; } @@ -329,7 +343,7 @@ return as_value(); } - BroadcasterVisitor visitor(fn.arg(0).to_string(), fn.env()); + BroadcasterVisitor visitor(fn); listeners->visitAll(visitor); unsigned int dispatched = visitor.eventsDispatched(); Index: testsuite/actionscript.all/AsBroadcaster.as =================================================================== RCS file: /sources/gnash/gnash/testsuite/actionscript.all/AsBroadcaster.as,v retrieving revision 1.3 retrieving revision 1.4 diff -u -b -r1.3 -r1.4 --- testsuite/actionscript.all/AsBroadcaster.as 11 Sep 2007 17:41:11 -0000 1.3 +++ testsuite/actionscript.all/AsBroadcaster.as 12 Sep 2007 16:17:05 -0000 1.4 @@ -19,7 +19,7 @@ // compile this test case with Ming makeswf, and then // execute it like this gnash -1 -r 0 -v out.swf -rcsid="$Id: AsBroadcaster.as,v 1.3 2007/09/11 17:41:11 strk Exp $"; +rcsid="$Id: AsBroadcaster.as,v 1.4 2007/09/12 16:17:05 strk Exp $"; #include "check.as" @@ -230,10 +230,37 @@ ret = bcast.broadcastMessage('onUnexistent'); check_equals(typeof(ret), 'undefined'); -// TODO: test broadcastMessage with additional arguments -// and effects of overriding Function.apply -// (should have no effects, being broadcastMessage -// a native functioN) +//-------------------------------- +// broadcaseMessage with args +//-------------------------------- + +_root.total = 0; +o = {}; +o.addThis = function(what) +{ + //note("Arg0 is "+what); + _root.total += what; +}; +o.setSum = function() +{ + _root.total = 0; + for (var i=0; i< arguments.length; ++i) + { + //note("Arg "+i+" is "+arguments[i]); + _root.total += arguments[i]; + } +}; +bcast.addListener(o); +bcast.broadcastMessage('addThis', 3); +check_equals(_root.total, 3); +bcast.broadcastMessage('addThis', 2); +check_equals(_root.total, 5); +bcast.broadcastMessage('setSum', 1, 2, 3, 4); +check_equals(_root.total, 10); +bcast.broadcastMessage('setSum', 1, 2, 3, 4, 5, 6, 7, 8); +check_equals(_root.total, 36); +bcast.broadcastMessage('setSum', 'one', 'two', 'three'); +check_equals(_root.total, '0onetwothree'); #endif // OUTPUT_VERSION >= 6 _______________________________________________ Gnash-commit mailing list Gnash-commit@gnu.org http://lists.gnu.org/mailman/listinfo/gnash-commit