gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] [SCM] Gnash branch, master, updated. 1afc8d995dbe9ec94477


From: Benjamin Wolsey
Subject: [Gnash-commit] [SCM] Gnash branch, master, updated. 1afc8d995dbe9ec9447744fa4745e2f781e84576
Date: Tue, 16 Nov 2010 16:06:36 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Gnash".

The branch, master has been updated
       via  1afc8d995dbe9ec9447744fa4745e2f781e84576 (commit)
       via  f5630958501fb73b5ee0cf9b47942e68f795c34c (commit)
       via  aad0fd6b6085edde132445dc3e6363182e7f6137 (commit)
       via  fe8ebcf738b982a2473330dec637f5e679cc50d3 (commit)
      from  391debf87d40cef32d299634feb629838adf79ef (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit//commit/?id=1afc8d995dbe9ec9447744fa4745e2f781e84576


commit 1afc8d995dbe9ec9447744fa4745e2f781e84576
Author: Benjamin Wolsey <address@hidden>
Date:   Tue Nov 16 16:41:05 2010 +0100

    Update more comments, clean up.

diff --git a/libcore/as_environment.cpp b/libcore/as_environment.cpp
index fb8e612..8022a5f 100644
--- a/libcore/as_environment.cpp
+++ b/libcore/as_environment.cpp
@@ -18,8 +18,14 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-#include "smart_ptr.h" // GNASH_USE_GC
 #include "as_environment.h"
+
+#include <string>
+#include <utility>
+#include <boost/algorithm/string/case_conv.hpp>
+#include <boost/format.hpp>
+
+#include "smart_ptr.h"
 #include "MovieClip.h"
 #include "movie_root.h"
 #include "as_value.h"
@@ -31,11 +37,6 @@
 #include "CallStack.h"
 #include "Global_as.h"
 
-#include <string>
-#include <utility> // for std::pair
-#include <boost/algorithm/string/case_conv.hpp>
-#include <boost/format.hpp>
-
 // Define this to have find_target() calls trigger debugging output
 //#define DEBUG_TARGET_FINDING 1
 
@@ -461,15 +462,12 @@ as_environment::set_target(DisplayObject* target)
     m_target = target;
 }
 
-#ifdef GNASH_USE_GC
-
 void
 as_environment::markReachableResources() const
 {
     if (m_target) m_target->setReachable();
     if (_original_target) _original_target->setReachable();
 }
-#endif // GNASH_USE_GC
 
 bool
 parsePath(const std::string& var_path_in, std::string& path, std::string& var)
diff --git a/libcore/as_environment.h b/libcore/as_environment.h
index c8d049a..65e271e 100644
--- a/libcore/as_environment.h
+++ b/libcore/as_environment.h
@@ -19,22 +19,24 @@
 #ifndef GNASH_AS_ENVIRONMENT_H
 #define GNASH_AS_ENVIRONMENT_H
 
-#include "smart_ptr.h" // GNASH_USE_GC
-#include "as_value.h" // for composition (vector + frame_slot)
-#include "SafeStack.h"
-
-#include <string> // for frame_slot name
+#include <string> 
 #include <vector>
+#include <algorithm>
 
