gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog server/array.cpp server/array.h...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/array.cpp server/array.h...
Date: Tue, 21 Nov 2006 10:53:08 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  06/11/21 10:53:08

Modified files:
        .              : ChangeLog 
        server         : array.cpp array.h 
        testsuite/actionscript.all: array.as 

Log message:
                * server/array.h: documented ::slice function
                * server/array.cpp: more fixes.
                * testsuite/actionscript.all/array.as: added some tests for
                  invalid calls to Array.slice()

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.1689&r2=1.1690
http://cvs.savannah.gnu.org/viewcvs/gnash/server/array.cpp?cvsroot=gnash&r1=1.43&r2=1.44
http://cvs.savannah.gnu.org/viewcvs/gnash/server/array.h?cvsroot=gnash&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/array.as?cvsroot=gnash&r1=1.10&r2=1.11

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.1689
retrieving revision 1.1690
diff -u -b -r1.1689 -r1.1690
--- ChangeLog   21 Nov 2006 09:47:12 -0000      1.1689
+++ ChangeLog   21 Nov 2006 10:53:08 -0000      1.1690
@@ -1,5 +1,9 @@
 2006-11-21 Sandro Santilli <address@hidden>
 
+       * server/array.h: documented ::slice function
+       * server/array.cpp: more fixes. 
+       * testsuite/actionscript.all/array.as: added some tests for
+         invalid calls to Array.slice()
        * server/array.cpp (slice): handled some unexpected user input.
        * testsuite/actionscript.all/Makefile.am (make check):
          run the all-inclusive testcases (one for each target version).

