Gnash  0.8.11dev
ExecutableCode.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 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 
20 #ifndef GNASH_EXECUTABLECODE_H
21 #define GNASH_EXECUTABLECODE_H
22 
23 #include <vector>
24 #include <boost/noncopyable.hpp>
25 
26 #include "ActionExec.h"
27 #include "Global_as.h"
28 #include "fn_call.h"
29 #include "ConstantPool.h"
30 
31 namespace gnash {
32 
34 class ExecutableCode : boost::noncopyable
35 {
36 public:
37 
38  ExecutableCode(DisplayObject* t) : _target(t) {}
39 
40  virtual void execute() = 0;
41 
42  virtual ~ExecutableCode() {}
43 
44  virtual void setReachable() const {}
45 
47  void markReachableResources() const {
48  setReachable();
49  if (_target) _target->setReachable();
50  }
51 
52  DisplayObject* target() const {
53  return _target;
54  }
55 
56 private:
57 
58  DisplayObject* _target;
59 };
60 
62 class GlobalCode : public ExecutableCode
63 {
64 public:
65 
66  GlobalCode(const action_buffer& nBuffer, DisplayObject* nTarget)
67  :
68  ExecutableCode(nTarget),
69  buffer(nBuffer)
70  {}
71 
72  virtual void execute() {
73  if (!target()->unloaded()) {
74  ActionExec exec(buffer, target()->get_environment());
75  exec();
76  }
77  }
78 
79 private:
80  const action_buffer& buffer;
81 };
82 
84 class EventCode : public ExecutableCode
85 {
86 public:
87 
88  typedef std::vector<const action_buffer*> BufferList;
89 
91  :
92  ExecutableCode(nTarget)
93  {}
94 
95  EventCode(DisplayObject* nTarget, const BufferList& buffers)
96  :
97  ExecutableCode(nTarget),
98  _buffers(buffers)
99  {}
100 
102  //
108  void addAction(const action_buffer& buffer) {
109  // don't push actions for destroyed DisplayObjects,
110  // our opcode guard is bogus at the moment.
111  if (!target()->isDestroyed()) {
112  _buffers.push_back(&buffer);
113  }
114  }
115 
116  virtual void execute() {
117  for (BufferList::iterator it = _buffers.begin(),
118  itEnd = _buffers.end(); it != itEnd; ++it) {
119 
120  // onClipEvents code are guarded by isDestroyed(),
121  // still might be also guarded by unloaded()
122  if (target()->isDestroyed()) break;
123 
124  PoolGuard guard(getVM(target()->get_environment()), 0);
125  ActionExec exec(*(*it), target()->get_environment(), false);
126  exec();
127  }
128  }
129 
130 private:
131  BufferList _buffers;
132 };
133 
135 //
146 {
147 public:
148 
150  as_object* obj, const ObjectURI& name,
151  const as_value& arg1, const as_value& arg2)
152  :
153  ExecutableCode(target),
154  _obj(obj),
155  _name(name),
156  _arg1(arg1),
157  _arg2(arg2)
158  {}
159 
160  virtual void execute() {
161  callMethod(_obj, _name, _arg1, _arg2);
162  }
163 
165  virtual void setReachable() const {
166  _obj->setReachable();
167  _arg1.setReachable();
168  _arg2.setReachable();
169  }
170 
171 private:
172  as_object* _obj;
173  ObjectURI _name;
174  as_value _arg1, _arg2;
175 };
176 
177 
178 
179 } // namespace gnash
180 
181 #endif // GNASH_EXECUTABLECODE_H