gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r11440: Remove obsolete functions fr


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r11440: Remove obsolete functions from interface. Correct XML properties.
Date: Wed, 26 Aug 2009 12:43:43 +0200
User-agent: Bazaar (1.16.1)

------------------------------------------------------------
revno: 11440 [merge]
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Wed 2009-08-26 12:43:43 +0200
message:
  Remove obsolete functions from interface. Correct XML properties.
modified:
  libcore/as_object.h
  libcore/asobj/Date_as.h
  libcore/asobj/flash/xml/XMLDocument_as.cpp
  libcore/asobj/flash/xml/XMLDocument_as.h
  libcore/vm/Machine.cpp
  testsuite/actionscript.all/XML.as
  testsuite/actionscript.all/XMLNode.as
=== modified file 'libcore/as_object.h'
--- a/libcore/as_object.h       2009-08-21 12:29:40 +0000
+++ b/libcore/as_object.h       2009-08-26 08:47:23 +0000
@@ -268,11 +268,6 @@
     ///
     void dump_members(std::map<std::string, as_value>& to);
 
-    /// Return true if instances of this ActionScript class should use 
-    /// a custom toString method, when available, for converting the object
-    /// to a string.
-    virtual bool useCustomToString() const { return true; }
-
     /// Set a member value
     //
     ///
@@ -676,11 +671,6 @@
     ///
     virtual as_object* get_path_element(string_table::key key);
 
-    /// Chad: Document
-    bool isQName() const { return false; /* TODO: Implement */ }
-    bool isXML() const { return false; /* TODO */ }
-    bool isDictionary() const { return false; /* TODO */ }
-
     /// Get the super object of this object.
     ///
     /// The super should be __proto__ if this is a prototype object
@@ -867,19 +857,9 @@
         return const_cast<as_object*>(this)->toDisplayObject();
     }
 
-    /// 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; }
-
     /// Return true if this is a 'super' object
     virtual bool isSuper() const { return false; }
 
-
     /// Add an interface to the list of interfaces.
     /// Used by instanceOf
     void add_interface(as_object* ctor);
@@ -1038,10 +1018,30 @@
     ///
     void set_prototype(const as_value& proto, int flags = DefaultFlags);
 
+    /// Set the as_object's Relay object.
+    //
+    /// This is a pointer to a native object that contains special type
+    /// characteristics. Setting the Relay object allows native functions
+    /// to get or set non-ActionScript properties.
+    //
+    /// This function should only be used in native functions such as
+    /// constructors and special creation functions like
+    /// MovieClip.createTextField(). As Relay objects are not available to
+    /// ActionScript, this should never appear in built-in functions.
     void setRelay(Relay* p) {
         _relay.reset(p);
     }
 
+    /// Access the as_object's Relay object.
+    //
+    /// 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
+    /// isNativeType() to access the Relay object.
+    //
+    /// Relay objects are not available to ActionScript, so this object
+    /// should not be used in built-in functions (that is, functions
+    /// implemented in ActionScript).
     Relay* relay() const {
         return _relay.get();
     }
@@ -1114,15 +1114,19 @@
 
 private:
  
+    /// The polymorphic Relay object for native types.
+    //
+    /// This is owned by the as_object and destroyed when the as_object's
+    /// destructor is called.
     boost::scoped_ptr<Relay> _relay;
 
-    /// The global object whose scope contains this object.
+    /// The VM containing this object.
     VM& _vm;   
 
     /// Properties of this objects 
     PropertyList _members;
 
-    /// Don't allow implicit copy, must think about behaviour
+    /// Don't allow implicit copy.
     as_object& operator=(const as_object&);
 
     /// \brief

=== modified file 'libcore/asobj/Date_as.h'
--- a/libcore/asobj/Date_as.h   2009-08-21 07:07:11 +0000
+++ b/libcore/asobj/Date_as.h   2009-08-26 08:56:04 +0000
@@ -36,8 +36,6 @@
 
     std::string toString() const;
 
-    bool isDateObject() { return true; }
-
 private:
 
     double _timeValue;

=== modified file 'libcore/asobj/flash/xml/XMLDocument_as.cpp'
--- a/libcore/asobj/flash/xml/XMLDocument_as.cpp        2009-08-21 12:29:40 
+0000
+++ b/libcore/asobj/flash/xml/XMLDocument_as.cpp        2009-08-26 07:58:52 
+0000
@@ -57,10 +57,13 @@
     as_value xml_createElement(const fn_call& fn);
     as_value xml_createTextNode(const fn_call& fn);
     as_value xml_parseXML(const fn_call& fn);
