[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog server/swf_function.cpp server/...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog server/swf_function.cpp server/... |
Date: |
Wed, 28 Feb 2007 07:46:23 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 07/02/28 07:46:23
Modified files:
. : ChangeLog
server : swf_function.cpp swf_function.h
testsuite/actionscript.all: Function.as
Log message:
* server/swf_function.{h,cpp}: properly setup
the 'arguments' variable at dispatch time.
* testsuite/actionscript.all/Function.as:
Test the 'arguments' variable in function context.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2488&r2=1.2489
http://cvs.savannah.gnu.org/viewcvs/gnash/server/swf_function.cpp?cvsroot=gnash&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/gnash/server/swf_function.h?cvsroot=gnash&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/Function.as?cvsroot=gnash&r1=1.22&r2=1.23
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2488
retrieving revision 1.2489
diff -u -b -r1.2488 -r1.2489
--- ChangeLog 28 Feb 2007 07:41:27 -0000 1.2488
+++ ChangeLog 28 Feb 2007 07:46:22 -0000 1.2489
@@ -1,5 +1,9 @@
2007-02-28 Sandro Santilli <address@hidden>
+ * server/swf_function.{h,cpp}: properly setup
+ the 'arguments' variable at dispatch time.
+ * testsuite/actionscript.all/Function.as:
+ Test the 'arguments' variable in function context.
* server/array.{cpp,h}: allow resize trough
setting the 'length' property.
* testsuite/actionscript.all/array.as: test
Index: server/swf_function.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/swf_function.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- server/swf_function.cpp 26 Feb 2007 08:24:34 -0000 1.19
+++ server/swf_function.cpp 28 Feb 2007 07:46:23 -0000 1.20
@@ -139,6 +139,27 @@
}
+/*private static*/
+as_array_object*
+swf_function::getArguments(swf_function& callee, const fn_call& fn)
+{
+ // We'll be storing the callee as_object into an as_value
+ // so you must make sure you have a reference on it before
+ // callign this function.
+ assert(callee.get_ref_count() > 0);
+
+ // Super class prototype is : obj.__proto__.constructor.prototype
+ as_array_object* arguments = new as_array_object();
+ for (int i=0; i<fn.nargs; ++i)
+ {
+ arguments->push(fn.arg(i));
+ }
+ arguments->set_member("callee", &callee);
+
+ return arguments;
+
+}
+
// Dispatch.
void
swf_function::operator()(const fn_call& fn)
@@ -172,12 +193,16 @@
our_env->add_local(m_args[i].m_name, fn.arg(i));
}
+ // Add 'this'
assert(fn.this_ptr);
our_env->set_local("this", fn.this_ptr);
// Add 'super'
as_object* super = getSuper(*(fn.this_ptr));
our_env->set_local("super", super);
+
+ // Add 'arguments'
+ our_env->set_local("arguments", getArguments(*this, fn));
}
else
{
@@ -228,14 +253,7 @@
boost::intrusive_ptr<as_array_object> arg_array;
if ((m_function2_flags & PRELOAD_ARGUMENTS) || !
(m_function2_flags & SUPPRESS_ARGUMENTS))
{
- arg_array = new as_array_object;
-
- as_value index_number;
- for (int i = 0; i < fn.nargs; i++)
- {
- index_number.set_int(i);
-
arg_array->init_member(index_number.to_string(), fn.arg(i));
- }
+ arg_array = getArguments(*this, fn);
}
if (m_function2_flags & PRELOAD_ARGUMENTS)
Index: server/swf_function.h
===================================================================
RCS file: /sources/gnash/gnash/server/swf_function.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- server/swf_function.h 6 Feb 2007 17:46:25 -0000 1.8
+++ server/swf_function.h 28 Feb 2007 07:46:23 -0000 1.9
@@ -32,6 +32,7 @@
namespace gnash {
class action_buffer;
class as_environmnet;
+ class as_array_object;
}
namespace gnash {
@@ -88,6 +89,18 @@
///
static as_object* getSuper(as_object& obj);
+ /// Return an 'arguments' object.
+ //
+ /// The 'arguments' variable is an array with an additional
+ /// 'callee' member, set to the function being called.
+ ///
+ /// NOTE: the callee as_object will be stored in an as_value, thus
+ /// getting wrapped into an intrusive_ptr. Make sure you have
+ /// a reference on it!
+ ///
+ ///
+ static as_array_object* getArguments(swf_function& callee, const
fn_call& fn);
+
public:
enum SWFDefineFunction2Flags
Index: testsuite/actionscript.all/Function.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/Function.as,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- testsuite/actionscript.all/Function.as 7 Feb 2007 10:28:40 -0000
1.22
+++ testsuite/actionscript.all/Function.as 28 Feb 2007 07:46:23 -0000
1.23
@@ -20,7 +20,7 @@
// 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.22 2007/02/07 10:28:40 strk Exp $";
+rcsid="$Id: Function.as,v 1.23 2007/02/28 07:46:23 strk Exp $";
#include "check.as"
@@ -344,3 +344,45 @@
check_equals(this.a, "a_in_root");
+//----------------------------------------------------------
+// Test the 'arguments' object
+//----------------------------------------------------------
+
+// this is to be called argsChecker(1,2,3)
+function argsChecker()
+{
+ check_equals(typeof(arguments), 'object');
+ check(arguments instanceOf Array);
+ check(arguments instanceOf Object);
+ check_equals(typeof(arguments.callee), 'function');
+ check_equals(arguments.callee, argsChecker);
+ check_equals(arguments.length, 3);
+ check_equals(arguments[0], 1);
+ check_equals(arguments[1], 2);
+ check_equals(arguments[2], 3);
+ check_equals(arguments[3], undefined);
+ arguments[3] = 3;
+ check_equals(arguments[3], 3);
+ arguments[0] = 'zero';
+ check_equals(arguments[0], 'zero');
+ arguments.length = 10;
+ check_equals(arguments.length, 10);
+ arguments.pop();
+ check_equals(arguments.length, 9);
+ arguments.somethingelse = "can extend";
+ check_equals(arguments.somethingelse, "can extend");
+}
+argsChecker(1, 2, 3);
+
+function argsCounter() {
+ return arguments.length;
+}
+check_equals(argsCounter(1,2,3), 3);
+check_equals(argsCounter(a,b,c,d), 4);
+check_equals(argsCounter([a,b]), 1);
+
+function factorial(n) {
+ return n <= 1 ? n : n*factorial(n-1);
+}
+check_equals(factorial(3), 6);
+check_equals(factorial(4), 24);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog server/swf_function.cpp server/...,
Sandro Santilli <=