-namespace gnash {
+#include "smart_ptr.h"
+#include "as_value.h" 
+#include "SafeStack.h"
 
 // Forward declarations
-class DisplayObject;
-class VM;
-class Global_as;
-class movie_root;
-class string_table;
-class UserFunction;
+namespace gnash {
+    class DisplayObject;
+    class VM;
+    class Global_as;
+    class movie_root;
+    class string_table;
+}
+
+namespace gnash {
 
 /// ActionScript execution environment.
 class as_environment
@@ -53,11 +55,9 @@ public:
 
     /// Set default target for timeline opcodes
     //
-    /// @param target
-    /// A DisplayObject to apply timeline opcodes on.
-    /// Zero is a valid target, disabling timeline
-    /// opcodes (would get ignored).
-    ///
+    /// @param target   A DisplayObject to apply timeline opcodes on.
+    ///                 Zero is a valid target, disabling timeline
+    ///                 opcodes (would get ignored).
     void set_target(DisplayObject* target);
 
     void set_original_target(DisplayObject* target) {
@@ -75,13 +75,12 @@ public:
     }
 
     /// Pops an as_value off the stack top and return it.
-    as_value pop() {
-        try {
-            return _stack.pop();
-        }
-        catch (const StackException&) {
-            return as_value();
-        }
+    as_value pop()
+    try {
+        return _stack.pop();
+    }
+    catch (const StackException&) {
+        return as_value();
     }
 
     /// Get stack value at the given distance from top.
@@ -90,13 +89,12 @@ public:
     ///
     /// Throw StackException if index is out of range
     ///
-    as_value& top(size_t dist) const
-    {
-        try {
-            return _stack.top(dist);
-        } catch (StackException&) {
-            return undefVal;
-        }
+    as_value& top(size_t dist) const 
+    try {
+        return _stack.top(dist);
+    }
+    catch (const StackException&) {
+        return undefVal;
     }
 
     /// Drop 'count' values off the top of the stack.
@@ -140,9 +138,7 @@ public:
 
     /// Mark all reachable resources.
     //
-    /// Reachable resources from an as_environment
-    /// would be global registers, stack (expected to be empty
-    /// actually), stack frames and targets (original and current).
+    /// Only the targets are reachable.
     void markReachableResources() const;
 
     /// Find the sprite/movie referenced by the given path.
@@ -196,7 +192,6 @@ private:
 ///
 /// TODO: return an integer: 0 not a path, 1 a slash-based path, 2 a
 /// dot-based path
-///
 bool parsePath(const std::string& var_path, std::string& path,
         std::string& var);
 

http://git.savannah.gnu.org/cgit//commit/?id=f5630958501fb73b5ee0cf9b47942e68f795c34c


commit f5630958501fb73b5ee0cf9b47942e68f795c34c
Author: Benjamin Wolsey <address@hidden>
Date:   Tue Nov 16 16:30:18 2010 +0100

    Update comments.

diff --git a/libcore/as_environment.cpp b/libcore/as_environment.cpp
index 3b15a78..fb8e612 100644
--- a/libcore/as_environment.cpp
+++ b/libcore/as_environment.cpp
@@ -193,33 +193,27 @@ as_environment::delVariableRaw(const std::string& varname,
     assert(varname.find_first_of(":/.") == std::string::npos);
 
     string_table::key varkey = _vm.getStringTable().find(varname);
-    as_value val;
 
     // Check the with-stack.
-    for (size_t i = scopeStack.size(); i > 0; --i)
-    {
-        as_object* obj = scopeStack[i-1];
-        if (obj)
-        {
-            std::pair<bool,bool> ret = obj->delProperty(varkey);
-            if (ret.first)
-            {
+    for (size_t i = scopeStack.size(); i > 0; --i) {
+        as_object* obj = scopeStack[i - 1];
+
+        if (obj) {
+            std::pair<bool, bool> ret = obj->delProperty(varkey);
+            if (ret.first) {
                 return ret.second;
             }
         }
     }
 
     // Check locals for deletion.
-    if (_vm.calling() && deleteLocal(_vm.currentCall().locals(), varname))
-    {
+    if (_vm.calling() && deleteLocal(_vm.currentCall().locals(), varname)) {
         return true;
     }
 
-
     // Try target
-    std::pair<bool,bool> ret = getObject(m_target)->delProperty(varkey);
-    if ( ret.first )
-    {
+    std::pair<bool, bool> ret = getObject(m_target)->delProperty(varkey);
+    if (ret.first) {
         return ret.second;
     }
 
diff --git a/libcore/as_environment.h b/libcore/as_environment.h
index aafcceb..c8d049a 100644
--- a/libcore/as_environment.h
+++ b/libcore/as_environment.h
@@ -108,44 +108,23 @@ public:
 
     size_t stack_size() const { return _stack.size(); }
 
-    /// \brief
-    /// Delete a variable, w/out support for the path, using
-    /// a ScopeStack.
+    /// Delete a variable, without support for the path, using a ScopeStack.
     //
-    /// @param varname 
-    /// Variable name. Must not contain path elements.
-    /// TODO: should be case-insensitive up to SWF6.
-    /// NOTE: no case conversion is performed currently,
-    ///       so make sure you do it yourself. Note that
-    ///       ActionExec performs the conversion
-    ///       before calling this method.
-    ///
-    /// @param scopeStack
-    /// The Scope stack to use for lookups.
+    /// @param varname      Variable name. Must not contain path elements.
+    /// @param scopeStack   The Scope stack to use for lookups.
     bool delVariableRaw(const std::string& varname,
             const ScopeStack& scopeStack);
 
-    /// Return the (possibly UNDEFINED) value of the named var.
+    /// Return the (possibly undefined) value of the named var.
     //
-    /// @param varname 
-    /// Variable name. Can contain path elements.
-    /// TODO: should be case-insensitive up to SWF6.
-    /// NOTE: no case conversion is performed currently,
-    ///       so make sure you do it yourself. Note that
-    ///       ActionExec performs the conversion
-    ///       before calling this method.
-    ///
-    /// @param scopeStack
-    /// The Scope stack to use for lookups.
-    ///
-    /// @param retTarget
-    /// If not NULL, the pointer will be set to the actual object containing 
the
-    /// found variable (if found).
-    ///
+    /// @param varname      Variable name. Can contain path elements.
+    /// @param scopeStack   The Scope stack to use for lookups.
+    /// @param retTarget    If not null, the pointer will be set to
+    ///                     the actual object containing the
+    ///                     found variable (if found).
     as_value get_variable(const std::string& varname,
         const ScopeStack& scopeStack, as_object** retTarget=NULL) const;
 
-    /// \brief
     /// Given a path to variable, set its value.
     //
     /// If no variable with that name is found, a new one is created.
@@ -153,16 +132,9 @@ public:
     /// For path-less variables, this would act as a proxy for
     /// set_variable_raw.
     ///
-    /// @param path
-    /// Variable path. 
-    /// TODO: should be case-insensitive up to SWF6.
-    ///
-    /// @param val
-    /// The value to assign to the variable.
-    ///
-    /// @param scopeStack
-    /// The Scope stack to use for lookups.
-    ///
+    /// @param path         Variable path. 
+    /// @param val          The value to assign to the variable.
+    /// @param scopeStack   The Scope stack to use for lookups.
     void set_variable(const std::string& path, const as_value& val,
         const ScopeStack& scopeStack);
 
@@ -171,48 +143,26 @@ public:
     /// Reachable resources from an as_environment
     /// would be global registers, stack (expected to be empty
     /// actually), stack frames and targets (original and current).
-    ///
     void markReachableResources() const;
 
     /// Find the sprite/movie referenced by the given path.
     //
     /// Supports both /slash/syntax and dot.syntax
-    /// Case insensitive for SWF up to 6, sensitive from 7 up
-    ///
     DisplayObject* find_target(const std::string& path) const;
 
     /// Find the object referenced by the given path.
     //
     /// Supports both /slash/syntax and dot.syntax
-    /// Case insensitive for SWF up to 6, sensitive from 7 up
-    ///
     as_object* find_object(const std::string& path,
             const ScopeStack* scopeStack = 0) const;
     
     /// Return the SWF version we're running for.
     //
-    /// NOTE: this is the version encoded in the first loaded
-    ///       movie, and cannot be changed during play even if
-    ///       replacing the root movie with an externally loaded one.
-    ///
+    /// This is merely a proxy for VM::getSWFVersion.
     int get_version() const;
 
 private:
 
-    /// Given a variable name, set its value (no support for path)
-    //
-    /// If no variable with that name is found, a new one
-    /// will be created as a member of current target.
-    ///
-    /// @param var
-    /// Variable name. Can not contain path elements.
-    /// TODO: should be case-insensitive up to SWF6.
-    ///
-    /// @param val
-    /// The value to assign to the variable, if found.
-    void set_variable_raw(const std::string& path, const as_value& val,
-        const ScopeStack& scopeStack);
-
     VM& _vm;
 
     /// Stack of as_values in this environment

http://git.savannah.gnu.org/cgit//commit/?id=aad0fd6b6085edde132445dc3e6363182e7f6137


commit aad0fd6b6085edde132445dc3e6363182e7f6137
Author: Benjamin Wolsey <address@hidden>
Date:   Tue Nov 16 16:22:39 2010 +0100

    More rearranging.

diff --git a/libcore/as_environment.cpp b/libcore/as_environment.cpp
index 6b76f8c..3b15a78 100644
--- a/libcore/as_environment.cpp
+++ b/libcore/as_environment.cpp
@@ -90,6 +90,13 @@ namespace {
         const as_environment::ScopeStack& scopeStack,
         as_object** retTarget = 0);
 
+    void setVariableRaw(const as_environment& env, const std::string& varname,
+        const as_value& val, const as_environment::ScopeStack& scopeStack);
+
+    // Search for next '.' or '/' character in this word.  Return
+    // a pointer to it, or null if it wasn't found.
+    static const char* next_slash_or_dot(const char* word);
+
 }
 
 as_value as_environment::undefVal;
@@ -178,7 +185,6 @@ validRawVariableName(const std::string& varname)
     return (varname.find(":::") == std::string::npos);
 }
 
-
 bool
 as_environment::delVariableRaw(const std::string& varname,
         const ScopeStack& scopeStack) 
@@ -254,73 +260,8 @@ as_environment::set_variable(const std::string& varname, 
const as_value& val,
         }
     }
     else {
-        set_variable_raw(varname, val, scopeStack);
-    }
-}
-
-// No path rigamarole.
-void
-as_environment::set_variable_raw(const std::string& varname,
-    const as_value& val, const ScopeStack& scopeStack)
-{
-
-    if (!validRawVariableName(varname))
-    {
-        IF_VERBOSE_ASCODING_ERRORS(
-            log_aserror(_("Won't set invalid raw variable name: %s"), varname);
-        );
-        return;
-    }
-
-    VM& vm = _vm;
-    string_table& st = vm.getStringTable();
-    string_table::key varkey = st.find(varname);
-
-    // in SWF5 and lower, scope stack should just contain 'with' elements 
-
-    // Check the scope stack.
-    for (size_t i = scopeStack.size(); i > 0; --i)
-    {
-        as_object* obj = scopeStack[i-1];
-        if (obj && obj->set_member(varkey, val, true)) {
-            return;
-        }
-    }
-    
-    const int swfVersion = vm.getSWFVersion();
-    if (swfVersion < 6 && _vm.calling()) {
-       if (setLocal(_vm.currentCall().locals(), varname, val)) return;
-    }
-    
-    // TODO: shouldn't m_target be in the scope chain ?
-    if (m_target) getObject(m_target)->set_member(varkey, val);
-    else if (_original_target) {
-        getObject(_original_target)->set_member(varkey, val);
-    }
-    else
-    {
-        log_error("as_environment(%p)::set_variable_raw(%s, %s): "
-       "neither current target nor original target are defined, "
-           "can't set the variable",
-           this, varname, val);
-    }
-}
-
-// Search for next '.' or '/' DisplayObject in this word.  Return
-// a pointer to it, or to NULL if it wasn't found.
-static const char*
-next_slash_or_dot(const char* word)
-{
-    for (const char* p = word; *p; p++) {
-        if (*p == '.' && p[1] == '.') {
-            ++p;
-        }
-        else if (*p == '.' || *p == '/' || *p == ':') {
-            return p;
-        }
+        setVariableRaw(*this, varname, val, scopeStack);
     }
-    
-    return NULL;
 }
 
 /// Find the sprite/movie referenced by the given path.
@@ -563,6 +504,51 @@ parsePath(const std::string& var_path_in, std::string& 
path, std::string& var)
 
 namespace {
 
+// No path rigamarole.
+void
+setVariableRaw(const as_environment& env, const std::string& varname,
+    const as_value& val, const as_environment::ScopeStack& scopeStack)
+{
+
+    if (!validRawVariableName(varname)) {
+        IF_VERBOSE_ASCODING_ERRORS(
+            log_aserror(_("Won't set invalid raw variable name: %s"), varname);
+        );
+        return;
+    }
+
+    VM& vm = env.getVM();
+    string_table& st = vm.getStringTable();
+    string_table::key varkey = st.find(varname);
+
+    // in SWF5 and lower, scope stack should just contain 'with' elements 
+
+    // Check the scope stack.
+    for (size_t i = scopeStack.size(); i > 0; --i) {
+        as_object* obj = scopeStack[i - 1];
+        if (obj && obj->set_member(varkey, val, true)) {
+            return;
+        }
+    }
+    
+    const int swfVersion = vm.getSWFVersion();
+    if (swfVersion < 6 && vm.calling()) {
+       if (setLocal(vm.currentCall().locals(), varname, val)) return;
+    }
+    
+    // TODO: shouldn't m_target be in the scope chain ?
+    if (env.get_target()) getObject(env.get_target())->set_member(varkey, val);
+    else if (env.get_original_target()) {
+        getObject(env.get_original_target())->set_member(varkey, val);
+    }
+    else {
+        log_error("as_environment::setVariableRaw(%s, %s): "
+           "neither current target nor original target are defined, "
+           "can't set the variable",
+           varname, val);
+    }
+}
+
 as_value
 getVariableRaw(const as_environment& env, const std::string& varname,
     const as_environment::ScopeStack& scopeStack, as_object** retTarget)
@@ -698,6 +684,20 @@ getElement(as_object* obj, const ObjectURI& uri)
     return getPathElement(*obj, uri);
 }
 
+static const char*
+next_slash_or_dot(const char* word)
+{
+    for (const char* p = word; *p; p++) {
+        if (*p == '.' && p[1] == '.') {
+            ++p;
+        }
+        else if (*p == '.' || *p == '/' || *p == ':') {
+            return p;
+        }
+    }
+    return 0;
+}
+
 } // unnamed namespace 
 
 string_table&

http://git.savannah.gnu.org/cgit//commit/?id=fe8ebcf738b982a2473330dec637f5e679cc50d3


commit fe8ebcf738b982a2473330dec637f5e679cc50d3
Author: Benjamin Wolsey <address@hidden>
Date:   Tue Nov 16 16:06:57 2010 +0100

    Rearrange as_environment.

diff --git a/libcore/as_environment.cpp b/libcore/as_environment.cpp
index 8e01aee..6b76f8c 100644
--- a/libcore/as_environment.cpp
+++ b/libcore/as_environment.cpp
@@ -45,76 +45,50 @@
 namespace gnash {
 
 namespace {
-
-/// Find a variable in the given as_object
-//
-/// @param varname
-/// Name of the local variable
-///
-/// @param ret
-/// If a variable is found it's assigned to this parameter.
-/// Untouched if the variable is not found.
-///
-/// @return true if the variable was found, false otherwise
-bool
-getLocal(as_object& locals, const std::string& name, as_value& ret)
-{
-    string_table& st = getStringTable(locals);
-    return locals.get_member(st.find(name), &ret);
-}
-
-bool
-findLocal(as_object& locals, const std::string& varname, as_value& ret,
-        as_object** retTarget) 
-{
-
-    if (getLocal(locals, varname, ret)) {
-        if (retTarget) *retTarget = &locals;
-        return true;
-    }
-
-    return false;
-}
-
-/// Delete a local variable
-//
-/// @param varname
-/// Name of the local variable
-///
-/// @return true if the variable was found and deleted, false otherwise
-bool
-deleteLocal(as_object& locals, const std::string& varname)
-{
-    string_table& st = getStringTable(locals);
-    return locals.delProperty(st.find(varname)).second;
-}
-
-/// Set a variable of the given object, if it exists.
-//
-/// @param varname
-/// Name of the local variable
-///
-/// @param val
-/// Value to assign to the variable
-///
-/// @return true if the variable was found, false otherwise
-bool
-setLocal(as_object& locals, const std::string& varname, const as_value& val)
-{
-    string_table& st = getStringTable(locals);
-    Property* prop = locals.getOwnProperty(st.find(varname));
-    if (!prop) return false;
-    prop->setValue(locals, val);
-    return true;
-}
-
-as_object*
-getElement(as_object* obj, const ObjectURI& uri)
-{
-    DisplayObject* d = obj->displayObject();
-    if (d) return d->pathElement(uri);
-    return getPathElement(*obj, uri);
-}
+    /// Find a variable in the given as_object
+    //
+    /// @param varname
+    /// Name of the local variable
+    ///
+    /// @param ret
+    /// If a variable is found it's assigned to this parameter.
+    /// Untouched if the variable is not found.
+    ///
+    /// @return true if the variable was found, false otherwise
+    bool getLocal(as_object& locals, const std::string& name, as_value& ret);
+
+    bool findLocal(as_object& locals, const std::string& varname, as_value& 
ret,
+            as_object** retTarget);
+
+    /// Delete a local variable
+    //
+    /// @param varname
+    /// Name of the local variable
+    ///
+    /// @return true if the variable was found and deleted, false otherwise
+    bool deleteLocal(as_object& locals, const std::string& varname);
+
+    /// Set a variable of the given object, if it exists.
+    //
+    /// @param varname
+    /// Name of the local variable
+    ///
+    /// @param val
+    /// Value to assign to the variable
+    ///
+    /// @return true if the variable was found, false otherwise
+    bool setLocal(as_object& locals, const std::string& varname,
+        const as_value& val);
+
+    as_object* getElement(as_object* obj, const ObjectURI& uri);
+
+    /// @param retTarget
+    /// If not NULL, the pointer will be set to the actual object containing 
the
+    /// found variable (if found).
+    as_value getVariableRaw(const as_environment& env,
+        const std::string& varname,
+        const as_environment::ScopeStack& scopeStack,
+        as_object** retTarget = 0);
 
 }
 
@@ -158,38 +132,35 @@ as_environment::get_variable(const std::string& varname,
         }
         else
         {
-
             IF_VERBOSE_ASCODING_ERRORS(
-            log_aserror(_("find_object(\"%s\") [ varname = '%s' - "
-                        "current target = '%s' ] failed"),
-                        path, varname, m_target);
-            as_value tmp = get_variable_raw(path, scopeStack, retTarget);
-            if ( ! tmp.is_undefined() )
-            {
-                log_aserror(_("...but get_variable_raw(%s, <scopeStack>) "
-                            "succeeded (%s)!"), path, tmp);
-            }
+                log_aserror(_("find_object(\"%s\") [ varname = '%s' - "
+                            "current target = '%s' ] failed"),
+                            path, varname, m_target);
+                as_value tmp = getVariableRaw(*this, path, scopeStack, 
retTarget);
+                if (!tmp.is_undefined()) {
+                    log_aserror(_("...but getVariableRaw(%s, <scopeStack>) "
+                                "succeeded (%s)!"), path, tmp);
+                }
             );
-            return as_value(); // TODO: should we check get_variable_raw ?
+            // TODO: should we check getVariableRaw ?
+            return as_value();
         }
     }
-    else
-    {
-    // TODO: have this checked by parse_path as an optimization 
-    if (varname.find('/') != std::string::npos &&
-            varname.find(':') == std::string::npos)
-        {
+    else {
+        // 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 ) 
-            {
+            if (target) {
                 // ... but only if it resolves to a sprite
                 DisplayObject* d = target->displayObject();
                 MovieClip* m = d ? d->to_movie() : 0;
                 if (m) return as_value(getObject(m));
             }
         }
-        return get_variable_raw(varname, scopeStack, retTarget);
+        return getVariableRaw(*this, varname, scopeStack, retTarget);
     }
 }
 
@@ -207,120 +178,6 @@ validRawVariableName(const std::string& varname)
     return (varname.find(":::") == std::string::npos);
 }
 
-as_value
-as_environment::get_variable_raw(const std::string& varname,
-    const ScopeStack& scopeStack, as_object** retTarget) const
-    // varname must be a plain variable name; no path parsing.
-{
-#ifdef GNASH_DEBUG_GET_VARIABLE
-    log_debug(_("get_variable_raw(%s)"), varname);
-#endif
-
-    if (!validRawVariableName(varname))
-    {
-        IF_VERBOSE_ASCODING_ERRORS(
-        log_aserror(_("Won't get invalid raw variable name: %s"), varname);
-        );
-        return as_value();
-    }
-
-    as_value    val;
-
-    VM& vm = _vm;
-    int swfVersion = vm.getSWFVersion();
-    string_table& st = vm.getStringTable();
-    string_table::key key = st.find(varname);
-
-    // Check the scope stack.
-    for (size_t i = scopeStack.size(); i > 0; --i)
-    {
-        as_object* obj = scopeStack[i-1];
-        if (obj && obj->get_member(key, &val))
-        {
-            // Found the var in with context.
-#ifdef GNASH_DEBUG_GET_VARIABLE
-            log_debug("Found %s in object %d/%d of scope stack (%p)",
-                    varname, i, scopeStack.size(), obj);
-#endif
-            if ( retTarget ) *retTarget = obj;
-            return val;
-        }
-    }
-
-    // Check locals for getting them
-    // for SWF6 and up locals should be in the scope stack
-    if (swfVersion < 6 && _vm.calling()) {
-       if (findLocal(_vm.currentCall().locals(), varname, val, retTarget)) {
-           return val;
-       }
-    }
-
-    // Check current target members. TODO: shouldn't target be in scope stack ?
-    if (m_target)
-    {
-        as_object* obj = getObject(m_target);
-        assert(obj);
-        if (obj->get_member(key, &val)) {
-#ifdef GNASH_DEBUG_GET_VARIABLE
-            log_debug("Found %s in target %p", varname, m_target->getTarget());
-#endif
-            if ( retTarget ) *retTarget = obj;
-            return val;
-        }
-    }
-    else if ( _original_target ) // this only for swf5+ ?
-    {
-        as_object* obj = getObject(_original_target);
-        assert(obj);
-        if (obj->get_member(key, &val)) {
-#ifdef GNASH_DEBUG_GET_VARIABLE
-            log_debug("Found %s in original target %s", varname, 
_original_target->getTarget());
-#endif
-            if ( retTarget ) *retTarget = obj;
-            return val;
-        }
-    }
-
-    // Looking for "this"  (TODO: add NSV::PROP_THIS)
-    if (varname == "this") {
-#ifdef GNASH_DEBUG_GET_VARIABLE
-        log_debug("Took %s as this, returning original target %s", varname, 
_original_target->getTarget());
-#endif
-        val.set_as_object(getObject(_original_target));
-        if ( retTarget ) *retTarget = NULL; // correct ??
-        return val;
-    }
-
-    as_object* global = vm.getGlobal();
-
-    if ( swfVersion > 5 && key == NSV::PROP_uGLOBAL )
-    {
-#ifdef GNASH_DEBUG_GET_VARIABLE
-        log_debug("Took %s as _global, returning _global", varname);
-#endif
-        // The "_global" ref was added in SWF6
-        if ( retTarget ) *retTarget = NULL; // correct ??
-        return as_value(global);
-    }
-
-    if (global->get_member(key, &val))
-    {
-#ifdef GNASH_DEBUG_GET_VARIABLE
-        log_debug("Found %s in _global", varname);
-#endif
-        if ( retTarget ) *retTarget = global;
-        return val;
-    }
-    
-    // Fallback.
-    // FIXME, should this be log_error?  or log_swferror?
-    IF_VERBOSE_ASCODING_ERRORS (
-    log_aserror(_("reference to non-existent variable '%s'"),
-           varname);
-    );
-
-    return as_value();
-}
 
 bool
 as_environment::delVariableRaw(const std::string& varname,
@@ -704,6 +561,145 @@ parsePath(const std::string& var_path_in, std::string& 
path, std::string& var)
     return true;
 }
 
+namespace {
+
+as_value
+getVariableRaw(const as_environment& env, const std::string& varname,
+    const as_environment::ScopeStack& scopeStack, as_object** retTarget)
+{
+
+    if (!validRawVariableName(varname)) {
+        IF_VERBOSE_ASCODING_ERRORS(
+            log_aserror(_("Won't get invalid raw variable name: %s"), varname);
+        );
+        return as_value();
+    }
+
+    as_value val;
+
+    VM& vm = env.getVM();
+    const int swfVersion = vm.getSWFVersion();
+    string_table& st = vm.getStringTable();
+    string_table::key key = st.find(varname);
+
+    // Check the scope stack.
+    for (size_t i = scopeStack.size(); i > 0; --i) {
+
+        as_object* obj = scopeStack[i - 1];
+        if (obj && obj->get_member(key, &val)) {
+            if (retTarget) *retTarget = obj;
+            return val;
+        }
+    }
+
+    // Check locals for getting them
+    // for SWF6 and up locals should be in the scope stack
+    if (swfVersion < 6 && vm.calling()) {
+       if (findLocal(vm.currentCall().locals(), varname, val, retTarget)) {
+           return val;
+       }
+    }
+
+    // Check current target members. TODO: shouldn't target be in scope stack ?
+    if (env.get_target()) {
+        as_object* obj = getObject(env.get_target());
+        assert(obj);
+        if (obj->get_member(key, &val)) {
+            if (retTarget) *retTarget = obj;
+            return val;
+        }
+    }
+    else if (env.get_original_target()) {
+        as_object* obj = getObject(env.get_original_target());
+        assert(obj);
+        if (obj->get_member(key, &val)) {
+            if (retTarget) *retTarget = obj;
+            return val;
+        }
+    }
+
+    // Looking for "this"  (TODO: add NSV::PROP_THIS)
+    if (varname == "this") {
+        val.set_as_object(getObject(env.get_original_target()));
+        if (retTarget) *retTarget = NULL; // correct ??
+        return val;
+    }
+
+    as_object* global = vm.getGlobal();
+
+    if (swfVersion > 5 && key == NSV::PROP_uGLOBAL) {
+#ifdef GNASH_DEBUG_GET_VARIABLE
+        log_debug("Took %s as _global, returning _global", varname);
+#endif
+        // The "_global" ref was added in SWF6
+        if (retTarget) *retTarget = NULL; // correct ??
+        return as_value(global);
+    }
+
+    if (global->get_member(key, &val)) {
+#ifdef GNASH_DEBUG_GET_VARIABLE
+        log_debug("Found %s in _global", varname);
+#endif
+        if (retTarget) *retTarget = global;
+        return val;
+    }
+    
+    // Fallback.
+    // FIXME, should this be log_error?  or log_swferror?
+    IF_VERBOSE_ASCODING_ERRORS(
+        log_aserror(_("reference to non-existent variable '%s'"), varname);
+    );
+
+    return as_value();
+}
+
+bool
+getLocal(as_object& locals, const std::string& name, as_value& ret)
+{
+    string_table& st = getStringTable(locals);
+    return locals.get_member(st.find(name), &ret);
+}
+
+bool
+findLocal(as_object& locals, const std::string& varname, as_value& ret,
+        as_object** retTarget) 
+{
+
+    if (getLocal(locals, varname, ret)) {
+        if (retTarget) *retTarget = &locals;
+        return true;
+    }
+
+    return false;
+}
+
+bool
+deleteLocal(as_object& locals, const std::string& varname)
+{
+    string_table& st = getStringTable(locals);
+    return locals.delProperty(st.find(varname)).second;
+}
+
+bool
+setLocal(as_object& locals, const std::string& varname, const as_value& val)
+{
+    string_table& st = getStringTable(locals);
+    Property* prop = locals.getOwnProperty(st.find(varname));
+    if (!prop) return false;
+    prop->setValue(locals, val);
+    return true;
+}
+
+as_object*
+getElement(as_object* obj, const ObjectURI& uri)
+{
+    DisplayObject* d = obj->displayObject();
+    if (d) return d->pathElement(uri);
+    return getPathElement(*obj, uri);
+}
+
+} // unnamed namespace 
+
 string_table&
 getStringTable(const as_environment& env)
 {
diff --git a/libcore/as_environment.h b/libcore/as_environment.h
index 5ac9979..aafcceb 100644
--- a/libcore/as_environment.h
+++ b/libcore/as_environment.h
@@ -213,15 +213,6 @@ private:
     void set_variable_raw(const std::string& path, const as_value& val,
         const ScopeStack& scopeStack);
 
-    /// Same of the above, but no support for path.
-    ///
-    /// @param retTarget
-    /// If not NULL, the pointer will be set to the actual object containing 
the
-    /// found variable (if found).
-    ///
-    as_value get_variable_raw(const std::string& varname,
-        const ScopeStack& scopeStack, as_object** retTarget=NULL) const;
-
     VM& _vm;
 
     /// Stack of as_values in this environment

-----------------------------------------------------------------------

Summary of changes:
 libcore/as_environment.cpp |  578 ++++++++++++++++++++++----------------------
 libcore/as_environment.h   |  150 ++++--------
 2 files changed, 326 insertions(+), 402 deletions(-)


hooks/post-receive
-- 
Gnash



reply via email to

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