gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r11639: Cleanups. Don't initialize _


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r11639: Cleanups. Don't initialize __constructor__ property of AS3 objects as they
Date: Fri, 20 Nov 2009 13:37:59 +0100
User-agent: Bazaar (1.16.1)

------------------------------------------------------------
revno: 11639 [merge]
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Fri 2009-11-20 13:37:59 +0100
message:
  Cleanups. Don't initialize __constructor__ property of AS3 objects as they 
  do not have one.
  
  Movie processLoad to be a member function of movie_root::LoadCallback.
modified:
  libcore/asobj/Globals.cpp
  libcore/asobj/LoadableObject.cpp
  libcore/asobj/LoadableObject.h
  libcore/asobj/flash/desktop/Clipboard_as.cpp
  libcore/asobj/flash/net/Socket_as.cpp
  libcore/asobj/flash/net/URLLoader_as.cpp
  libcore/asobj/flash/text/StaticText_as.cpp
  libcore/asobj/flash/text/TextSnapshot_as.cpp
  libcore/movie_root.cpp
  libcore/movie_root.h
  libcore/vm/Machine.cpp
  testsuite/as3compile.all/class.as
=== modified file 'libcore/asobj/Globals.cpp'
--- a/libcore/asobj/Globals.cpp 2009-11-18 12:01:08 +0000
+++ b/libcore/asobj/Globals.cpp 2009-11-19 08:08:36 +0000
@@ -310,8 +310,6 @@
         prototype->init_member(NSV::PROP_CONSTRUCTOR, cl); 
         cl->init_member(NSV::PROP_PROTOTYPE, prototype);
     }
-    cl->init_member(NSV::PROP_CONSTRUCTOR,
-            as_function::getFunctionConstructor());
     return cl;
 }
 

=== modified file 'libcore/asobj/LoadableObject.cpp'
--- a/libcore/asobj/LoadableObject.cpp  2009-11-15 14:33:03 +0000
+++ b/libcore/asobj/LoadableObject.cpp  2009-11-19 07:43:46 +0000
@@ -75,88 +75,6 @@
     vm.registerNative(loadableobject_decode, 301, 3);
 }
 
-// TODO: make a member of movie_root::LoadCallback ? 
-bool
-processLoad(movie_root::LoadCallbacks::value_type& v)
-{
-    IOChannel* lt = v.stream.get();
-    as_object* obj = v.obj;
-    SimpleBuffer& buf = v.buf;
-
-    if (!lt) {
-        callMethod(obj, NSV::PROP_ON_DATA, as_value());
-        return true;
-    }
-
-    static const size_t chunksize = 65535;
-    uint8_t chunk[chunksize];
-
-    size_t actuallyRead = lt->readNonBlocking(chunk, chunksize);
-
-    // We must still call onData if the stream is in error condition, e.g.
-    // when an HTTP 404 error is returned.
-    if (lt->bad()) {
-        callMethod(obj, NSV::PROP_ON_DATA, as_value());
-        return true;
-    }
-
-    if (actuallyRead) {
-
-        // set total size only on first read
-        if (buf.empty()) {
-            obj->set_member(NSV::PROP_uBYTES_TOTAL, lt->size());
-        }
-
-        buf.append(chunk, actuallyRead);
-
-        obj->set_member(NSV::PROP_uBYTES_LOADED, buf.size());
-
-        log_debug("LoadableObject Loaded %d bytes, reaching %d/%d",
-            actuallyRead, buf.size(), lt->size());
-    }
-
-    // We haven't finished till EOF 
-    if (!lt->eof()) return false;
-
-    log_debug("LoadableObject reached EOF (%d/%d loaded)",
-                buf.size(), lt->size());
-
-    // got nothing, won't bother BOFs of nulls
-    if (buf.empty()) {
-        callMethod(obj, NSV::PROP_ON_DATA, as_value());
-        return true;
-    }
-
-    // Terminate the string
-    buf.appendByte('\0');
-
-    // Strip BOM, if any.
-    // See http://savannah.gnu.org/bugs/?19915
-    utf8::TextEncoding encoding;
-    size_t size = buf.size();
-    // NOTE: the call below will possibly change 'size' parameter
-    char* bufptr = utf8::stripBOM((char*)buf.data(), size, encoding);
-    if (encoding != utf8::encUTF8 && encoding != utf8::encUNSPECIFIED) {
-        log_unimpl("%s to utf8 conversion in LoadableObject input parsing", 
-                utf8::textEncodingName(encoding));
-    }
-
-    // NOTE: Data copy here !!
-    as_value dataVal(bufptr); 
-
-    // NOTE: we could release memory associated
-    // with the buffer here, before invoking a new method,
-    // but at the time of writing there's no method of SimpleBuffer
-    // providing memory release except destruction. Will be
-    // destroyed as soon as we return though...
-
-    // NOTE: Another data copy here !
-    callMethod(obj, NSV::PROP_ON_DATA, dataVal);
-
-    return true;
-
-}
-
 /// Functors for use with foreachArray
 namespace {
 

=== modified file 'libcore/asobj/LoadableObject.h'
--- a/libcore/asobj/LoadableObject.h    2009-10-23 09:43:08 +0000
+++ b/libcore/asobj/LoadableObject.h    2009-11-19 07:43:46 +0000
@@ -36,8 +36,6 @@
 /// This implements built-in functions.
 void attachLoadableInterface(as_object& where, int flags);
 
-bool processLoad(movie_root::LoadCallbacks::value_type& v);
-
 }
 
 #endif

