[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog TODO server/System.cpp server/a...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog TODO server/System.cpp server/a... |
Date: |
Sat, 08 Jul 2006 00:15:10 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 06/07/08 00:15:10
Modified files:
. : ChangeLog TODO
server : System.cpp action.cpp action.h
server/swf : ASHandlers.cpp
testsuite/actionscript.all: System.as
Log message:
* TODO: removed ActionNewMethod from missing opcodes
* server/swf/ASHandlers.cpp: implemented ActionNewMethod,
added static construct_object() utility function.
* server/System.cpp: handled 'new System' attempts.
* testsuite/actionscript.all/System.as: don't try
to instantiate the non-instantiatable 'System' class.
* server/action.cpp, server/action.h: cleaned up and documented
call_method function.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.481&r2=1.482
http://cvs.savannah.gnu.org/viewcvs/gnash/TODO?cvsroot=gnash&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/gnash/server/System.cpp?cvsroot=gnash&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/gnash/server/action.cpp?cvsroot=gnash&r1=1.94&r2=1.95
http://cvs.savannah.gnu.org/viewcvs/gnash/server/action.h?cvsroot=gnash&r1=1.36&r2=1.37
http://cvs.savannah.gnu.org/viewcvs/gnash/server/swf/ASHandlers.cpp?cvsroot=gnash&r1=1.34&r2=1.35
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/System.as?cvsroot=gnash&r1=1.4&r2=1.5
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.481
retrieving revision 1.482
diff -u -b -r1.481 -r1.482
--- ChangeLog 7 Jul 2006 23:29:51 -0000 1.481
+++ ChangeLog 8 Jul 2006 00:15:09 -0000 1.482
@@ -1,5 +1,13 @@
2006-07-08 Sandro Santilli <address@hidden>
+ * TODO: removed ActionNewMethod from missing opcodes
+ * server/swf/ASHandlers.cpp: implemented ActionNewMethod,
+ added static construct_object() utility function.
+ * server/System.cpp: handled 'new System' attempts.
+ * testsuite/actionscript.all/System.as: don't try
+ to instantiate the non-instantiatable 'System' class.
+ * server/action.cpp, server/action.h: cleaned up and documented
+ call_method function.
* server/as_object.h, server/as_object.cpp:
added public dump_members() and private set_prototype()
methods.
Index: TODO
===================================================================
RCS file: /sources/gnash/gnash/TODO,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- TODO 7 Jul 2006 14:52:39 -0000 1.5
+++ TODO 8 Jul 2006 00:15:09 -0000 1.6
@@ -27,7 +27,6 @@
case 0x37: // mb chr
case 0x43: // declare object
case 0x45: // get target
-case 0x53: // new method
case 0x69: // extends
case 0x8A: // wait for frame (unneeded until we stream)
case 0x8D: // wait for frame expression (unneeded until we stream)
Index: server/System.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/System.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- server/System.cpp 7 Jul 2006 13:49:40 -0000 1.12
+++ server/System.cpp 8 Jul 2006 00:15:09 -0000 1.13
@@ -168,6 +168,16 @@
log_msg("%s:unimplemented \n", __FUNCTION__);
}
+static void
+do_nothing(const fn_call& fn)
+{
+ log_msg("User tried to invoke new System()");
+ if ( fn.result )
+ {
+ fn.result->set_undefined();
+ }
+}
+
void
system_init(as_object* glob)
{
@@ -176,7 +186,7 @@
if ( sys == NULL )
{
- sys = new builtin_function(NULL, getSystemInterface());
+ sys = new builtin_function(do_nothing, getSystemInterface());
// We replicate interface to the System class itself
attachSystemInterface(sys);
Index: server/action.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/action.cpp,v
retrieving revision 1.94
retrieving revision 1.95
diff -u -b -r1.94 -r1.95
--- server/action.cpp 7 Jul 2006 13:49:40 -0000 1.94
+++ server/action.cpp 8 Jul 2006 00:15:09 -0000 1.95
@@ -251,32 +251,37 @@
//
-as_value call_method(
+as_value
+call_method(
const as_value& method,
as_environment* env,
as_object* this_ptr, // this is ourself
int nargs,
int first_arg_bottom_index)
- // first_arg_bottom_index is the stack index, from the bottom, of the
first argument.
- // Subsequent arguments are at *lower* indices. E.g. if
first_arg_bottom_index = 7,
- // then arg1 is at env->bottom(7), arg2 is at env->bottom(6), etc.
+ // first_arg_bottom_index is the stack index, from the bottom,
+ // of the first argument.
+ // Subsequent arguments are at *lower* indices.
+ // E.g. if first_arg_bottom_index = 7, then arg1 is at env->bottom(7),
+ // arg2 is at env->bottom(6), etc.
{
as_value val;
+ fn_call call(&val, this_ptr, env, nargs, first_arg_bottom_index);
- as_c_function_ptr func = method.to_c_function();
- if (func)
+ if ( as_c_function_ptr func = method.to_c_function() )
{
// It's a C function. Call it.
- (*func)(fn_call(&val, this_ptr, env, nargs,
first_arg_bottom_index));
+ (*func)(call);
}
- else if (as_function* as_func = method.to_as_function())
+ else if ( as_function* as_func = method.to_as_function() )
{
// It's an ActionScript function. Call it.
- (*as_func)(fn_call(&val, this_ptr, env, nargs,
first_arg_bottom_index));
+ (*as_func)(call);
}
else
{
- log_error("error in call_method(): '%s' is not an ActionScript
function\n",
+ log_error(
+ "error in call_method(): "
+ "'%s' is neither a C nor an ActionScript function\n",
method.to_string());
}
Index: server/action.h
===================================================================
RCS file: /sources/gnash/gnash/server/action.h,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -b -r1.36 -r1.37
--- server/action.h 5 Jul 2006 17:10:39 -0000 1.36
+++ server/action.h 8 Jul 2006 00:15:09 -0000 1.37
@@ -209,6 +209,10 @@
const as_value& method, as_environment* env, as_object*
this_ptr,
const as_value& arg0, const as_value& arg1, const as_value&
arg2);
+ /// Call a method, be it an as_function or a c_function.
+ //
+ /// This is a thin wrapper around operator() and fn_call,
+ /// probably worth dropping.
///
/// first_arg_bottom_index is the stack index, from the bottom,
/// of the first argument. Subsequent arguments are at *lower*
Index: server/swf/ASHandlers.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/swf/ASHandlers.cpp,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -b -r1.34 -r1.35
--- server/swf/ASHandlers.cpp 7 Jul 2006 14:52:39 -0000 1.34
+++ server/swf/ASHandlers.cpp 8 Jul 2006 00:15:09 -0000 1.35
@@ -86,6 +86,68 @@
return true;
}
+//
+// Utility: construct an object using given constructor.
+// This is used by both ActionNew and ActionNewMethod and
+// hides differences between builtin and actionscript-defined
+// constructors.
+//
+static as_value
+construct_object(const as_value& constructor,
+ as_environment& env, unsigned int nargs,
+ unsigned int first_arg_index)
+{
+
+ as_value new_obj;
+
+ if (constructor.get_type() == as_value::C_FUNCTION)
+ {
+ log_action("Constructor is a C_FUNCTION\n");
+ // C function is responsible for creating the new object and setting
members.
+ fn_call call(&new_obj, NULL, &env, nargs, first_arg_index);
+
+ (constructor.to_c_function())(call);
+ }
+
+ else if (as_function* ctor_as_func = constructor.to_as_function())
+ {
+ // This function is being used as a constructor; make sure
+ // it has a prototype object.
+ log_action("Constructor is an AS_FUNCTION\n");
+
+ // a built-in class takes care of assigning a prototype
+ // TODO: change this
+ if ( ctor_as_func->isBuiltin() ) {
+ log_action("it's a built-in class");
+ fn_call call(&new_obj, NULL, &env, nargs, first_arg_index);
+ (*ctor_as_func)(call);
+ } else {
+ // Set up the prototype.
+ as_value proto;
+ bool func_has_prototype = ctor_as_func->get_member("prototype",
&proto);
+ assert(func_has_prototype);
+
+ log_action("constructor prototype is %s", proto.to_string());
+
+ // Create an empty object, with a ref to the constructor's
prototype.
+ smart_ptr<as_object> new_obj_ptr(new as_object(proto.to_object()));
+
+ new_obj.set_as_object(new_obj_ptr.get_ptr());
+
+ // Call the actual constructor function; new_obj is its 'this'.
+ // We don't need the function result.
+ call_method(constructor, &env, new_obj_ptr.get_ptr(), nargs,
first_arg_index);
+ }
+ }
+
+ else
+ {
+ assert(0);
+ }
+
+ return new_obj;
+}
+
static void unsupported_action_handler(ActionExec& /*thread*/)
{
@@ -1777,51 +1839,13 @@
ensure_stack(env, nargs); // previous 2 entries popped
as_value constructor = env.get_variable(classname.to_tu_string());
- as_value new_obj;
- if (constructor.get_type() == as_value::C_FUNCTION)
- {
- log_action("Constructor is a C_FUNCTION\n");
- // C function is responsible for creating the new object and setting
members.
- (constructor.to_c_function())(fn_call(&new_obj, NULL, &env, nargs,
env.get_top_index()));
- }
- else if (as_function* ctor_as_func = constructor.to_as_function())
- {
- // This function is being used as a constructor; make sure
- // it has a prototype object.
- log_action("Constructor is an AS_FUNCTION\n");
- // a built-in class takes care of assigning a prototype
- if ( ctor_as_func->isBuiltin() ) {
- log_action("it's a built-in class");
- (*ctor_as_func)(fn_call(&new_obj, NULL, &env, nargs,
env.get_top_index()));
- } else {
- // Set up the prototype.
- as_value proto;
- bool func_has_prototype = ctor_as_func->get_member("prototype",
&proto);
- assert(func_has_prototype);
-
- log_action("constructor prototype is %s\n", proto.to_string());
-
- // Create an empty object, with a ref to the constructor's
prototype.
- smart_ptr<as_object> new_obj_ptr(new
as_object(proto.to_object()));
-
- new_obj.set_as_object(new_obj_ptr.get_ptr());
-
- // Call the actual constructor function; new_obj is its 'this'.
- // We don't need the function result.
- call_method(constructor, &env, new_obj_ptr.get_ptr(), nargs,
env.get_top_index());
- }
- } else {
- if (classname != "String") {
- log_error("can't create object with unknown class '%s'\n",
- classname.to_tu_string().c_str());
- } else {
- log_msg("Created special String class\n");
- }
- }
+ as_value new_obj = construct_object(constructor, env, nargs,
+ env.get_top_index());
env.drop(nargs);
env.push(new_obj);
+
#if 0
log_msg("new object at %p\n", new_obj.to_object());
#endif
@@ -2287,11 +2311,56 @@
}
void
-SWFHandlers::ActionNewMethod(ActionExec& /*thread*/)
+SWFHandlers::ActionNewMethod(ActionExec& thread)
{
// GNASH_REPORT_FUNCTION;
-// as_environment& env = thread.env;
- dbglogfile << __PRETTY_FUNCTION__ << ": unimplemented!" << endl;
+
+ as_environment& env = thread.env;
+
+ assert( thread.code[thread.pc] == SWF::ACTION_NEWMETHOD );
+
+ ensure_stack(env, 3); // method, object, nargs
+
+ as_value method_name = env.pop().to_string();
+ as_value obj_val = env.pop();
+ int nargs = (int)env.pop().to_number();
+
+ ensure_stack(env, nargs); // previous 3 entries popped
+
+ as_object* obj = obj_val.to_object();
+ if ( ! obj )
+ {
+ // SWF integrity check
+ log_warning(
+ "On ActionNewMethod: "
+ "no object found on stack on ActionMethod");
+ env.drop(nargs);
+ return;
+ }
+
+ as_value method_val;
+ if ( ! obj->get_member(method_name.to_tu_stringi(), &method_val) )
+ {
+ // SWF integrity check
+ log_warning(
+ "On ActionNewMethod: "
+ "can't find method %s of object %s",
+ method_name.to_string(), obj_val.to_string());
+ env.drop(nargs);
+ return;
+ }
+
+ // Construct the object
+ as_value new_obj = construct_object(method_val, env, nargs,
+ env.get_top_index());
+
+ log_msg("%s.%s( [%d args] ) returned %s", obj_val.to_string(),
+ method_name.to_string(), nargs, new_obj.to_string());
+
+
+ env.drop(nargs);
+ env.push(new_obj);
+
}
void
Index: testsuite/actionscript.all/System.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/System.as,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- testsuite/actionscript.all/System.as 20 Jun 2006 20:45:27 -0000
1.4
+++ testsuite/actionscript.all/System.as 8 Jul 2006 00:15:10 -0000
1.5
@@ -40,22 +40,25 @@
// compile this test case with Ming makeswf, and then
// execute it like this gnash -1 -r 0 -v out.swf
-rcsid="$Id: System.as,v 1.4 2006/06/20 20:45:27 strk Exp $";
+rcsid="$Id: System.as,v 1.5 2006/07/08 00:15:10 strk Exp $";
#include "check.as"
+// test the System constuctor (should fail, it's not instantiatable)
var systemObj = new System;
-
-// test the System constuctor
-check (systemObj != undefined);
+check (systemObj == undefined);
// test the System::security.allowdomain method
-check (systemObj.security.allowdomain != undefined);
-// test the System::security.allowinsecuredomain method
-check (systemObj.security.allowinsecuredomain != undefined);
-// test the System::security.loadpolicyfile method
-check (systemObj.security.loadpolicyfile != undefined);
-// test the System::setclipboard method
-check (systemObj.setclipboard != undefined);
-// test the System::showsettings method
-check (systemObj.showsettings != undefined);
+check (System.security.allowdomain != undefined);
+
+// test the System.security.allowinsecuredomain method
+check (System.security.allowinsecuredomain != undefined);
+
+// test the System.security.loadpolicyfile method
+check (System.security.loadpolicyfile != undefined);
+
+// test the System.setclipboard method
+check (System.setclipboard != undefined);
+
+// test the System.showsettings method
+check (System.showsettings != undefined);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog TODO server/System.cpp server/a...,
Sandro Santilli <=