[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r10400: Clean up Object class.
From: |
Benjamin Wolsey |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r10400: Clean up Object class. |
Date: |
Tue, 09 Dec 2008 10:19:27 +0100 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 10400
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Tue 2008-12-09 10:19:27 +0100
message:
Clean up Object class.
modified:
libcore/asobj/Object.cpp
libcore/asobj/Object.h
libcore/vm/ASHandlers.cpp
------------------------------------------------------------
revno: 10399.1.1
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Tue 2008-12-09 10:04:55 +0100
message:
Cleanup Object.{cpp,h}, and don't pass as_objects by auto_ptr.
modified:
libcore/asobj/Object.cpp
libcore/asobj/Object.h
libcore/vm/ASHandlers.cpp
=== modified file 'libcore/asobj/Object.cpp'
--- a/libcore/asobj/Object.cpp 2008-12-08 15:58:46 +0000
+++ b/libcore/asobj/Object.cpp 2008-12-09 09:04:55 +0000
@@ -35,17 +35,74 @@
namespace gnash {
// Forward declarations
-static as_value object_addproperty(const fn_call&);
-static as_value object_registerClass(const fn_call& fn);
-static as_value object_hasOwnProperty(const fn_call&);
-static as_value object_isPropertyEnumerable(const fn_call&);
-static as_value object_isPrototypeOf(const fn_call&);
-static as_value object_watch(const fn_call&);
-static as_value object_unwatch(const fn_call&);
-static as_value object_toLocaleString(const fn_call&);
-
-
-static void
+namespace {
+
+ as_value object_addproperty(const fn_call&);
+ as_value object_registerClass(const fn_call& fn);
+ as_value object_hasOwnProperty(const fn_call&);
+ as_value object_isPropertyEnumerable(const fn_call&);
+ as_value object_isPrototypeOf(const fn_call&);
+ as_value object_watch(const fn_call&);
+ as_value object_unwatch(const fn_call&);
+ as_value object_toLocaleString(const fn_call&);
+ as_value object_ctor(const fn_call& fn);
+
+ void attachObjectInterface(as_object& o);
+
+}
+
+
+as_object*
+init_object_instance()
+{
+ return new as_object(getObjectInterface());
+}
+
+
+// extern (used by Global.cpp)
+void object_class_init(as_object& global)
+{
+ // This is going to be the global Object "class"/"function"
+ static boost::intrusive_ptr<builtin_function> cl=NULL;
+
+ VM& vm = global.getVM();
+
+ if ( cl == NULL )
+ {
+ cl=new builtin_function(&object_ctor, getObjectInterface());
+
+ // Object.registerClass() --
+ // TODO: should this only be in SWF6 or higher ?
+ vm.registerNative(object_registerClass, 101, 8);
+ cl->init_member("registerClass", vm.getNative(101, 8));
+
+ }
+
+ // Register _global.Object (should only be visible in SWF5 up)
+ int flags = as_prop_flags::dontEnum;
+ global.init_member("Object", cl.get(), flags);
+
+}
+
+
+as_object*
+getObjectInterface()
+{
+ static boost::intrusive_ptr<as_object> o;
+ if ( o == NULL )
+ {
+ o = new as_object(); // end of the inheritance chain
+ attachObjectInterface(*o);
+ }
+ return o.get();
+}
+
+
+
+
+namespace {
+
+void
attachObjectInterface(as_object& o)
{
VM& vm = o.getVM();
@@ -61,71 +118,26 @@
vm.registerNative(object_isPrototypeOf, 101, 6);
vm.registerNative(object_isPropertyEnumerable, 101, 7);
- // Then will attach to the prototype based on version
-
- //int target_version = vm.getSWFVersion();
-
- // Object.valueOf()
o.init_member("valueOf", vm.getNative(101, 3));
-
- // Object.toString()
o.init_member("toString", vm.getNative(101, 4));
-
- // Object.toLocaleString()
- o.init_member("toLocaleString", new
builtin_function(object_toLocaleString));
-
- int swf6flags =
as_prop_flags::dontEnum|as_prop_flags::dontDelete|as_prop_flags::onlySWF6Up;
- //if ( target_version < 6 ) return;
-
- // Object.addProperty()
+ o.init_member("toLocaleString",
+ new builtin_function(object_toLocaleString));
+
+ int swf6flags = as_prop_flags::dontEnum |
+ as_prop_flags::dontDelete |
+ as_prop_flags::onlySWF6Up;
+
o.init_member("addProperty", vm.getNative(101, 2), swf6flags);
-
- // Object.hasOwnProperty()
o.init_member("hasOwnProperty", vm.getNative(101, 5), swf6flags);
-
- // Object.isPropertyEnumerable()
o.init_member("isPropertyEnumerable", vm.getNative(101, 7), swf6flags);
-
- // Object.isPrototypeOf()
o.init_member("isPrototypeOf", vm.getNative(101, 6), swf6flags);
-
- // Object.watch()
o.init_member("watch", vm.getNative(101, 0), swf6flags);
-
- // Object.unwatch()
o.init_member("unwatch", vm.getNative(101, 1), swf6flags);
}
-as_object*
-getObjectInterface()
-{
- static boost::intrusive_ptr<as_object> o;
- if ( o == NULL )
- {
- o = new as_object(); // end of the inheritance chain
- attachObjectInterface(*o);
- //o->set_prototype(o.get()); // proto is self ?
- }
- return o.get();
-}
-
-// FIXME: add some useful methods :)
-class object_as_object : public as_object
-{
-
-public:
-
- object_as_object()
- :
- as_object(getObjectInterface())
- {
- }
-
-};
-
-static as_value
+
+as_value
object_ctor(const fn_call& fn)
- // Constructor for ActionScript class Object.
{
if ( fn.nargs == 1 ) // copy constructor
{
@@ -140,58 +152,23 @@
boost::intrusive_ptr<as_object> new_obj;
if ( fn.nargs == 0 )
{
- new_obj = new object_as_object();
+ new_obj = new as_object(getObjectInterface());
}
else
{
IF_VERBOSE_ASCODING_ERRORS (
log_aserror(_("Too many args to Object constructor"));
)
- new_obj = new object_as_object();
+ new_obj = new as_object(getObjectInterface());
}
return as_value(new_obj.get()); // will keep alive
}
-std::auto_ptr<as_object>
-init_object_instance()
-{
- return std::auto_ptr<as_object>(new object_as_object);
-}
-
-
-// extern (used by Global.cpp)
-void object_class_init(as_object& global)
-{
- // This is going to be the global Object "class"/"function"
- static boost::intrusive_ptr<builtin_function> cl=NULL;
-
- VM& vm = global.getVM();
-
- if ( cl == NULL )
- {
- cl=new builtin_function(&object_ctor, getObjectInterface());
-
- // TODO: is this needed ?
- //cl->init_member("prototype", as_value(getObjectInterface()));
-
- // Object.registerClass() -- TODO: should this only be in SWF6
or higher ?
- vm.registerNative(object_registerClass, 101, 8);
- cl->init_member("registerClass", vm.getNative(101, 8));
-
-
- }
-
- // Register _global.Object (should only be visible in SWF5 up)
- int flags = as_prop_flags::dontEnum;
- global.init_member("Object", cl.get(), flags);
-
-}
-
/// The return value is not dependent on the result of add_property (though
/// this is always true anyway), but rather on the validity of the arguments.
-static as_value
+as_value
object_addproperty(const fn_call& fn)
{
assert(fn.this_ptr);
@@ -259,7 +236,8 @@
return as_value(true);
}
-static as_value
+
+as_value
object_registerClass(const fn_call& fn)
{
assert(fn.this_ptr);
@@ -362,6 +340,7 @@
return as_value(true);
}
+
as_value
object_hasOwnProperty(const fn_call& fn)
{
@@ -420,6 +399,7 @@
return as_value( ! prop->getFlags().get_dont_enum() );
}
+
as_value
object_isPrototypeOf(const fn_call& fn)
{
@@ -445,6 +425,7 @@
}
+
as_value
object_watch(const fn_call& fn)
{
@@ -482,6 +463,7 @@
return as_value(obj->watch(propkey, *trig, cust));
}
+
as_value
object_unwatch(const fn_call& fn)
{
@@ -507,6 +489,7 @@
return as_value(obj->unwatch(propkey));
}
+
as_value
object_toLocaleString(const fn_call& fn)
{
@@ -514,4 +497,5 @@
return obj->callMethod(NSV::PROP_TO_STRING);
}
+} // anonymous namespace
} // namespace gnash
=== modified file 'libcore/asobj/Object.h'
--- a/libcore/asobj/Object.h 2008-01-21 20:55:39 +0000
+++ b/libcore/asobj/Object.h 2008-12-09 09:04:55 +0000
@@ -14,27 +14,21 @@
// 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
-
-//
-//
-//
-
-// Implementation for ActionScript Number object.
+//
+// Implementation for ActionScript Object.
#ifndef GNASH_OBJECT_H
#define GNASH_OBJECT_H
-#include <memory> // for auto_ptr
-
namespace gnash {
class as_object;
-/// Initialize the global Number class
+/// Initialize the global Object class
void object_class_init(as_object& global);
/// Return an Object instance
-std::auto_ptr<as_object> init_object_instance();
+as_object* init_object_instance();
as_object* getObjectInterface();
=== modified file 'libcore/vm/ASHandlers.cpp'
--- a/libcore/vm/ASHandlers.cpp 2008-12-03 15:49:57 +0000
+++ b/libcore/vm/ASHandlers.cpp 2008-12-09 09:04:55 +0000
@@ -2928,7 +2928,7 @@
const int nmembers = env.pop().to_int();
- boost::intrusive_ptr<as_object>
new_obj_ptr(init_object_instance().release());
+ boost::intrusive_ptr<as_object> new_obj_ptr(init_object_instance());
// Set provided members
for (int i = 0; i < nmembers; ++i) {
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r10400: Clean up Object class.,
Benjamin Wolsey <=