-    as_value xml_ondata(const fn_call& fn);
+    as_value xml_onData(const fn_call& fn);
+    as_value xml_onLoad(const fn_call& fn);
     as_value xml_xmlDecl(const fn_call& fn);
     as_value xml_docTypeDecl(const fn_call& fn);
     as_value xml_escape(const fn_call& fn);
+    as_value xml_loaded(const fn_call& fn);
+    as_value xml_status(const fn_call& fn);
 
     bool textAfterWhitespace(const std::string& xml,
             std::string::const_iterator& it);
@@ -71,7 +74,6 @@
             std::string& content);
        
        
-    as_value xmldocument_ctor(const fn_call& fn);
     void attachXMLProperties(as_object& o);
        void attachXMLInterface(as_object& o);
     as_object* getXMLInterface();
@@ -81,7 +83,7 @@
 XMLDocument_as::XMLDocument_as() 
     :
     as_object(getXMLInterface()),
-    _loaded(-1), 
+    _loaded(XML_LOADED_UNDEFINED), 
     _status(XML_OK)
 {
 }
@@ -90,7 +92,7 @@
 XMLDocument_as::XMLDocument_as(const std::string& xml)
     :
     as_object(getXMLInterface()),
-    _loaded(-1), 
+    _loaded(XML_LOADED_UNDEFINED), 
     _status(XML_OK)
 {
     parseXML(xml);
@@ -145,56 +147,6 @@
     XMLNode_as::toString(o, encode);
 }
 
-bool
-XMLDocument_as::get_member(string_table::key name, as_value *val,
-        string_table::key nsname)
-{
-    if (name == NSV::PROP_STATUS) 
-    {
-        val->set_int(_status);
-        return true;
-    }
-    else if (name == NSV::PROP_LOADED)
-    {
-        if ( _loaded < 0 ) val->set_undefined();
-        else val->set_bool(_loaded);
-        return true;
-    }
-
-    return as_object::get_member(name, val, nsname);
-}
-
-bool
-XMLDocument_as::set_member(string_table::key name, const as_value& val, 
-    string_table::key nsname, bool ifFound)
-{
-    if (name == NSV::PROP_STATUS)
-    {
-        // TODO: this should really be a proper property (see XML.as)
-        if ( ! val.is_number() )
-        {
-            _status = static_cast<ParseStatus>(
-                    std::numeric_limits<boost::int32_t>::min());
-        }
-        else
-        {
-            unsigned int statusNumber = static_cast<int>(val.to_number());
-            _status = static_cast<ParseStatus>(statusNumber);
-        }
-        return true;
-    }
-    else if (name == NSV::PROP_LOADED)
-    {
-        // TODO: this should really be a proper property
-        bool b = val.to_bool();
-        if ( b ) _loaded = 1;
-        else _loaded = 0;
-        return true;
-    }
-
-    return as_object::set_member(name, val, nsname, ifFound);
-}
-
 void
 XMLDocument_as::parseAttribute(XMLNode_as* node, const std::string& xml,
         std::string::const_iterator& it, Attributes& attributes)
@@ -631,6 +583,12 @@
     const int flags = 0;
     o.init_property("xmlDecl", &xml_xmlDecl, &xml_xmlDecl, flags);
     o.init_property("docTypeDecl", &xml_docTypeDecl, &xml_docTypeDecl, flags);
+
+    as_object* proto = o.get_prototype().get();
+    if (!proto) return;
+    proto->init_property("loaded", xml_loaded, xml_loaded);
+    proto->init_property("status", xml_status, xml_status);
+
 }
 
 
@@ -656,7 +614,8 @@
     o.init_member("parseXML", vm.getNative(253, 10), flags); 
     o.init_member("send", vm.getNative(301, 1), flags);
     o.init_member("sendAndLoad", vm.getNative(301, 2), flags);
-    o.init_member("onData", gl->createFunction(xml_ondata), flags);
+    o.init_member("onData", gl->createFunction(xml_onData), flags);
+    o.init_member("onLoad", gl->createFunction(xml_onLoad), flags);
 
 }
 
@@ -725,6 +684,50 @@
     return as_value(xml_obj);
 }
 