=== modified file 'libcore/asobj/flash/desktop/Clipboard_as.cpp'
--- a/libcore/asobj/flash/desktop/Clipboard_as.cpp      2009-11-18 11:51:35 
+0000
+++ b/libcore/asobj/flash/desktop/Clipboard_as.cpp      2009-11-19 07:58:46 
+0000
@@ -41,19 +41,11 @@
 }
 
 // extern (used by Global.cpp)
-void clipboard_class_init(as_object& where, const ObjectURI& uri)
+void
+clipboard_class_init(as_object& where, const ObjectURI& uri)
 {
-    Global_as& gl = getGlobal(where);
-    as_object* proto = gl.createObject();
-
-    as_object* cl = gl.createClass(&clipboard_ctor, proto);
-
-    attachClipboardInterface(*proto);
-    attachClipboardStaticInterface(*cl);
-
-    // Register _global.Clipboard
-    where.init_member(getName(uri), cl, as_object::DefaultFlags,
-            getNamespace(uri));
+    registerBuiltinClass(where, clipboard_ctor, attachClipboardInterface,
+            attachClipboardInterface, uri);
 }
 
 namespace {

=== modified file 'libcore/asobj/flash/net/Socket_as.cpp'
--- a/libcore/asobj/flash/net/Socket_as.cpp     2009-11-18 13:05:53 +0000
+++ b/libcore/asobj/flash/net/Socket_as.cpp     2009-11-19 07:58:46 +0000
@@ -74,15 +74,8 @@
 void
 socket_class_init(as_object& where, const ObjectURI& uri)
 {
-    Global_as& gl = getGlobal(where);
-    as_object* proto = gl.createObject();
-    attachSocketInterface(*proto);
-    as_object* cl = gl.createClass(&socket_ctor, proto);
-    attachSocketStaticInterface(*cl);
-
-    // Register _global.Socket
-    where.init_member(getName(uri), cl, as_object::DefaultFlags,
-            getNamespace(uri));
+    registerBuiltinClass(where, socket_ctor, attachSocketInterface,
+            attachSocketStaticInterface, uri);
 }
 
 namespace {

=== modified file 'libcore/asobj/flash/net/URLLoader_as.cpp'
--- a/libcore/asobj/flash/net/URLLoader_as.cpp  2009-11-18 13:05:53 +0000
+++ b/libcore/asobj/flash/net/URLLoader_as.cpp  2009-11-19 07:58:46 +0000
@@ -50,15 +50,8 @@
 void
 urlloader_class_init(as_object& where, const ObjectURI& uri)
 {
-    Global_as& gl = getGlobal(where);
-    as_object* proto = gl.createObject();
-    attachURLLoaderInterface(*proto);
-    as_object* cl = gl.createClass(&urlloader_ctor, proto);
-    attachURLLoaderStaticInterface(*cl);
-
-    // Register _global.URLLoader
-    where.init_member(getName(uri), cl, as_object::DefaultFlags,
-            getNamespace(uri));
+    registerBuiltinClass(where, urlloader_ctor, attachURLLoaderInterface,
+            attachURLLoaderStaticInterface, uri);
 }
 
 namespace {

=== modified file 'libcore/asobj/flash/text/StaticText_as.cpp'
--- a/libcore/asobj/flash/text/StaticText_as.cpp        2009-11-18 10:52:53 
+0000
+++ b/libcore/asobj/flash/text/StaticText_as.cpp        2009-11-19 07:58:46 
+0000
@@ -43,15 +43,8 @@
 void
 statictext_class_init(as_object& where, const ObjectURI& uri)
 {
-    Global_as& gl = getGlobal(where);
-    as_object* proto = gl.createObject();
-    as_object* cl = gl.createClass(&statictext_ctor, proto);
-    attachStaticTextInterface(*proto);
-    attachStaticTextStaticInterface(*cl);
-
-    // Register _global.StaticText
-    where.init_member(getName(uri), cl, as_object::DefaultFlags,
-            getNamespace(uri));
+    registerBuiltinClass(where, statictext_ctor, attachStaticTextInterface,
+            attachStaticTextStaticInterface, uri);
 }
 
 namespace {

=== modified file 'libcore/asobj/flash/text/TextSnapshot_as.cpp'
--- a/libcore/asobj/flash/text/TextSnapshot_as.cpp      2009-11-18 11:51:35 
+0000
+++ b/libcore/asobj/flash/text/TextSnapshot_as.cpp      2009-11-19 07:58:46 
+0000
@@ -147,15 +147,8 @@
 void
 textsnapshot_class_init(as_object& where, const ObjectURI& uri)
 {
-
-    Global_as& gl = getGlobal(where);
-    as_object* proto = gl.createObject();
-    as_object* cl = gl.createClass(&textsnapshot_ctor, proto);
-    attachTextSnapshotStaticInterface(*cl);
-    attachTextSnapshotInterface(*proto);
-
-   where.init_member(getName(uri), cl, as_object::DefaultFlags,
-               getNamespace(uri));
+    registerBuiltinClass(where, textsnapshot_ctor, attachTextSnapshotInterface,
+            attachTextSnapshotStaticInterface, uri);
 }
 
 /// The member _textFields is initialized here unnecessarily to show

=== modified file 'libcore/movie_root.cpp'
--- a/libcore/movie_root.cpp    2009-11-15 15:46:12 +0000
+++ b/libcore/movie_root.cpp    2009-11-19 07:43:34 +0000
@@ -36,7 +36,6 @@
 #include "GnashNumeric.h"
 #include "Global_as.h"
 #include "utf8.h"
-#include "LoadableObject.h"
 #include "IOChannel.h"
 
 #include <boost/algorithm/string/replace.hpp>
@@ -1569,7 +1568,8 @@
     }
 
     if (!_loadCallbacks.empty()) {
-        _loadCallbacks.remove_if(processLoad);
+        _loadCallbacks.remove_if(
+                std::mem_fun_ref(&movie_root::LoadCallback::processLoad));
     }
 
     processActionQueue();
@@ -1660,10 +1660,8 @@
     std::for_each(_objectCallbacks.begin(), _objectCallbacks.end(),
             std::mem_fun(&ActiveRelay::setReachable));
 
-    for (LoadCallbacks::const_iterator i = _loadCallbacks.begin(),
-            e = _loadCallbacks.end(); i != e; ++i) {
-        i->obj->setReachable();
-    }
+    std::for_each(_loadCallbacks.begin(), _loadCallbacks.end(),
+            std::mem_fun_ref(&movie_root::LoadCallback::setReachable));
 
     // Mark LoadMovieRequest handlers as reachable
     _movieLoader.setReachable();
@@ -2211,6 +2209,89 @@
 
 }
 
+void
+movie_root::LoadCallback::setReachable() const
+{
+    _obj->setReachable();
+}
+
+bool
+movie_root::LoadCallback::processLoad()
+{
+
+    if (!_stream) {
+        callMethod(_obj, NSV::PROP_ON_DATA, as_value());
+        return true;
+    }
+
+    const size_t chunksize = 65535;
+    uint8_t chunk[chunksize];
+
+    size_t actuallyRead = _stream->readNonBlocking(chunk, chunksize);
+
+    // We must still call onData if the stream is in error condition, e.g.
+    // when an HTTP 404 error is returned.
+    if (_stream->bad()) {
+        callMethod(_obj, NSV::PROP_ON_DATA, as_value());
+        return true;
+    }
+
+    if (actuallyRead) {
+
+        // set total size only on first read
+        if (_buf.empty()) {
+            _obj->set_member(NSV::PROP_uBYTES_TOTAL, _stream->size());
+        }
+
+        _buf.append(chunk, actuallyRead);
+
+        _obj->set_member(NSV::PROP_uBYTES_LOADED, _buf.size());
+
+        log_debug("LoadableObject Loaded %d bytes, reaching %d/%d",
+            actuallyRead, _buf.size(), _stream->size());
+    }
+
+    // We haven't finished till EOF 
+    if (!_stream->eof()) return false;
+
+    log_debug("LoadableObject reached EOF (%d/%d loaded)",
+                _buf.size(), _stream->size());
+
+    // got nothing, won't bother BOFs of nulls
+    if (_buf.empty()) {
+        callMethod(_obj, NSV::PROP_ON_DATA, as_value());
+        return true;
+    }
+
+    // Terminate the string
+    _buf.appendByte('\0');
+
+    // Strip BOM, if any.
+    // See http://savannah.gnu.org/bugs/?19915
+    utf8::TextEncoding encoding;
+    size_t size = _buf.size();
+
+    // NOTE: the call below will possibly change 'size' parameter
+    char* bufptr = utf8::stripBOM((char*)_buf.data(), size, encoding);
+    if (encoding != utf8::encUTF8 && encoding != utf8::encUNSPECIFIED) {
+        log_unimpl("%s to utf8 conversion in LoadableObject input parsing", 
+                utf8::textEncodingName(encoding));
+    }
+
+    // NOTE: Data copy here !!
+    as_value dataVal(bufptr); 
+
+    // NOTE: we could release memory associated
+    // with the buffer here, before invoking a new method,
+    // but at the time of writing there's no method of SimpleBuffer
+    // providing memory release except destruction. Will be
+    // destroyed as soon as we return though...
+
+    // NOTE: Another data copy here !
+    callMethod(_obj, NSV::PROP_ON_DATA, dataVal);
+
+    return true;
+}
 
 namespace {
 

=== modified file 'libcore/movie_root.h'
--- a/libcore/movie_root.h      2009-11-16 08:55:32 +0000
+++ b/libcore/movie_root.h      2009-11-19 07:43:34 +0000
@@ -147,12 +147,19 @@
 
 public:
 
-    struct LoadCallback {
-        boost::shared_ptr<IOChannel> stream;
-        as_object* obj;
-        SimpleBuffer buf;
+    class LoadCallback {
+    public:
         LoadCallback(boost::shared_ptr<IOChannel> s, as_object* o)
-            : stream(s), obj(o) {}
+            :
+            _stream(s),
+            _obj(o)
+        {}
+        bool processLoad();
+        void setReachable() const;
+    private:
+        boost::shared_ptr<IOChannel> _stream;
+        SimpleBuffer _buf;
+        as_object* _obj;
     };
         
     typedef std::list<LoadCallback> LoadCallbacks;

=== modified file 'libcore/vm/Machine.cpp'
--- a/libcore/vm/Machine.cpp    2009-11-18 11:51:35 +0000
+++ b/libcore/vm/Machine.cpp    2009-11-20 08:00:47 +0000
@@ -1524,8 +1524,7 @@
                     
                     as_object* obj = _stack.top(argc).to_object(*_global);
 
-                    // Using get_super() here fails; is it broken, or is
-                    // prototype what we want?
+                    // Is get_prototype what we want?
                     as_object* super = obj ? obj->get_prototype() : 0;
                     log_abc("CONSTRUCTSUPER: object %s, super %s, args %s",
                             _stack.top(argc), super, argc);
@@ -1715,11 +1714,6 @@
                     // What if there isn't one?
                     assert(scmethod);
                     
-                    /// This can be null.
-                    as_function* static_constructor = scmethod->getPrototype();
-                    new_class->init_member(NSV::PROP_uuCONSTRUCTORuu,
-                            as_value(static_constructor), 0);
-                    
                     as_function* ctor = c->getConstructor()->getPrototype();
                     new_class->init_member(NSV::PROP_CONSTRUCTOR, ctor, 0);
 
@@ -1728,14 +1722,15 @@
                     // Call the class's static constructor (which may be
                     // undefined).
                     as_environment env = as_environment(_vm);
-                    as_value property = new_class->getMember(
-                            NSV::PROP_uuCONSTRUCTORuu, 0);
 
+                    /// This can be null.
+                    as_function* staticCtor = scmethod->getPrototype();
+                    
+                    // We don't care about the return.
                     fn_call::Args args;
-                    as_value value = invoke(property, env, new_class,
-                            args);
+                    invoke(staticCtor, env, new_class, args);
 
-                    log_abc("NEWCLASS(%2%) finished. Return: %1%", value,
+                    log_abc("NEWCLASS(%1%) finished.",
                             mST.value(c->getName()));
 
                     break;

=== modified file 'testsuite/as3compile.all/class.as'
--- a/testsuite/as3compile.all/class.as 2009-07-06 09:28:29 +0000
+++ b/testsuite/as3compile.all/class.as 2009-11-20 12:37:59 +0000
@@ -57,7 +57,7 @@
 
             xcheck_equals(S, "[class S]");
             xcheck_equals(S.constructor, "[class Class]");
-            xcheck_equals(S.__constructor__, undefined);
+            check_equals(S.__constructor__, undefined);
             
             check_equals(S.s, null);
             xcheck_equals(typeof(S.s), "object");
@@ -74,8 +74,8 @@
 
             xcheck_equals(Derived.constructor, "[class Class]");
             xcheck_equals(Base.constructor, "[class Class]");
-            xcheck_equals(Derived.__constructor__, undefined);
-            xcheck_equals(Base.__constructor__, undefined);
+            check_equals(Derived.__constructor__, undefined);
+            check_equals(Base.__constructor__, undefined);
 
             // Objects are objects in AS3, not functions.
             check_equals(typeof(Base), "object");


reply via email to

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