Gnash  0.8.11dev
as_environment.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 #ifndef GNASH_AS_ENVIRONMENT_H
20 #define GNASH_AS_ENVIRONMENT_H
21 
22 #include <string>
23 #include <vector>
24 #include <algorithm>
25 
26 #include "dsodefs.h" // for DSOTEXPORT
27 #include "as_value.h"
28 #include "SafeStack.h"
29 
30 // Forward declarations
31 namespace gnash {
32  class DisplayObject;
33  class VM;
34  class Global_as;
35  class movie_root;
36  class string_table;
37 }
38 
39 namespace gnash {
40 
41 
43 //
47 //
51 {
52 public:
53 
55  typedef std::vector<as_object*> ScopeStack;
56 
58 
59  VM& getVM() const { return _vm; }
60 
61  DisplayObject* target() const { return _target; }
62 
64  //
69  if (!_original_target) _original_target = target;
70  _target = target;
71  }
72 
74  _original_target = target;
75  }
76 
77  DisplayObject* get_original_target() const { return _original_target; }
78 
79  // Reset target to its original value
80  void reset_target() { _target = _original_target; }
81 
83  void push(const as_value& val) {
84  _stack.push(val);
85  }
86 
89  try {
90  return _stack.pop();
91  }
92  catch (const StackException&) {
93  return as_value();
94  }
95 
97  //
102  as_value& top(size_t dist) const
103  try {
104  return _stack.top(dist);
105  }
106  catch (const StackException&) {
107  return undefVal;
108  }
109 
111  void drop(size_t count) {
112  // in case count > stack size, just drop all, forget about
113  // exceptions...
114  _stack.drop(std::min(count, _stack.size()));
115  }
116 
117  size_t stack_size() const { return _stack.size(); }
118 
120  //
122  void markReachableResources() const;
123 
125  //
127  int get_version() const;
128 
129 private:
130 
131  VM& _vm;
132 
134  SafeStack<as_value>& _stack;
135 
137  DisplayObject* _target;
138 
140  DisplayObject* _original_target;
141 
142  static as_value undefVal;
143 
144 };
145 
147 //
153 as_value getVariable(const as_environment& ctx, const std::string& varname,
154  const as_environment::ScopeStack& scope, as_object** retTarget = nullptr);
155 
157 //
162 //
167 void setVariable(const as_environment& ctx, const std::string& path,
168  const as_value& val, const as_environment::ScopeStack& scope);
169 
171 //
175 bool delVariable(const as_environment& ctx, const std::string& varname,
176  const as_environment::ScopeStack& scope);
177 
196 DSOEXPORT bool parsePath(const std::string& var_path, std::string& path,
197  std::string& var);
198 
200 //
202 //
204 //
208 DSOEXPORT as_object* findObject(const as_environment& ctx, const std::string& path,
209  const as_environment::ScopeStack* scope = nullptr);
210 
212 //
215 //
219 DisplayObject* findTarget(const as_environment& env, const std::string& path);
220 
221 inline VM&
223 {
224  return env.getVM();
225 }
226 
227 movie_root& getRoot(const as_environment& env);
228 string_table& getStringTable(const as_environment& env);
229 int getSWFVersion(const as_environment& env);
230 DSOTEXPORT Global_as& getGlobal(const as_environment &env);
231 
232 } // namespace gnash
233 
234 #endif
235 
236 
237 // Local Variables:
238 // mode: C++
239 // indent-tabs-mode: t
240 // End:
path
VGPath path
Definition: testr_gtk.cpp:84
gnash::DisplayObject::getAsRoot
virtual MovieClip * getAsRoot()
Return the _root ActionScript property of this DisplayObject.
Definition: DisplayObject.cpp:847
movie_root.h
gnash::as_environment::getVM
VM & getVM() const
Definition: as_environment.h:59
name
std::string name
Definition: LocalConnection_as.cpp:149
gnash::key::d
@ d
Definition: GnashKey.h:150
gnash::as_object
The base class for all ActionScript objects.
Definition: as_object.h:162
as_object.h
gnash::log_action
void log_action(StringType msg, Args... args)
Definition: log.h:307
gnash::string_table
A general use string table.
Definition: string_table.h:42
dsodefs.h
gnash::VM::getStringTable
string_table & getStringTable() const
Get a reference to the string table used by the VM.
Definition: VM.h:117
gnash::log_debug
void log_debug(StringType msg, Args... args)
Definition: log.h:301
gnash::key::i
@ i
Definition: GnashKey.h:155
gnash::delVariable
bool delVariable(const as_environment &ctx, const std::string &varname, const as_environment::ScopeStack &scope)
Delete a variable, without support for the path, using a ScopeStack.
Definition: as_environment.cpp:357
gnash::getPathElement
as_object * getPathElement(as_object &o, const ObjectURI &uri)
Resolve the given relative path component.
Definition: as_object.cpp:1089
gnash::setLocal
void setLocal(CallFrame &c, const ObjectURI &name, const as_value &val)
Set a local variable in this CallFrame.
Definition: CallStack.cpp:80
CallStack.h
gnash::getVariable
as_value getVariable(const as_environment &env, const std::string &varname, const as_environment::ScopeStack &scope, as_object **retTarget)
Return the (possibly undefined) value of the named var.
Definition: as_environment.cpp:289
_
#define _(String)
Definition: log.h:44
gnash::VM::getRoot
movie_root & getRoot() const
Get a pointer to this VM's Root movie (stage)
Definition: VM.cpp:143
gnash::as_environment
Provides information about timeline context.
Definition: as_environment.h:51
gnash::parsePath
bool parsePath(const std::string &var_path_in, std::string &path, std::string &var)
Definition: as_environment.cpp:397
gnash::VM
The AVM1 virtual machine.
Definition: VM.h:72
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
gnash::VM::getGlobal
Global_as * getGlobal() const
Get a pointer to this VM's _global Object.
Definition: VM.cpp:149
gnash::key::m
@ m
Definition: GnashKey.h:159
as_value.h
Global_as.h
gnash::NSV::PROP_uGLOBAL
@ PROP_uGLOBAL
Definition: namedStrings.h:104
gnash::getGlobal
Global_as & getGlobal(const as_environment &env)
Definition: as_environment.cpp:651
gnash::MovieClip
A MovieClip is a container for DisplayObjects.
Definition: MovieClip.h:84
gnash::getVM
VM & getVM(const as_environment &env)
Definition: as_environment.h:222
gnash::log_error
void log_error(StringType msg, Args... args)
Definition: log.h:283
gnash::as_environment::get_version
int get_version() const
Return the SWF version we're running for.
Definition: as_environment.cpp:276
gnash::StackException
Definition: SafeStack.h:29
gnash::as_environment::push
void push(const as_value &val)
Push a value on the stack.
Definition: as_environment.h:83
gnash::as_environment::stack_size
size_t stack_size() const
Definition: as_environment.h:117
Property.h
IF_VERBOSE_ASCODING_ERRORS
#define IF_VERBOSE_ASCODING_ERRORS(x)
Definition: log.h:397
gnash::as_environment::ScopeStack
std::vector< as_object * > ScopeStack
A stack of objects used for variables/members lookup.
Definition: as_environment.h:55
gnash::as_object::get_member
virtual bool get_member(const ObjectURI &uri, as_value *val)
Get a property by name if it exists.
Definition: as_object.cpp:378
gnash::as_object::displayObject
DisplayObject * displayObject() const
Return the DisplayObject associated with this object.
Definition: as_object.h:638
MovieClip.h
gnash::as_environment::set_original_target
void set_original_target(DisplayObject *target)
Definition: as_environment.h:73
gnash::as_environment::markReachableResources
void markReachableResources() const
Mark all reachable resources.
Definition: as_environment.cpp:282
gnash::key::p
@ p
Definition: GnashKey.h:162
gnash::as_environment::target
DisplayObject * target() const
Definition: as_environment.h:61
gnash::VM::getSWFVersion
int getSWFVersion() const
Get SWF version context for the currently running actions.
Definition: VM.h:106
gnash::VM::calling
bool calling() const
Whether a function call is in progress.
Definition: VM.h:240
gnash::as_value
ActionScript value type.
Definition: as_value.h:95
VM.h
gnash::as_environment::as_environment
DSOTEXPORT as_environment(VM &vm)
Definition: as_environment.cpp:106
gnash::as_environment::drop
void drop(size_t count)
Drop 'count' values off the top of the stack.
Definition: as_environment.h:111
gnash::log_aserror
void log_aserror(StringType msg, Args... args)
Definition: log.h:331
log.h
gnash::setVariable
void setVariable(const as_environment &env, const std::string &varname, const as_value &val, const as_environment::ScopeStack &scope)
Given a path to variable, set its value.
Definition: as_environment.cpp:328
gnash::getRoot
movie_root & getRoot(const as_environment &env)
Definition: as_environment.cpp:645
IF_VERBOSE_ACTION
#define IF_VERBOSE_ACTION(x)
Definition: log.h:384
gnash::ObjectURI::CaseEquals
Definition: ObjectURI.h:147
gnash::as_object::delProperty
DSOTEXPORT std::pair< bool, bool > delProperty(const ObjectURI &uri)
Delete a property of this object, unless protected from deletion.
Definition: as_object.cpp:313
gnash::as_environment::get_original_target
DisplayObject * get_original_target() const
Definition: as_environment.h:77
as_environment.h
gnash::getObject
as_object * getObject(const DisplayObject *d)
Return the as_object associated with a DisplayObject if it exists.
Definition: DisplayObject.h:1160
gnash::findTarget
DisplayObject * findTarget(const as_environment &env, const std::string &path)
Find the DisplayObject referenced by the given path.
Definition: as_environment.cpp:632
DSOTEXPORT
#define DSOTEXPORT
Definition: dsodefs.h:63
namedStrings.h
gnash::as_object::set_member
virtual bool set_member(const ObjectURI &uri, const as_value &val, bool ifFound=false)
Set a member value.
Definition: as_object.cpp:583
gnash::as_environment::set_target
void set_target(DisplayObject *target)
Set default target for timeline opcodes.
Definition: as_environment.h:68
gnash::getSWFVersion
int getSWFVersion(const as_environment &env)
Definition: as_environment.cpp:657
test.uri
uri
Definition: test.py:12
gnash::as_environment::pop
as_value pop()
Pops an as_value off the stack top and return it.
Definition: as_environment.h:88
gnash::getStringTable
string_table & getStringTable(const as_environment &env)
Definition: as_environment.cpp:639
DSOEXPORT
#define DSOEXPORT
Definition: dsodefs.h:55
gnash::getURI
ObjectURI getURI(const VM &vm, const std::string &str, bool lowerCaseHint=false)
Definition: VM.h:290
gnash::DisplayObject
DisplayObject is the base class for all DisplayList objects.
Definition: DisplayObject.h:169
gnash::caseless
bool caseless(const as_object &o)
Return whether property matching is caseless.
Definition: as_object.h:924
gnash::ObjectURI
A URI for describing as_objects.
Definition: ObjectURI.h:45
gnash::as_environment::reset_target
void reset_target()
Definition: as_environment.h:80
SafeStack.h
gnash::findObject
as_object * findObject(const as_environment &ctx, const std::string &path, const as_environment::ScopeStack *scope)
Find the object referenced by the given path.
Definition: as_environment.cpp:116
test.v
v
Definition: test.py:11
gnash::NSV::PROP_THIS
@ PROP_THIS
Definition: namedStrings.h:96
gnash::CallFrame::locals
as_object & locals()
Access the local variables for this function call.
Definition: CallStack.h:73
gnash::as_environment::top
as_value & top(size_t dist) const
Get stack value at the given distance from top.
Definition: as_environment.h:102
gnash::VM::currentCall
CallFrame & currentCall()
Return the CallFrame of the currently executing function.
Definition: VM.cpp:229
gnash::GcResource::setReachable
void setReachable() const
Mark this resource as being reachable.
Definition: GC.h:92
gnash::SafeStack
Definition: SafeStack.h:42