+/// This is attached to the prototype (an XMLNode) on construction of XML
+//
+/// It has the curious effect of giving the XML object an inherited 'loaded'
+/// property that fails when called on the prototype, because the prototype
+/// is of type XMLNode.
+as_value
+xml_loaded(const fn_call& fn)
+{
+    boost::intrusive_ptr<XMLDocument_as> ptr =
+        ensureType<XMLDocument_as>(fn.this_ptr);
+
+    if (!fn.nargs) {
+        XMLDocument_as::LoadStatus ls = ptr->loaded();
+        if (ls == XMLDocument_as::XML_LOADED_UNDEFINED) return as_value();
+        return as_value(static_cast<bool>(ls));
+    }
+    ptr->setLoaded(
+            static_cast<XMLDocument_as::LoadStatus>(fn.arg(0).to_bool()));
+    return as_value();
+}
+
+as_value
+xml_status(const fn_call& fn)
+{
+    boost::intrusive_ptr<XMLDocument_as> ptr =
+        ensureType<XMLDocument_as>(fn.this_ptr);
+    
+    if (!fn.nargs) {
+        return as_value(ptr->status());
+    }
+
+    const double status = fn.arg(0).to_number();
+    if (isNaN(status) ||
+            status > std::numeric_limits<boost::int32_t>::max() ||
+            status < std::numeric_limits<boost::int32_t>::min()) {
+
+        ptr->setStatus(static_cast<XMLDocument_as::ParseStatus>(
+                    std::numeric_limits<boost::int32_t>::min()));
+    }
+
+    ptr->setStatus(static_cast<XMLDocument_as::ParseStatus>(status));
+    return as_value();
+}
+
 /// Only available as ASnative.
 as_value
 xml_escape(const fn_call& fn)
@@ -856,8 +859,15 @@
 
 }
 
-as_value
-xml_ondata(const fn_call& fn)
+/// XML.prototype has an empty onLoad function defined.
+as_value
+xml_onLoad(const fn_call& /*fn*/)
+{
+    return as_value();
+}
+
+as_value
+xml_onData(const fn_call& fn)
 {
 
     as_object* thisPtr = fn.this_ptr;
@@ -942,14 +952,6 @@
     return true;
 }
 
-as_value
-xmldocument_ctor(const fn_call& /*fn*/)
-{
-    boost::intrusive_ptr<as_object> obj = new XMLDocument_as;
-
-    return as_value(obj.get()); // will keep alive
-}
-
 } // anonymous namespace 
 } // gnash namespace
 

=== modified file 'libcore/asobj/flash/xml/XMLDocument_as.h'
--- a/libcore/asobj/flash/xml/XMLDocument_as.h  2009-08-20 15:33:23 +0000
+++ b/libcore/asobj/flash/xml/XMLDocument_as.h  2009-08-26 07:58:52 +0000
@@ -62,6 +62,12 @@
             XML_MISSING_OPEN_TAG = -10
     };
 
+    enum LoadStatus {
+        XML_LOADED_UNDEFINED = -1,
+        XML_LOADED_FALSE = false,
+        XML_LOADED_TRUE = true
+    };
+
     XMLDocument_as();
 
     XMLDocument_as(const std::string& xml);
@@ -96,20 +102,6 @@
         _docTypeDecl = docType;
     }
 
-    /// This is overridden to provide the 'status' and 'loaded' members,
-    /// which are NOT proper properties !
-    /// See actionscript.all/XML.as
-    ///
-    bool get_member(string_table::key name, as_value *val,
-               string_table::key nsname = 0);
-
-    /// This is overridden to provide the 'status' and 'loaded' members,
-    /// which are NOT proper properties !
-    /// See actionscript.all/XML.as
-    ///
-    bool set_member(string_table::key name, const as_value& val,
-                string_table::key nsname = 0, bool ifFound=false);
-
     // Methods
 
     /// Parses an XML document into the specified XML object tree.
@@ -135,6 +127,22 @@
 
     XMLNode_as* createTextNode(const std::string& name);
 
+    ParseStatus status() const {
+        return _status;
+    }
+
+    void setStatus(ParseStatus st) {
+        _status = st;
+    }
+
+    LoadStatus loaded() const {
+        return _loaded;
+    }
+
+    void setLoaded(LoadStatus st) {
+        _loaded = st;
+    }
+
 private:
 
     typedef std::map<std::string, std::string> Entities;
@@ -175,7 +183,7 @@
     // -1 if never asked to load anything
     //  0 if asked to load but not yet loaded (or failure)
     //  1 if successfully loaded
-    int _loaded;
+    LoadStatus _loaded;
 
     ParseStatus _status;       
  

=== modified file 'libcore/vm/Machine.cpp'
--- a/libcore/vm/Machine.cpp    2009-08-21 05:39:19 +0000
+++ b/libcore/vm/Machine.cpp    2009-08-26 08:56:22 +0000
@@ -2248,9 +2248,10 @@
                 /// Do: If obj is not XML based, throw TypeError
                 case SWF::ABC_ACTION_CHECKFILTER:
                 {
-                    if (!_stack.top(0).is_object() ||
-                            !_stack.top(0).to_object(*_global)->isXML())
+                    if (!_stack.top(0).is_object()) { 
+                        // TODO: check whether it is an XML object.
                         throw ASTypeError();
+                    }
                     break;
                 }
 
