~ubuntu-branches/ubuntu/saucy/gnash/saucy-proposed

« back to all changes in this revision

Viewing changes to libcore/as_environment.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sindhudweep Narayan Sarkar
  • Date: 2009-10-07 00:06:10 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20091007000610-mj9rwqe774gizn1j
Tags: 0.8.6-0ubuntu1
new upstream release 0.8.6 (LP: #435897)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include "smart_ptr.h" // GNASH_USE_GC
21
21
#include "as_environment.h"
22
22
#include "MovieClip.h"
23
 
#include "shape_character_def.h"
 
23
#include "movie_root.h"
24
24
#include "as_value.h"
25
25
#include "VM.h"
26
26
#include "log.h"
29
29
#include "namedStrings.h"
30
30
#include "as_function.h" 
31
31
#include "CallStack.h"
 
32
#include "Global_as.h"
32
33
 
33
34
#include <string>
34
35
#include <utility> // for std::pair
89
90
            IF_VERBOSE_ASCODING_ERRORS(
90
91
            log_aserror(_("find_object(\"%s\") [ varname = '%s' - "
91
92
                        "current target = '%s' ] failed"),
92
 
                        path, varname, m_target ? m_target->get_text_value() : "<null>");
 
93
                        path, varname, m_target);
93
94
            as_value tmp = get_variable_raw(path, scopeStack, retTarget);
94
95
            if ( ! tmp.is_undefined() )
95
96
            {
103
104
    else
104
105
    {
105
106
    // TODO: have this checked by parse_path as an optimization 
106
 
    if ( varname.find_first_of('/') != std::string::npos && varname.find_first_of(':') == std::string::npos )
107
 
    {
108
 
        // Consider it all a path ...
109
 
            as_object* target = find_object(varname, &scopeStack); 
110
 
        if ( target ) 
 
107
    if (varname.find('/') != std::string::npos &&
 
108
            varname.find(':') == std::string::npos)
111
109
        {
112
 
            // ... but only if it resolves to a sprite
113
 
            MovieClip* m = target->to_movie();
114
 
            if ( m ) return as_value(m);
 
110
            // Consider it all a path ...
 
111
                as_object* target = find_object(varname, &scopeStack); 
 
112
            if ( target ) 
 
113
            {
 
114
                // ... but only if it resolves to a sprite
 
115
                MovieClip* m = target->to_movie();
 
116
                if ( m ) return as_value(m);
 
117
            }
115
118
        }
116
 
    }
117
119
        return get_variable_raw(varname, scopeStack, retTarget);
118
120
    }
119
121
}
525
527
    return true;
526
528
}
527
529
 
528
 
// Search for next '.' or '/' character in this word.  Return
 
530
// Search for next '.' or '/' DisplayObject in this word.  Return
529
531
// a pointer to it, or to NULL if it wasn't found.
530
532
static const char*
531
533
next_slash_or_dot(const char* word)
545
547
//
546
548
// Supports both /slash/syntax and dot.syntax
547
549
//
548
 
character*
 
550
DisplayObject*
549
551
as_environment::find_target(const std::string& path_in) const
550
552
{
551
553
    as_object* o = find_object(path_in);
552
 
    if ( o ) return o->to_character(); // can be NULL (not a character)...
 
554
    if ( o ) return o->toDisplayObject(); // can be NULL (not a DisplayObject)...
553
555
    else return NULL;
554
556
}
555
557
 
584
586
    {
585
587
        // Absolute path.  Start at the (AS) root (handle _lockroot)
586
588
        MovieClip* root = 0;
587
 
        if ( m_target ) root = const_cast<MovieClip*>(m_target->getAsRoot());
 
589
        if ( m_target ) root = m_target->getAsRoot();
588
590
        else {
589
591
            if ( _original_target )
590
592
            {
591
593
                log_debug("current target is undefined on "
592
594
                        "as_environment::find_object, we'll use original");
593
 
                root = const_cast<MovieClip*>(_original_target->getAsRoot());
 
595
                root = _original_target->getAsRoot();
594
596
            }
595
597
            else
596
598
            {
637
639
#ifdef DEBUG_TARGET_FINDING 
638
640
            log_debug(_("Path is %s, returning whatever we were up to"), path);
639
641
#endif
 
642
 
640
643
            return env;
641
644
        }
642
645
 
750
753
 
751
754
#ifdef DEBUG_TARGET_FINDING 
752
755
            log_debug(_("Invoking get_path_element(%s) on object "
753
 
                    "%p (%s)"), subpart, (void *)env, env->get_text_value());
 
756
                    "%p"), subpart, (void *)env);
754
757
#endif
755
758
 
756
759
            as_object* element = env->get_path_element(subpartKey);
939
942
    // TODO: override from gnashrc.
940
943
    
941
944
    // A stack size of 0 is apparently legitimate.
942
 
    const boost::uint16_t maxstacksize = 
943
 
        func->getVM().getRoot().getRecursionLimit();
944
 
 
945
 
    // Doesn't proceed if the stack size would reach the limit; should
946
 
    // this check be done somewhere after adding to the stack? Would
947
 
    // it make any difference?
948
 
    if ( _localFrames.size() + 1 >= maxstacksize )
949
 
    {
 
945
    const boost::uint16_t recursionLimit = getRoot(*func).getRecursionLimit();
 
946
 
 
947
    // Don't proceed if local call frames would reach the recursion limit.
 
948
    if (_localFrames.size() + 1 >= recursionLimit) {
 
949
 
950
950
        std::ostringstream ss;
951
 
        ss << boost::format(_("Max stack count reached (%u)")) % 
952
 
            _localFrames.size();
 
951
        ss << boost::format(_("Recursion limit reached (%u)")) % recursionLimit;
953
952
 
954
953
        // throw something
955
954
        throw ActionLimitException(ss.str()); 
967
966
}
968
967
    
969
968
void
970
 
as_environment::set_target(character* target)
 
969
as_environment::set_target(DisplayObject* target)
971
970
{
972
971
    //assert(target);
973
972
    if ( ! _original_target )
1078
1077
}
1079
1078
#endif // GNASH_USE_GC
1080
1079
 
 
1080
string_table&
 
1081
getStringTable(const as_environment& env)
 
1082
{
 
1083
    return env.getVM().getStringTable();
 
1084
}
 
1085
 
 
1086
movie_root&
 
1087
getRoot(const as_environment& env)
 
1088
{
 
1089
    return env.getVM().getRoot();
 
1090
}
 
1091
 
 
1092
Global_as*
 
1093
getGlobal(const as_environment& env)
 
1094
{
 
1095
    return env.getVM().getGlobal();
 
1096
}
 
1097
 
 
1098
int
 
1099
getSWFVersion(const as_environment& env)
 
1100
{
 
1101
    return env.getVM().getSWFVersion();
 
1102
}
 
1103
 
1081
1104
} // end of gnash namespace
1082
1105
 
1083
1106