gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r11192: Create a separate Global obj


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r11192: Create a separate Global object for each VM. This split means that changing
Date: Wed, 01 Jul 2009 15:25:26 +0200
User-agent: Bazaar (1.13.1)

------------------------------------------------------------
revno: 11192
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Wed 2009-07-01 15:25:26 +0200
message:
  Create a separate Global object for each VM. This split means that changing
  one object will no longer cause changes in the other. However, as we still
  mostly use the same objects, changing an object prototype will still
  result in changes to both machines, which is wrong.
  
  The AVM1 Global object no longer has AVM2 objects; the AVM2 one no longer
  has AVM1 objects, but does not yet have all AVM2 objects.
  
  Use ClassHierarchy to register objects. Enable namespace support in
  ClassHierarchy. The package object system is no longer used for AVM2; it
  treated flash and subpackages as objects when they should be namespaces.
  Packages for AS3 (not AS2!) can be removed.
modified:
  libcore/ClassHierarchy.cpp
  libcore/ClassHierarchy.h
  libcore/asNamespace.cpp
  libcore/asNamespace.h
  libcore/as_environment.cpp
  libcore/asobj/Global.cpp
  libcore/asobj/Global.h
  libcore/namedStrings.cpp
  libcore/namedStrings.h
  libcore/parser/Makefile.am
  libcore/parser/abc_block.cpp
  libcore/swf/DoABCTag.h
  libcore/vm/ActionExec.cpp
  libcore/vm/Machine.cpp
  libcore/vm/Machine.h
  libcore/vm/VM.cpp
  libcore/vm/VM.h
    ------------------------------------------------------------
    revno: 11188.1.1
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-06-30 08:03:37 +0200
    message:
      Initialize the Machine's global object on construction as a precursor to
      using separate global objects for AVM1 and AVM2.
    modified:
      libcore/swf/DoABCTag.h
      libcore/vm/Machine.cpp
      libcore/vm/Machine.h
    ------------------------------------------------------------
    revno: 11188.1.2
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-06-30 08:23:43 +0200
    message:
      Rename Global to AVM1Global. Add documentation about the two global
      objects. Define AVM2Global.
    modified:
      libcore/asobj/Global.cpp
      libcore/asobj/Global.h
      libcore/vm/VM.cpp
    ------------------------------------------------------------
    revno: 11188.1.3
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-06-30 09:03:28 +0200
    message:
      Rename some types. Provide a constructor for NativeClass. Move list of
      classes from ClassHierarchy to Global as the available classes depend on
      the global object.
      
      Do not initialize AS3 classes (int, Namespace) for AVM1.
    modified:
      libcore/ClassHierarchy.cpp
      libcore/ClassHierarchy.h
      libcore/asobj/Global.cpp
    ------------------------------------------------------------
    revno: 11188.1.4
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-06-30 11:09:03 +0200
    message:
      Pass ClassHierarchy to asNamespace::stubPrototype() to avoid using VM
      singleton. This could also be avoided by storing a reference to 
ClassHierarchy
      in asNamespace.
    modified:
      libcore/asNamespace.cpp
      libcore/asNamespace.h
    ------------------------------------------------------------
    revno: 11188.1.5
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-06-30 11:10:28 +0200
    message:
      Drop ClassHierarchy member of Machine; get it from the global object 
instead.
    modified:
      libcore/vm/Machine.cpp
      libcore/vm/Machine.h
    ------------------------------------------------------------
    revno: 11188.1.6
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-06-30 11:11:23 +0200
    message:
      Move class definition up. Correct stubPrototype usage.
    modified:
      libcore/ClassHierarchy.cpp
      libcore/ClassHierarchy.h
    ------------------------------------------------------------
    revno: 11188.1.7
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-06-30 11:12:07 +0200
    message:
      Get the ClassHierarchy from Machine using an ugly hack (to be improved).
    modified:
      libcore/parser/abc_block.cpp
    ------------------------------------------------------------
    revno: 11188.1.8
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-06-30 11:12:37 +0200
    message:
      Drop ClassHierarchy member as this should be owned by the Global classes.
      Return the appropriate Global class according to VM version.
    modified:
      libcore/vm/VM.cpp
      libcore/vm/VM.h
    ------------------------------------------------------------
    revno: 11188.1.9
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-06-30 11:13:40 +0200
    message:
      Add libltdl as an include (should probably be temporary).
    modified:
      libcore/parser/Makefile.am
    ------------------------------------------------------------
    revno: 11188.1.10
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-06-30 11:13:55 +0200
    message:
      Create separate AVM1 and AVM2 Global objects, each owned by the respective
      VM and owning its own ClassHierarchy. This is necessary to allow runs with
      mixed VM versions.
    modified:
      libcore/asobj/Global.cpp
      libcore/asobj/Global.h
    ------------------------------------------------------------
    revno: 11188.1.11
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-06-30 11:17:41 +0200
    message:
      Drop logging, remove obsolete comment.
    modified:
      libcore/asobj/Global.cpp
    ------------------------------------------------------------
    revno: 11188.1.12
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-06-30 11:41:16 +0200
    message:
      Initialize Sprite class.
    modified:
      libcore/asobj/Global.cpp
    ------------------------------------------------------------
    revno: 11188.1.13
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2009-06-30 16:22:20 +0200
    message:
      declare_native_function doesn't need to know about extensions.
    modified:
      libcore/ClassHierarchy.cpp
    ------------------------------------------------------------
    revno: 11188.1.14
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Wed 2009-07-01 12:35:31 +0200
    message:
      Don't pass the Object prototype to declare_{native,extension}_function's
      base ctor (as_function), as this sets Object.prototype.constructor to
      that function on each declaration!
      
      This only worked before because object_class_init was called *after* all 
the
      classes were declared, thus setting Object.prototype.constructor to the
      correct value.
    modified:
      libcore/ClassHierarchy.cpp
    ------------------------------------------------------------
    revno: 11188.1.15
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Wed 2009-07-01 12:38:58 +0200
    message:
      Drop logging for finding the Object prototype bug.
    modified:
      libcore/ClassHierarchy.cpp
    ------------------------------------------------------------
    revno: 11188.1.16
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Wed 2009-07-01 12:40:08 +0200
    message:
      Drop a PROPNAME.
    modified:
      libcore/vm/ActionExec.cpp
    ------------------------------------------------------------
    revno: 11188.1.17
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Wed 2009-07-01 12:40:30 +0200
    message:
      Indentation.
    modified:
      libcore/as_environment.cpp
    ------------------------------------------------------------
    revno: 11188.1.18
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Wed 2009-07-01 13:21:24 +0200
    message:
      Correct global properties for avm2 and avm1. Put all avm1 classes in the
      global namespace (adding more wastes memory).
      
      Add correct namespaces for all avm2 classes in the list.
    modified:
      libcore/asobj/Global.cpp
    ------------------------------------------------------------
    revno: 11188.1.19
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Wed 2009-07-01 13:29:51 +0200
    message:
      Add flash.errors namespace. Consistent indentation.
    modified:
      libcore/namedStrings.cpp
      libcore/namedStrings.h
    ------------------------------------------------------------
    revno: 11188.1.20
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Wed 2009-07-01 13:29:56 +0200
    message:
      Add more avm2 classes.
    modified:
      libcore/asobj/Global.cpp
    ------------------------------------------------------------
    revno: 11188.1.21
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Wed 2009-07-01 13:41:58 +0200
    message:
      Correct typo.
    modified:
      libcore/asobj/Global.cpp
    ------------------------------------------------------------
    revno: 11188.1.22
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Wed 2009-07-01 13:42:05 +0200
    message:
      Be stricter about namespaces now that avm1 values are properly declared
      in the global namespace.
    modified:
      libcore/ClassHierarchy.cpp
    ------------------------------------------------------------
    revno: 11188.1.23
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Wed 2009-07-01 13:46:51 +0200
    message:
      Drop mIsAS3.
    modified:
      libcore/vm/Machine.cpp
      libcore/vm/Machine.h
    ------------------------------------------------------------
    revno: 11188.1.24
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Wed 2009-07-01 14:20:58 +0200
    message:
      Update comments.
    modified:
      libcore/ClassHierarchy.cpp
    ------------------------------------------------------------
    revno: 11188.1.25
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Wed 2009-07-01 14:49:14 +0200
    message:
      Expose ClassHierarchy (hopefully temporarily).
    modified:
      libcore/vm/Machine.h
=== modified file 'libcore/ClassHierarchy.cpp'
--- a/libcore/ClassHierarchy.cpp        2009-06-17 15:33:51 +0000
+++ b/libcore/ClassHierarchy.cpp        2009-07-01 12:20:58 +0000
@@ -19,55 +19,13 @@
 #include "as_object.h"
 #include "as_prop_flags.h"
 #include "as_value.h"
-#include "as_function.h" // for function_class_init
-#include "Button.h"
-#include "AsBroadcaster.h"
-#include "flash/accessibility/Accessibility_as.h"
-#include "Boolean_as.h"
-#include "flash/media/Camera_as.h"
-#include "Color_as.h"
-#include "flash/ui/ContextMenu_as.h"
-#include "CustomActions.h"
-#include "Date_as.h"
-#include "Error_as.h"
-#include "Global.h"
-#include "int_as.h"
-#include "String_as.h"
-#include "flash/ui/Keyboard_as.h"
-#include "LoadVars_as.h"
-#include "flash/net/LocalConnection_as.h"
-#include "flash/media/Microphone_as.h"
-#include "Number_as.h"
-#include "Object.h"
-#include "Math_as.h"
-#include "Namespace_as.h"
-#include "flash/ui/Mouse_as.h"
-#include "flash/display/MovieClip_as.h"
-#include "MovieClipLoader.h"
-#include "movie_definition.h"
-#include "NetConnection_as.h"
-#include "NetStream_as.h"
-#include "Selection_as.h"
-#include "flash/net/SharedObject_as.h"
-#include "flash/display/Stage_as.h"
-#include "flash/media/Sound_as.h"
-#include "flash/system/System_as.h"
-#include "flash/text/TextSnapshot_as.h"
-#include "TextFormat_as.h"
-#include "Video.h"
-#include "extension.h"
-#include "VM.h"
-#include "URL.h" // for URL::encode and URL::decode (escape/unescape)
-#include "builtin_function.h"
-#include "TextField.h"
 #include "namedStrings.h"
 #include "ClassHierarchy.h"
