CVSROOT: /sources/gnash Module name: gnash Changes by: Sandro Santilli <strk> 07/08/02 20:11:35
Modified files: . : ChangeLog server : as_value.cpp testsuite/actionscript.all: ops.as Log message: * server/as_value.cpp (equals): yet another pass at abstract equality operator. We're still not there, but getting closer. * testsuite/actionscript.all/ops.as: xcheck -> check. CVSWeb URLs: http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.3920&r2=1.3921 http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_value.cpp?cvsroot=gnash&r1=1.62&r2=1.63 http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/ops.as?cvsroot=gnash&r1=1.7&r2=1.8 Patches: Index: ChangeLog =================================================================== RCS file: /sources/gnash/gnash/ChangeLog,v retrieving revision 1.3920 retrieving revision 1.3921 diff -u -b -r1.3920 -r1.3921 --- ChangeLog 2 Aug 2007 19:10:51 -0000 1.3920 +++ ChangeLog 2 Aug 2007 20:11:35 -0000 1.3921 @@ -1,5 +1,12 @@ 2007-08-02 Sandro Santilli <[EMAIL PROTECTED]> + * server/as_value.cpp (equals): yet another pass at + abstract equality operator. We're still not there, but + getting closer. + * testsuite/actionscript.all/ops.as: xcheck -> check. + +2007-08-02 Sandro Santilli <[EMAIL PROTECTED]> + * testsuite/actionscript.all/: Function.as, ops.as: Moved tests for equality operator against MovieClip where it belongs. Index: server/as_value.cpp =================================================================== RCS file: /sources/gnash/gnash/server/as_value.cpp,v retrieving revision 1.62 retrieving revision 1.63 diff -u -b -r1.62 -r1.63 --- server/as_value.cpp 2 Aug 2007 18:28:42 -0000 1.62 +++ server/as_value.cpp 2 Aug 2007 20:11:35 -0000 1.63 @@ -46,6 +46,9 @@ // rather then by "target" ref. #define MOVIECLIP_AS_SOFTREF +// Define the macro below to make abstract equality operator verbose +//#define GNASH_DEBUG_EQUALITY + namespace gnash { // @@ -632,7 +635,12 @@ bool as_value::equals(const as_value& v, as_environment& env) const { - //log_msg("equals(%s, %s) called", to_debug_string().c_str(), v.to_debug_string().c_str()); + // Comments starting with numbers refer to the ECMA-262 document + +#ifdef GNASH_DEBUG_EQUALITY + static int count=0; + log_debug("equals(%s, %s) called [%d]", to_debug_string().c_str(), v.to_debug_string().c_str(), count++); +#endif bool this_nulltype = (m_type == UNDEFINED || m_type == NULLTYPE); bool v_nulltype = (v.get_type() == UNDEFINED || v.get_type() == NULLTYPE); @@ -648,46 +656,82 @@ if ( obj_or_func && v_obj_or_func ) return m_object_value == v.m_object_value; if ( m_type == v.m_type ) return equalsSameType(v); + // 16. If Type(x) is Number and Type(y) is String, + // return the result of the comparison x == ToNumber(y). else if (m_type == NUMBER && v.m_type == STRING) { return equalsSameType(v.to_number(&env)); } + + // 17. If Type(x) is String and Type(y) is Number, + // return the result of the comparison ToNumber(x) == y. else if (v.m_type == NUMBER && m_type == STRING) { return v.equalsSameType(to_number(&env)); } - else if (m_type == STRING) - { - return m_string_value == v.to_string(&env); - } + + // 18. If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y. else if (m_type == BOOLEAN) { return as_value(to_number(&env)).equals(v, env); // m_boolean_value == v.to_bool(); } + + // 19. If Type(y) is Boolean, return the result of the comparison x == ToNumber(y). else if (v.m_type == BOOLEAN) { return as_value(v.to_number(&env)).equals(*this, env); } - else if (m_type == OBJECT || m_type == AS_FUNCTION) + // 20. If Type(x) is either String or Number and Type(y) is Object, + // return the result of the comparison x == ToPrimitive(y). + else if ( (m_type == STRING || m_type == NUMBER ) && ( v.is_object() ) ) // v.m_type == OBJECT || v.m_type == AS_FUNCTION ) ) + { + // convert this value to a primitive and recurse + as_value v2 = v.to_primitive(env); +#ifdef GNASH_DEBUG_EQUALITY + log_debug(" convertion to primitive : %s -> %s", v.to_debug_string().c_str(), v2.to_debug_string().c_str()); +#endif + if ( v.strictly_equals(v2) ) // returned self ? + { + return false; // no valid conversion + } + else return equals(v2, env); + } + + // 21. If Type(x) is Object and Type(y) is either String or Number, + // return the result of the comparison ToPrimitive(x) == y. + else if ( (v.m_type == STRING || v.m_type == NUMBER ) && ( is_object() ) ) // m_type == OBJECT || m_type == AS_FUNCTION ) ) { - assert ( ! (v.m_type == OBJECT || v.m_type == AS_FUNCTION) ); // convert this value to a primitive and recurse as_value v2 = to_primitive(env); - if ( v2.m_type == OBJECT || v2.m_type == AS_FUNCTION ) return false; // no valid conversion +#ifdef GNASH_DEBUG_EQUALITY + log_debug(" convertion to primitive : %s -> %s", to_debug_string().c_str(), v2.to_debug_string().c_str()); +#endif + if ( strictly_equals(v2) ) // returned self ? + { + return false; // no valid conversion + } else return v2.equals(v, env); } - else if (v.m_type == OBJECT || v.m_type == AS_FUNCTION) + // Both operands are objects (OBJECT,AS_FUNCTION,MOVIECLIP) + assert(is_object() && v.is_object()); + + // If any of the two converts to a primitive, we recurse + + as_value p = to_primitive(env); + as_value vp = v.to_primitive(env); +#ifdef GNASH_DEBUG_EQUALITY + log_debug(" convertion to primitive (this): %s -> %s", to_debug_string().c_str(), p.to_debug_string().c_str()); + log_debug(" convertion to primitive (that): %s -> %s", v.to_debug_string().c_str(), vp.to_debug_string().c_str()); +#endif + if ( strictly_equals(p) && v.strictly_equals(vp) ) // both returned self ? { - assert ( ! (m_type == OBJECT || m_type == AS_FUNCTION) ); - // convert this value to a primitive and recurse - as_value v2 = v.to_primitive(env); - if ( v2.m_type == OBJECT || v2.m_type == AS_FUNCTION ) return false; // no valid conversion - else return equals(v2, env); + return false; // no valid conversion } - return false; + return p.equals(vp, env); + } // Sets *this to this string plus the given string. Index: testsuite/actionscript.all/ops.as =================================================================== RCS file: /sources/gnash/gnash/testsuite/actionscript.all/ops.as,v retrieving revision 1.7 retrieving revision 1.8 diff -u -b -r1.7 -r1.8 --- testsuite/actionscript.all/ops.as 2 Aug 2007 19:10:51 -0000 1.7 +++ testsuite/actionscript.all/ops.as 2 Aug 2007 20:11:35 -0000 1.8 @@ -20,7 +20,7 @@ * Test binary predicates (equal, less_then, greater_then, logical and bitwise ops) */ -rcsid="$Id: ops.as,v 1.7 2007/08/02 19:10:51 strk Exp $"; +rcsid="$Id: ops.as,v 1.8 2007/08/02 20:11:35 strk Exp $"; #include "check.as" @@ -56,7 +56,7 @@ ary2 = [1,2,3]; check( ! (ary1 == ary2) ); // two different objects check( ! (ary1 == "1,2,3") ); // the array doesn't get converted to a string -xcheck( ! ("1,2,3" == ary1) ); // the array doesn't get converted to a string +check( ! ("1,2,3" == ary1) ); // the array doesn't get converted to a string // for String str1 = new String("hello"); _______________________________________________ Gnash-commit mailing list Gnash-commit@gnu.org http://lists.gnu.org/mailman/listinfo/gnash-commit