[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog server/as_object.h server/as_va...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog server/as_object.h server/as_va... |
Date: |
Fri, 26 Oct 2007 07:39:48 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 07/10/26 07:39:48
Modified files:
. : ChangeLog
server : as_object.h as_value.cpp as_value.h
server/asobj : Date.cpp
Log message:
* server/as_object.h: add virtual isDateObject() method.
* server/asobj/Date.cpp: implement isDateObject, have valueOf
always return a number.
* server/as_value.{cpp,h}: to_primitive for date objects returns
a string rather then a number.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.4715&r2=1.4716
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_object.h?cvsroot=gnash&r1=1.76&r2=1.77
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_value.cpp?cvsroot=gnash&r1=1.88&r2=1.89
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_value.h?cvsroot=gnash&r1=1.71&r2=1.72
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/Date.cpp?cvsroot=gnash&r1=1.51&r2=1.52
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.4715
retrieving revision 1.4716
diff -u -b -r1.4715 -r1.4716
--- ChangeLog 25 Oct 2007 22:27:06 -0000 1.4715
+++ ChangeLog 26 Oct 2007 07:39:47 -0000 1.4716
@@ -1,3 +1,11 @@
+2007-10-26 Sandro Santilli <address@hidden>
+
+ * server/as_object.h: add virtual isDateObject() method.
+ * server/asobj/Date.cpp: implement isDateObject, have valueOf
+ always return a number.
+ * server/as_value.{cpp,h}: to_primitive for date objects returns
+ a string rather then a number.
+
2007-10-25 Sandro Santilli <address@hidden>
* testsuite/actionscript.all/Date.as: couple more tests.
Index: server/as_object.h
===================================================================
RCS file: /sources/gnash/gnash/server/as_object.h,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -b -r1.76 -r1.77
--- server/as_object.h 24 Oct 2007 07:58:14 -0000 1.76
+++ server/as_object.h 26 Oct 2007 07:39:47 -0000 1.77
@@ -611,6 +611,15 @@
/// Cast to a as_function, or return NULL
virtual as_function* to_function() { return NULL; }
+ /// Return true if this is a Date object.
+ //
+ /// This is needed for special handling of Date objects
+ /// by the as_value::to_primitive method, also described
+ /// in ECMA-262 "8.6.2.6 [[DefaultValue]] (hint)"
+ ///
+ ///
+ virtual bool isDateObject() { return false; }
+
/// Add an interface to the list of interfaces.
/// Used by instanceOf
void add_interface(as_object* ctor);
Index: server/as_value.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/as_value.cpp,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -b -r1.88 -r1.89
--- server/as_value.cpp 18 Oct 2007 11:47:54 -0000 1.88
+++ server/as_value.cpp 26 Oct 2007 07:39:47 -0000 1.89
@@ -183,15 +183,70 @@
return to_string(env);
}
+primitive_types
+as_value::ptype() const
+{
+ VM& vm = VM::get();
+ int swfVersion = vm.getSWFVersion();
+
+ switch (m_type)
+ {
+ case STRING: return PTYPE_STRING;
+ case NUMBER: return PTYPE_NUMBER;
+ case AS_FUNCTION:
+ case UNDEFINED:
+ case NULLTYPE:
+ case MOVIECLIP:
+ return PTYPE_NUMBER;
+ case OBJECT:
+ {
+ as_object* obj = getObj().get();
+ // Date objects should return TYPE_STRING (but only from SWF6
up)
+ // See ECMA-262 8.6.2.6
+ if ( swfVersion > 5 && obj->isDateObject() ) return
PTYPE_STRING;
+ return PTYPE_NUMBER;
+ }
+ case BOOLEAN:
+ return PTYPE_BOOLEAN;
+ default:
+ break; // Should be only exceptions here.
+ }
+ return PTYPE_NUMBER;
+}
+
// Conversion to primitive value.
as_value
as_value::to_primitive(as_environment& env) const
{
+ VM& vm = VM::get();
+ int swfVersion = vm.getSWFVersion();
+
+ type hint = NUMBER;
- if ( m_type == OBJECT || m_type == AS_FUNCTION )
+ if ( m_type == OBJECT && swfVersion > 5 && getObj()->isDateObject() )
{
- as_object* obj = m_type == OBJECT ? getObj().get() :
getFun().get();
- string_table::key methodname = NSV::PROP_VALUE_OF;
+ hint = STRING;
+ }
+
+ return to_primitive(env, hint);
+}
+
+// Conversion to primitive value.
+as_value
+as_value::to_primitive(as_environment& env, type hint) const
+{
+ if ( m_type != OBJECT && m_type != AS_FUNCTION ) return *this;
+
+ as_object* obj;
+ if ( m_type == OBJECT ) obj = getObj().get();
+ else obj = getFun().get();
+
+ // TODO: implement DefaultValue (ECMA-262 - 8.6.2.6)
+
+ string_table::key methodname;
+ if (hint == NUMBER) { methodname=NSV::PROP_VALUE_OF; }
+ else { assert(hint==STRING); methodname=NSV::PROP_TO_STRING; }
+
as_value method;
if ( obj->get_member(methodname, &method) )
{
@@ -201,7 +256,6 @@
{
log_msg(_("get_member(%s) returned false"),
VM::get().getStringTable().value(methodname).c_str());
}
- }
return *this;
Index: server/as_value.h
===================================================================
RCS file: /sources/gnash/gnash/server/as_value.h,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -b -r1.71 -r1.72
--- server/as_value.h 18 Oct 2007 11:47:54 -0000 1.71
+++ server/as_value.h 26 Oct 2007 07:39:47 -0000 1.72
@@ -15,7 +15,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-/* $Id: as_value.h,v 1.71 2007/10/18 11:47:54 cmusick Exp $ */
+/* $Id: as_value.h,v 1.72 2007/10/26 07:39:47 strk Exp $ */
#ifndef GNASH_AS_VALUE_H
#define GNASH_AS_VALUE_H
@@ -211,27 +211,7 @@
const char* typeOf() const;
/// Get the primitive type of this value
- primitive_types ptype() const
- {
- switch (m_type)
- {
- case STRING: return PTYPE_STRING;
- case NUMBER: return PTYPE_NUMBER;
- case AS_FUNCTION:
- case UNDEFINED:
- case NULLTYPE:
- case MOVIECLIP:
- return PTYPE_NUMBER;
- case OBJECT:
- // TODO: Date objects should return TYPE_STRING
- return PTYPE_NUMBER;
- case BOOLEAN:
- return PTYPE_BOOLEAN;
- default:
- break; // Should be only exceptions here.
- }
- return PTYPE_NUMBER;
- }
+ primitive_types ptype() const;
// Chad: Document
bool conforms_to(string_table::key name);
@@ -402,13 +382,26 @@
/// Return value as a primitive type
//
/// Primitive types are: undefined, null, boolean, string, number.
- /// See ECMA-2.6.2 (section 4.3.2).
+ /// See ECMA-2.6.2 (sections 4.3.2 and 8.6.2.6).
///
/// @param env
/// The environment to use for calling the valueOf method.
///
as_value to_primitive(as_environment& env) const;
+ /// Return value as a primitive type, with a preference
+ //
+ /// Primitive types are: undefined, null, boolean, string, number.
+ /// See ECMA-2.6.2 (sections 4.3.2 and 8.6.2.6).
+ ///
+ /// @param env
+ /// The environment to use for calling the valueOf method.
+ ///
+ /// @param hint
+ /// NUMBER or STRING, the preferred representation we're asking for.
+ ///
+ as_value to_primitive(as_environment& env, type hint) const;
+
/// Force type to number.
//
/// @param env
Index: server/asobj/Date.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/Date.cpp,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -b -r1.51 -r1.52
--- server/asobj/Date.cpp 25 Oct 2007 15:35:36 -0000 1.51
+++ server/asobj/Date.cpp 26 Oct 2007 07:39:47 -0000 1.52
@@ -342,6 +342,8 @@
{
}
+ bool isDateObject() { return true; }
+
as_value tostring()
{
char buffer[40]; // 32 chars + slop
@@ -1350,9 +1352,11 @@
static as_value date_valueof(const fn_call& fn) {
boost::intrusive_ptr<date_as_object> date =
ensureType<date_as_object>(fn.this_ptr);
+#if 0
if (fn.env().get_version() > 5)
return as_value(date->tostring());
else
+#endif
return as_value(date->value);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog server/as_object.h server/as_va...,
Sandro Santilli <=