[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog server/as_value.cpp server/as_v...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog server/as_value.cpp server/as_v... |
Date: |
Mon, 05 May 2008 21:02:02 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 08/05/05 21:02:02
Modified files:
. : ChangeLog
server : as_value.cpp as_value.h
server/asobj/flash/geom: Rectangle_as.cpp
testsuite/actionscript.all: Makefile.am
Added files:
testsuite/actionscript.all: Rectangle.as
Log message:
* server/as_value.{cpp,h}: add convert_to_primitive to
possibly reduce copies of as_value; add newAdd and subtract
methods doing the same as the corresponding opcodes to
make C++ implementation of AS-like code easier.
(opcodes untoched, would likely be worth delegating).
* testsuite/actionscript.all/: Makefile.am, Rectangle.as:
Initial tests for flash.geom.Rectangle class
* server/asobj/flash/geom/Rectangle_as.cpp: implement constructor,
left/top/right/bottom getter-setters, isEmpty method.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6513&r2=1.6514
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_value.cpp?cvsroot=gnash&r1=1.132&r2=1.133
http://cvs.savannah.gnu.org/viewcvs/gnash/server/as_value.h?cvsroot=gnash&r1=1.90&r2=1.91
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/flash/geom/Rectangle_as.cpp?cvsroot=gnash&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/Makefile.am?cvsroot=gnash&r1=1.89&r2=1.90
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/Rectangle.as?cvsroot=gnash&rev=1.1
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6513
retrieving revision 1.6514
diff -u -b -r1.6513 -r1.6514
--- ChangeLog 5 May 2008 19:01:54 -0000 1.6513
+++ ChangeLog 5 May 2008 21:02:00 -0000 1.6514
@@ -1,5 +1,17 @@
2008-05-05 Sandro Santilli <address@hidden>
+ * server/as_value.{cpp,h}: add convert_to_primitive to
+ possibly reduce copies of as_value; add newAdd and subtract
+ methods doing the same as the corresponding opcodes to
+ make C++ implementation of AS-like code easier.
+ (opcodes untoched, would likely be worth delegating).
+ * testsuite/actionscript.all/: Makefile.am, Rectangle.as:
+ Initial tests for flash.geom.Rectangle class
+ * server/asobj/flash/geom/Rectangle_as.cpp: implement constructor,
+ left/top/right/bottom getter-setters, isEmpty method.
+
+2008-05-05 Sandro Santilli <address@hidden>
+
* server/namedStrings.{cpp,h}: add PROP_WIDTH and PROP_HEIGHT.
2008-05-05 Benjamin Wolsey <address@hidden>
Index: server/as_value.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/as_value.cpp,v
retrieving revision 1.132
retrieving revision 1.133
diff -u -b -r1.132 -r1.133
--- server/as_value.cpp 3 May 2008 15:06:28 -0000 1.132
+++ server/as_value.cpp 5 May 2008 21:02:01 -0000 1.133
@@ -264,6 +264,29 @@
return to_primitive(hint);
}
+as_value&
+as_value::convert_to_primitive()
+{
+ VM& vm = VM::get();
+ int swfVersion = vm.getSWFVersion();
+
+ type hint = NUMBER;
+
+ if ( m_type == OBJECT && swfVersion > 5 && getObj()->isDateObject() )
+ {
+ hint = STRING;
+ }
+
+#if 0
+ else if ( m_type == MOVIECLIP && swfVersion > 5 )
+ {
+ throw ActionTypeError();
+ }
+#endif
+
+ return convert_to_primitive(hint);
+}
+
// Conversion to primitive value.
as_value
as_value::to_primitive(type hint) const
@@ -375,6 +398,108 @@
}
+// Conversion to primitive value.
+as_value&
+as_value::convert_to_primitive(type hint)
+{
+ if ( m_type != OBJECT && m_type != AS_FUNCTION ) return *this;
+ //if ( ! is_object() ) return *this; // include MOVIECLIP !!
+
+#if GNASH_DEBUG_CONVERSION_TO_PRIMITIVE
+ log_debug("to_primitive(%s)", hint==NUMBER ? "NUMBER" : "STRING");
+#endif
+
+ // TODO: implement as_object::DefaultValue (ECMA-262 - 8.6.2.6)
+
+ as_value method;
+ as_object* obj = NULL;
+
+ if (hint == NUMBER)
+ {
+ if ( m_type == MOVIECLIP )
+ {
+ set_double(NAN);
+ return *this;
+ }
+ if ( m_type == OBJECT ) obj = getObj().get();
+ else obj = getFun().get();
+
+ if ( (!obj->get_member(NSV::PROP_VALUE_OF, &method)) ||
(!method.is_object()) ) // ECMA says ! is_object()
+ {
+#if GNASH_DEBUG_CONVERSION_TO_PRIMITIVE
+ log_debug(" valueOf not found");
+#endif
+ // Returning undefined here instead of throwing
+ // a TypeError passes tests in
actionscript.all/Object.as
+ // and many swfdec tests, with no new failures (though
+ // perhaps we aren't testing enough).
+ set_undefined();
+ return *this;
+
+ }
+ }
+ else
+ {
+ assert(hint==STRING);
+
+ if ( m_type == MOVIECLIP )
+ {
+ set_string(getCharacterProxy().getTarget());
+ return *this;
+ }
+
+ if ( m_type == OBJECT ) obj = getObj().get();
+ else obj = getFun().get();
+
+ // @@ Moock says, "the value that results from
+ // calling toString() on the object".
+ //
+ // When the toString() method doesn't exist, or
+ // doesn't return a valid number, the default
+ // text representation for that object is used
+ // instead.
+ //
+ if ( ! obj->useCustomToString() )
+ {
+#if GNASH_DEBUG_CONVERSION_TO_PRIMITIVE
+ log_debug(" not using custom toString");
+#endif
+ set_string(obj->get_text_value());
+ return *this;
+ }
+
+ if ( (!obj->get_member(NSV::PROP_TO_STRING, &method)) ||
(!method.is_function()) ) // ECMA says ! is_object()
+ {
+#if GNASH_DEBUG_CONVERSION_TO_PRIMITIVE
+ log_debug(" toString not found");
+#endif
+ if ( (!obj->get_member(NSV::PROP_VALUE_OF, &method)) ||
(!method.is_function()) ) // ECMA says ! is_object()
+ {
+#if GNASH_DEBUG_CONVERSION_TO_PRIMITIVE
+ log_debug(" valueOf not found");
+#endif
+ throw ActionTypeError();
+ }
+ }
+ }
+
+ assert(obj);
+
+ as_environment env;
+ as_value ret = call_method0(method, &env, obj);
+#if GNASH_DEBUG_CONVERSION_TO_PRIMITIVE
+ log_debug("to_primitive: method call returned %s",
ret.to_debug_string().c_str());
+#endif
+ if ( ret.m_type == OBJECT || ret.m_type == AS_FUNCTION ) // not a
primitive
+ {
+ throw ActionTypeError();
+ }
+
+ *this = ret;
+
+ return *this;
+}
+
double
as_value::to_number() const
{
@@ -1575,6 +1700,63 @@
if ( _ptr ) _ptr->setReachable();
}
+as_value&
+as_value::newAdd(const as_value& op2)
+{
+ as_value v2=op2;
+
+ try { convert_to_primitive(); }
+ catch (ActionTypeError& e)
+ {
+ log_debug("%s.to_primitive() threw an error during as_value
operator+",
+ to_debug_string().c_str());
+ }
+
+ try { v2 = v2.to_primitive(); }
+ catch (ActionTypeError& e)
+ {
+ log_debug("%s.to_primitive() threw an error during as_value
operator+",
+ op2.to_debug_string().c_str());
+ }
+
+#if GNASH_DEBUG
+ log_debug(_("(%s + %s) [primitive conversion done]"),
+ to_debug_string().c_str(),
+ v2.to_debug_string().c_str());
+#endif
+
+ if (is_string() || v2.is_string() )
+ {
+ // use string semantic
+
+ int version = VM::get().getSWFVersion();
+ convert_to_string_versioned(version);
+ string_concat(v2.to_string_versioned(version));
+ }
+ else
+ {
+ // use numeric semantic
+ double v2num = v2.to_number();
+ //log_debug(_("v2 num = %g"), v2num);
+ double v1num = to_number();
+ //log_debug(_("v1 num = %g"), v1num);
+
+ set_double(v2num + v1num);
+
+ }
+
+ return *this;
+}
+
+as_value&
+as_value::subtract(const as_value& op2)
+{
+ double operand1 = to_number();
+ double operand2 = op2.to_number();
+ set_double(operand1 - operand2);
+ return *this;
+}
+
} // namespace gnash
Index: server/as_value.h
===================================================================
RCS file: /sources/gnash/gnash/server/as_value.h,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -b -r1.90 -r1.91
--- server/as_value.h 31 Mar 2008 07:13:59 -0000 1.90
+++ server/as_value.h 5 May 2008 21:02:01 -0000 1.91
@@ -385,13 +385,19 @@
/// or NULL if it is not an ActionScript function.
as_function* to_as_function() const;
- /// Return value as a primitive type
+ /// Convert this value to a primitive type
//
/// 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.
+ /// @throw ActionTypeError if an object can't be converted to a
primitive
+ ///
+ as_value& convert_to_primitive();
+
+ /// Return value as a primitive type
+ //
+ /// Primitive types are: undefined, null, boolean, string, number.
+ /// See ECMA-2.6.2 (sections 4.3.2 and 8.6.2.6).
///
/// @throw ActionTypeError if an object can't be converted to a
primitive
///
@@ -412,6 +418,18 @@
///
as_value to_primitive(type hint) const;
+ /// Convert this value to 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 hint
+ /// NUMBER or STRING, the preferred representation we're asking for.
+ ///
+ /// @throw ActionTypeError if an object can't be converted to a
primitive
+ ///
+ as_value& convert_to_primitive(type hint);
+
/// Force type to number.
//
/// @param env
@@ -550,6 +568,14 @@
/// Sets this value to this string plus the given string.
void string_concat(const std::string& str);
+ /// Equivalent of ActionNewAdd
+ as_value& newAdd(const as_value& v1);
+
+ // Equivalent of ActionSubtract
+ as_value& subtract(const as_value& o);
+
+
+
/// Set any object value as reachable (for the GC)
//
/// Object values are values stored by pointer (objects and functions)
Index: server/asobj/flash/geom/Rectangle_as.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/flash/geom/Rectangle_as.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- server/asobj/flash/geom/Rectangle_as.cpp 5 May 2008 18:53:32 -0000
1.5
+++ server/asobj/flash/geom/Rectangle_as.cpp 5 May 2008 21:02:01 -0000
1.6
@@ -30,6 +30,8 @@
#include "GnashException.h" // for ActionException
#include "Object.h" // for AS inheritance
#include "VM.h" // for addStatics
+#include "as_value.h"
+#include "namedStrings.h"
#include <sstream>
@@ -52,15 +54,11 @@
static as_value Rectangle_union(const fn_call& fn);
static as_value Rectangle_bottom_getset(const fn_call& fn);
static as_value Rectangle_bottomRight_getset(const fn_call& fn);
-static as_value Rectangle_height_getset(const fn_call& fn);
static as_value Rectangle_left_getset(const fn_call& fn);
static as_value Rectangle_right_getset(const fn_call& fn);
static as_value Rectangle_size_getset(const fn_call& fn);
static as_value Rectangle_top_getset(const fn_call& fn);
static as_value Rectangle_topLeft_getset(const fn_call& fn);
-static as_value Rectangle_width_getset(const fn_call& fn);
-static as_value Rectangle_x_getset(const fn_call& fn);
-static as_value Rectangle_y_getset(const fn_call& fn);
as_value Rectangle_ctor(const fn_call& fn);
@@ -68,38 +66,33 @@
static void
attachRectangleInterface(as_object& o)
{
- o.init_member("clone", new builtin_function(Rectangle_clone));
- o.init_member("contains", new builtin_function(Rectangle_contains));
- o.init_member("containsPoint", new
builtin_function(Rectangle_containsPoint));
- o.init_member("containsRectangle", new
builtin_function(Rectangle_containsRectangle));
- o.init_member("equals", new builtin_function(Rectangle_equals));
- o.init_member("inflate", new builtin_function(Rectangle_inflate));
- o.init_member("inflatePoint", new
builtin_function(Rectangle_inflatePoint));
- o.init_member("intersection", new
builtin_function(Rectangle_intersection));
- o.init_member("intersects", new builtin_function(Rectangle_intersects));
- o.init_member("isEmpty", new builtin_function(Rectangle_isEmpty));
- o.init_member("offset", new builtin_function(Rectangle_offset));
- o.init_member("offsetPoint", new builtin_function(Rectangle_offsetPoint));
- o.init_member("setEmpty", new builtin_function(Rectangle_setEmpty));
- o.init_member("toString", new builtin_function(Rectangle_toString));
- o.init_member("union", new builtin_function(Rectangle_union));
- o.init_property("bottom", Rectangle_bottom_getset,
Rectangle_bottom_getset);
- o.init_property("bottomRight", Rectangle_bottomRight_getset,
Rectangle_bottomRight_getset);
- o.init_property("height", Rectangle_height_getset,
Rectangle_height_getset);
- o.init_property("left", Rectangle_left_getset, Rectangle_left_getset);
- o.init_property("right", Rectangle_right_getset, Rectangle_right_getset);
- o.init_property("size", Rectangle_size_getset, Rectangle_size_getset);
- o.init_property("top", Rectangle_top_getset, Rectangle_top_getset);
- o.init_property("topLeft", Rectangle_topLeft_getset,
Rectangle_topLeft_getset);
- o.init_property("width", Rectangle_width_getset, Rectangle_width_getset);
- o.init_property("x", Rectangle_x_getset, Rectangle_x_getset);
- o.init_property("y", Rectangle_y_getset, Rectangle_y_getset);
+ o.init_member("clone", new builtin_function(Rectangle_clone), 0);
+ o.init_member("contains", new builtin_function(Rectangle_contains), 0);
+ o.init_member("containsPoint", new
builtin_function(Rectangle_containsPoint), 0);
+ o.init_member("containsRectangle", new
builtin_function(Rectangle_containsRectangle), 0);
+ o.init_member("equals", new builtin_function(Rectangle_equals), 0);
+ o.init_member("inflate", new builtin_function(Rectangle_inflate), 0);
+ o.init_member("inflatePoint", new
builtin_function(Rectangle_inflatePoint), 0);
+ o.init_member("intersection", new
builtin_function(Rectangle_intersection), 0);
+ o.init_member("intersects", new builtin_function(Rectangle_intersects), 0);
+ o.init_member("isEmpty", new builtin_function(Rectangle_isEmpty), 0);
+ o.init_member("offset", new builtin_function(Rectangle_offset), 0);
+ o.init_member("offsetPoint", new builtin_function(Rectangle_offsetPoint),
0);
+ o.init_member("setEmpty", new builtin_function(Rectangle_setEmpty), 0);
+ o.init_member("toString", new builtin_function(Rectangle_toString), 0);
+ o.init_member("union", new builtin_function(Rectangle_union), 0);
+ o.init_property("bottom", Rectangle_bottom_getset,
Rectangle_bottom_getset, 0);
+ o.init_property("bottomRight", Rectangle_bottomRight_getset,
Rectangle_bottomRight_getset, 0);
+ o.init_property("left", Rectangle_left_getset, Rectangle_left_getset, 0);
+ o.init_property("right", Rectangle_right_getset, Rectangle_right_getset,
0);
+ o.init_property("size", Rectangle_size_getset, Rectangle_size_getset, 0);
+ o.init_property("top", Rectangle_top_getset, Rectangle_top_getset, 0);
+ o.init_property("topLeft", Rectangle_topLeft_getset,
Rectangle_topLeft_getset, 0);
}
static void
-attachRectangleStaticProperties(as_object& o)
+attachRectangleStaticProperties(as_object& /*o*/)
{
-
}
static as_object*
@@ -224,9 +217,24 @@
Rectangle_isEmpty(const fn_call& fn)
{
boost::intrusive_ptr<Rectangle_as> ptr =
ensureType<Rectangle_as>(fn.this_ptr);
- UNUSED(ptr);
- LOG_ONCE( log_unimpl (__FUNCTION__) );
- return as_value();
+
+ as_value w;
+ ptr->get_member(NSV::PROP_WIDTH, &w);
+ if ( w.is_undefined() || w.is_null() ) return as_value(true);
+
+ as_value h;
+ ptr->get_member(NSV::PROP_HEIGHT, &h);
+ if ( h.is_undefined() || h.is_null() ) return as_value(true);
+
+ double wn = w.to_number();
+ if ( ! isfinite(wn) || wn == 0 ) return as_value(true);
+
+ double hn = h.to_number();
+ if ( ! isfinite(hn) || hn == 0 ) return as_value(true);
+
+ log_debug("Width: %g, Height: %g", wn, hn);
+
+ return as_value(false);
}
static as_value
@@ -260,9 +268,22 @@
Rectangle_toString(const fn_call& fn)
{
boost::intrusive_ptr<Rectangle_as> ptr =
ensureType<Rectangle_as>(fn.this_ptr);
- UNUSED(ptr);
- LOG_ONCE( log_unimpl (__FUNCTION__) );
- return as_value();
+
+ as_value x, y, w, h;
+
+ ptr->get_member(NSV::PROP_X, &x);
+ ptr->get_member(NSV::PROP_Y, &y);
+ ptr->get_member(NSV::PROP_WIDTH, &w);
+ ptr->get_member(NSV::PROP_HEIGHT, &h);
+
+ std::stringstream ss;
+ ss << "(x=" << x.to_string()
+ << ", y=" << y.to_string()
+ << ", w=" << w.to_string()
+ << ", h=" << h.to_string()
+ << ")";
+
+ return as_value(ss.str());
}
static as_value
@@ -278,22 +299,31 @@
Rectangle_bottom_getset(const fn_call& fn)
{
boost::intrusive_ptr<Rectangle_as> ptr =
ensureType<Rectangle_as>(fn.this_ptr);
- UNUSED(ptr);
- LOG_ONCE( log_unimpl (__FUNCTION__) );
- return as_value();
-}
-static as_value
-Rectangle_bottomRight_getset(const fn_call& fn)
-{
- boost::intrusive_ptr<Rectangle_as> ptr =
ensureType<Rectangle_as>(fn.this_ptr);
- UNUSED(ptr);
- LOG_ONCE( log_unimpl (__FUNCTION__) );
- return as_value();
+ as_value ret;
+
+ if ( ! fn.nargs ) // getter
+ {
+ as_value height;
+ ptr->get_member(NSV::PROP_Y, &ret);
+ ptr->get_member(NSV::PROP_HEIGHT, &height);
+ ret.newAdd(height);
+ }
+ else // setter
+ {
+ as_value y;
+ ptr->get_member(NSV::PROP_Y, &y);
+
+ as_value bottom = fn.arg(0);
+ as_value newh = bottom.subtract(y);
+ ptr->set_member(NSV::PROP_HEIGHT, newh);
+ }
+
+ return ret;
}
static as_value
-Rectangle_height_getset(const fn_call& fn)
+Rectangle_bottomRight_getset(const fn_call& fn)
{
boost::intrusive_ptr<Rectangle_as> ptr =
ensureType<Rectangle_as>(fn.this_ptr);
UNUSED(ptr);
@@ -305,18 +335,56 @@
Rectangle_left_getset(const fn_call& fn)
{
boost::intrusive_ptr<Rectangle_as> ptr =
ensureType<Rectangle_as>(fn.this_ptr);
- UNUSED(ptr);
- LOG_ONCE( log_unimpl (__FUNCTION__) );
- return as_value();
+
+ as_value ret;
+
+ if ( ! fn.nargs ) // getter
+ {
+ ptr->get_member(NSV::PROP_X, &ret);
+ }
+ else // setter
+ {
+ as_value oldx;
+ ptr->get_member(NSV::PROP_X, &oldx);
+
+ as_value newx = fn.arg(0);
+ ptr->set_member(NSV::PROP_X, newx);
+
+ as_value w;
+ ptr->get_member(NSV::PROP_WIDTH, &w);
+
+ w.newAdd(oldx.subtract(newx));
+ ptr->set_member(NSV::PROP_WIDTH, w);
+ }
+
+ return ret;
}
static as_value
Rectangle_right_getset(const fn_call& fn)
{
boost::intrusive_ptr<Rectangle_as> ptr =
ensureType<Rectangle_as>(fn.this_ptr);
- UNUSED(ptr);
- LOG_ONCE( log_unimpl (__FUNCTION__) );
- return as_value();
+
+ as_value ret;
+
+ if ( ! fn.nargs ) // getter
+ {
+ as_value width;
+ ptr->get_member(NSV::PROP_X, &ret);
+ ptr->get_member(NSV::PROP_WIDTH, &width);
+ ret.newAdd(width);
+ }
+ else // setter
+ {
+ as_value x;
+ ptr->get_member(NSV::PROP_X, &x);
+
+ as_value right = fn.arg(0);
+ as_value neww = right.subtract(x);
+ ptr->set_member(NSV::PROP_WIDTH, neww);
+ }
+
+ return ret;
}
static as_value
@@ -332,40 +400,33 @@
Rectangle_top_getset(const fn_call& fn)
{
boost::intrusive_ptr<Rectangle_as> ptr =
ensureType<Rectangle_as>(fn.this_ptr);
- UNUSED(ptr);
- LOG_ONCE( log_unimpl (__FUNCTION__) );
- return as_value();
-}
-static as_value
-Rectangle_topLeft_getset(const fn_call& fn)
-{
- boost::intrusive_ptr<Rectangle_as> ptr =
ensureType<Rectangle_as>(fn.this_ptr);
- UNUSED(ptr);
- LOG_ONCE( log_unimpl (__FUNCTION__) );
- return as_value();
-}
+ as_value ret;
-static as_value
-Rectangle_width_getset(const fn_call& fn)
-{
- boost::intrusive_ptr<Rectangle_as> ptr =
ensureType<Rectangle_as>(fn.this_ptr);
- UNUSED(ptr);
- LOG_ONCE( log_unimpl (__FUNCTION__) );
- return as_value();
-}
+ if ( ! fn.nargs ) // getter
+ {
+ ptr->get_member(NSV::PROP_Y, &ret);
+ }
+ else // setter
+ {
+ as_value oldy;
+ ptr->get_member(NSV::PROP_Y, &oldy);
-static as_value
-Rectangle_x_getset(const fn_call& fn)
-{
- boost::intrusive_ptr<Rectangle_as> ptr =
ensureType<Rectangle_as>(fn.this_ptr);
- UNUSED(ptr);
- LOG_ONCE( log_unimpl (__FUNCTION__) );
- return as_value();
+ as_value newy = fn.arg(0);
+ ptr->set_member(NSV::PROP_Y, newy);
+
+ as_value h;
+ ptr->get_member(NSV::PROP_HEIGHT, &h);
+
+ h.newAdd(oldy.subtract(newy));
+ ptr->set_member(NSV::PROP_HEIGHT, h);
+ }
+
+ return ret;
}
static as_value
-Rectangle_y_getset(const fn_call& fn)
+Rectangle_topLeft_getset(const fn_call& fn)
{
boost::intrusive_ptr<Rectangle_as> ptr =
ensureType<Rectangle_as>(fn.this_ptr);
UNUSED(ptr);
@@ -374,19 +435,48 @@
}
-
as_value
Rectangle_ctor(const fn_call& fn)
{
boost::intrusive_ptr<as_object> obj = new Rectangle_as;
- if ( fn.nargs )
+ as_value x;
+ as_value y;
+ as_value w;
+ as_value h;
+
+ if ( ! fn.nargs )
{
+ x.set_double(0);
+ y.set_double(0);
+ w.set_double(0);
+ h.set_double(0);
+ }
+ else
+ {
+ do {
+ x = fn.arg(0);
+ if ( fn.nargs < 2 ) break;
+ y = fn.arg(1);
+ if ( fn.nargs < 3 ) break;
+ w = fn.arg(2);
+ if ( fn.nargs < 4 ) break;
+ h = fn.arg(3);
+ if ( fn.nargs < 5 ) break;
+ IF_VERBOSE_ASCODING_ERRORS(
std::stringstream ss;
fn.dump_args(ss);
- LOG_ONCE( log_unimpl("Rectangle(%s): %s", ss.str(),
_("arguments discarded")) );
+ log_aserror("flash.geom.Rectangle(%s): %s",
ss.str(), _("arguments after the first four discarded"));
+ );
+ } while(0);
}
+ // TODO: use named strings (we have PROP_X and PROP_Y, lack PROP_WIDTH
and PROP_HEIGHT)
+ obj->set_member(NSV::PROP_X, x);
+ obj->set_member(NSV::PROP_Y, y);
+ obj->set_member(NSV::PROP_WIDTH, w);
+ obj->set_member(NSV::PROP_HEIGHT, h);
+
return as_value(obj.get()); // will keep alive
}
Index: testsuite/actionscript.all/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/Makefile.am,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -b -r1.89 -r1.90
--- testsuite/actionscript.all/Makefile.am 25 Apr 2008 09:00:20 -0000
1.89
+++ testsuite/actionscript.all/Makefile.am 5 May 2008 21:02:02 -0000
1.90
@@ -120,6 +120,7 @@
case.as \
ops.as \
toString_valueOf.as \
+ Rectangle.as \
$(NULL)
ASTESTS_OUT = $(ASTESTS:.as=.swf)
Index: testsuite/actionscript.all/Rectangle.as
===================================================================
RCS file: testsuite/actionscript.all/Rectangle.as
diff -N testsuite/actionscript.all/Rectangle.as
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/actionscript.all/Rectangle.as 5 May 2008 21:02:02 -0000
1.1
@@ -0,0 +1,268 @@
+//
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+//
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+//
+// Test case for TextFormat ActionScript class
+// compile this test case with Ming makeswf, and then
+// execute it like this gnash -1 -r 0 -v out.swf
+
+rcsid="$Id: Rectangle.as,v 1.1 2008/05/05 21:02:02 strk Exp $";
+
+#include "check.as"
+
+#if OUTPUT_VERSION < 8
+
+check_equals(typeof(flash), 'undefined');
+
+check_totals(1);
+
+#else
+
+Rectangle = flash.geom.Rectangle;
+check_equals(typeof(Rectangle), 'function');
+check_equals(typeof(Rectangle.prototype), 'object');
+check(Rectangle.prototype.hasOwnProperty('bottom'));
+check(Rectangle.prototype.hasOwnProperty('bottomRight'));
+check(Rectangle.prototype.hasOwnProperty('left'));
+check(Rectangle.prototype.hasOwnProperty('right'));
+check(Rectangle.prototype.hasOwnProperty('size'));
+check(Rectangle.prototype.hasOwnProperty('top'));
+check(Rectangle.prototype.hasOwnProperty('topLeft'));
+check(Rectangle.prototype.hasOwnProperty('clone'));
+check(Rectangle.prototype.hasOwnProperty('contains'));
+check(Rectangle.prototype.hasOwnProperty('containsPoint'));
+check(Rectangle.prototype.hasOwnProperty('containsRectangle'));
+check(Rectangle.prototype.hasOwnProperty('equals'));
+check(Rectangle.prototype.hasOwnProperty('inflate'));
+check(Rectangle.prototype.hasOwnProperty('inflatePoint'));
+check(Rectangle.prototype.hasOwnProperty('intersection'));
+check(Rectangle.prototype.hasOwnProperty('intersects'));
+check(Rectangle.prototype.hasOwnProperty('isEmpty'));
+check(Rectangle.prototype.hasOwnProperty('offset'));
+check(Rectangle.prototype.hasOwnProperty('offsetPoint'));
+check(Rectangle.prototype.hasOwnProperty('setEmpty'));
+check(Rectangle.prototype.hasOwnProperty('toString'));
+check(Rectangle.prototype.hasOwnProperty('union'));
+check(!Rectangle.prototype.hasOwnProperty('height'));
+check(!Rectangle.prototype.hasOwnProperty('width'));
+check(!Rectangle.prototype.hasOwnProperty('x'));
+check(!Rectangle.prototype.hasOwnProperty('y'));
+
+//-------------------------------------------------------------
+// Test constructor (and width, height, x, y)
+//-------------------------------------------------------------
+
+r0 = new Rectangle();
+check_equals(typeof(r0), 'object');
+check(r0 instanceof Rectangle);
+check(r0.hasOwnProperty('height'));
+check(r0.hasOwnProperty('width'));
+check(r0.hasOwnProperty('x'));
+check(r0.hasOwnProperty('y'));
+check_equals(''+r0, '(x=0, y=0, w=0, h=0)');
+check(r0.isEmpty());
+check_equals(typeof(r0.x), 'number');
+check_equals(typeof(r0.y), 'number');
+check_equals(typeof(r0.width), 'number');
+check_equals(typeof(r0.height), 'number');
+
+a = []; for (var i in r0) a.push(i);
+check_equals(a.length, 26); // most of them...
+
+r0 = new Rectangle(1);
+check(r0.hasOwnProperty('height'));
+check(r0.hasOwnProperty('width'));
+check(r0.hasOwnProperty('x'));
+check(r0.hasOwnProperty('y'));
+check_equals(''+r0, '(x=1, y=undefined, w=undefined, h=undefined)');
+check(r0.isEmpty());
+
+r0 = new Rectangle(1, 1, 1, 'string');
+check_equals(''+r0, '(x=1, y=1, w=1, h=string)');
+check(r0.isEmpty());
+
+r0 = new Rectangle(['a',3], 1, -30, 'string');
+check_equals(''+r0, '(x=a,3, y=1, w=-30, h=string)');
+check(r0.isEmpty());
+check_equals(typeof(r0.width), 'number');
+check_equals(typeof(r0.height), 'string');
+
+o1 = {}; o1.toString = function() { return '2'; };
+r0 = new Rectangle(0, 0, o1, null);
+check_equals(''+r0, '(x=0, y=0, w=2, h=null)');
+check(r0.isEmpty());
+check_equals(typeof(r0.width), 'object');
+check_equals(typeof(r0.height), 'null');
+
+r0 = new Rectangle(0, 0, o1, o1);
+check_equals(''+r0, '(x=0, y=0, w=2, h=2)');
+check(r0.isEmpty()); // but it's still considered empty!
+check_equals(typeof(r0.width), 'object');
+check_equals(typeof(r0.height), 'object');
+
+r0 = new Rectangle('string', 0, 2, 2);
+check_equals(''+r0, '(x=string, y=0, w=2, h=2)');
+check(!r0.isEmpty()); // just checks width and height
+check_equals(r0.x, 'string');
+check_equals(r0.y, 0);
+check_equals(r0.width, 2);
+check_equals(r0.height, 2);
+
+r0.width = 40;
+r0.height = 'string2';
+r0.x = 32;
+r0.y = -30;
+check_equals(''+r0, '(x=32, y=-30, w=40, h=string2)');
+check(delete r0.x);
+check_equals(''+r0, '(x=undefined, y=-30, w=40, h=string2)');
+
+//-------------------------------------------------------------
+// Test bottom, right, left top
+//-------------------------------------------------------------
+
+r0 = new Rectangle('x', 'y', 'w', 'h');
+check_equals(r0.left, 'x');
+check_equals(r0.top, 'y');
+check_equals(r0.right, 'xw');
+check_equals(r0.bottom, 'yh');
+
+r0.left = 10;
+check_equals(r0.x, 10);
+check_equals(r0.left, 10);
+check_equals(r0.width, 'wNaN'); // w + old_x-10 ?
+check_equals(r0.right, '10wNaN');
+
+r0.right = 20;
+check_equals(r0.x, 10);
+check_equals(typeof(r0.width), 'number');
+check_equals(r0.width, 10); // right-left
+
+r0.top = 5;
+check_equals(r0.y, 5);
+check_equals(r0.bottom, '5hNaN');
+r0.bottom = 10;
+check_equals(r0.height, '5'); // 10-5
+
+r0 = new Rectangle(10, 10, 20, 20);
+r0.left = 15;
+check_equals(r0.width, 15); // old width (20) + ( old left (10) - new left
(15) )
+
+//-------------------------------------------------------------
+// Test bottomRight, topLeft
+//-------------------------------------------------------------
+
+r0 = new Rectangle('x', 'y', 'w', 'h');
+xcheck(r0.bottomRight instanceof flash.geom.Point);
+xcheck(r0.topLeft instanceof flash.geom.Point);
+xcheck_equals(''+r0.bottomRight, '(x=xw, y=yh)');
+xcheck_equals(''+r0.topLeft, '(x=x, y=y)');
+
+//-------------------------------------------------------------
+// Test size
+//-------------------------------------------------------------
+
+r0 = new Rectangle('x', 'y', 'w', 'h');
+xcheck(r0.size instanceof flash.geom.Point);
+xcheck_equals(''+r0.size, '(x=w, y=h)');
+
+//-------------------------------------------------------------
+// Test clone
+//-------------------------------------------------------------
+
+r0 = new Rectangle('x', 'y', 'w', 'h');
+r2 = r0.clone();
+xcheck_equals(r2.toString(), '(x=x, y=y, w=w, h=h)');
+
+//-------------------------------------------------------------
+// Test contains
+//-------------------------------------------------------------
+
+// TODO
+
+//-------------------------------------------------------------
+// Test containsPoint
+//-------------------------------------------------------------
+
+// TODO
+
+//-------------------------------------------------------------
+// Test containsRectangle
+//-------------------------------------------------------------
+
+// TODO
+
+//-------------------------------------------------------------
+// Test equals
+//-------------------------------------------------------------
+
+// TODO
+
+//-------------------------------------------------------------
+// Test inflate
+//-------------------------------------------------------------
+
+// TODO
+
+//-------------------------------------------------------------
+// Test inflatePoint
+//-------------------------------------------------------------
+
+// TODO
+
+//-------------------------------------------------------------
+// Test intersection
+//-------------------------------------------------------------
+
+// TODO
+
+//-------------------------------------------------------------
+// Test intersects
+//-------------------------------------------------------------
+
+// TODO
+
+//-------------------------------------------------------------
+// Test offset
+//-------------------------------------------------------------
+
+// TODO
+
+//-------------------------------------------------------------
+// Test offsetPoint
+//-------------------------------------------------------------
+
+// TODO
+
+//-------------------------------------------------------------
+// Test setEmpty
+//-------------------------------------------------------------
+
+// TODO
+
+//-------------------------------------------------------------
+// Test union
+//-------------------------------------------------------------
+
+// TODO
+
+//-------------------------------------------------------------
+// END OF TEST
+//-------------------------------------------------------------
+
+check_totals(92);
+
+#endif // OUTPUT_VERSION >= 8
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog server/as_value.cpp server/as_v...,
Sandro Santilli <=