@@ -2965,10 +2966,6 @@
        if (name.isRuntime())
        {
                as_value obj = _stack.top(offset);
-               if (obj.is_object() && obj.to_object(*_global)->isQName()) {
-                       name.fill(obj.to_object(*_global).get());
-            ++size;
-        }
 
                if (name.isRtns()) {
                        ++size; // Ignore the Namespace.

=== modified file 'testsuite/actionscript.all/XML.as'
--- a/testsuite/actionscript.all/XML.as 2009-08-21 11:42:13 +0000
+++ b/testsuite/actionscript.all/XML.as 2009-08-26 07:59:32 +0000
@@ -47,7 +47,7 @@
 check(! XML.prototype.hasOwnProperty("attributes"));
 check(! XML.prototype.hasOwnProperty("nodeValue"));
 check(XML.prototype.hasOwnProperty("onData"));
-xcheck(XML.prototype.hasOwnProperty("onLoad")); // it seems it wouldn't do 
anything anyway, would it ?
+check(XML.prototype.hasOwnProperty("onLoad")); // it seems it wouldn't do 
anything anyway, would it ?
 check(XML.prototype.hasOwnProperty("createElement") );
 check(XML.prototype.hasOwnProperty("addRequestHeader") );
 check(XML.prototype.hasOwnProperty("createTextNode") );
@@ -123,9 +123,19 @@
 
 check_equals(typeof(tmp.status), 'number');
 check(! tmp.hasOwnProperty("status"));
-xcheck(tmp.__proto__.hasOwnProperty('status') );
+check(tmp.__proto__.hasOwnProperty('status') );
 
 tmp = new XML();
+
+// These are added on construction
+check(tmp.__proto__.hasOwnProperty("status"));
+check(tmp.__proto__.hasOwnProperty("loaded"));
+
+// These aren't
+check(!tmp.__proto__.hasOwnProperty("toString"));
+check(!tmp.hasOwnProperty("toString"));
+
+/// Setting status always results in a number.
 check_equals(tmp.status, 0);
 tmp.status = -1;
 check_equals(tmp.status, -1);
@@ -136,12 +146,26 @@
 check_equals(typeof(tmp.status), 'number');
 check_equals(tmp.status, -2147483648.0); // 0xFFFFFFFF
 tmp.status = 7;
+check_equals(tmp.status, 7); 
+
 returnFour = function() { return 4; };
 o.toString = returnFour;
 tmp.status = o;
 check_equals(typeof(tmp.status), 'number');
 check_equals(tmp.status, -2147483648.0); // 0xFFFFFFFF
 
+o.valueOf = function() { return 5; };
+tmp.status = o;
+check_equals(typeof(tmp.status), 'number');
+check_equals(tmp.status, 5); 
+
+tmp.status = 34e+45;
+check_equals(typeof(tmp.status), 'number');
+check_equals(tmp.status, -2147483648.0); // 0xFFFFFFFF
+
+tmp.status = -100000;
+check_equals(tmp.status, -100000);
+
 check_equals(typeof(tmp.loaded), 'undefined');
 check(! tmp.hasOwnProperty("loaded"));
 
@@ -152,7 +176,11 @@
 check_equals(typeof(tmp.loaded), 'boolean');
 check(!tmp.loaded);
 check(! tmp.hasOwnProperty("loaded"));
+check(tmp.__proto__.hasOwnProperty("loaded"));
 
+tmp.loaded = true;
+check_equals(tmp.loaded, true);
+check_equals(tmp.__proto__.loaded, undefined);
 
 // test the XML constuctor
 if (tmp) {
@@ -867,12 +895,12 @@
 #endif
        {
 #if OUTPUT_VERSION < 6
-               check_totals(406);
+               check_totals(419);
 #else
 # if OUTPUT_VERSION < 8
-               check_totals(441);
+               check_totals(454);
 # else
-               check_totals(422);
+               check_totals(435);
 # endif
 #endif
                play();

=== modified file 'testsuite/actionscript.all/XMLNode.as'
--- a/testsuite/actionscript.all/XMLNode.as     2009-02-25 22:33:03 +0000
+++ b/testsuite/actionscript.all/XMLNode.as     2009-08-26 06:52:28 +0000
@@ -381,4 +381,12 @@
 check_equals(ns.localName, "tag");
 check_equals(ns.prefix, "");
 
-check_totals(175);
+// xmlDecl and docTypeDecl don't work for XMLNode
+xn = new XMLNode(1, "");
+xn.xmlDecl = "hello";
+xn.docTypeDecl = "dtd";
+xcheck_equals(xn.toString(), "< />");
+
+
+
+check_totals(176);


reply via email to

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