gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog server/timers.cpp server/timers...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/timers.cpp server/timers...
Date: Fri, 30 Mar 2007 10:18:29 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  07/03/30 10:18:29

Modified files:
        .              : ChangeLog 
        server         : timers.cpp timers.h 
        testsuite/misc-ming.all: intervalTest.as intervalTestRunner.cpp 

Log message:
                * server/timers.{cpp,h}: add support for passing arguments to
                  setInterval() callbacks.
                * testsuite/misc-ming.all/: intervalTest.as, 
intervalTestRunner.cpp:
                  All tests pass now.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2729&r2=1.2730
http://cvs.savannah.gnu.org/viewcvs/gnash/server/timers.cpp?cvsroot=gnash&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/gnash/server/timers.h?cvsroot=gnash&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/misc-ming.all/intervalTest.as?cvsroot=gnash&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/misc-ming.all/intervalTestRunner.cpp?cvsroot=gnash&r1=1.2&r2=1.3

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2729
retrieving revision 1.2730
diff -u -b -r1.2729 -r1.2730
--- ChangeLog   30 Mar 2007 09:31:48 -0000      1.2729
+++ ChangeLog   30 Mar 2007 10:18:29 -0000      1.2730
@@ -1,5 +1,12 @@
 2007-03-30 Sandro Santilli <address@hidden>
 
+       * server/timers.{cpp,h}: add support for passing arguments to
+         setInterval() callbacks.
+       * testsuite/misc-ming.all/: intervalTest.as, intervalTestRunner.cpp:
+         All tests pass now.
+
+2007-03-30 Sandro Santilli <address@hidden>
+
        * testsuite/misc-ming.all/: intervalTest.as, intervalTestRunner.cpp:
          Add test for setInterval() calls with additinal args (Gnash fails).
        * server/asobj/xmlsocket.cpp: don't attempt to send

Index: server/timers.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/timers.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- server/timers.cpp   22 Mar 2007 22:37:45 -0000      1.26
+++ server/timers.cpp   30 Mar 2007 10:18:29 -0000      1.27
@@ -18,7 +18,7 @@
 //
 //
 
-/* $Id: timers.cpp,v 1.26 2007/03/22 22:37:45 bjacques Exp $ */
+/* $Id: timers.cpp,v 1.27 2007/03/30 10:18:29 strk Exp $ */
 
 #include "timers.h"
 #include "as_function.h" // for class as_function
@@ -60,6 +60,19 @@
   }
 
   void
+  Timer::setInterval(as_function& method, unsigned ms, 
boost::intrusive_ptr<as_object> this_ptr, as_environment *env,
+                 std::vector<as_value>& args)
+  {
+    _function = &method;
+    _interval = ms * 1000; // transform to microseconds 
+    //log_msg("_interval microseconds: %lu", _interval);
+    _env = env;
+    _object = this_ptr;
+    _args = args;
+    start();
+  }
+
+  void
   Timer::clearInterval()
   {
     _interval = 0;
@@ -105,7 +118,19 @@
     //log_msg("INTERVAL ID is %d\n", getIntervalID());
 
     as_value timer_method(_function.get());
-    as_value val = call_method(timer_method, _env, _object.get(), 0, 0);
+
+    // Push args to the as_environment stack if needed
+    for ( ArgsContainer::reverse_iterator it=_args.rbegin(), 
itEnd=_args.rend();
+                   it != itEnd; ++it )
+    {
+           //log_msg("Env-pushing %s", it->to_debug_string().c_str());
+           _env->push(*it);
+    }
+
+    size_t firstArgBottomIndex = _env->stack_size()-1; 
+
+    as_value val = call_method(timer_method, _env, _object.get(),
+                   _args.size(), firstArgBottomIndex);
 
 }
 
@@ -190,16 +215,15 @@
        // Get interval time
        int ms = int(fn.arg(timer_arg).to_number());
 
-       // TODO: parse arguments !!
-       if ( fn.nargs > timer_arg+1 )
+       // Parse arguments 
+       Timer::ArgsContainer args;
+       for (unsigned i=timer_arg+1; i<fn.nargs; ++i)
        {
-               std::stringstream ss; fn.dump_args(ss);
-               log_error("FIXME: discarding arguments "
-                               "in setInterval(%s) call", ss.str().c_str());
+               args.push_back(fn.arg(i));
        }
 
        Timer timer;
