gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r11648: Check ImplementsOp and updat


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r11648: Check ImplementsOp and update documentation. Rename as_object::add_interface
Date: Mon, 23 Nov 2009 08:45:25 +0100
User-agent: Bazaar (1.16.1)

------------------------------------------------------------
revno: 11648 [merge]
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Mon 2009-11-23 08:45:25 +0100
message:
  Check ImplementsOp and update documentation. Rename as_object::add_interface
  to conform to coding guidelines.
modified:
  libcore/as_object.cpp
  libcore/as_object.h
  libcore/vm/ASHandlers.cpp
=== modified file 'libcore/as_object.cpp'
--- a/libcore/as_object.cpp     2009-11-20 11:34:33 +0000
+++ b/libcore/as_object.cpp     2009-11-20 15:13:16 +0000
@@ -868,12 +868,13 @@
 }
 
 void
-as_object::add_interface(as_object* obj)
+as_object::addInterface(as_object* obj)
 {
        assert(obj);
-
-       if (std::find(mInterfaces.begin(), mInterfaces.end(), obj) == 
mInterfaces.end())
-               mInterfaces.push_back(obj);
+       if (std::find(_interfaces.begin(), _interfaces.end(), obj) ==
+            _interfaces.end()) {
+               _interfaces.push_back(obj);
+    }
 }
 
 bool
@@ -884,52 +885,53 @@
     if (!ctor) return false;
 
        as_value protoVal;
