[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog server/as_object.cpp server/as_...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog server/as_object.cpp server/as_... |
Date: |
Fri, 09 Mar 2007 01:11:42 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 07/03/09 01:11:42
Modified files:
. : ChangeLog
server : as_object.cpp as_object.h
server/asobj : Object.cpp
testsuite/actionscript.all: Object.as
Log message:
* server/as_object.{cpp,h}: add getOwnProperty and prototypeOf()
public methods.
* server/asobj/Object.cpp: implement Object.hasOwnProperty(),
Object.isPropertyEnumerable() and isPrototypeOf(); stub
Object.watch() and Object.unwatch().
* testsuite/actionscript.all/Object.as: add tests for
Object.hasOwnProperty(), Object.isPropertyEnumerable() and
isPrototypeOf(); add TODO note for testing Object.watch()
and Object.unwatch().
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2583&r2=1.2584
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_object.cpp?cvsroot=gnash&r1=1.39&r2=1.40
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_object.h?cvsroot=gnash&r1=1.41&r2=1.42
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/Object.cpp?cvsroot=gnash&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/Object.as?cvsroot=gnash&r1=1.22&r2=1.23
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2583
retrieving revision 1.2584
diff -u -b -r1.2583 -r1.2584
--- ChangeLog 8 Mar 2007 18:40:18 -0000 1.2583
+++ ChangeLog 9 Mar 2007 01:11:42 -0000 1.2584
@@ -1,25 +1,37 @@
-2007-03-07 Udo Giacomozzi <address@hidden>
+2007-03-09 Sandro Santilli <address@hidden>
+
+ * server/as_object.{cpp,h}: add getOwnProperty and prototypeOf()
+ public methods.
+ * server/asobj/Object.cpp: implement Object.hasOwnProperty(),
+ Object.isPropertyEnumerable() and isPrototypeOf(); stub
+ Object.watch() and Object.unwatch().
+ * testsuite/actionscript.all/Object.as: add tests for
+ Object.hasOwnProperty(), Object.isPropertyEnumerable() and
+ isPrototypeOf(); add TODO note for testing Object.watch()
+ and Object.unwatch().
+
+2007-03-08 Udo Giacomozzi <address@hidden>
* server/character.h: drop m_enabled since nobody uses it
* server/button_character_instance.{h,cpp}: add "enabled" property
and receive mouse events only when enabled
-2007-03-07 Bastiaan Jacques <address@hidden>
+2007-03-08 Bastiaan Jacques <address@hidden>
* gui/gtk.cpp: Fix GTK/AGG redrawing upon expose events by switching
to the new invalidation interface. In this incarnation, only the area
which is newly exposed is redrawn.
-2007-03-07 Udo Giacomozzi <address@hidden>
+2007-03-08 Udo Giacomozzi <address@hidden>
* extensions/fileio/fileio.cpp: Fixed fread()
-2007-03-07 Sandro Santilli <address@hidden>
+2007-03-08 Sandro Santilli <address@hidden>
* server/as_object.h: new protected clearProperties() method.
* server/sprite_instance.cpp (restart): clear properties.
-2007-03-07 Sandro Santilli <address@hidden>
+2007-03-08 Sandro Santilli <address@hidden>
* server/sprite_instance.cpp (construct):
Ensure first frame is loaded, to eventually not waiting for
@@ -29,7 +41,7 @@
the call to ::adnvace and relying on the crappy
m_onload_event_called flag.
-2007-03-07 Sandro Santilli <address@hidden>
+2007-03-08 Sandro Santilli <address@hidden>
* server/character.h: document set_event_hanlder,
get_event_handler (as we're getting it wrong).
@@ -40,7 +52,7 @@
m_update_frame variable. (restart): simplify
and properly reset the displayList backup.
-2007-03-07 Zou Lunkai <address@hidden>
+2007-03-08 Zou Lunkai <address@hidden>
* testsuite/misc-ming.all/action_execution_order_extend_test.c:
Add a check, seems PlaceObject2 tag should not define any functions
Index: server/as_object.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/as_object.cpp,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -b -r1.39 -r1.40
--- server/as_object.cpp 6 Mar 2007 11:08:46 -0000 1.39
+++ server/as_object.cpp 9 Mar 2007 01:11:42 -0000 1.40
@@ -328,6 +328,27 @@
return false;
}
+bool
+as_object::prototypeOf(as_object& instance)
+{
+ const as_object* obj = &instance;
+
+ std::set<const as_object*> visited;
+
+ while (obj && visited.insert(obj).second )
+ {
+ if ( obj->get_prototype() == this ) return true;
+ obj = obj->get_prototype();
+ }
+
+ // See actionscript.all/Inheritance.as for a way to trigger this
+ IF_VERBOSE_ASCODING_ERRORS(
+ if ( obj ) log_aserror("Circular inheritance chain detected during
isPrototypeOf call");
+ );
+
+ return false;
+}
+
void
as_object::dump_members()
{
@@ -498,6 +519,21 @@
}
}
+Property*
+as_object::getOwnProperty(const std::string& name)
+{
+ if ( _vm.getSWFVersion() < 7 )
+ {
+ std::string key = name;
+ boost::to_lower(key, _vm.getLocale());
+ return _members.getProperty(key);
+ }
+ else
+ {
+ return _members.getProperty(name);
+ }
+}
+
void
as_object::tostring_method(const fn_call& fn)
{
Index: server/as_object.h
===================================================================
RCS file: /sources/gnash/gnash/server/as_object.h,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -b -r1.41 -r1.42
--- server/as_object.h 8 Mar 2007 14:51:35 -0000 1.41
+++ server/as_object.h 9 Mar 2007 01:11:42 -0000 1.42
@@ -235,6 +235,21 @@
///
std::pair<bool,bool> delProperty(const std::string& name);
+ /// Get this object's own named property, if existing.
+ //
+ /// This function does *not* recurse in this object's prototype.
+ ///
+ /// @parame name
+ /// Name of the property.
+ /// Case insensitive up to SWF6,
+ /// case *sensitive* from SWF7 up.
+ ///
+ /// @return
+ /// a Property pointer, or NULL if this object doesn't
+ /// contain the named property.
+ ///
+ Property* getOwnProperty(const std::string& name);
+
/// Set member flags (probably used by ASSetPropFlags)
//
/// @parame name
@@ -262,6 +277,7 @@
void clear();
+ /// \brief
/// Check whether this object is an instance of the given
/// as_function constructor
//
@@ -270,6 +286,12 @@
///
bool instanceOf(as_function* ctor);
+ /// \brief
+ /// Check whether this object is a 'prototype' in the given
+ /// object's inheritance chain.
+ //
+ bool prototypeOf(as_object& instance);
+
/// Set property flags
//
/// @param props
Index: server/asobj/Object.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/Object.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- server/asobj/Object.cpp 4 Mar 2007 02:00:42 -0000 1.15
+++ server/asobj/Object.cpp 9 Mar 2007 01:11:42 -0000 1.16
@@ -18,7 +18,7 @@
//
//
-/* $Id: Object.cpp,v 1.15 2007/03/04 02:00:42 strk Exp $ */
+/* $Id: Object.cpp,v 1.16 2007/03/09 01:11:42 strk Exp $ */
// Implementation of ActionScript Object class.
@@ -43,7 +43,12 @@
// Forward declarations
static void object_addproperty(const fn_call&);
-static void object_registerClass(const fn_call&);
+static void object_registerClass(const fn_call& fn);
+static void object_hasOwnProperty(const fn_call&);
+static void object_isPropertyEnumerable(const fn_call&);
+static void object_isPrototypeOf(const fn_call&);
+static void object_watch(const fn_call&);
+static void object_unwatch(const fn_call&);
static void
@@ -62,8 +67,13 @@
o.init_member("toString", new
builtin_function(as_object::tostring_method));
if ( target_version < 6 ) return;
+
o.init_member("addProperty", new builtin_function(object_addproperty));
- o.set_member_flags("addProperty", 1); // hidden
+ o.init_member("hasOwnProperty", new
builtin_function(object_hasOwnProperty));
+ o.init_member("isPropertyEnumerable", new
builtin_function(object_isPropertyEnumerable));
+ o.init_member("isPrototypeOf", new
builtin_function(object_isPrototypeOf));
+ o.init_member("watch", new builtin_function(object_watch));
+ o.init_member("unwatch", new builtin_function(object_unwatch));
}
as_object*
@@ -313,4 +323,99 @@
fn.result->set_bool(false);
}
+void
+object_hasOwnProperty(const fn_call& fn)
+{
+ assert(fn.result->is_undefined());
+ if ( fn.nargs < 1 )
+ {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror("Object.hasOwnProperty() requires one arg");
+ );
+ return;
+ }
+ as_value& arg = fn.arg(0);
+ std::string propname = arg.to_std_string();
+ if ( arg.is_undefined() || propname.empty() )
+ {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror("Invalid call to Object.hasOwnProperty('%s')",
arg.to_string());
+ );
+ return;
+ }
+ fn.result->set_bool(fn.this_ptr->getOwnProperty(propname) != NULL);
+ log_warning("TESTING: %s", __FUNCTION__);
+}
+
+void
+object_isPropertyEnumerable(const fn_call& fn)
+{
+ assert(fn.result->is_undefined());
+ if ( fn.nargs < 1 )
+ {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror("Object.isPropertyEnumerable() requires one arg");
+ );
+ return;
+ }
+ as_value& arg = fn.arg(0);
+ std::string propname = arg.to_std_string();
+ if ( arg.is_undefined() || propname.empty() )
+ {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror("Invalid call to
Object.isPropertyEnumerable('%s')", arg.to_string());
+ );
+ return;
+ }
+
+ Property* prop = fn.this_ptr->getOwnProperty(propname);
+ if ( ! prop )
+ {
+ fn.result->set_bool(false);
+ return;
+ }
+
+ fn.result->set_bool( ! prop->getFlags().get_dont_enum() );
+ log_warning("TESTING: %s", __FUNCTION__);
+}
+
+void
+object_isPrototypeOf(const fn_call& fn)
+{
+ assert(fn.result->is_undefined());
+ if ( fn.nargs < 1 )
+ {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror("Object.isPrototypeOf() requires one arg");
+ );
+ fn.result->set_bool(false);
+ return;
+ }
+
+ as_object* obj = fn.arg(0).to_object();
+ if ( ! obj )
+ {
+ IF_VERBOSE_ASCODING_ERRORS(
+ log_aserror("First arg to Object.isPrototypeOf(%s) is not an
object", fn.arg(0).to_string());
+ );
+ fn.result->set_bool(false);
+ return;
+ }
+
+ fn.result->set_bool(fn.this_ptr->prototypeOf(*obj));
+ log_warning("TESTING: %s", __FUNCTION__);
+}
+
+void
+object_watch(const fn_call&)
+{
+ log_error("FIXME: %s: unimplemented", __FUNCTION__);
+}
+
+void
+object_unwatch(const fn_call&)
+{
+ log_error("FIXME: %s: unimplemented", __FUNCTION__);
+}
+
} // namespace gnash
Index: testsuite/actionscript.all/Object.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/Object.as,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- testsuite/actionscript.all/Object.as 7 Feb 2007 21:51:57 -0000
1.22
+++ testsuite/actionscript.all/Object.as 9 Mar 2007 01:11:42 -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: Object.as,v 1.22 2007/02/07 21:51:57 strk Exp $";
+rcsid="$Id: Object.as,v 1.23 2007/03/09 01:11:42 strk Exp $";
#include "check.as"
@@ -31,8 +31,18 @@
check_equals(typeof(Object.prototype.valueOf), 'function');
#if OUTPUT_VERSION > 5
check_equals(typeof(Object.prototype.addProperty), 'function');
+check_equals(typeof(Object.prototype.hasOwnProperty), 'function');
+check_equals(typeof(Object.prototype.isPropertyEnumerable), 'function');
+check_equals(typeof(Object.prototype.isPrototypeOf), 'function');
+check_equals(typeof(Object.prototype.watch), 'function');
+check_equals(typeof(Object.prototype.unwatch), 'function');
#else
check_equals(typeof(Object.prototype.addProperty), 'undefined');
+check_equals(typeof(Object.prototype.hasOwnProperty), 'undefined');
+check_equals(typeof(Object.prototype.isPropertyEnumerable), 'undefined');
+check_equals(typeof(Object.prototype.isPrototypeOf), 'undefined');
+check_equals(typeof(Object.prototype.watch), 'undefined');
+check_equals(typeof(Object.prototype.unwatch), 'undefined');
#endif
// Test Object creation using 'new'
@@ -94,9 +104,9 @@
check (copy.__proto__.constructor == Object);
-//----------------------
-// Test addProperty
-//----------------------
+//---------------------------------------------
+// Test addProperty / hasOwnProperty (SWF6 up)
+//---------------------------------------------
// Object.addProperty wasn't in SWF5
#if OUTPUT_VERSION > 5
@@ -115,6 +125,22 @@
var ret = obj3.addProperty("len", getLen, setLen);
check_equals(ret, true);
+// toString is not obj3 "own" property, but it's inherited !
+check_equals(typeof(obj3.toString), 'function');
+ownPropertyCheck = obj3.hasOwnProperty("toString");
+check_equals(typeof(ownPropertyCheck), 'boolean');
+check(!ownPropertyCheck);
+
+// 'member' is an obj3 "own" member (not inherited)
+ownPropertyCheck = obj3.hasOwnProperty("member");
+check_equals(typeof(ownPropertyCheck), 'boolean');
+check(ownPropertyCheck);
+
+// 'len' is an obj3 "own" property (not inherited)
+ownPropertyCheck = obj3.hasOwnProperty("len");
+check_equals(typeof(ownPropertyCheck), 'boolean');
+check(ownPropertyCheck);
+
check_equals (obj3.len, undefined);
obj3._len = 3;
check_equals (obj3.len, 3);
@@ -157,6 +183,7 @@
o.addProperty = function(a, b) { return a+b; };
var c = o.addProperty(2,5);
check_equals(c, 7);
+check(o.addProperty != Object.prototype.addProperty );
// Object.addProperty wasn't in SWF5
#endif // OUTPUT_VERSION > 5
@@ -208,3 +235,87 @@
#else
check_equals(obj5['A'], undefined);
#endif
+
+//----------------------------------------------------
+// Test Object.isPropertyEnumerable (SWF6 up)
+//----------------------------------------------------
+
+#if OUTPUT_VERSION > 5
+
+// quick built-ins check
+check( Object.prototype.hasOwnProperty("isPropertyEnumerable") );
+check( ! Object.prototype.isPropertyEnumerable("isPropertyEnumerable") );
+check( Object.prototype.hasOwnProperty("addProperty") );
+check( ! Object.prototype.isPropertyEnumerable("addProperty") );
+check( Object.prototype.hasOwnProperty("hasOwnProperty") );
+check( ! Object.prototype.isPropertyEnumerable("hasOwnProperty") );
+
+obj6 = new Object();
+obj6.member = "a member";
+
+ret = obj6.isPropertyEnumerable('unexistent');
+check_equals(typeof(ret), 'boolean');
+check( ! ret ); // non-existant
+
+ret = obj6.isPropertyEnumerable('member');
+check_equals(typeof(ret), 'boolean');
+check( ret );
+
+function enumerableThings()
+{
+ this.member1 = "a string";
+ this.member2 = 3;
+ ASSetPropFlags(this, "member2", 1); // hide member2
+}
+enumerableThings.prototype.member3 = new Object;
+
+ret = enumerableThing.isPropertyEnumerable('member1');
+check_equals( typeof(ret), 'undefined' );
+
+obj7 = new enumerableThings();
+check( obj7.isPropertyEnumerable('member1') );
+check( ! obj7.isPropertyEnumerable('member2') );
+check_equals( typeof(obj7.member3), 'object' );
+check( ! obj7.isPropertyEnumerable('member3') );
+
+#endif // OUTPUT_VERSION > 5
+
+//----------------------------------------------------
+// Test Object.isPrototypeOf (SWF6 up)
+//----------------------------------------------------
+
+#if OUTPUT_VERSION > 5
+
+obj8 = function() {};
+obj9 = function() {};
+obj9.__proto__ = new obj8;
+obj10 = new obj9;
+
+check_equals( typeof(obj8.isPrototypeOf(obj8)), 'boolean' );
+check_equals( typeof(obj8.isPrototypeOf(undefined)), 'boolean' );
+check( obj9.prototype.isPrototypeOf(obj10) );
+check( ! obj8.prototype.isPrototypeOf(obj10) );
+check( obj8.prototype.isPrototypeOf(obj9) );
+// TODO: add tests here !
+
+#endif // OUTPUT_VERSION > 5
+
+//----------------------------------------------------
+// Test Object.watch (SWF6 up)
+//----------------------------------------------------
+
+#if OUTPUT_VERSION > 5
+
+// TODO: add tests here !
+
+#endif // OUTPUT_VERSION > 5
+
+//----------------------------------------------------
+// Test Object.unwatch (SWF6 up)
+//----------------------------------------------------
+
+#if OUTPUT_VERSION > 5
+
+// TODO: add tests here !
+
+#endif // OUTPUT_VERSION > 5
- [Gnash-commit] gnash ChangeLog server/as_object.cpp server/as_...,
Sandro Santilli <=