gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog server/as_function.cpp testsuit...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/as_function.cpp testsuit...
Date: Mon, 06 Nov 2006 15:11:04 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  06/11/06 15:11:04

Modified files:
        .              : ChangeLog 
        server         : as_function.cpp 
        testsuite/actionscript.all: Function.as 

Log message:
        (Fwd port)
                * server/as_function.cpp (function_apply): don't abort
                  on invalid calls, warn about them if requested.
                * testsuite/actionscript.all/Function.as: added tests for
                  invalid Function.apply() calls.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.1538&r2=1.1539
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_function.cpp?cvsroot=gnash&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/Function.as?cvsroot=gnash&r1=1.14&r2=1.15

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.1538
retrieving revision 1.1539
diff -u -b -r1.1538 -r1.1539
--- ChangeLog   6 Nov 2006 13:24:37 -0000       1.1538
+++ ChangeLog   6 Nov 2006 15:11:04 -0000       1.1539
@@ -1,5 +1,9 @@
 2006-11-06 Sandro Santilli <address@hidden>
 
+       * server/as_function.cpp (function_apply): don't abort
+         on invalid calls, warn about them if requested.
+       * testsuite/actionscript.all/Function.as: added tests for
+         invalid Function.apply() calls.
        * server/parser/sprite_definition.h: dirty patch for dirtier
          programmatically-created MovieClip implementation.
        * testsuite/actionscript.all/MovieClip.as: expect failures.

Index: server/as_function.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/as_function.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- server/as_function.cpp      3 Nov 2006 22:57:44 -0000       1.5
+++ server/as_function.cpp      6 Nov 2006 15:11:04 -0000       1.6
@@ -162,36 +162,66 @@
        fn_call new_fn_call(fn);
        new_fn_call.nargs=0;
 
+       assert(fn.this_ptr);
+
        if ( ! fn.nargs )
        {
-            dbglogfile << "Function.apply() with no args" << endl;
+               IF_VERBOSE_ASCODING_ERRORS(
+               log_warning ("Function.apply() called with no args");
+               );
        }
        else
        {
                // Get the object to use as 'this' reference
                as_object *this_ptr = fn.arg(0).to_object();
-               new_fn_call.this_ptr = this_ptr;
+               if ( this_ptr ) new_fn_call.this_ptr = this_ptr;
+               // ... or recycle this function's call 'this' pointer
+               // (most likely the Function instance)
+               else new_fn_call.this_ptr = fn.this_ptr;
 
                if ( fn.nargs > 1 )
                // we have an 'arguments' array
                {
+                       IF_VERBOSE_ASCODING_ERRORS(
                        if ( fn.nargs > 2 )
                        {
-                            dbglogfile << "Function.apply() with more then 2 
args" << endl;
+                                       log_warning("Function.apply() got %d"
+                                               " args, expected at most 2"
+                                               " -- discarding the ones in"
+                                               " excess",
+                                               fn.nargs);
                        }
+                       );
 
                        as_object *arg1 = fn.arg(1).to_object();
-                       assert(arg1);
+                       if ( ! arg1 )
+                       {
+                               IF_VERBOSE_ASCODING_ERRORS(
+                                       log_warning("Second arg of 
Function.apply"
+                                               " is of type %d, with value %s"
+                                               " (expected array)"
+                                               " - considering as call with no 
args",
+                                               fn.arg(1).get_type(),
+                                               fn.arg(1).to_string());
+                               );
+                               goto call_it;
+                       }
 
                        as_array_object *arg_array = \
                                        dynamic_cast<as_array_object*>(arg1);
 
                        if ( ! arg_array )
                        {
-                            dbglogfile << "Second argument to Function.apply() 
is not an array" << endl;
+                               IF_VERBOSE_ASCODING_ERRORS(
+                                       log_warning("Second arg of 
Function.apply"
+                                               " is of type %d, with value %s"
+                                               " (expected array)"
+                                               " - considering as call with no 
args",
+                                               fn.arg(1).get_type(),
+                                               fn.arg(1).to_string());
+                               );
+                               goto call_it;
                        }
-                       else
-                       {
 
                                unsigned int nelems = arg_array->size();
 
@@ -200,7 +230,6 @@
                                for (unsigned int i=nelems; i; i--)
                                {
                                        value=arg_array->at(i-1);
-                                       //log_msg("value: %s\n", 
value.to_string());
                                        fn.env->push_val(value);
                                        pushed++;
                                }
@@ -209,7 +238,8 @@
                                new_fn_call.nargs=nelems;
                        }
                }
-       }
+
+       call_it:
 
        // Call the function 
        (*function_obj)(new_fn_call);
@@ -217,7 +247,6 @@
        // Drop additional values we pushed on the stack 
        fn.env->drop(pushed);
 
-       //log_msg("at function_apply exit, stack: \n"); fn.env->dump_stack();
 }
 
 void

Index: testsuite/actionscript.all/Function.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/Function.as,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- testsuite/actionscript.all/Function.as      5 Nov 2006 00:45:27 -0000       
1.14
+++ testsuite/actionscript.all/Function.as      6 Nov 2006 15:11:04 -0000       
1.15
@@ -20,12 +20,14 @@
 // compile this test case with Ming makeswf, and then
 // execute it like this gnash -1 -r 0 -v out.swf
 
-rcsid="$Id: Function.as,v 1.14 2006/11/05 00:45:27 rsavoye Exp $";
+rcsid="$Id: Function.as,v 1.15 2006/11/06 15:11:04 strk Exp $";
 
 #include "check.as"
 
+
 // Define a function returning 'this'.name and the given args
 function getThisName(a,b,c) { return this.name+a+b+c; }
+
 check (getThisName != undefined);
 check ( typeof(getThisName) == "function" );
 
@@ -41,6 +43,22 @@
 var ret=getThisName.apply(this_ref, [1,2,3]);
 check ( ret == "extname123" );
 
+// Test invalid Function.apply calls
+var ret=getThisName.apply();
+check_equals ( ret , 0 ); // result of the *numerical* sum of all undefined
+var ret=getThisName.apply(this_ref, [4,5,6], 4);
+check_equals ( ret , "extname456" );
+var ret=getThisName.apply(this_ref, "8");
+check_equals ( ret , "extname" );
+var ret=getThisName.apply(this_ref, 9);
+check_equals ( ret , "extname" );
+var ret=getThisName.apply(undefined, [4,5,6], 4);
+check_equals ( ret , 15 ); // the sum will be considered numerical
+var ret=getThisName.apply(undefined, 7);
+check_equals ( ret , 0 );
+var ret=getThisName.apply(undefined, "7");
+check_equals ( ret , 0 );
+
 // Test Function.call(arg1, arg2, arg3)
 check ( getThisName.call(this_ref, 1, 2, 3) == "extname123" );
 
@@ -101,3 +119,4 @@
 // Test the instanceof operator
 check ( testInstance instanceof TestClass );
 check ( stringInstance instanceof String );
+




reply via email to

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