[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ./ChangeLog server/Function.cpp server/ac...
From: |
strk |
Subject: |
[Gnash-commit] gnash ./ChangeLog server/Function.cpp server/ac... |
Date: |
Tue, 07 Feb 2006 03:49:43 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Branch:
Changes by: strk <address@hidden> 06/02/07 03:49:43
Modified files:
. : ChangeLog
server : Function.cpp action.cpp
Log message:
Function.apply() implemented. See Function.as test for details.
Additional tests would be nice to have.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/ChangeLog.diff?tr1=1.103&tr2=1.104&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/server/Function.cpp.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/server/action.cpp.diff?tr1=1.27&tr2=1.28&r1=text&r2=text
Patches:
Index: gnash/ChangeLog
diff -u gnash/ChangeLog:1.103 gnash/ChangeLog:1.104
--- gnash/ChangeLog:1.103 Tue Feb 7 03:13:33 2006
+++ gnash/ChangeLog Tue Feb 7 03:49:43 2006
@@ -8,6 +8,7 @@
Function.apply()
* testsuite/actionscript.all/Makefile.am: rule to build
'visual tracing' version of tests (.vswf)
+ * server/Function.cpp: implemented Function.apply()
2006-02-05 Sandro Santilli <address@hidden>
Index: gnash/server/Function.cpp
diff -u gnash/server/Function.cpp:1.2 gnash/server/Function.cpp:1.3
--- gnash/server/Function.cpp:1.2 Mon Feb 6 04:11:04 2006
+++ gnash/server/Function.cpp Tue Feb 7 03:49:43 2006
@@ -20,6 +20,7 @@
#include "config.h"
#endif
+#include <typeinfo>
#include "log.h"
#include "Function.h"
#include "array.h"
@@ -40,7 +41,7 @@
m_function2_flags(0),
m_properties(NULL)
{
- //log_msg("function_as_object %x reduced ctor\n", this);
+ //log_msg("function_as_object %p reduced ctor\n", this);
}
function_as_object::function_as_object(action_buffer* ab, as_environment* env,
@@ -57,8 +58,7 @@
m_properties(NULL)
{
assert(m_action_buffer);
-
- //log_msg("function_as_object %x full ctor\n", this);
+ //log_msg("function_as_object %p full ctor\n", this);
}
// Dispatch.
@@ -72,6 +72,11 @@
}
assert(our_env);
+#if 0
+ log_msg("function_as_object() stack:\n"); fn.env->dump_stack();
+ log_msg(" first_arg_bottom_index: %d\n", fn.first_arg_bottom_index);
+#endif
+
// Set up local stack frame, for parameters and locals.
int local_stack_top = our_env->get_local_frame_top();
our_env->add_frame_barrier();
@@ -87,6 +92,12 @@
assert(m_args[i].m_register == 0);
our_env->add_local(m_args[i].m_name, fn.arg(i));
}
+
+ // Set up local variable 'this'.
+ // --strk(2006-02-07);
+ assert(fn.this_ptr);
+ our_env->set_local("this", fn.this_ptr);
+
}
else
{
@@ -224,10 +235,12 @@
if (m_properties == NULL)
{
m_properties = new as_object();
+//log_msg("m_properties for function %p @ %p\n", this, m_properties);
m_properties->add_ref();
// Create new empty prototype
as_object *proto_obj = new as_object();
+
proto_obj->set_member("apply", &function_apply);
proto_obj->set_member("call", &function_call);
@@ -236,28 +249,11 @@
}
}
-Function::Function() {
-}
-
-Function::~Function() {
-}
-
-
-void
-Function::apply()
-{
- log_msg("%s:unimplemented \n", __FUNCTION__);
-}
-
-void
-Function::call()
-{
- log_msg("%s:unimplemented \n", __FUNCTION__);
-}
void
function_new(const fn_call& fn)
{
function_as_object *function_obj = new function_as_object(fn.env);
+
for (int i=0; i<fn.nargs; i++)
{
function_obj->add_arg(0, fn.arg(i).to_tu_string().c_str());
@@ -265,9 +261,79 @@
fn.result->set_as_object_interface(function_obj);
}
-void function_apply(const fn_call& fn) {
- log_msg("%s:unimplemented \n", __FUNCTION__);
+
+void function_apply(const fn_call& fn)
+{
+ int pushed=0; // new values we push on the stack
+
+ // Get function body
+ function_as_object* function_obj = fn.env->top(1).to_as_function();
+ assert(function_obj);
+
+ // Copy new function call from old one, we'll modify
+ // the copy only if needed
+ fn_call new_fn_call(fn);
+ new_fn_call.nargs=0;
+
+ if ( ! fn.nargs )
+ {
+ IF_VERBOSE_DEBUG(log_msg("Function.apply() with no args\n"));
+ }
+ else
+ {
+ // Get the object to use as 'this' reference
+ as_object_interface *this_ptr = fn.arg(0).to_object();
+ new_fn_call.this_ptr = this_ptr;
+
+ if ( fn.nargs > 1 )
+ // we have an 'arguments' array
+ {
+ if ( fn.nargs > 2 )
+ {
+ IF_VERBOSE_DEBUG(log_msg("Function.apply() with more then 2 args\n"));
+ }
+
+ as_object_interface *arg1 = fn.arg(1).to_object();
+ assert(arg1);
+
+ as_array_object *arg_array = \
+ dynamic_cast<as_array_object*>(arg1);
+
+ if ( ! arg_array )
+ {
+ IF_VERBOSE_DEBUG(log_msg("Second argument to Function.apply() "
+ "is not an array\n"));
+ }
+ else
+ {
+
+ unsigned int nelems = arg_array->size();
+
+ //log_error("Function.apply(this_ref,
array[%d])\n", nelems);
+ as_value index, value;
+ for (unsigned int i=nelems; i; i--)
+ {
+ value=arg_array->elements[i-1];
+ //log_msg("value: %s\n",
value.to_string());
+ fn.env->push_val(value);
+ pushed++;
+ }
+
+
new_fn_call.first_arg_bottom_index=fn.env->get_top_index();
+ new_fn_call.nargs=nelems;
+ }
+ }
+ }
+
+ // Call the function
+ (*function_obj)(new_fn_call);
+
+ // 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 function_call(const fn_call& fn) {
log_msg("%s:unimplemented \n", __FUNCTION__);
}
Index: gnash/server/action.cpp
diff -u gnash/server/action.cpp:1.27 gnash/server/action.cpp:1.28
--- gnash/server/action.cpp:1.27 Tue Feb 7 02:45:20 2006
+++ gnash/server/action.cpp Tue Feb 7 03:49:43 2006
@@ -2091,7 +2091,7 @@
//log_msg("xxx init array end: top of
stack = %d, trace(top(0)) =", env->get_top_index());//xxxxxxx
- as_global_trace(fn_call(NULL, NULL,
env, 1, env->get_top_index())); //xxxx
+ //as_global_trace(fn_call(NULL, NULL,
env, 1, env->get_top_index())); //xxxx
break;
}
- [Gnash-commit] gnash ./ChangeLog server/Function.cpp server/ac...,
strk <=