Index: server/array.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/array.cpp,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -b -r1.43 -r1.44
--- server/array.cpp    21 Nov 2006 10:05:18 -0000      1.43
+++ server/array.cpp    21 Nov 2006 10:53:08 -0000      1.44
@@ -290,35 +290,15 @@
 std::auto_ptr<as_array_object>
 as_array_object::slice(unsigned int start, unsigned int one_past_end)
 {
+       assert(one_past_end >= start);
+       assert(one_past_end <= size());
+       assert(start <= size());
+
        std::auto_ptr<as_array_object> newarray(new as_array_object);
 
        log_msg("Array.slice(%u, %u) called", start, one_past_end);
 
-       if ( one_past_end < start )
-       {
-               // Not wrapped in IF_VERBOSE_ASCODING_ERROR
-               // as I think we should support this somehow
-               log_warning("FIXME: Array.slice(%u, %u) called - "
-                       "expected second argument to be greather "
-                       "or equal first one. What to do in these cases ?",
-                       start, one_past_end);
-               return newarray;
-       }
-
-       size_t newsize = one_past_end - start + 1;
-
-       if ( newsize > elements.size() )
-       {
-               // Not wrapped in IF_VERBOSE_ASCODING_ERROR
-               // as I think we should support this somehow
-               log_warning("FIXME: Array.slice(%u, %u) called on an array "
-                       "with less elements then requested "
-                       "(want %u, have %u). What to do in these cases ?",
-                       start, one_past_end,
-                       newsize, elements.size());
-               return newarray;
-       }
-
+       size_t newsize = one_past_end - start;
        newarray->elements.resize(newsize);
 
        // maybe there's a standard algorithm for this ?
@@ -691,8 +671,11 @@
 
        if (fn.nargs > 2)
        {
-               log_error("More than 2 arguments sent to slice, and I don't 
know what to do with them!\n"
+               IF_VERBOSE_ASCODING_ERRORS(
+               log_warning("More than 2 arguments sent to slice, "
+                       "and I don't know what to do with them!\n"
                        "Ignoring them as we continue...\n");
+               );
        }
 
        // They passed no arguments: simply duplicate the array
@@ -710,44 +693,29 @@
        // if the index is negative, it means "places from the end"
        // where -1 is the last element
        if (startindex < 0) startindex = startindex + array->size();
-       // if it's still negative, this is a problem
-       if (startindex < 0 || (unsigned int)startindex > array->size())
-       {
-               IF_VERBOSE_ASCODING_ERRORS(
-               log_warning("Bad startindex sent to array_slice! "
-                       "StartIndex: %s, Length: %d. "
-                       "Ignoring call.",
-                       fn.arg(0).to_string(),array->size());
-               );
-               return;                         
-       }
+
        // if we sent at least two arguments, setup endindex
        if (fn.nargs >= 2)
        {
                endindex = int(fn.arg(1).to_number());
+
                // if the index is negative, it means
                // "places from the end" where -1 is the last element
                if (endindex < 0) endindex = endindex + array->size();
-               // the endindex is non-inclusive, so add 1
-               endindex++;
-               if (endindex < 0)
-               {
-                       log_error("bad endindex sent to array_slice! endindex: 
%s, length: %d"
-                               "Ignoring call.",
-                               fn.arg(1).to_string(),array->size());
-                       return;                         
-               }
-               // If they overshoot the end of the array,
-               // just copy to the end
-               if ((unsigned int)endindex > array->size() + 1)
-                       endindex = array->size() + 1;
        }
        else
        {
-               // They didn't specify where to end, so choose the end of the 
array
-               endindex = array->size() + 1;
+               // They didn't specify where to end,
+               // so choose the end of the array
+               endindex = array->size();
        }
 
+       if ( startindex < 0 ) startindex = 0;
+       else if ( startindex  > array->size() ) startindex = array->size();
+
+       if ( endindex < 1 ) endindex = 1;
+       else if ( endindex  > array->size() ) endindex = array->size();
+
        std::auto_ptr<as_array_object> newarray(array->slice(
                startindex, endindex));
 

Index: server/array.h
===================================================================
RCS file: /sources/gnash/gnash/server/array.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- server/array.h      29 Oct 2006 18:34:11 -0000      1.16
+++ server/array.h      21 Nov 2006 10:53:08 -0000      1.17
@@ -89,6 +89,25 @@
 
        void concat(const as_array_object& other);
 
+       /// \brief
+       /// Return a newly created array containing elements
+       /// from 'start' up to but not including 'end'.
+       //
+       ///
+       /// NOTE: assertions are:
+       ///
+       ///     assert(one_past_end >= start);
+       ///     assert(one_past_end <= size());
+       ///     assert(start <= size());
+       ///
+       /// @param start
+       ///     index to first element to include in result
+       ///     0-based index.
+       ///
+       /// @param one_past_end
+       ///     index to one-past element to include in result
+       ///     0-based index.
+       ///
        std::auto_ptr<as_array_object> slice(
                unsigned int start, unsigned int one_past_end);
 

Index: testsuite/actionscript.all/array.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/array.as,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- testsuite/actionscript.all/array.as 15 Oct 2006 02:30:55 -0000      1.10
+++ testsuite/actionscript.all/array.as 21 Nov 2006 10:53:08 -0000      1.11
@@ -5,7 +5,7 @@
 // Updated with sort functions, and to use check() macro
 // by Mike Carlson Feb. 14th, 2006
 
-rcsid="$Id: array.as,v 1.10 2006/10/15 02:30:55 rsavoye Exp $";
+rcsid="$Id: array.as,v 1.11 2006/11/21 10:53:08 strk Exp $";
 
 #include "check.as"
 
@@ -118,6 +118,18 @@
 portion = portion.slice(1, 2);
 check_equals ( portion.toString() , "4" );
 check_equals ( portion.length, 1);
+portion = concatted.slice(-2, -1);
+check_equals ( portion.toString(), "5");
+portion = concatted.slice(-2);
+check_equals ( portion.toString(), "5,6");
+
+// invalid calls
+portion = concatted.slice(-18);
+check_equals ( portion.toString(), "0,1,2,3,4,5,6");
+portion = concatted.slice(-18, 3);
+check_equals ( portion.toString(), "0,1,2");
+portion = concatted.slice(18);
+check_equals ( portion.toString(), "");
 
 // Test single parameter constructor, and implicitly expanding array
 var c = new Array(10);
@@ -132,6 +144,12 @@
 check_equals ( c.length, 1001 );
 
 // $Log: array.as,v $
+// Revision 1.11  2006/11/21 10:53:08  strk
+//         * server/array.h: documented ::slice function
+//         * server/array.cpp: more fixes.
+//         * testsuite/actionscript.all/array.as: added some tests for
+//           invalid calls to Array.slice()
+//
 // Revision 1.10  2006/10/15 02:30:55  rsavoye
 //     * testsuite/actionscript.all/swf_exists.exp: Use local_exec()
 //     instead of spawn/expect. This works better with batch tests.




reply via email to

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