+#include "as_function.h"
 #include "builtin_function.h"
-#include "flash/net/XMLSocket_as.h"
-#include "xml/XMLDocument_as.h"
-#include "xml/XMLNode_as.h"
 #include "asClass.h"
-#include "flash/text/TextFieldAutoSize_as.h"
+#include "Object.h"
+#include "extension.h"
 
 namespace gnash {
 
@@ -100,17 +58,19 @@
 class declare_extension_function : public as_function
 {
 private:
-    ClassHierarchy::extensionClass mDeclaration;
+    ClassHierarchy::ExtensionClass mDeclaration;
     as_object *mTarget;
     Extension *mExtension;
 
 public:
     bool isBuiltin() { return true; }
 
-    declare_extension_function(ClassHierarchy::extensionClass &c,
-        as_object *g, Extension* e) :
-        as_function(getObjectInterface()),
-        mDeclaration(c), mTarget(g), mExtension(e)
+    declare_extension_function(ClassHierarchy::ExtensionClass &c,
+        as_object *g, Extension* e)
+        :
+        mDeclaration(c),
+        mTarget(g),
+        mExtension(e)
     {
         init_member("constructor", 
as_function::getFunctionConstructor().get());
     }
@@ -166,17 +126,17 @@
 class declare_native_function : public as_function
 {
 private:
-    ClassHierarchy::nativeClass mDeclaration;
+    ClassHierarchy::NativeClass mDeclaration;
     as_object *mTarget;
-    Extension *mExtension;
 
 public:
     bool isBuiltin() { return true; }
 
-    declare_native_function(const ClassHierarchy::nativeClass &c,
-        as_object *g, Extension *e) :
-        as_function(getObjectInterface()),
-        mDeclaration(c), mTarget(g), mExtension(e)
+    declare_native_function(const ClassHierarchy::NativeClass &c,
+        as_object *g)
+        :
+        mDeclaration(c),
+        mTarget(g)
     {
         // does it make any sense to set a 'constructor' here ??
         //init_member("constructor", this);
@@ -191,8 +151,9 @@
         mDeclaration.initializer(*mTarget);
         // Successfully loaded it, now find it, set its proto, and return.
         as_value us;
-        if ( mTarget->get_member(mDeclaration.name, &us) )
-        {
+        if (mTarget->get_member(mDeclaration.name, &us,
+                    mDeclaration.namespace_name)) {
+
             as_value super;
             if (mDeclaration.super_name)
             {
@@ -218,14 +179,15 @@
                 }
                 assert(super.to_as_function());
             }
-            if ( ! us.to_object() )
-            {
-                log_error("Native class %s is not an object after 
initialization (%s)",
-                    st.value(mDeclaration.name), us);
+            if (!us.to_object()) {
+                log_error("Native class %s is not an object after "
+                        "initialization (%s)", st.value(mDeclaration.name), 
us);
             }
-            if (mDeclaration.super_name && 
!us.to_object()->hasOwnProperty(NSV::PROP_uuPROTOuu))
-            {
-                
us.to_object()->set_prototype(super.to_as_function()->getPrototype());
+            if (mDeclaration.super_name &&
+                    !us.to_object()->hasOwnProperty(NSV::PROP_uuPROTOuu)) {
+                
+                us.to_object()->set_prototype(
+                        super.to_as_function()->getPrototype());
             }
         }
         else
@@ -244,140 +206,54 @@
 }
 
 bool
-ClassHierarchy::declareClass(extensionClass& c)
+ClassHierarchy::declareClass(ExtensionClass& c)
 {
     if (!mExtension) return false; 
 
-    mGlobalNamespace->stubPrototype(c.name);
+    mGlobalNamespace->stubPrototype(*this, c.name);
     mGlobalNamespace->getClass(c.name)->setDeclared();
     mGlobalNamespace->getClass(c.name)->setSystem();
 
     boost::intrusive_ptr<as_function> getter =
         new declare_extension_function(c, mGlobal, mExtension);
 
+
     int flags=as_prop_flags::dontEnum;
     addVisibilityFlag(flags, c.version);
     return mGlobal->init_destructive_property(c.name, *getter, flags);
 }
 
 bool
-ClassHierarchy::declareClass(const nativeClass& c)
+ClassHierarchy::declareClass(const NativeClass& c)
 {
-    // For AS2 and below, registering with mGlobal _should_ make it equivalent
-    // to being in the global namespace, since everything is global there.
+    // AS2 classes should be registered with namespace 0, so they all
+    // appear in a single global namespace.
     asNamespace *nso = findNamespace(c.namespace_name);
 
     if (!nso) nso = addNamespace(c.namespace_name);
 
-    nso->stubPrototype(c.name);
+    nso->stubPrototype(*this, c.name);
     nso->getClass(c.name)->setDeclared();
     nso->getClass(c.name)->setSystem();
 
     boost::intrusive_ptr<as_function> getter =
-        new declare_native_function(c, mGlobal, mExtension);
-
+        new declare_native_function(c, mGlobal);
+    
     int flags = as_prop_flags::dontEnum;
     addVisibilityFlag(flags, c.version);
-    return mGlobal->init_destructive_property(c.name, *getter, flags);
+    return mGlobal->init_destructive_property(c.name, *getter, flags,
+            c.namespace_name);
 }
 
-static const ClassHierarchy::nativeClass knownClasses[] =
-{
-// This makes clear the difference between "We don't know where the
-// class belongs" and "it belongs in the global namespace", even though
-// the result is the same.
-    #define NS_GLOBAL 0
-    #define NS_UNKNOWN 0
-
-//  { function_name, name key, super name key, lowest version },
-    { system_class_init, NSV::CLASS_SYSTEM, 0, NSV::NS_FLASH_SYSTEM, 1 },
-    { stage_class_init, NSV::CLASS_STAGE, 0, NSV::NS_FLASH_DISPLAY, 1 },
-    { movieclip_class_init, NSV::CLASS_MOVIE_CLIP, 0, NSV::NS_FLASH_DISPLAY, 3 
},
-    { textfield_class_init, NSV::CLASS_TEXT_FIELD, 0, NSV::NS_FLASH_TEXT, 3 },
-    { math_class_init, NSV::CLASS_MATH, 0, NS_GLOBAL, 4 },
-    { boolean_class_init, NSV::CLASS_BOOLEAN, NSV::CLASS_OBJECT, NS_GLOBAL, 5 
},
-    { Button::init, NSV::CLASS_BUTTON, NSV::CLASS_OBJECT, NS_GLOBAL, 5 },
-    { color_class_init, NSV::CLASS_COLOR, NSV::CLASS_OBJECT, NS_GLOBAL, 5 },
-    { selection_class_init, NSV::CLASS_SELECTION, NSV::CLASS_OBJECT,
-        NS_UNKNOWN, 5 },
-    { Sound_as::init, NSV::CLASS_SOUND, NSV::CLASS_OBJECT,
-        NSV::NS_FLASH_MEDIA, 5 },
-    { xmlsocket_class_init, NSV::CLASS_XMLSOCKET, NSV::CLASS_OBJECT,
-        NSV::NS_FLASH_NET, 5 },
-    { Date_as::init, NSV::CLASS_DATE, NSV::CLASS_OBJECT, NS_GLOBAL, 5 },
-    { XMLDocument_as::init, NSV::CLASS_XML, NSV::CLASS_OBJECT, NS_GLOBAL, 5 },
-    { XMLNode_as::init, NSV::CLASS_XMLNODE, NSV::CLASS_OBJECT,
-        NSV::NS_FLASH_XML, 5 },
-    { mouse_class_init, NSV::CLASS_MOUSE, NSV::CLASS_OBJECT, NSV::NS_FLASH_UI,
-        5 },
-    { number_class_init, NSV::CLASS_NUMBER, NSV::CLASS_OBJECT, NS_GLOBAL, 5 },
-    { TextFormat_as::init, NSV::CLASS_TEXT_FORMAT, NSV::CLASS_OBJECT,
-        NS_GLOBAL, 5 },
-    { Keyboard_as::init, NSV::CLASS_KEY, NSV::CLASS_OBJECT, NS_GLOBAL, 5 },
-    { AsBroadcaster::init, NSV::CLASS_AS_BROADCASTER, NSV::CLASS_OBJECT,
-        NS_GLOBAL, 5 },
-    { TextSnapshot_as::init, NSV::CLASS_TEXT_SNAPSHOT, NSV::CLASS_OBJECT,
-        NSV::NS_FLASH_TEXT, 5 },
-    { video_class_init, NSV::CLASS_VIDEO, NSV::CLASS_OBJECT,
-        NSV::NS_FLASH_MEDIA, 6 },
-    { camera_class_init, NSV::CLASS_CAMERA, NSV::CLASS_OBJECT,
-        NSV::NS_FLASH_MEDIA, 6 },
-    { microphone_class_init, NSV::CLASS_MICROPHONE, NSV::CLASS_OBJECT,
-        NSV::NS_FLASH_MEDIA, 6 },
-    { sharedobject_class_init, NSV::CLASS_SHARED_OBJECT, NSV::CLASS_OBJECT,
-        NSV::NS_FLASH_NET, 5 },
-    { loadvars_class_init, NSV::CLASS_LOAD_VARS, NSV::CLASS_OBJECT, NS_GLOBAL, 
6 },
-    { LocalConnection_as::init, NSV::CLASS_LOCALCONNECTION, NSV::CLASS_OBJECT,
-        NSV::NS_FLASH_NET, 6 },
-    { customactions_class_init, NSV::CLASS_CUSTOM_ACTIONS, NSV::CLASS_OBJECT,
-        NSV::NS_ADOBE_UTILS, 6 },
-    { NetConnection_as::init, NSV::CLASS_NET_CONNECTION, NSV::CLASS_OBJECT,
-        NSV::NS_FLASH_NET, 6 },
-    { NetStream_as::init, NSV::CLASS_NET_STREAM, NSV::CLASS_OBJECT,
-        NSV::NS_FLASH_NET, 6 },
-    { contextmenu_class_init, NSV::CLASS_CONTEXTMENU, NSV::CLASS_OBJECT,
-        NSV::NS_FLASH_UI, 7 },
-    { moviecliploader_class_init, NSV::CLASS_MOVIE_CLIP_LOADER,
-        NSV::CLASS_OBJECT, NS_GLOBAL, 7 },
-    { Error_class_init, NSV::CLASS_ERROR, NSV::CLASS_OBJECT, NS_GLOBAL, 5 },
-    { accessibility_class_init, NSV::CLASS_ACCESSIBILITY, NSV::CLASS_OBJECT,
-          NSV::NS_FLASH_ACCESSIBILITY, 5 },
-    { int_class_init, NSV::CLASS_INT, NSV::CLASS_OBJECT, NS_GLOBAL, 9 },
-    { namespace_class_init, NSV::CLASS_NAMESPACE, NSV::CLASS_OBJECT,
-        NS_GLOBAL, 9 }
-//  { function_name, name key, super name key, lowest version },
-
-// These classes are all implicitly constructed; that is, it is not necessary 
for
-// the class name to be used to construct the class, so they must always be 
available.
-//  { object_class_init, NSV::CLASS_OBJECT, 0, NS_GLOBAL, 5 }
-//  { function_class_init, NSV::CLASS_FUNCTION, NSV::CLASS_OBJECT,
-//  NS_GLOBAL, 6 }
-//  { array_class_init, NSV::CLASS_ARRAY, NSV::CLASS_OBJECT, NS_GLOBAL, 5 }
-//  { string_class_init, NSV::CLASS_STRING, NSV::CLASS_OBJECT, NS_GLOBAL, 5 }
-
-};
 
 void
-ClassHierarchy::massDeclare()
+ClassHierarchy::declareAll(const NativeClasses& classes)
 {
-    // Natives get declared first. It doesn't make any sense for a native
-    // to depend on an extension, but it does make sense the other way
-    // around.
-    const size_t size = sizeof (knownClasses) / sizeof (nativeClass);
-    for (size_t i = 0; i < size; ++i)
-    {
-        const nativeClass& c = knownClasses[i];
-
-        if ( ! declareClass(c) )
-        {
-            log_error("Could not declare class %s", c);
-        }
-    }
-
-    if (mExtension != NULL)
-    {
-        /* Load extensions here */
-    }
+    // This is necessary to resolve the overload...
+    bool(ClassHierarchy::*nf)(const NativeClass& f) =
+        &ClassHierarchy::declareClass;
+
+    std::for_each(classes.begin(), classes.end(), boost::bind(nf, this, _1));
 }
 
 void
@@ -387,7 +263,7 @@
 }
 
 std::ostream&
-operator<<(std::ostream& os, const ClassHierarchy::nativeClass& c)
+operator<<(std::ostream& os, const ClassHierarchy::NativeClass& c)
 {
     string_table& st = VM::get().getStringTable();
 
@@ -402,7 +278,7 @@
 }
 
 std::ostream&
-operator<<(std::ostream& os, const ClassHierarchy::extensionClass& c)
+operator<<(std::ostream& os, const ClassHierarchy::ExtensionClass& c)
 {
     string_table& st = VM::get().getStringTable();
 

=== modified file 'libcore/ClassHierarchy.h'
--- a/libcore/ClassHierarchy.h  2009-05-27 17:45:42 +0000
+++ b/libcore/ClassHierarchy.h  2009-06-30 09:11:23 +0000
@@ -47,14 +47,12 @@
 class ClassHierarchy
 {
 public:
-       struct extensionClass
+       struct ExtensionClass
        {
-               /// \brief
-               /// The file name which contains the library, relative to the 
-               /// plugins directory.
+               /// The filename for the library relative to the plugins 
directory.
                std::string file_name;
 
-               /// \brief Initialization function name
+               /// Initialization function name
                ///
                /// The name of the function which will yield the prototype
                /// object. It should be a function with signature:
@@ -64,77 +62,98 @@
                /// mysql_class_init
                std::string init_name;
 
-               /// \brief The name of the class.
+               /// The name of the class.
                string_table::key name;
 
-               /// \brief
-               /// The name of the inherited class.
-               /// Ordinarily should be CLASS_OBJECT
+               /// The name of the inherited class. Ordinarily should be 
CLASS_OBJECT
                string_table::key super_name;
 
-               /// \brief
                /// The name of the namespace in which this belongs.
                string_table::key namespace_name;
 
-               /// \brief
                /// The version at which this should be added.
                int version;
        };
 
-       struct nativeClass
+       struct NativeClass
        {
-               /// The type of function to use for initing.
-               typedef void (*init_func)(as_object& obj);
-
-               /// \brief
+               
+        /// The type of function to use for initialization
+               typedef void (*InitFunc)(as_object& obj);
+
+        NativeClass(InitFunc init, string_table::key n,
+                string_table::key sc, string_table::key ns, int ver)
+            :
+            initializer(init),
+            name(n),
+            super_name(sc),
+            namespace_name(ns),
+            version(ver)
+        {}
+
                /// The initialization function
                ///
-               /// See extensionClass.init_name for the necessary function.
-               init_func initializer;
+               /// See ExtensionClass.init_name for the necessary function.
+               InitFunc initializer;
 
                /// The name of the class.
                string_table::key name;
 
-               /// \brief
                /// The name of the inherited class. Object is assumed if
                /// none is given. (Unless name is itself Object)
                string_table::key super_name;
 
-               /// \brief
                /// The name of the namespace in which this belongs.
                string_table::key namespace_name;
 
-               /// \brief
-               /// The version at which this should be added.
+               /// The version at which this should be visible.
                int version;
        };
-
-       /// \brief
-       /// Declare an ActionScript class, with information on how
-       /// to load it from an extension.
-       ///
-       /// @param c
-       /// The extensionClass structure which defines the class.
-       ///
-       /// @return true, unless the class with c.name already existed.
-       bool declareClass(extensionClass& c);
-
-       /// \brief
-       /// Declare an ActionScript class, with information on how
-       /// to instantiate it from the core.
-       ///
-       /// @param c
-       /// The nativeClass structure which defines the class.
-       ///
-       /// @return true, unless the class with c.name already existed.
-       bool declareClass(const nativeClass& c);
-
-       /// \brief
-       /// Declare all of the native and extension classes from the
-       /// tables contained in the source file.
-       ///
-       void massDeclare();
-
+       
+    /// \brief
+       /// Construct the declaration object. Later set the global and
+       /// extension objects using setGlobal and setExtension
+       ClassHierarchy(as_object* global, Extension* e)
+        :
+               mGlobal(global),
+        mExtension(e) ,
+               mAnonNamespaces(),
+        mGlobalNamespace(anonNamespace(0)),
+               mClassMemory()
+#ifdef ENABLE_AVM2
+        ,
+        mExceptionMemory(),
+               mMethodMemory(),
+               mBoundValueMemory(),
+        mBoundAccessorMemory()
+#endif
+       {}
+
+       /// \brief
+       /// Delete our private namespaces.
+       ~ClassHierarchy();
+
+
+    typedef std::vector<NativeClass> NativeClasses;
+
+       /// Declare an ActionScript class, with information on how to load it.
+       ///
+       /// @param c
+       /// The ExtensionClass structure which defines the class.
+       ///
+       /// @return true, unless the class with c.name already existed.
+       bool declareClass(ExtensionClass& c);
+
+       /// Declare an ActionScript class and how to instantiate it from the 
core.
+       ///
+       /// @param c
+       /// The NativeClass structure which defines the class.
+       ///
+       /// @return true, unless the class with c.name already existed.
+       bool declareClass(const NativeClass& c);
+
+       /// Declare a list of native classes.
+       void declareAll(const NativeClasses& classes);
 
        /// The global namespace
        ///
@@ -219,38 +238,9 @@
 
 #endif
 
-       /// Set the extension object, since it wasn't set on construction.
-       void setExtension(Extension *e) { mExtension = e; }
-
-       /// Set the global object, for registrations.
-       void setGlobal(as_object *g) { mGlobal = g; }
-
        /// Mark objects for garbage collector.
        void markReachableResources() const;
 
-       /// \brief
-       /// Construct the declaration object. Later set the global and
-       /// extension objects using setGlobal and setExtension
-       ClassHierarchy()
-        :
-               mGlobal(0),
-        mExtension(0) ,
-               mAnonNamespaces(),
-        mGlobalNamespace(anonNamespace(0)),
-               mClassMemory()
-#ifdef ENABLE_AVM2
-        ,
-        mExceptionMemory(),
-               mMethodMemory(),
-               mBoundValueMemory(),
-        mBoundAccessorMemory()
-#endif
-       {}
-
-       /// \brief
-       /// Delete our private namespaces.
-       ~ClassHierarchy();
-
 private:
        as_object* mGlobal;
        Extension* mExtension;
@@ -270,9 +260,10 @@
 };
 
 std::ostream&
-operator<< (std::ostream& os, const ClassHierarchy::nativeClass& c);
+operator<< (std::ostream& os, const ClassHierarchy::NativeClass& c);
+
 std::ostream&
-operator<< (std::ostream& os, const ClassHierarchy::extensionClass& c);
+operator<< (std::ostream& os, const ClassHierarchy::ExtensionClass& c);
 
 } 
 #endif 

=== modified file 'libcore/asNamespace.cpp'
--- a/libcore/asNamespace.cpp   2009-05-14 10:30:48 +0000
+++ b/libcore/asNamespace.cpp   2009-06-30 09:09:03 +0000
@@ -22,9 +22,9 @@
 namespace gnash {
 
 void
-asNamespace::stubPrototype(string_table::key name)
+asNamespace::stubPrototype(ClassHierarchy& ch, string_table::key name)
 {
-       asClass *pClass = VM::get().getClassHierarchy()->newClass();
+       asClass *pClass = ch.newClass();
        pClass->setName(name);
        addClass(name, pClass);
 }

=== modified file 'libcore/asNamespace.h'
--- a/libcore/asNamespace.h     2009-06-26 05:54:45 +0000
+++ b/libcore/asNamespace.h     2009-06-30 09:09:03 +0000
@@ -24,6 +24,7 @@
 // Forward declarations
 namespace gnash {
     class asClass;
+    class ClassHierarchy;
 }
 
 namespace gnash {
@@ -75,7 +76,7 @@
                return true;
        }
 
-       void stubPrototype(string_table::key name);
+       void stubPrototype(ClassHierarchy& ch, string_table::key name);
 
        /// Get the named class. Returns NULL if information is not known
        /// about the class. (Stubbed classes still return NULL here.)

=== modified file 'libcore/as_environment.cpp'
--- a/libcore/as_environment.cpp        2009-06-03 16:05:40 +0000
+++ b/libcore/as_environment.cpp        2009-07-01 10:40:30 +0000
@@ -105,16 +105,16 @@
     // TODO: have this checked by parse_path as an optimization 
     if (varname.find('/') != std::string::npos &&
             varname.find(':') == std::string::npos)
-    {
-        // Consider it all a path ...
-            as_object* target = find_object(varname, &scopeStack); 
-        if ( target ) 
         {
-            // ... but only if it resolves to a sprite
-            MovieClip* m = target->to_movie();
-            if ( m ) return as_value(m);
+            // Consider it all a path ...
+                as_object* target = find_object(varname, &scopeStack); 
+            if ( target ) 
+            {
+                // ... but only if it resolves to a sprite
+                MovieClip* m = target->to_movie();
+                if ( m ) return as_value(m);
+            }
         }
-    }
         return get_variable_raw(varname, scopeStack, retTarget);
     }
 }

=== modified file 'libcore/asobj/Global.cpp'
--- a/libcore/asobj/Global.cpp  2009-06-17 15:33:51 +0000
+++ b/libcore/asobj/Global.cpp  2009-07-01 11:41:58 +0000
@@ -33,9 +33,8 @@
 #include "Color_as.h"
 #include "flash/ui/ContextMenu_as.h"
 #include "CustomActions.h"
-#include "Date_as.h" // for registerDateNative
+#include "Date_as.h" 
 #include "Error_as.h"
-#include "Global.h"
 #include "String_as.h"
 #include "flash/ui/Keyboard_as.h"
 #include "Selection_as.h"
@@ -47,7 +46,11 @@
 #include "flash/xml/XMLDocument_as.h"
 #include "flash/net/XMLSocket_as.h"
 #include "flash/ui/Mouse_as.h"
+#include "flash/display/InteractiveObject_as.h"
+#include "flash/display/DisplayObjectContainer_as.h"
+#include "flash/display/DisplayObject_as.h"
 #include "flash/display/MovieClip_as.h"
+#include "flash/display/Sprite_as.h"
 #include "MovieClipLoader.h"
 #include "movie_definition.h"
 #include "NetConnection_as.h"
@@ -61,7 +64,7 @@
 #include "extension.h"
 #include "VM.h"
 #include "Timers.h"
-#include "URL.h" // for URL::encode and URL::decode (escape/unescape)
+#include "URL.h" 
 #include "builtin_function.h"
 #include "TextField.h"
 #include "rc.h"
@@ -69,12 +72,21 @@
 #include "namedStrings.h"
 #include "GnashNumeric.h" // for isfinite replacement
 #include "flash_pkg.h"
-
 #include "fn_call.h"
+#include "Button.h"
+#include "flash/accessibility/Accessibility_as.h"
+#include "Global.h"
+#include "int_as.h"
+#include "LoadVars_as.h"
+#include "flash/net/LocalConnection_as.h"
+#include "Namespace_as.h"
+#include "xml/XMLNode_as.h"
+#include "flash/text/TextFieldAutoSize_as.h"
 
-#include <limits> // for numeric_limits<double>::infinity
+#include <limits> 
 #include <sstream>
 #include <boost/lexical_cast.hpp>
+#include <boost/assign/list_of.hpp>
 
 // Common code to warn and return if a required single arg is not present
 // and to warn if there are extra args.
@@ -93,6 +105,10 @@
 namespace gnash {
 
 namespace {
+
+    const ClassHierarchy::NativeClasses& avm1Classes();
+    const ClassHierarchy::NativeClasses& avm2Classes();
+
     as_value global_trace(const fn_call& fn);
     as_value global_isNaN(const fn_call& fn);
     as_value global_isfinite(const fn_call& fn);
@@ -115,9 +131,46 @@
     void registerNatives(as_object& global);
 }
 
-Global::Global(VM& vm, ClassHierarchy *ch)
-    :
-    as_object()
+AVM2Global::AVM2Global(Machine& machine)
+    :
+    as_object(),
+    _classes(this, 0)
+{
+    
+    _classes.declareAll(avm2Classes());
+    
+    init_member("trace", new builtin_function(global_trace));
+    init_member("escape", new builtin_function(global_escape));
+   
+    object_class_init(*this); 
+    string_class_init(*this); 
+    array_class_init(*this); 
+
+    function_class_init(*this);
+
+    _classes.getGlobalNs()->stubPrototype(_classes, NSV::CLASS_FUNCTION);
+    
+    _classes.getGlobalNs()->getClass(NSV::CLASS_FUNCTION)->setDeclared();
+
+    _classes.getGlobalNs()->stubPrototype(_classes, NSV::CLASS_OBJECT);
+    _classes.getGlobalNs()->getClass(NSV::CLASS_OBJECT)->setDeclared();
+    _classes.getGlobalNs()->stubPrototype(_classes, NSV::CLASS_ARRAY);
+    _classes.getGlobalNs()->getClass(NSV::CLASS_ARRAY)->setDeclared();
+    _classes.getGlobalNs()->stubPrototype(_classes, NSV::CLASS_STRING);
+    _classes.getGlobalNs()->getClass(NSV::CLASS_STRING)->setDeclared();        
+}
+
+void 
+AVM1Global::markReachableResources() const
+{
+    _classes.markReachableResources();
+    markAsObjectReachable();
+}
+
+AVM1Global::AVM1Global(VM& vm)
+    :
+    as_object(),
+    _classes(this, &_et)
 {
 
     registerNatives(*this);
@@ -147,9 +200,7 @@
     init_member("setTimeout", new builtin_function(global_setTimeout));
     init_member("clearTimeout", new builtin_function(global_clearInterval));
 
-    ch->setGlobal(this);
-    ch->setExtension(&_et);
-    ch->massDeclare();
+    _classes.declareAll(avm1Classes());
 
     object_class_init(*this); 
     string_class_init(*this); 
@@ -173,17 +224,20 @@
         case 7:
         case 6:
 
-            ch->getGlobalNs()->stubPrototype(NSV::CLASS_FUNCTION);
-            ch->getGlobalNs()->getClass(NSV::CLASS_FUNCTION)->setDeclared();
+            _classes.getGlobalNs()->stubPrototype(_classes, 
+                    NSV::CLASS_FUNCTION);
+            
+            _classes.getGlobalNs()->getClass(
+                    NSV::CLASS_FUNCTION)->setDeclared();
 
         case 5:
         
-            ch->getGlobalNs()->stubPrototype(NSV::CLASS_OBJECT);
-            ch->getGlobalNs()->getClass(NSV::CLASS_OBJECT)->setDeclared();
-            ch->getGlobalNs()->stubPrototype(NSV::CLASS_ARRAY);
-            ch->getGlobalNs()->getClass(NSV::CLASS_ARRAY)->setDeclared();
-            ch->getGlobalNs()->stubPrototype(NSV::CLASS_STRING);
-            ch->getGlobalNs()->getClass(NSV::CLASS_STRING)->setDeclared();     
   
+            _classes.getGlobalNs()->stubPrototype(_classes, NSV::CLASS_OBJECT);
+            _classes.getGlobalNs()->getClass(NSV::CLASS_OBJECT)->setDeclared();
+            _classes.getGlobalNs()->stubPrototype(_classes, NSV::CLASS_ARRAY);
+            _classes.getGlobalNs()->getClass(NSV::CLASS_ARRAY)->setDeclared();
+            _classes.getGlobalNs()->stubPrototype(_classes, NSV::CLASS_STRING);
+            
_classes.getGlobalNs()->getClass(NSV::CLASS_STRING)->setDeclared();        
             // This is surely not correct, but they are not available
             // in SWF4
             init_member("escape", vm.getNative(100, 0));
@@ -215,7 +269,7 @@
 // if a plugin defines a class that a movie actually wants to
 // use.
 void
-Global::loadExtensions()
+AVM1Global::loadExtensions()
 {
 
     if ( RcInitFile::getDefaultInstance().enableExtensions() )
@@ -230,9 +284,175 @@
 
 }
 
-
 namespace {
 
+const ClassHierarchy::NativeClasses&
+avm1Classes()
+{
+
+    const string_table::key NS_GLOBAL = 0;
+
+    typedef ClassHierarchy::NativeClass N;
+
+    // Since we maintain separate lists for AVM1 and AVM2, these are all
+    // considered to be in the 'Global' namespace (AVM1 has no namespaces).
+    static const ClassHierarchy::NativeClasses s = boost::assign::list_of
+
+        (N(system_class_init, NSV::CLASS_SYSTEM, 0, NS_GLOBAL, 1))
+        (N(stage_class_init, NSV::CLASS_STAGE, 0, NS_GLOBAL, 1))
+        (N(movieclip_class_init, NSV::CLASS_MOVIE_CLIP, 0, NS_GLOBAL, 3))
+        (N(textfield_class_init, NSV::CLASS_TEXT_FIELD, 0, NS_GLOBAL, 3))
+        (N(math_class_init, NSV::CLASS_MATH, 0, NS_GLOBAL, 4))
+        (N(boolean_class_init, NSV::CLASS_BOOLEAN, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 5))
+        (N(Button::init, NSV::CLASS_BUTTON, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 5))
+        (N(color_class_init, NSV::CLASS_COLOR, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 5))
+        (N(selection_class_init, NSV::CLASS_SELECTION, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 5))
+        (N(Sound_as::init, NSV::CLASS_SOUND, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 5))
+        (N(xmlsocket_class_init, NSV::CLASS_XMLSOCKET, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 5))
+        (N(Date_as::init, NSV::CLASS_DATE, NSV::CLASS_OBJECT, NS_GLOBAL, 5))
+        (N(XMLDocument_as::init, NSV::CLASS_XML, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 5))
+        (N(XMLNode_as::init, NSV::CLASS_XMLNODE, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 5))
+        (N(mouse_class_init, NSV::CLASS_MOUSE, NSV::CLASS_OBJECT, NS_GLOBAL, 
5))
+        (N(number_class_init, NSV::CLASS_NUMBER, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 5))
+        (N(TextFormat_as::init, NSV::CLASS_TEXT_FORMAT, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 5))
+        (N(Keyboard_as::init, NSV::CLASS_KEY, NSV::CLASS_OBJECT, NS_GLOBAL, 5))
+        (N(AsBroadcaster::init, NSV::CLASS_AS_BROADCASTER, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 5))
+        (N(TextSnapshot_as::init, NSV::CLASS_TEXT_SNAPSHOT, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 5))
+        (N(video_class_init, NSV::CLASS_VIDEO, NSV::CLASS_OBJECT, NS_GLOBAL, 
6))
+        (N(camera_class_init, NSV::CLASS_CAMERA, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 6))
+        (N(microphone_class_init, NSV::CLASS_MICROPHONE, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 6))
+        (N(sharedobject_class_init, NSV::CLASS_SHARED_OBJECT,
+           NSV::CLASS_OBJECT, NS_GLOBAL, 5))
+        (N(loadvars_class_init, NSV::CLASS_LOAD_VARS, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 6))
+        (N(LocalConnection_as::init, NSV::CLASS_LOCALCONNECTION,
+           NSV::CLASS_OBJECT, NS_GLOBAL, 6))
+        (N(customactions_class_init, NSV::CLASS_CUSTOM_ACTIONS,
+           NSV::CLASS_OBJECT, NS_GLOBAL, 6))
+        (N(NetConnection_as::init, NSV::CLASS_NET_CONNECTION,
+           NSV::CLASS_OBJECT, NS_GLOBAL, 6))
+        (N(NetStream_as::init, NSV::CLASS_NET_STREAM, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 6))
+        (N(contextmenu_class_init, NSV::CLASS_CONTEXTMENU, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 7))
+        (N(moviecliploader_class_init, NSV::CLASS_MOVIE_CLIP_LOADER,
+           NSV::CLASS_OBJECT, NS_GLOBAL, 7))
+        (N(Error_class_init, NSV::CLASS_ERROR, NSV::CLASS_OBJECT, NS_GLOBAL, 
5))
+        (N(accessibility_class_init, NSV::CLASS_ACCESSIBILITY,
+           NSV::CLASS_OBJECT, NS_GLOBAL, 5));
+
+    return s;
+
+}
+
+const ClassHierarchy::NativeClasses&
+avm2Classes()
+{
+
+    const string_table::key NS_GLOBAL = 0;
+
+    typedef ClassHierarchy::NativeClass N;
+
+    static const ClassHierarchy::NativeClasses s = boost::assign::list_of
+
+        // Global classes
+        (N(math_class_init, NSV::CLASS_MATH, 0, NS_GLOBAL, 4))
+        (N(boolean_class_init, NSV::CLASS_BOOLEAN, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 5))
+        (N(number_class_init, NSV::CLASS_NUMBER, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 5))
+        (N(int_class_init, NSV::CLASS_INT, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 5))
+        (N(namespace_class_init, NSV::CLASS_NAMESPACE, NSV::CLASS_OBJECT,
+           NS_GLOBAL, 5))
+        (N(Date_as::init, NSV::CLASS_DATE, NSV::CLASS_OBJECT, NS_GLOBAL, 5))
+
+        // System classes
+        (N(system_class_init, NSV::CLASS_SYSTEM, 0, NSV::NS_FLASH_SYSTEM, 1))
+
+        // Display classes
+        (N(stage_class_init, NSV::CLASS_STAGE, 0, NSV::NS_FLASH_DISPLAY, 1))
+        (N(movieclip_class_init, NSV::CLASS_MOVIE_CLIP, 0,
+           NSV::NS_FLASH_DISPLAY, 3))
+        (N(sprite_class_init, NSV::CLASS_SPRITE, 0, NSV::NS_FLASH_DISPLAY, 3))
+        (N(displayobjectcontainer_class_init, 
NSV::CLASS_DISPLAYOBJECTCONTAINER,
+           0, NSV::NS_FLASH_DISPLAY, 3))
+        (N(interactiveobject_class_init, NSV::CLASS_INTERACTIVEOBJECT,
+           0, NSV::NS_FLASH_DISPLAY, 3))
+        (N(displayobject_class_init, NSV::CLASS_DISPLAYOBJECT, 0,
+           NSV::NS_FLASH_DISPLAY, 3))
+        (N(Button::init, NSV::CLASS_BUTTON, NSV::CLASS_OBJECT,
+           NSV::NS_FLASH_DISPLAY, 5))
+
+        // Text classes
+        (N(textfield_class_init, NSV::CLASS_TEXT_FIELD, 0,
+           NSV::NS_FLASH_TEXT, 3))
+        (N(TextFormat_as::init, NSV::CLASS_TEXT_FORMAT, NSV::CLASS_OBJECT,
+           NSV::NS_FLASH_TEXT, 5))
+        (N(TextSnapshot_as::init, NSV::CLASS_TEXT_SNAPSHOT, NSV::CLASS_OBJECT,
+           NSV::NS_FLASH_TEXT, 5))
+        
+        // Media classes
+        (N(Sound_as::init, NSV::CLASS_SOUND, NSV::CLASS_OBJECT,
+           NSV::NS_FLASH_MEDIA, 5))
+        (N(video_class_init, NSV::CLASS_VIDEO, NSV::CLASS_OBJECT,
+           NSV::NS_FLASH_MEDIA, 6))
+        (N(camera_class_init, NSV::CLASS_CAMERA, NSV::CLASS_OBJECT,
+           NSV::NS_FLASH_MEDIA, 6))
+        (N(microphone_class_init, NSV::CLASS_MICROPHONE, NSV::CLASS_OBJECT,
+           NSV::NS_FLASH_MEDIA, 6))
+
+        // Net classes
+        (N(xmlsocket_class_init, NSV::CLASS_XMLSOCKET, NSV::CLASS_OBJECT,
+           NSV::NS_FLASH_NET, 5))
+        (N(sharedobject_class_init, NSV::CLASS_SHARED_OBJECT,
+           NSV::CLASS_OBJECT, NSV::NS_FLASH_NET, 5))
+        (N(LocalConnection_as::init, NSV::CLASS_LOCALCONNECTION,
+           NSV::CLASS_OBJECT, NSV::NS_FLASH_NET, 6))
+        (N(NetConnection_as::init, NSV::CLASS_NET_CONNECTION,
+           NSV::CLASS_OBJECT, NSV::NS_FLASH_NET, 6))
+        (N(NetStream_as::init, NSV::CLASS_NET_STREAM, NSV::CLASS_OBJECT,
+           NSV::NS_FLASH_NET, 6))
+        
+        // XML classes
+        (N(XMLDocument_as::init, NSV::CLASS_XML, NSV::CLASS_OBJECT,
+           NSV::NS_FLASH_XML, 5))
+        (N(XMLNode_as::init, NSV::CLASS_XMLNODE, NSV::CLASS_OBJECT,
+           NSV::NS_FLASH_XML, 5))
+
+        // UI classes
+        (N(mouse_class_init, NSV::CLASS_MOUSE, NSV::CLASS_OBJECT,
+           NSV::NS_FLASH_UI, 5))
+        (N(Keyboard_as::init, NSV::CLASS_KEY, NSV::CLASS_OBJECT,
+           NSV::NS_FLASH_UI, 5))
+        (N(contextmenu_class_init, NSV::CLASS_CONTEXTMENU, NSV::CLASS_OBJECT,
+           NSV::NS_FLASH_UI, 7))
+        
+        // Error classes
+        (N(Error_class_init, NSV::CLASS_ERROR, NSV::CLASS_OBJECT,
+           NSV::NS_FLASH_ERRORS, 5))
+        
+        // Accessibility classes
+        (N(accessibility_class_init, NSV::CLASS_ACCESSIBILITY,
+           NSV::CLASS_OBJECT, NSV::NS_FLASH_ACCESSIBILITY, 5));
+
+    return s;
+}
+
 as_value
 global_trace(const fn_call& fn)
 {
@@ -665,7 +885,6 @@
        return as_value(id);
 }
 
-// TODO: move to Global.cpp
 as_value
 global_setTimeout(const fn_call& fn)
 {

=== modified file 'libcore/asobj/Global.h'
--- a/libcore/asobj/Global.h    2009-04-28 07:30:36 +0000
+++ b/libcore/asobj/Global.h    2009-06-30 09:13:55 +0000
@@ -16,37 +16,103 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-// Implementation of the Global ActionScript Object
-
+/// This file provides implementations of two different ActionScript global
+/// objects: one for AVM1, one for AVM2.
+//
+/// The AVM1 global object has more (known) global functions. All AS2 classes
+/// are initialized as object prototypes and functions attached to the 
+/// global object. From SWF8, the 'flash' package is attached as follows:
+///
+///                             _global
+///                                 |
+///                               flash
+///                                 |
+///            ---------------------------------------------------
+///            |         |          |          |         |       |
+///         display     net     external    filters     geom    text
+///
+/// where each item is an object.
+///
+/// The AVM2 global object has functions such as trace(), escape(),
+/// parseFloat(), parseInt() in common with AVM1. Some classes, such as
+/// Array, Boolean, Date, String, and Object, are also directly attached.
+/// Other classes, however, are different. The flash package in AVM2 is a 
+/// namespace, not an object, and all members of the flash package are
+/// attached with a namespace to the global object. As we do this on
+/// demand, the AVM2 global object is much emptier than the AVM1 equivalent
+/// to start with.
 #ifndef GNASH_GLOBAL_H
 #define GNASH_GLOBAL_H
 
 #include "as_object.h" // for inheritance
-#include "extension.h" // for composition
+#include "extension.h"
+#include "ClassHierarchy.h"
 
 // Forward declarations
 namespace gnash {
+       class Machine;
        class VM;
        class fn_call;
-       class ClassHierarchy;
 }
 
 namespace gnash {
 
-class Global: public as_object
+class AVM1Global : public as_object
 {
 public:
 
-       Global(VM& vm, ClassHierarchy *ch);
-       ~Global() {}
+       AVM1Global(VM& vm);
+       ~AVM1Global() {}
+
+    const ClassHierarchy& classHierarchy() const {
+        return _classes;
+    }
+    
+    ClassHierarchy& classHierarchy() {
+        return _classes;
+    }
+
+protected:
+    
+    void markReachableResources() const;
 
 private:
 
     void loadExtensions();
        Extension _et;
 
+    ClassHierarchy _classes;
+
+};
+
+class AVM2Global : public as_object
+{
+public:
+
+       AVM2Global(Machine& m);
+       ~AVM2Global() {}
+
+    const ClassHierarchy& classHierarchy() const {
+        return _classes;
+    }
+    
+    ClassHierarchy& classHierarchy() {
+        return _classes;
+    }
+
+protected:
+
+    void markReachableResources() const {
+        _classes.markReachableResources();
+        markAsObjectReachable();
+    }
+
+private:
+
+    ClassHierarchy _classes;
+
 };
 
 } // namespace gnash
 
-#endif // ndef GNASH_GLOBAL_H
+#endif 

=== modified file 'libcore/namedStrings.cpp'
--- a/libcore/namedStrings.cpp  2009-06-07 21:14:22 +0000
+++ b/libcore/namedStrings.cpp  2009-07-01 11:29:51 +0000
@@ -210,6 +210,7 @@
        string_table::svt( "flash.system", NSV::NS_FLASH_SYSTEM ),
        string_table::svt( "flash.utils", NSV::NS_FLASH_UTILS ),
        string_table::svt( "flash.events", NSV::NS_FLASH_EVENTS ),
+       string_table::svt( "flash.errors", NSV::NS_FLASH_ERRORS ),
        string_table::svt( "flash.accessibility", NSV::NS_FLASH_ACCESSIBILITY ),
        string_table::svt( "flash.media", NSV::NS_FLASH_MEDIA ),
        string_table::svt( "flash.xml", NSV::NS_FLASH_XML ),

=== modified file 'libcore/namedStrings.h'
--- a/libcore/namedStrings.h    2009-05-27 13:02:02 +0000
+++ b/libcore/namedStrings.h    2009-07-01 11:29:51 +0000
@@ -49,194 +49,195 @@
 namespace NSV {
 
 enum NamedStrings {
-               CLASS_ACCESSIBILITY = 1,
-               CLASS_ARRAY,
-               CLASS_AS_BROADCASTER,
-               CLASS_BOOLEAN,
-               CLASS_BUTTON,
-               CLASS_CAMERA,
-               CLASS_COLOR,
-               CLASS_CONTEXTMENU,
-               CLASS_CUSTOM_ACTIONS,
-               CLASS_DATE,
-               CLASS_DISPLAYOBJECT,
-               CLASS_DISPLAYOBJECTCONTAINER,
-               CLASS_ERROR,
-               CLASS_EVENTDISPATCHER,
-               CLASS_FUNCTION,
-               CLASS_INT,
-               CLASS_INTERACTIVEOBJECT,
-               CLASS_KEY,
-               CLASS_LOAD_VARS,
-               CLASS_LOCALCONNECTION,
-               CLASS_MATH,
-               CLASS_MICROPHONE,
-               CLASS_MOUSE,
-               CLASS_MOVIE_CLIP,
-               CLASS_MOVIE_CLIP_LOADER,
-               CLASS_NAMESPACE,
-               CLASS_NET_CONNECTION,
-               CLASS_NET_STREAM,
-               CLASS_NUMBER,
-               CLASS_OBJECT,
-               CLASS_SELECTION,
-               CLASS_SHARED_OBJECT,
-               CLASS_SOUND,
-               CLASS_SPRITE,
-               CLASS_STAGE,
-               PROP_iSTAGE = CLASS_STAGE,
-               CLASS_STRING,
-               CLASS_SYSTEM,
-               CLASS_TEXT_FIELD,
-               CLASS_TEXT_FORMAT,
-               CLASS_TEXT_SNAPSHOT,
-               CLASS_TEXTFIELDAUTOSIZE,
-               CLASS_VIDEO,
-               CLASS_XML,
-               CLASS_XMLNODE,
-               CLASS_XMLSOCKET,
-               NS_ADOBE_UTILS,
-               NS_FLASH_ACCESSIBILITY,
-               NS_FLASH_DISPLAY,
-               NS_FLASH_EVENTS,
-               NS_FLASH_GEOM,
-               NS_FLASH_MEDIA,
-               NS_FLASH_NET,
-               NS_FLASH_SYSTEM,
-               NS_FLASH_TEXT,
-               NS_FLASH_UI,
-               NS_FLASH_UTILS,
-               NS_FLASH_XML,
-                PROP_A,
-               PROP_ADD_LISTENER,
-               PROP_ALIGN,
-               PROP_B,
-               PROP_BLOCK_INDENT,
-               PROP_BOLD,
-               PROP_BROADCAST_MESSAGE,
-               PROP_BULLET,
-               PROP_C,
-               PROP_CALLEE,
-               PROP_CALLER,
-               //PROP_COLOR, // clashes with CLASS_COLOR in case-insensitive 
mode
-               PROP_CONCAT,
-               PROP_CONSTRUCTOR,
-               PROP_CONTENT_TYPE,
-               PROP_D,
-                PROP_DATA,
-                PROP_DECODE,
-               PROP_E,
-               PROP_ENABLED,
-                PROP_ESCAPE,
-                PROP_FOCUS_ENABLED,
-                PROP_G,
-               PROP_H,
-               PROP_HEIGHT,
-               PROP_HTML_TEXT,
-               PROP_INDENT,
-               PROP_ITALIC,
-               PROP_LEADING,
-               PROP_LEFT_MARGIN,
-               PROP_LENGTH,
-               PROP_LOADED,
-               PROP_MATRIX_TYPE,
-                PROP_METH,
-               PROP_ON_CLOSE,
-               PROP_ON_CONNECT,
-               PROP_ON_CONSTRUCT,
-               PROP_ON_DATA,
-               PROP_ON_DRAG_OUT,
-               PROP_ON_DRAG_OVER,
-               PROP_ON_ENTER_FRAME,
-               PROP_ON_FULLSCREEN,
-               PROP_ON_INITIALIZE,
-               PROP_ON_KEY_DOWN,
-               PROP_ON_KEY_PRESS,
-               PROP_ON_KEY_UP,
-               PROP_ON_KILL_FOCUS,
-               PROP_ON_LOAD,
-               PROP_ON_LOAD_ERROR,
-               PROP_ON_LOAD_INIT,
-               PROP_ON_LOAD_PROGRESS,
-               PROP_ON_LOAD_START,
-               PROP_ON_META_DATA,
-               PROP_ON_MOUSE_DOWN,
-               PROP_ON_MOUSE_MOVE,
-               PROP_ON_MOUSE_UP,
-               PROP_ON_PRESS,
-               PROP_ON_RELEASE,
-               PROP_ON_RELEASE_OUTSIDE,
-               PROP_ON_RESIZE,
-               PROP_ON_RESULT,
-               PROP_ON_ROLL_OUT,
-               PROP_ON_ROLL_OVER,
-               PROP_ON_SELECT,
-               PROP_ON_SET_FOCUS,
-                PROP_ON_SOUND_COMPLETE,
-                PROP_ON_STATUS,
-               PROP_ON_TIMER,
-               PROP_ON_UNLOAD,
-               PROP_ON_XML,
-               PROP_PARSE_XML,
-               PROP_PROTOTYPE,
-               PROP_PUSH,
-               PROP_R,
-               PROP_REMOVE_LISTENER,
-               PROP_RIGHT_MARGIN,
-               PROP_SCALE_MODE,
-               PROP_SIZE,
-               PROP_SPLICE,
-               PROP_STATUS,
-               PROP_SUPER,
-               PROP_TEXT,
-               PROP_TEXT_COLOR,
-               PROP_TEXT_HEIGHT,
-               PROP_TEXT_WIDTH,
-               PROP_TO_LOWER_CASE,
-               PROP_TO_STRING,
-               PROP_TX,
-               PROP_TY,
-               PROP_uALPHA,
-               PROP_uCURRENTFRAME,
-               PROP_uCUSTOM_HEADERS,
-               PROP_uDROPTARGET,
-               PROP_uFOCUSRECT,
-               PROP_uFRAMESLOADED,
-               PROP_uGLOBAL,
-               PROP_uHEIGHT,
-               PROP_uHIGHQUALITY,
-               PROP_uQUALITY,
-               PROP_uLISTENERS,
-               PROP_uNAME,
-               PROP_UNDERLINE,
-               PROP_uPARENT,
-               PROP_uROOT,
-               PROP_uROTATION,
-               PROP_USEHANDCURSOR,
-               PROP_uSOUNDBUFTIME,
-               PROP_uTARGET,
-               PROP_uTOTALFRAMES,
-               PROP_uuCONSTRUCTORuu,
-               PROP_uuPROTOuu,
-                PROP_uuRESOLVE,
-               PROP_uURL,
-               PROP_uVISIBLE,
-               PROP_uWIDTH,
-               PROP_uX,
-               PROP_uXMOUSE,
-               PROP_uXSCALE,
-               PROP_uY,
-               PROP_uYMOUSE,
-               PROP_uYSCALE,
-               PROP_VALUE_OF,
-               PROP_W,
-               PROP_WIDTH,
-               PROP_X,
-               PROP_Y,
-               INTERNAL_INTERFACES,
-               INTERNAL_STACK_PARENT, // Any public property is unsafe
-               INTERNAL_TYPE // The type name
-       };
+        CLASS_ACCESSIBILITY = 1,
+        CLASS_ARRAY,
+        CLASS_AS_BROADCASTER,
+        CLASS_BOOLEAN,
+        CLASS_BUTTON,
+        CLASS_CAMERA,
+        CLASS_COLOR,
+        CLASS_CONTEXTMENU,
+        CLASS_CUSTOM_ACTIONS,
+        CLASS_DATE,
+        CLASS_DISPLAYOBJECT,
+        CLASS_DISPLAYOBJECTCONTAINER,
+        CLASS_ERROR,
+        CLASS_EVENTDISPATCHER,
+        CLASS_FUNCTION,
+        CLASS_INT,
+        CLASS_INTERACTIVEOBJECT,
+        CLASS_KEY,
+        CLASS_LOAD_VARS,
+        CLASS_LOCALCONNECTION,
+        CLASS_MATH,
+        CLASS_MICROPHONE,
+        CLASS_MOUSE,
+        CLASS_MOVIE_CLIP,
+        CLASS_MOVIE_CLIP_LOADER,
+        CLASS_NAMESPACE,
+        CLASS_NET_CONNECTION,
+        CLASS_NET_STREAM,
+        CLASS_NUMBER,
+        CLASS_OBJECT,
+        CLASS_SELECTION,
+        CLASS_SHARED_OBJECT,
+        CLASS_SOUND,
+        CLASS_SPRITE,
+        CLASS_STAGE,
+        PROP_iSTAGE = CLASS_STAGE,
+        CLASS_STRING,
+        CLASS_SYSTEM,
+        CLASS_TEXT_FIELD,
+        CLASS_TEXT_FORMAT,
+        CLASS_TEXT_SNAPSHOT,
+        CLASS_TEXTFIELDAUTOSIZE,
+        CLASS_VIDEO,
+        CLASS_XML,
+        CLASS_XMLNODE,
+        CLASS_XMLSOCKET,
+        NS_ADOBE_UTILS,
+        NS_FLASH_ACCESSIBILITY,
+        NS_FLASH_DISPLAY,
+        NS_FLASH_EVENTS,
+        NS_FLASH_ERRORS,
+        NS_FLASH_GEOM,
+        NS_FLASH_MEDIA,
+        NS_FLASH_NET,
+        NS_FLASH_SYSTEM,
+        NS_FLASH_TEXT,
+        NS_FLASH_UI,
+        NS_FLASH_UTILS,
+        NS_FLASH_XML,
+        PROP_A,
+        PROP_ADD_LISTENER,
+        PROP_ALIGN,
+        PROP_B,
+        PROP_BLOCK_INDENT,
+        PROP_BOLD,
+        PROP_BROADCAST_MESSAGE,
+        PROP_BULLET,
+        PROP_C,
+        PROP_CALLEE,
+        PROP_CALLER,
+        //PROP_COLOR, // clashes with CLASS_COLOR in case-insensitive mode
+        PROP_CONCAT,
+        PROP_CONSTRUCTOR,
+        PROP_CONTENT_TYPE,
+        PROP_D,
+        PROP_DATA,
+        PROP_DECODE,
+        PROP_E,
+        PROP_ENABLED,
+        PROP_ESCAPE,
+        PROP_FOCUS_ENABLED,
+        PROP_G,
+        PROP_H,
+        PROP_HEIGHT,
+        PROP_HTML_TEXT,
+        PROP_INDENT,
+        PROP_ITALIC,
+        PROP_LEADING,
+        PROP_LEFT_MARGIN,
+        PROP_LENGTH,
+        PROP_LOADED,
+        PROP_MATRIX_TYPE,
+        PROP_METH,
+        PROP_ON_CLOSE,
+        PROP_ON_CONNECT,
+        PROP_ON_CONSTRUCT,
+        PROP_ON_DATA,
+        PROP_ON_DRAG_OUT,
+        PROP_ON_DRAG_OVER,
+        PROP_ON_ENTER_FRAME,
+        PROP_ON_FULLSCREEN,
+        PROP_ON_INITIALIZE,
+        PROP_ON_KEY_DOWN,
+        PROP_ON_KEY_PRESS,
+        PROP_ON_KEY_UP,
+        PROP_ON_KILL_FOCUS,
+        PROP_ON_LOAD,
+        PROP_ON_LOAD_ERROR,
+        PROP_ON_LOAD_INIT,
+        PROP_ON_LOAD_PROGRESS,
+        PROP_ON_LOAD_START,
+        PROP_ON_META_DATA,
+        PROP_ON_MOUSE_DOWN,
+        PROP_ON_MOUSE_MOVE,
+        PROP_ON_MOUSE_UP,
+        PROP_ON_PRESS,
+        PROP_ON_RELEASE,
+        PROP_ON_RELEASE_OUTSIDE,
+        PROP_ON_RESIZE,
+        PROP_ON_RESULT,
+        PROP_ON_ROLL_OUT,
+        PROP_ON_ROLL_OVER,
+        PROP_ON_SELECT,
+        PROP_ON_SET_FOCUS,
+        PROP_ON_SOUND_COMPLETE,
+        PROP_ON_STATUS,
+        PROP_ON_TIMER,
+        PROP_ON_UNLOAD,
+        PROP_ON_XML,
+        PROP_PARSE_XML,
+        PROP_PROTOTYPE,
+        PROP_PUSH,
+        PROP_R,
+        PROP_REMOVE_LISTENER,
+        PROP_RIGHT_MARGIN,
+        PROP_SCALE_MODE,
+        PROP_SIZE,
+        PROP_SPLICE,
+        PROP_STATUS,
+        PROP_SUPER,
+        PROP_TEXT,
+        PROP_TEXT_COLOR,
+        PROP_TEXT_HEIGHT,
+        PROP_TEXT_WIDTH,
+        PROP_TO_LOWER_CASE,
+        PROP_TO_STRING,
+        PROP_TX,
+        PROP_TY,
+        PROP_uALPHA,
+        PROP_uCURRENTFRAME,
+        PROP_uCUSTOM_HEADERS,
+        PROP_uDROPTARGET,
+        PROP_uFOCUSRECT,
+        PROP_uFRAMESLOADED,
+        PROP_uGLOBAL,
+        PROP_uHEIGHT,
+        PROP_uHIGHQUALITY,
+        PROP_uQUALITY,
+        PROP_uLISTENERS,
+        PROP_uNAME,
+        PROP_UNDERLINE,
+        PROP_uPARENT,
+        PROP_uROOT,
+        PROP_uROTATION,
+        PROP_USEHANDCURSOR,
+        PROP_uSOUNDBUFTIME,
+        PROP_uTARGET,
+        PROP_uTOTALFRAMES,
+        PROP_uuCONSTRUCTORuu,
+        PROP_uuPROTOuu,
+        PROP_uuRESOLVE,
+        PROP_uURL,
+        PROP_uVISIBLE,
+        PROP_uWIDTH,
+        PROP_uX,
+        PROP_uXMOUSE,
+        PROP_uXSCALE,
+        PROP_uY,
+        PROP_uYMOUSE,
+        PROP_uYSCALE,
+        PROP_VALUE_OF,
+        PROP_W,
+        PROP_WIDTH,
+        PROP_X,
+        PROP_Y,
+        INTERNAL_INTERFACES,
+        INTERNAL_STACK_PARENT, // Any public property is unsafe
+        INTERNAL_TYPE // The type name
+    };
 
 /// Load the prenamed strings.
 /// version controls case

=== modified file 'libcore/parser/Makefile.am'
--- a/libcore/parser/Makefile.am        2009-06-05 08:28:27 +0000
+++ b/libcore/parser/Makefile.am        2009-06-30 09:13:40 +0000
@@ -38,6 +38,7 @@
        -I$(top_srcdir)/libmedia \
        -I$(top_srcdir)/libsound \
        -I$(top_srcdir)/libamf \
+       -I$(top_srcdir)/libltdl \
        $(GLIB_CFLAGS) \
        $(PTHREAD_CFLAGS) \
        $(BOOST_CFLAGS) \

=== modified file 'libcore/parser/abc_block.cpp'
--- a/libcore/parser/abc_block.cpp      2009-06-29 13:43:36 +0000
+++ b/libcore/parser/abc_block.cpp      2009-06-30 09:12:07 +0000
@@ -29,6 +29,7 @@
 #include "CodeStream.h"
 #include "action_buffer.h"
 #include "Machine.h"
+#include "Global.h"
 
 namespace gnash {
 
@@ -324,16 +325,18 @@
     :
     _stringTable(&VM::get().getStringTable())
 {
-       mCH = VM::get().getClassHierarchy();
+#if 1
+       mCH = 
&(dynamic_cast<AVM2Global*>(VM::get().getMachine()->global())->classHierarchy());
        // TODO: Make this the real 'Object' prototype.
-       mCH->getGlobalNs()->stubPrototype(NSV::CLASS_OBJECT);
+       mCH->getGlobalNs()->stubPrototype(*mCH, NSV::CLASS_OBJECT);
        mTheObject = mCH->getGlobalNs()->getClass(NSV::CLASS_OBJECT);
+#endif
 }
 
 void
 abc_block::prepare(Machine* mach)
 {
-    
+
     std::for_each(_classes.begin(), _classes.end(),
             std::mem_fun(&asClass::initPrototype));
 

=== modified file 'libcore/swf/DoABCTag.h'
--- a/libcore/swf/DoABCTag.h    2009-06-29 12:24:55 +0000
+++ b/libcore/swf/DoABCTag.h    2009-06-30 06:03:37 +0000
@@ -48,12 +48,11 @@
         
         log_debug("getting machine.");
                Machine *mach = vm.getMachine();
-               as_object* global = vm.getGlobal();
                
         _abc->prepare(mach);
 
                log_debug("Begin execute abc_block.");
-               mach->initMachine(_abc, global);
+               mach->initMachine(_abc);
                log_debug("Executing machine...");
                mach->execute();
        }

=== modified file 'libcore/vm/ActionExec.cpp'
--- a/libcore/vm/ActionExec.cpp 2009-06-15 11:32:49 +0000
+++ b/libcore/vm/ActionExec.cpp 2009-07-01 10:40:08 +0000
@@ -716,7 +716,7 @@
 as_value
 ActionExec::getVariable(const std::string& name)
 {
-    return env.get_variable(PROPNAME(name), getScopeStack());
+    return env.get_variable(name, getScopeStack());
 }
 
 as_value

=== modified file 'libcore/vm/Machine.cpp'
--- a/libcore/vm/Machine.cpp    2009-06-26 12:47:09 +0000
+++ b/libcore/vm/Machine.cpp    2009-07-01 11:46:51 +0000
@@ -28,6 +28,7 @@
 #include "action.h"
 #include "Object.h"
 #include "VM.h"
+#include "Global.h"
 
 namespace gnash {
 /// The type of exceptions thrown by ActionScript.
@@ -322,15 +323,13 @@
         mGlobalScope(0),
         mDefaultThis(0),
         mThis(0),
-        mGlobalObject(0),
+        _global(new AVM2Global(*this)),
         mGlobalReturn(),
         mIgnoreReturn(),
-        mIsAS3(false),
         mExitWithReturn(false),
         mPoolObject(0),
         mCurrentFunction(0),
-        _vm(vm),
-        mCH(_vm.getClassHierarchy())
+        _vm(vm)
 {
        // Local registers should be initialized at the beginning of each
     // function call, but we don't currently parse the number of local
@@ -462,7 +461,9 @@
                 {
                     boost::uint32_t soffset = mStream->read_V32();
                     const std::string& uri = pool_string(soffset, mPoolObject);
-                    mDefaultXMLNamespace = mCH->anonNamespace(mST.find(uri));
+
+                    ClassHierarchy& ch = _global->classHierarchy();
+                    mDefaultXMLNamespace = ch.anonNamespace(mST.find(uri));
                     break;
                 }
 
@@ -477,7 +478,9 @@
                 {
                     ENSURE_STRING(mStack.top(0));
                     const std::string& uri = mStack.top(0).to_string();
-                    mDefaultXMLNamespace = mCH->anonNamespace(mST.find(uri));
+                    
+                    ClassHierarchy& ch = _global->classHierarchy();
+                    mDefaultXMLNamespace = ch.anonNamespace(mST.find(uri));
                     mStack.drop(1);
                     break;
                 }
@@ -2958,7 +2961,7 @@
        if (!find_for_primitive) return 0;
 
        if (v.is_number()) {
-               return NULL; // TODO: mCH->getClass(NSV::CLASS_NUMBER);
+               return NULL; // TODO: _classes->getClass(NSV::CLASS_NUMBER);
        }
 
        // And so on...
@@ -3090,7 +3093,7 @@
 }
 
 void
-Machine::initMachine(abc_block* pool_block, as_object* global)
+Machine::initMachine(abc_block* pool_block)
 {
        mPoolObject = pool_block;
        log_debug("Getting entry script.");
@@ -3101,8 +3104,7 @@
        log_debug("Loading code stream.");
        mStream = constructor->getBody();
        mCurrentFunction = constructor->getPrototype();
-       setRegister(0, global);
-       mGlobalObject = global;
+       setRegister(0, _global);
 }
 
 //This is called by abc_functions to execute their code stream.

=== modified file 'libcore/vm/Machine.h'
--- a/libcore/vm/Machine.h      2009-06-26 08:40:15 +0000
+++ b/libcore/vm/Machine.h      2009-07-01 12:49:14 +0000
@@ -27,15 +27,20 @@
 #include "SWF.h"
 #include "as_environment.h"
 #include "VM.h"
-
-namespace gnash {
-
-class DisplayObject;
-class as_object;
-class abc_block;
-class asName;
-class Property;
-class CodeStream;
+#include "Global.h"
+
+namespace gnash {
+    class DisplayObject;
+    class as_object;
+    class abc_block;
+    class asName;
+    class Property;
+    class CodeStream;
+    class AVM2Global;
+}
+
+
+namespace gnash {
 
 /// This machine is intended to work without relying on the C++ call stack,
 /// by resetting its Stream and Stack members (actually, by limiting the stack)
@@ -49,10 +54,12 @@
 /// allows both ActionScript code and C++ code to use the exception handling
 /// with a minimum of hassle, and it helps with correctness.
 ///
-/// The intent is that the machine will run both AS2 and AS3 code. Despite the
-/// difference in presentation between the two, they should be compatible (or
-/// able to become so), so that extensions written for AS2 will work in AS3
-/// (and vice versa).
+/// It was intended that this Machine should run both AS2 and AS3 code.
+/// However, as the two codestreams must be strictly separated - different
+/// global objects, no sharing of resources, and no ability to communicate
+/// directly, there is no sense in using a single instance of this machine
+/// for both AS2 and AS3 interpretation. It's questionable whether there is
+/// any advantage in using this Machine for AS2; it is not a near-term goal.
 class Machine
 {
 public:
@@ -201,10 +208,11 @@
                as_value& storage, unsigned char stack_in, short stack_out);
 
        void immediateProcedure(const as_function *to_call, as_object *pthis,
-               unsigned char stack_in, short stack_out)
-       { immediateFunction(to_call, pthis, mIgnoreReturn, stack_in, 
stack_out); }
+               unsigned char stack_in, short stack_out) {
+        immediateFunction(to_call, pthis, mIgnoreReturn, stack_in, stack_out);
+    }
 
-       void initMachine(abc_block* pool_block,as_object* global);
+       void initMachine(abc_block* pool_block);
 
        as_value executeFunction(asMethod* function, const fn_call& fn);
 
@@ -212,14 +220,22 @@
 
        Machine(VM& vm);
 
-    /// Return the Global object.
+    /// Return the Global object for this Machine.
     //
-    /// TODO: is this really necessary? Which object should we
-    /// return anyway, i.e. why not mGlobalObject? (that is null
-    /// at inopportune moments right now, which is why VM::getGlobal()
-    /// is returned.
+    /// This should be different from the AVM1 global object because the VMs
+    /// do not share any ActionScript resources. It should be the same
+    /// for a complete run of the Machine so that modifications carried out
+    /// by scripts are preserved for subsequent scripts.
     as_object* global() {
-        return _vm.getGlobal();
+        return _global;
+    }
+
+    /// Return the ClassHierarchy used by our global object.
+    //
+    /// This is used in parsing, though maybe would be better accessed
+    /// through the Global object.
+    ClassHierarchy* classHierarchy() {
+        return &_global->classHierarchy();
     }
 
 private:
@@ -353,20 +369,20 @@
        as_object* mDefaultThis;
        as_object* mThis;
 
-       as_object* mGlobalObject;
+    /// The global object for this machine.
+    //
+    /// We need to know the type to access the ClassHierarchy.
+       AVM2Global* _global;
 
        as_value mGlobalReturn;
        as_value mIgnoreReturn; // Throw away returns go here.
 
-       bool mIsAS3; // Is the stream an AS3 stream.
        bool mExitWithReturn;
        abc_block* mPoolObject; // Where all of the pools are stored.
 
        abc_function* mCurrentFunction;
 
        VM& _vm;
-       
-    ClassHierarchy *mCH;
 };
 
 } // namespace gnash

=== modified file 'libcore/vm/VM.cpp'
--- a/libcore/vm/VM.cpp 2009-06-11 00:00:53 +0000
+++ b/libcore/vm/VM.cpp 2009-06-30 09:12:37 +0000
@@ -31,7 +31,6 @@
 #include "Global.h"
 #include "rc.h" //for overriding default version string with rcfile
 #include "namedStrings.h"
-#include "ClassHierarchy.h"
 #include "VirtualClock.h" // for getTime()
 
 #ifdef ENABLE_AVM2
@@ -66,8 +65,7 @@
        assert(_singleton.get());
        NSV::loadStrings(_singleton->_stringTable, _singleton->getSWFVersion());
 
-       _singleton->_classHierarchy.reset(new ClassHierarchy);
-       _singleton->setGlobal(new Global(*_singleton, 
_singleton->_classHierarchy.get()));
+       _singleton->setGlobal(new AVM1Global(*_singleton));
 
 #ifdef ENABLE_AVM2
        _singleton->_machine = new Machine(*_singleton);
@@ -217,6 +215,7 @@
 as_object*
 VM::getGlobal() const
 {
+    if (getAVMVersion() == VM::AVM2) return _machine->global();
        return _global.get();
 }
 
@@ -249,8 +248,6 @@
                (*i)->setReachable();
        }
 
-       _classHierarchy->markReachableResources();
-
     if (_shLib.get()) _shLib->markReachableResources();
 #endif
 

=== modified file 'libcore/vm/VM.h'
--- a/libcore/vm/VM.h   2009-06-04 06:48:54 +0000
+++ b/libcore/vm/VM.h   2009-06-30 09:12:37 +0000
@@ -50,8 +50,6 @@
 
 namespace gnash {
 
-class ClassHierarchy;
-
 /// A GC root used to mark all reachable collectable pointers
 class VmGcRoot : public GcRoot 
 {
@@ -245,9 +243,6 @@
        /// Get a pointer to this VM's _global Object
        as_object* getGlobal() const;
 
-       /// Get a pointer to this VM's global ClassHierarchy object.
-       ClassHierarchy* getClassHierarchy() const { return 
_classHierarchy.get(); }
-       
        /// Mark all reachable resources (for GC)
        //
        /// - root movie / stage (_rootMovie)
@@ -325,9 +320,6 @@
        /// Mutable since it should not affect how the VM runs.
        mutable string_table _stringTable;
 
-       /// Not mutable since changing this changes behavior of the VM.
-       std::auto_ptr<ClassHierarchy> _classHierarchy;
-
 #ifdef ENABLE_AVM2
        /// A running execution thread.
        Machine *_machine;


reply via email to

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