-       timer.setInterval(*as_func, ms, fn.this_ptr, &fn.env());
+       timer.setInterval(*as_func, ms, fn.this_ptr, &fn.env(), args);
     
        movie_root& root = VM::get().getRoot();
        int id = root.add_interval_timer(timer);

Index: server/timers.h
===================================================================
RCS file: /sources/gnash/gnash/server/timers.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- server/timers.h     20 Mar 2007 15:01:20 -0000      1.16
+++ server/timers.h     30 Mar 2007 10:18:29 -0000      1.17
@@ -52,9 +52,10 @@
 /// This is constructed when _global.setInterval() is called.
 /// Instances of this class will be stored in the movie_root singleton.
 ///
-/// A timer has a function to call, a context in which to call it, and
-/// interval specifying how often the function must be called.
-//
+/// A timer has a function to call, a context in which to call it, a
+/// list of arguments and an interval specifying how often the function must be
+/// called.
+///
 /// It is *not* a "smart" timer, which is
 /// it will *not* automatically execute at given intervals. Rather, it
 /// will be movie_root responsibility to execute the timer-associated
@@ -94,6 +95,31 @@
       ///
       void setInterval(as_function& method, unsigned ms, 
boost::intrusive_ptr<as_object> this_ptr, as_environment *env);
 
+      /// Setup the Timer, enabling it.
+      //
+      /// @param method
+      ///      The function to call from execution operator.
+      ///      Will be stored in an intrusive_ptr.
+      ///
+      /// @param ms
+      ///      The number of milliseconds between expires.
+      ///
+      /// @param this_ptr
+      ///      The object to be used as 'this' pointer when calling the
+      ///      associated function. Will be stored in an intrusive_ptr.
+      ///      It is allowed to be NULL as long as fn_call is allowed
+      ///      a NULL as 'this_ptr' (we might want to change this).
+      ///
+      /// @param env
+      ///      The environment in which the associated function will be run.
+      ///      Not sure we should provide this rather then extracting from 
this_ptr...
+      ///
+      /// @param args
+      ///      The list of arguments to pass to the function being invoked.
+      ///
+      void setInterval(as_function& method, unsigned ms, 
boost::intrusive_ptr<as_object> this_ptr, as_environment *env,
+                     std::vector<as_value>& args);
+
       /// Clear the timer, ready for reuse
       //
       /// When a Timer is cleared, the expired() function
@@ -112,6 +138,8 @@
       /// Execute associated function properly setting up context
       void operator() ();
       
+      /// Arguments list type
+      typedef std::vector<as_value> ArgsContainer;
       
 
 private:
@@ -137,6 +165,8 @@
       /// how to keep this alive ?
       as_environment *_env;
 
+      /// List of arguments
+      ArgsContainer _args;
 };
   
   as_value timer_setinterval(const fn_call& fn);

Index: testsuite/misc-ming.all/intervalTest.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/misc-ming.all/intervalTest.as,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- testsuite/misc-ming.all/intervalTest.as     30 Mar 2007 09:31:48 -0000      
1.3
+++ testsuite/misc-ming.all/intervalTest.as     30 Mar 2007 10:18:29 -0000      
1.4
@@ -51,7 +51,7 @@
 };
 
 push_args = function() {
-       xcheck_equals(arguments.length, 3);
+       check_equals(arguments.length, 3);
        clearInterval(push_interval);
        xtrace("Pushing "+arguments.length+" args");
        for (var i=0; i<arguments.length; i++)

Index: testsuite/misc-ming.all/intervalTestRunner.cpp
===================================================================
RCS file: /sources/gnash/gnash/testsuite/misc-ming.all/intervalTestRunner.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- testsuite/misc-ming.all/intervalTestRunner.cpp      30 Mar 2007 09:31:48 
-0000      1.2
+++ testsuite/misc-ming.all/intervalTestRunner.cpp      30 Mar 2007 10:18:29 
-0000      1.3
@@ -113,7 +113,8 @@
        check_equals(tmp.to_number(), 4);
 
        root->get_member("pushed_args", &tmp);
-       xcheck_equals(tmp.to_string(), "8,9,10");
+       as_environment env; // needed for proper to_string()
+       check_equals(tmp.to_string(&env), std::string("8,9,10"));
 
        root->get_member("test_completed", &tmp);
        check_equals(tmp.to_number(), 1);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]