[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog server/as_function.cpp testsuit... [relea
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog server/as_function.cpp testsuit... [release_0_7_2] |
Date: |
Mon, 06 Nov 2006 15:09:07 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Branch: release_0_7_2
Changes by: Sandro Santilli <strk> 06/11/06 15:09:07
Modified files:
. : ChangeLog
server : as_function.cpp
testsuite/actionscript.all: Function.as
Log message:
* 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&only_with_tag=release_0_7_2&r1=1.1412.2.94&r2=1.1412.2.95
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_function.cpp?cvsroot=gnash&only_with_tag=release_0_7_2&r1=1.1.2.3&r2=1.1.2.4
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/Function.as?cvsroot=gnash&only_with_tag=release_0_7_2&r1=1.12.2.1&r2=1.12.2.2
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.1412.2.94
retrieving revision 1.1412.2.95
diff -u -b -r1.1412.2.94 -r1.1412.2.95
--- ChangeLog 6 Nov 2006 14:13:20 -0000 1.1412.2.94
+++ ChangeLog 6 Nov 2006 15:09:06 -0000 1.1412.2.95
@@ -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.
* libbase/log.h: back-ported IF_VERBOSE_MALFORMED_SWF and
IF_VERBOSE_ASCODING_ERRORS macros.
* server/parser/sprite_definition.h: dirty patch for dirtier
Index: server/as_function.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/as_function.cpp,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -b -r1.1.2.3 -r1.1.2.4
--- server/as_function.cpp 3 Nov 2006 22:57:16 -0000 1.1.2.3
+++ server/as_function.cpp 6 Nov 2006 15:09:07 -0000 1.1.2.4
@@ -161,36 +161,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();
@@ -199,7 +229,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++;
}
@@ -208,7 +237,8 @@
new_fn_call.nargs=nelems;
}
}
- }
+
+ call_it:
// Call the function
(*function_obj)(new_fn_call);
@@ -216,7 +246,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.12.2.1
retrieving revision 1.12.2.2
diff -u -b -r1.12.2.1 -r1.12.2.2
--- testsuite/actionscript.all/Function.as 30 Oct 2006 14:28:55 -0000
1.12.2.1
+++ testsuite/actionscript.all/Function.as 6 Nov 2006 15:09:07 -0000
1.12.2.2
@@ -22,12 +22,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.12.2.1 2006/10/30 14:28:55 rsavoye Exp $";
+rcsid="$Id: Function.as,v 1.12.2.2 2006/11/06 15:09:07 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" );
@@ -43,6 +45,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" );
@@ -103,3 +121,4 @@
// Test the instanceof operator
check ( testInstance instanceof TestClass );
check ( stringInstance instanceof String );
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog server/as_function.cpp testsuit... [release_0_7_2],
Sandro Santilli <=