-       if ( ! ctor->get_member(NSV::PROP_PROTOTYPE, &protoVal) )
-       {
+       if (!ctor->get_member(NSV::PROP_PROTOTYPE, &protoVal)) {
 #ifdef GNASH_DEBUG_INSTANCE_OF
-               log_debug("Object %p can't be an instance of an object (%p) 
w/out 'prototype'",
+               log_debug("Object %p can't be an instance of an object (%p) "
+                "with no 'prototype'",
                        (void*)this, (void*)ctor);
 #endif
                return false;
        }
+
        as_object* ctorProto = protoVal.to_object(getGlobal(*this));
-       if ( ! ctorProto )
-       {
+       if (!ctorProto) {
 #ifdef GNASH_DEBUG_INSTANCE_OF
-               log_debug("Object %p can't be an instance of an object (%p) 
with non-object 'prototype' (%s)",
+               log_debug("Object %p can't be an instance of an object (%p) "
+                "with non-object 'prototype' (%s)",
                        (void*)this, (void*)ctor, protoVal);
 #endif
                return false;
        }
 
        // TODO: cleanup the iteration, make it more readable ...
-
-       std::set< as_object* > visited;
+       std::set<as_object*> visited;
 
        as_object* obj = this;
-       while (obj && visited.insert(obj).second )
-       {
+       while (obj && visited.insert(obj).second) {
                as_object* thisProto = obj->get_prototype();
-               if ( ! thisProto )
-               {
+               if (!thisProto) {
                        break;
                }
 
                // Check our proto
-               if ( thisProto == ctorProto )
-               {
+               if (thisProto == ctorProto) {
 #ifdef GNASH_DEBUG_INSTANCE_OF
-                       log_debug("Object %p is an instance of constructor %p 
as the constructor exposes our __proto__ %p",
+                       log_debug("Object %p is an instance of constructor %p 
as "
+                    "the constructor exposes our __proto__ %p",
                                (void*)obj, (void*)ctor, (void*)thisProto);
 #endif
                        return true;
                }
 
                // Check our proto interfaces
-               if (std::find(thisProto->mInterfaces.begin(), 
thisProto->mInterfaces.end(), ctorProto) != thisProto->mInterfaces.end())
-               {
+               if (std::find(thisProto->_interfaces.begin(),
+                    thisProto->_interfaces.end(), ctorProto)
+                != thisProto->_interfaces.end()) {
+
 #ifdef GNASH_DEBUG_INSTANCE_OF
-                       log_debug("Object %p __proto__ %p had one interface 
matching with the constructor prototype %p",
+                       log_debug("Object %p __proto__ %p had one interface 
matching "
+                    "with the constructor prototype %p",
                                (void*)obj, (void*)thisProto, (void*)ctorProto);
 #endif
                        return true;
@@ -946,7 +948,7 @@
 {
        boost::intrusive_ptr<as_object> obj = &instance;
 
-       std::set< as_object* > visited;
+       std::set<as_object*> visited;
 
        while (obj && visited.insert(obj.get()).second )
        {
@@ -1211,7 +1213,11 @@
         }
     }
 
-    /// Proxy objects can contain references to other as_objects.
+    // Mark interfaces reachable.
+    std::for_each(_interfaces.begin(), _interfaces.end(), 
+            std::mem_fun(&as_object::setReachable));
+
+    // Proxy objects can contain references to other as_objects.
     if (_relay) _relay->setReachable();
     if (_displayObject) _displayObject->setReachable();
 }

=== modified file 'libcore/as_object.h'
--- a/libcore/as_object.h       2009-11-20 11:11:54 +0000
+++ b/libcore/as_object.h       2009-11-20 15:13:16 +0000
@@ -783,8 +783,13 @@
     virtual bool isSuper() const { return false; }
 
     /// Add an interface to the list of interfaces.
-    /// Used by instanceOf
-    void add_interface(as_object* ctor);
+    //
+    /// This is used by the action "implements". This opcode is a compile-time
+    /// promise that a class will implement all the methods of an
+    /// otherwise unrelated interface class. The only use in AVM1 is to
+    /// allow instanceOf to return true when a class implements another
+    /// class.
+    void addInterface(as_object* ctor);
 
     /// \brief
     /// Check whether this object is an instance of the given
@@ -929,7 +934,7 @@
     //
     /// The Relay object is a polymorphic object containing native type
     /// characteristics. It is rarely useful to use this function directly.
-    /// Instead use the convenience functions ensureNativeType() and
+    /// Instead use the convenience functions ensure<>() and
     /// isNativeType() to access the Relay object.
     //
     /// Relay objects are not available to ActionScript, so this object
@@ -1073,9 +1078,11 @@
     void executeTriggers(Property* prop, const ObjectURI& uri,
             const as_value& val);
 
-    /// The constructors of the objects which are the interfaces
-    /// implemented by this one.
-    std::list<as_object*> mInterfaces;
+    /// The constructors of the objects implemented by this as_object.
+    //
+    /// There is no need to use a complex container as the list of 
+    /// interfaces is generally small and the opcode rarely used anyway.
+    std::vector<as_object*> _interfaces;
 
     typedef std::map<ObjectURI, Trigger> TriggerContainer;
     boost::scoped_ptr<TriggerContainer> _trigs;

=== modified file 'libcore/vm/ASHandlers.cpp'
--- a/libcore/vm/ASHandlers.cpp 2009-11-18 11:51:35 +0000
+++ b/libcore/vm/ASHandlers.cpp 2009-11-20 14:54:19 +0000
@@ -1359,88 +1359,87 @@
     }
 }
 
+
+/// Implements the "implements" opcode
+//
+/// Example AS code: "C implements B;"
+//
+/// The above code makes an instance of C ("var c = new C();") return true
+/// for "c instanceOf B);". That seems to be the end of its usefulness, as
+/// c inherits no properties from B.
 void
 SWFHandlers::ActionImplementsOp(ActionExec& thread)
 {
     
-//    TODO: This doesn't work quite right, yet.
     as_environment& env = thread.env;
 
     as_value objval = env.pop();
     as_object *obj = convertToObject(getGlobal(thread.env), objval);
     int count = static_cast<int>(env.pop().to_number());
-    as_value a(1);
 
-    if (!obj)
-    {
+    if (!obj) {
         IF_VERBOSE_ASCODING_ERRORS(
-        log_aserror(_("Stack value on IMPLEMENTSOP is not an object: %s."),
-            objval);
+            log_aserror(_("Stack value on IMPLEMENTSOP is not an object: %s."),
+                objval);
         );
         return;
     }
 
     as_value protoval;
-    if ( ! obj->get_member(NSV::PROP_PROTOTYPE, &protoval) )
-    {
+    if (!obj->get_member(NSV::PROP_PROTOTYPE, &protoval)) {
         IF_VERBOSE_ASCODING_ERRORS(
-        log_aserror(_("Target object for IMPLEMENTSOP has no prototype."));
+            log_aserror(_("Target object for IMPLEMENTSOP has no prototype."));
         );
         return;
     }
     obj = convertToObject(getGlobal(thread.env), protoval);
-    if (!obj)
-    {
-        IF_VERBOSE_ASCODING_ERRORS(
-        log_aserror(_("IMPLEMENTSOP target object's prototype is not an object 
(%s)"),
-            protoval);
-        );
-        return;
-    }
-
-    if ( count <= 0 )
-    {
-        IF_VERBOSE_ASCODING_ERRORS(
-        log_aserror(_("Invalid interfaces count (%d) on IMPLEMENTSOP"), count);
-        );
-        return;
-    }
-
-    while (count--)
-    {
+    if (!obj) {
+        IF_VERBOSE_ASCODING_ERRORS(
+            log_aserror(_("IMPLEMENTSOP target object's prototype is not "
+                    "an object (%s)"), protoval);
+        );
+        return;
+    }
+
+    if (count <= 0) {
+        IF_VERBOSE_ASCODING_ERRORS(
+            log_aserror(_("Invalid interfaces count (%d) on IMPLEMENTSOP"),
+                count);
+        );
+        return;
+    }
+
+    while (count--) {
         as_value ctorval = env.pop();
-
         as_object* ctor = convertToObject(getGlobal(thread.env), ctorval);
-        if ( ! ctor )
-        {
+        if (!ctor) {
             IF_VERBOSE_ASCODING_ERRORS(
-            log_aserror(_("class found on stack on IMPLEMENTSOP is not an 
object: %s"), ctorval);
+                log_aserror(_("class found on stack on IMPLEMENTSOP is "
+                        "not an object: %s"), ctorval);
             );
             continue;
         }
-        if ( ! ctor->get_member(NSV::PROP_PROTOTYPE, &protoval) )
-        {
+        if (!ctor->get_member(NSV::PROP_PROTOTYPE, &protoval)) {
             IF_VERBOSE_ASCODING_ERRORS(
-            log_aserror(_("Interface object for IMPLEMENTSOP has no 
prototype."));
+                log_aserror(_("Interface object for IMPLEMENTSOP has no "
+                        "prototype."));
             );
             continue;
         }
         as_object *inter = convertToObject(getGlobal(thread.env), protoval);
-        if ( ! inter )
-        {
+        if (!inter) {
             IF_VERBOSE_ASCODING_ERRORS(
-            log_aserror(_("Prototype of interface object for IMPLEMENTSOP is 
not an object (%s)."),
-                protoval);
+                log_aserror(_("Prototype of interface object for "
+                        "IMPLEMENTSOP is not an object (%s)."), protoval);
             );
             continue;
         }
 
         IF_VERBOSE_ACTION(
-        log_action("%s (with .prototype %p) implements %s (with .prototype 
%p)",
-            objval, (void*)obj, ctorval,
-            (void*)inter);
+            log_action("%s (with .prototype %p) implements %s (with "
+                ".prototype %p)", objval, (void*)obj, ctorval, (void*)inter);
         );
-        obj->add_interface(inter);
+        obj->addInterface(inter);
     }
 }
 


reply via email to

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