[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ./ChangeLog server/action.cpp server/acti...
From: |
strk |
Subject: |
[Gnash-commit] gnash ./ChangeLog server/action.cpp server/acti... |
Date: |
Fri, 10 Feb 2006 02:24:16 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Branch:
Changes by: strk <address@hidden> 06/02/10 02:24:16
Modified files:
. : ChangeLog
server : action.cpp action.h
testsuite/actionscript.all: Function.as
Log message:
* testsuite/actionscript.all/Function.as: added some tests
for prototype, prototype.constructor and __proto__ (inheritance)
* server/action.{cpp,h}: moved ACTION_NEW and ACTION_INSTANCEOF
handling code in action_buffer private doActionNew and
doActionInstanceOf (the latter being under development).
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/ChangeLog.diff?tr1=1.115&tr2=1.116&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/server/action.cpp.diff?tr1=1.35&tr2=1.36&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/server/action.h.diff?tr1=1.12&tr2=1.13&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/testsuite/actionscript.all/Function.as.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
Patches:
Index: gnash/ChangeLog
diff -u gnash/ChangeLog:1.115 gnash/ChangeLog:1.116
--- gnash/ChangeLog:1.115 Fri Feb 10 01:35:55 2006
+++ gnash/ChangeLog Fri Feb 10 02:24:16 2006
@@ -11,6 +11,11 @@
* doc/C/internals.xml: about writing tests
* testsuite/actionscript.all/Global.as: added two more tests,
fixed existing test to bypass preprocessor mangling.
+ * testsuite/actionscript.all/Function.as: added some tests
+ for prototype, prototype.constructor and __proto__ (inheritance)
+ * server/action.{cpp,h}: moved ACTION_NEW and ACTION_INSTANCEOF
+ handling code in action_buffer private doActionNew and
+ doActionInstanceOf (the latter being under development).
2006-02-09 Michael Carlson <address@hidden>
Index: gnash/server/action.cpp
diff -u gnash/server/action.cpp:1.35 gnash/server/action.cpp:1.36
--- gnash/server/action.cpp:1.35 Thu Feb 9 15:11:39 2006
+++ gnash/server/action.cpp Fri Feb 10 02:24:16 2006
@@ -1743,6 +1743,118 @@
}
+ /*private*/
+ void
+ action_buffer::doActionNew(as_environment* env,
+ array<with_stack_entry>& with_stack)
+ {
+ as_value classname = env->pop();
+ IF_VERBOSE_ACTION(log_msg("---new object: %s\n",
+ classname.to_tu_string().c_str()));
+ int nargs = (int) env->pop().to_number();
+ as_value constructor =
env->get_variable(classname.to_tu_string(), with_stack);
+ as_value new_obj;
+ if (constructor.get_type() == as_value::C_FUNCTION)
+ {
+ // 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 (function_as_object* ctor_as_func =
constructor.to_as_function())
+ {
+ // This function is being used as a constructor; make
sure
+ // it has a prototype object.
+ ctor_as_func->lazy_create_properties();
+ assert(ctor_as_func->m_properties);
+
+ // Set up the prototype.
+ as_value proto;
+ ctor_as_func->m_properties->get_member("prototype",
&proto);
+
+ assert(proto.to_object() != NULL);
+
+ // 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()));
+
+ // Set up the constructor member.
+ new_obj_ptr->set_member("constructor", constructor);
+ new_obj_ptr->set_member_flags("constructor", 1);
+
+ new_obj.set_as_object_interface(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");
+ }
+ }
+
+ env->drop(nargs);
+ env->push(new_obj);
+#if 0
+ log_msg("new object %s at %p\n",
classname.to_tu_string().c_str(), new_obj);
+#endif
+ }
+
+ /*private*/
+ void
+ action_buffer::doActionInstanceOf(as_environment* env)
+ {
+ // Get the "super" function
+ as_value& super = env->top(0);
+
+ // Get the "instance"
+ as_value& instance = env->top(1);
+
+
+ //IF_VERBOSE_ACTION(
+ log_msg("-- %s intance_of %s\n",
+ instance.to_string(),
+ super.to_string());
+ //);
+
+ as_value result;
+
+ // If any of the two is undefined, result is false
+ if ( instance.get_type() == as_value::UNDEFINED || \
+ super.get_type() == as_value::UNDEFINED )
+ {
+ result.set_bool(false);
+ }
+ else
+ {
+
+ // @@ TODO
+
+ // Check if 'instance' implements all
+ // methods of 'super'
+
+ // @@ TODO
+
+ result.set_undefined();
+
+
+ #if 0
+ if ( instance->implements(super) ) {
+ env->push(true);
+ } else {
+ env->push(false);
+ }
+ #endif
+ }
+ // @@ TODO
+ log_error("tocheck opcode: ACTION_INSTANCEOF (%02X)\n",
SWF::ACTION_INSTANCEOF);
+
+ env->drop(1);
+ env->top(0) = result;
+ }
+
void action_buffer::execute(
as_environment* env,
int start_pc,
@@ -2248,61 +2360,8 @@
break;
}
case SWF::ACTION_NEW: // new
- {
- as_value classname = env->pop();
- IF_VERBOSE_ACTION(log_msg("---new
object: %s\n",
-
classname.to_tu_string().c_str()));
- int nargs = (int)
env->pop().to_number();
- as_value constructor =
env->get_variable(classname.to_tu_string(), with_stack);
- as_value new_obj;
- if (constructor.get_type() ==
as_value::C_FUNCTION)
- {
- // 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 (function_as_object*
ctor_as_func = constructor.to_as_function())
- {
- // This function is being used
as a constructor; make sure
- // it has a prototype object.
-
ctor_as_func->lazy_create_properties();
-
assert(ctor_as_func->m_properties);
-
- // Set up the prototype.
- as_value proto;
-
ctor_as_func->m_properties->get_member("prototype", &proto);
-
- assert(proto.to_object() !=
NULL);
-
- // 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()));
-
- // Set up the constructor
member.
-
new_obj_ptr->set_member("constructor", constructor);
-
new_obj_ptr->set_member_flags("constructor", 1);
-
-
new_obj.set_as_object_interface(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");
- }
- }
-
- env->drop(nargs);
- env->push(new_obj);
-#if 0
- log_msg("new object %s at %p\n",
classname.to_tu_string().c_str(), new_obj);
-#endif
+ doActionNew(env, with_stack);
break;
- }
case SWF::ACTION_VAR: // declare local
{
const tu_string& varname =
env->top(0).to_tu_string();
Index: gnash/server/action.h
diff -u gnash/server/action.h:1.12 gnash/server/action.h:1.13
--- gnash/server/action.h:1.12 Thu Feb 9 09:19:51 2006
+++ gnash/server/action.h Fri Feb 10 02:24:16 2006
@@ -204,6 +204,13 @@
array<unsigned char> m_buffer;
array<const char*> m_dictionary;
int m_decl_dict_processed_at;
+
+ private:
+
+ void doActionNew(as_environment* env,
+ array<with_stack_entry>& with_stack);
+
+ void doActionInstanceOf(as_environment* env);
};
Index: gnash/testsuite/actionscript.all/Function.as
diff -u gnash/testsuite/actionscript.all/Function.as:1.6
gnash/testsuite/actionscript.all/Function.as:1.7
--- gnash/testsuite/actionscript.all/Function.as:1.6 Thu Feb 9 00:37:25 2006
+++ gnash/testsuite/actionscript.all/Function.as Fri Feb 10 02:24:16 2006
@@ -70,6 +70,22 @@
testInstance.setname("Test");
check (testInstance.name == "Test");
+// Test inheritance
+check (testInstance.__proto__ != undefined);
+check (testInstance.__proto__ == TestClass.prototype);
+check (TestClass.prototype.constructor != undefined);
+check (TestClass.prototype.constructor == TestClass);
+check (testInstance.__proto__.constructor == TestClass);
+
+// Test inheritance with built-in functions
+var stringInstance = new String();
+check (stringInstance.__proto__ != undefined);
+check (stringInstance.__proto__ == String.prototype);
+check (String.prototype.constructor != undefined);
+check (String.prototype.constructor == String);
+check (stringInstance.__proto__.constructor == String);
+
// Test the instanceof operator
check ( testInstance instanceof TestClass );
+check ( stringInstance instanceof String );