gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r11589: Small cleanups.


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r11589: Small cleanups.
Date: Mon, 26 Oct 2009 11:48:41 +0100
User-agent: Bazaar (1.16.1)

------------------------------------------------------------
revno: 11589 [merge]
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Mon 2009-10-26 11:48:41 +0100
message:
  Small cleanups.
modified:
  libcore/DisplayObject.cpp
  libcore/DisplayObject.h
  libcore/TextField.cpp
  libcore/as_object.cpp
  libcore/asobj/Color_as.cpp
  libcore/asobj/MovieClipLoader.cpp
  libcore/asobj/Selection_as.cpp
  libcore/asobj/flash/ui/ContextMenu_as.cpp
  libcore/namedStrings.cpp
  libcore/namedStrings.h
  testsuite/actionscript.all/ContextMenu.as
  testsuite/swfdec/PASSING
=== modified file 'libcore/DisplayObject.cpp'
--- a/libcore/DisplayObject.cpp 2009-10-23 06:25:25 +0000
+++ b/libcore/DisplayObject.cpp 2009-10-26 08:22:49 +0000
@@ -915,18 +915,15 @@
 ///    way to do it, but as it is done like this, this must be called here.
 ///    It will cause an infinite recursion otherwise.
 bool
-getDisplayObjectProperty(as_object& obj, string_table::key key,
+getDisplayObjectProperty(DisplayObject& obj, string_table::key key,
         as_value& val)
 {
-    assert(obj.displayObject());
     
     string_table& st = getStringTable(obj);
     const std::string& propname = st.value(key);
-    
-    DisplayObject& o = static_cast<DisplayObject&>(obj);
 
     // Check _level0.._level9
-    movie_root& mr = getRoot(o);
+    movie_root& mr = getRoot(obj);
     unsigned int levelno;
     if (mr.isLevelTarget(propname, levelno)) {
         Movie* mo = mr.getLevel(levelno);
@@ -954,21 +951,19 @@
         default:
             break;
         case NSV::PROP_uROOT:
-            if (getSWFVersion(o) < 5) break;
-            val = o.getAsRoot();
+            if (getSWFVersion(obj) < 5) break;
+            val = obj.getAsRoot();
             return true;
         case NSV::PROP_uGLOBAL:
-            if (getSWFVersion(o) < 6) break;
-            val = &getGlobal(o);
+            if (getSWFVersion(obj) < 6) break;
+            val = &getGlobal(obj);
             return true;
     }
-    
-
 
     // These magic properties are case insensitive in all versions!
     const string_table::key noCaseKey = 
st.find(boost::to_lower_copy(propname));
 
-    if (doGet(noCaseKey, o, val)) return true;
+    if (doGet(noCaseKey, obj, val)) return true;
 
     // Check MovieClip such as TextField variables.
     // TODO: check if there's a better way to find these properties.
@@ -979,15 +974,14 @@
     
 
 bool
-setDisplayObjectProperty(as_object& obj, string_table::key key, 
+setDisplayObjectProperty(DisplayObject& obj, string_table::key key, 
         const as_value& val)
 {
-    assert(obj.displayObject());
     // These magic properties are case insensitive in all versions!
     string_table& st = getStringTable(obj);
     const std::string& propname = st.value(key);
     const string_table::key noCaseKey = 
st.find(boost::to_lower_copy(propname));
-    return doSet(noCaseKey, static_cast<DisplayObject&>(obj), val);
+    return doSet(noCaseKey, obj, val);
 }
 
 namespace {

=== modified file 'libcore/DisplayObject.h'
--- a/libcore/DisplayObject.h   2009-10-21 07:10:41 +0000
+++ b/libcore/DisplayObject.h   2009-10-26 08:22:49 +0000
@@ -68,17 +68,15 @@
 
 /// Set special properties
 //
-/// This will abort if called with a non DisplayObject. It sets the magic
-/// properties of DisplayObjects.
-bool setDisplayObjectProperty(as_object& obj, string_table::key key,
+/// This sets the magic properties of DisplayObjects.
+bool setDisplayObjectProperty(DisplayObject& obj, string_table::key key,
         const as_value& val);
 
 /// Get special properties
 //
-/// This will abort if called with a non DisplayObject. It gets the magic
-/// properties of DisplayObjects and handles special MovieClip properties
-/// such as DisplayList members.
-bool getDisplayObjectProperty(as_object& obj, string_table::key key,
+/// This gets the magic properties of DisplayObjects and handles special
+/// MovieClip properties such as DisplayList members.
+bool getDisplayObjectProperty(DisplayObject& obj, string_table::key key,
         as_value& val);
 
 /// Get a property by its numeric index.

=== modified file 'libcore/TextField.cpp'
--- a/libcore/TextField.cpp     2009-10-23 06:25:25 +0000
+++ b/libcore/TextField.cpp     2009-10-26 08:41:46 +0000
@@ -2346,9 +2346,8 @@
             getNamespace(uri));
 
     // ASSetPropFlags is called on the TextField class.
-    string_table& st = getStringTable(where);
     as_object* null = 0;
-    gl.callMethod(st.find("ASSetPropFlags"), cl, null, 131);
+    gl.callMethod(NSV::PROP_AS_SET_PROP_FLAGS, cl, null, 131);
 }
 
 void
@@ -3732,10 +3731,9 @@
     AsBroadcaster::initialize(o);
 
     // Finally ASSetPropFlags is called on the prototype.
-    string_table& st = getStringTable(o);
     Global_as& gl = getGlobal(o);
     as_object* null = 0;
-    gl.callMethod(st.find("ASSetPropFlags"), &o, null, 131);
+    gl.callMethod(NSV::PROP_AS_SET_PROP_FLAGS, &o, null, 131);
 }
 
 void

=== modified file 'libcore/as_object.cpp'
--- a/libcore/as_object.cpp     2009-10-23 06:25:25 +0000
+++ b/libcore/as_object.cpp     2009-10-26 08:22:49 +0000
@@ -398,7 +398,8 @@
        Property* prop = pr.getProperty();
     if (!prop) {
         if (displayObject()) {
-            if (getDisplayObjectProperty(*this, name, *val)) return true;
+            DisplayObject& d = static_cast<DisplayObject&>(*this);
+            if (getDisplayObjectProperty(d, name, *val)) return true;
         }
         while (pr()) {
             if ((prop = pr.getProperty())) break;
@@ -705,7 +706,8 @@
        if (!prop) { 
 
         if (displayObject()) {
-            if (setDisplayObjectProperty(*this, key, val)) return true;
+            DisplayObject& d = static_cast<DisplayObject&>(*this);
+            if (setDisplayObjectProperty(d, key, val)) return true;
             // TODO: should we execute triggers?
         }
 
@@ -1065,7 +1067,10 @@
 {
        assert(env.top(0).is_undefined());
 
-       enumerateNonProperties(env);
+    // Hack to handle MovieClips.
+       if (displayObject()) {
+        static_cast<const DisplayObject&>(*this).enumerateNonProperties(env);
+    }
 
        // this set will keep track of visited objects,
        // to avoid infinite loops

=== modified file 'libcore/asobj/Color_as.cpp'
--- a/libcore/asobj/Color_as.cpp        2009-10-23 06:25:25 +0000
+++ b/libcore/asobj/Color_as.cpp        2009-10-26 08:41:46 +0000
@@ -238,7 +238,7 @@
 color_ctor(const fn_call& fn)
 {
        
-    as_object* obj = fn.this_ptr;
+    as_object* obj = ensure<ValidThis>(fn);
     
     as_value target;
     if (fn.nargs) target = fn.arg(0);
@@ -247,6 +247,10 @@
 
     obj->init_member(NSV::PROP_TARGET, target, flags); 
 
+    Global_as& gl = getGlobal(fn);
+    as_object* null = 0;
+    gl.callMethod(NSV::PROP_AS_SET_PROP_FLAGS, obj, null, 7);
+
        return as_value(); 
 }
 

=== modified file 'libcore/asobj/MovieClipLoader.cpp'
--- a/libcore/asobj/MovieClipLoader.cpp 2009-10-23 17:32:35 +0000
+++ b/libcore/asobj/MovieClipLoader.cpp 2009-10-26 08:41:46 +0000
@@ -139,9 +139,8 @@
   
        AsBroadcaster::initialize(*proto);
 
-    string_table& st = getStringTable(where);
     as_object* null = 0;
-    gl.callMethod(st.find("ASSetPropFlags"), proto, null, 1027);
+    gl.callMethod(NSV::PROP_AS_SET_PROP_FLAGS, proto, null, 1027);
 
        where.init_member(getName(uri), cl, as_object::DefaultFlags,
             getNamespace(uri)); 

=== modified file 'libcore/asobj/Selection_as.cpp'
--- a/libcore/asobj/Selection_as.cpp    2009-10-23 06:25:25 +0000
+++ b/libcore/asobj/Selection_as.cpp    2009-10-26 08:41:46 +0000
@@ -63,10 +63,9 @@
     AsBroadcaster::initialize(*o);
 
     // All properties are protected using ASSetPropFlags.
-    string_table& st = getStringTable(where);
     Global_as& gl = getGlobal(where);
     as_object* null = 0;
-    gl.callMethod(st.find("ASSetPropFlags"), o, null, 7);
+    gl.callMethod(NSV::PROP_AS_SET_PROP_FLAGS, o, null, 7);
 }
 
 void

=== modified file 'libcore/asobj/flash/ui/ContextMenu_as.cpp'
--- a/libcore/asobj/flash/ui/ContextMenu_as.cpp 2009-10-23 06:25:25 +0000
+++ b/libcore/asobj/flash/ui/ContextMenu_as.cpp 2009-10-26 08:29:00 +0000
@@ -22,15 +22,15 @@
 #endif
 
 #include "ui/ContextMenu_as.h"
-#include "as_object.h" // for inheritance
+#include "as_object.h" 
 #include "log.h"
 #include "fn_call.h"
 #include "Global_as.h"
-#include "smart_ptr.h" // for boost intrusive_ptr
-#include "builtin_function.h" // need builtin_function
-#include "GnashException.h" // for ActionException
-#include "Object.h" // for getObjectInterface
+#include "smart_ptr.h" 
+#include "builtin_function.h" 
+#include "Object.h" 
 #include "namedStrings.h"
+#include "Array_as.h"
 
 namespace gnash {
 
@@ -56,6 +56,27 @@
 
 namespace {
 
+/// Functor to implement ContextMenu.copy for the customItems array.
+//
+/// This pushes the return of copy() called on each array element to the new
+/// customItems array.
+class CopyMenuItems
+{
+public:
+    CopyMenuItems(string_table::key c, as_object& nc) : _c(c), _target(nc) {}
+
+    void operator()(const as_value& val) {
+        Global_as& gl = getGlobal(_target);
+        as_object* obj = val.to_object(gl);
+        as_value cp = obj ? obj->callMethod(_c) : as_value();
+        _target.callMethod(NSV::PROP_PUSH, cp);
+    }
+private:
+    const string_table::key _c;
+    as_object& _target;
+};
+
+
 void
 setBuiltInItems(as_object& o, bool setting)
 {
@@ -98,6 +119,7 @@
     return as_value();
 }
 
+
 as_value
 contextmenu_copy(const fn_call& fn)
 {
@@ -128,19 +150,29 @@
     o->set_member(NSV::PROP_ON_SELECT, onSelect);
     o->set_member(st.find("builtInItems"), builtInItems);
 
-    // The customItems object is a deep copy, but only of elements that are
-    // instances of ContextMenuItem (have its prototype as a __proto__ member).
-    as_object* nc = gl.createArray();
-    as_object* customs;
-
-    if (customItems.is_object() &&
-            (customs = customItems.to_object(getGlobal(fn)))) {
-        // TODO: only copy properties that are ContextMenuItems.
-        nc->copyProperties(*customs);
-        customItems = nc;
+    // The customItems object is a deep copy that works by calling
+    // the copy property of each array member.
+
+    as_value nc;
+
+    // Call new Array(), not []
+    as_function* arrayctor = getClassConstructor(fn, "Array");
+    if (arrayctor) {
+        fn_call::Args args;
+        as_object* arr = arrayctor->constructInstance(fn.env(), args).get();
+        if (arr) {
+            as_object* customs;
+            if (customItems.is_object() &&
+                    (customs = customItems.to_object(getGlobal(fn)))) {
+                string_table::key copykey = getStringTable(fn).find("copy");
+                CopyMenuItems c(copykey, *arr);
+                foreachArray(*customs, c);
+            }
+            nc = arr;
+        }
     }
 
-    o->set_member(st.find("customItems"), customItems);
+    o->set_member(st.find("customItems"), nc);
 
     return as_value(o);
 }

=== modified file 'libcore/namedStrings.cpp'
--- a/libcore/namedStrings.cpp  2009-08-13 11:17:20 +0000
+++ b/libcore/namedStrings.cpp  2009-10-26 08:41:46 +0000
@@ -35,6 +35,7 @@
        string_table::svt( "addListener", NSV::PROP_ADD_LISTENER ),
        string_table::svt( "align", NSV::PROP_ALIGN ),
        string_table::svt( "ASnative", NSV::PROP_AS_NATIVE ),
+       string_table::svt( "ASSetPropFlags", NSV::PROP_AS_SET_PROP_FLAGS ),
        string_table::svt( "_alpha", NSV::PROP_uALPHA ),
        string_table::svt( "b", NSV::PROP_B ),
        string_table::svt( "blockIndent", NSV::PROP_BLOCK_INDENT ),

=== modified file 'libcore/namedStrings.h'
--- a/libcore/namedStrings.h    2009-08-13 11:17:20 +0000
+++ b/libcore/namedStrings.h    2009-10-26 08:41:46 +0000
@@ -129,6 +129,7 @@
         PROP_ADD_LISTENER,
         PROP_ALIGN,
         PROP_AS_NATIVE,
+        PROP_AS_SET_PROP_FLAGS,
         PROP_B,
         PROP_BLOCK_INDENT,
         PROP_BOLD,

=== modified file 'testsuite/actionscript.all/ContextMenu.as'
--- a/testsuite/actionscript.all/ContextMenu.as 2009-07-10 08:27:54 +0000
+++ b/testsuite/actionscript.all/ContextMenu.as 2009-10-26 08:33:05 +0000
@@ -133,19 +133,19 @@
 
   f.customItems = 88;
   ff = f.copy();
-  xcheck_equals(typeof(ff.customItems), "object");
+  check_equals(typeof(ff.customItems), "object");
 
   f.customItems = {};
   f.customItems.p = "hello";
   ff = f.copy();
   check_equals(ff.customItems.length, 0);
-  xcheck_equals(ff.customItems.p, undefined);
+  check_equals(ff.customItems.p, undefined);
 
   f.customItems = new Array;
   f.customItems.push("hello");
   ff = f.copy();
   check_equals(ff.customItems.length, 1);
-  xcheck_equals(ff.customItems[0], undefined);
+  check_equals(ff.customItems[0], undefined);
 
   h = function() {};
 
@@ -165,12 +165,12 @@
   check_equals(f.customItems[2].caption, "moo");
   ff = f.copy();
   check_equals(ff.customItems.length, 3);
-  xcheck_equals(ff.customItems[2].caption, undefined);
+  check_equals(ff.customItems[2].caption, undefined);
 
   // Properties are only copied properly if instanceOf ContextMenuItem;
   // otherwise they are undefined.
   c.__proto__ = ContextMenuItem.prototype;
-  xcheck_equals(ff.customItems[2].caption, undefined);
+  check_equals(ff.customItems[2].caption, undefined);
   ff = f.copy();
   check_equals(ff.customItems.length, 3);
   check_equals(ff.customItems[2].caption, "moo");

=== modified file 'testsuite/swfdec/PASSING'
--- a/testsuite/swfdec/PASSING  2009-10-23 15:29:39 +0000
+++ b/testsuite/swfdec/PASSING  2009-10-26 08:58:13 +0000
@@ -215,6 +215,10 @@
 color-matrix-filter-properties-7.swf:584a31bbd059b354169fc47fce089b55
 color-matrix-filter-properties-8.swf:16258fad9126858838fcb66acd619382
 color-new.swf:b19cf3d46f416b919eb312da473b6756
+color-properties-5.swf:fa0fade9ce28b750593b1adb6f86898c
+color-properties-6.swf:d5d6b8a4727d024c4c2434e4bf965fb1
+color-properties-7.swf:20f3b3832419655c629d84562ae8edd7
+color-properties-8.swf:a1ae8b87ebc7cc1adf7d9acb8da6592f
 color-setRGB.swf:0841414e9ac7d2f9b57e40aec3d2f44f
 color-setTransform-empty.swf:2a72a5273ab8713ee289ff1726b0959c
 color-setTransform-full.swf:7a8e59cef9592c4546f07fb9f391c61a


reply via email to

[Prev in Thread] Current Thread [Next in Thread]