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, BufferList buffers)
96  :
97  ExecutableCode(nTarget),
98  _buffers(std::move(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 (const action_buffer* buffer : _buffers) {
118 
119  // onClipEvents code are guarded by isDestroyed(),
120  // still might be also guarded by unloaded()
121  if (target()->isDestroyed()) break;
122 
123  PoolGuard guard(getVM(target()->get_environment()), nullptr);
124  ActionExec exec(*buffer, target()->get_environment(), false);
125  exec();
126  }
127  }
128 
129 private:
130  BufferList _buffers;
131 };
132 
134 //
145 {
146 public:
147 
149  as_object* obj, ObjectURI name,
150  as_value arg1, as_value arg2)
151  :
152  ExecutableCode(target),
153  _obj(obj),
154  _name(std::move(name)),
155  _arg1(std::move(arg1)),
156  _arg2(std::move(arg2))
157  {}
158 
159  virtual void execute() {
160  callMethod(_obj, _name, _arg1, _arg2);
161  }
162 
164  virtual void setReachable() const {
165  _obj->setReachable();
166  _arg1.setReachable();
167  _arg2.setReachable();
168  }
169 
170 private:
171  as_object* _obj;
172  ObjectURI _name;
173  as_value _arg1, _arg2;
174 };
175 
176 
177 
178 } // namespace gnash
179 
180 #endif // GNASH_EXECUTABLECODE_H
Event code.
Definition: ExecutableCode.h:84
ExecutableCode(DisplayObject *t)
Definition: ExecutableCode.h:38
void setReachable() const
Mark this resource as being reachable.
Definition: GC.h:92
DisplayObject is the base class for all DisplayList objects.
Definition: DisplayObject.h:168
virtual void execute()
Definition: ExecutableCode.h:159
Definition: ConstantPool.h:34
ActionScript value type.
Definition: as_value.h:94
EventCode(DisplayObject *nTarget, BufferList buffers)
Definition: ExecutableCode.h:95
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
The base class for all ActionScript objects.
Definition: as_object.h:161
virtual void execute()
Definition: ExecutableCode.h:72
Global code (out of any function)
Definition: ExecutableCode.h:62
virtual ~ExecutableCode()
Definition: ExecutableCode.h:42
A URI for describing as_objects.
Definition: ObjectURI.h:44
Any executable code.
Definition: ExecutableCode.h:34
Definition: GnashKey.h:166
DelayedFunctionCall(DisplayObject *target, as_object *obj, ObjectURI name, as_value arg1, as_value arg2)
Definition: ExecutableCode.h:148
virtual void execute()=0
VM & getVM(const as_environment &env)
Definition: as_environment.h:222
virtual void setReachable() const
Mark reachable resources (for the GC)
Definition: ExecutableCode.h:164
Executor of an action_buffer.
Definition: ActionExec.h:118
void markReachableResources() const
Mark reachable resources (for the GC)
Definition: ExecutableCode.h:47
This class is used to queue a function call action.
Definition: ExecutableCode.h:144
void addAction(const action_buffer &buffer)
Add an action buffer to this event handler.
Definition: ExecutableCode.h:108
EventCode(DisplayObject *nTarget)
Definition: ExecutableCode.h:90
DisplayObject * target() const
Definition: ExecutableCode.h:52
as_value callMethod(fn_call::Args &args, as_object *obj, const ObjectURI &uri)
Call a member function of this object in an AS-compatible way.
Definition: Global_as.h:219
GlobalCode(const action_buffer &nBuffer, DisplayObject *nTarget)
Definition: ExecutableCode.h:66
virtual void setReachable() const
Definition: ExecutableCode.h:44
virtual void execute()
Definition: ExecutableCode.h:116
A code segment.
Definition: action_buffer.h:49
std::vector< const action_buffer * > BufferList
Definition: ExecutableCode.h:88
std::string name
Definition: LocalConnection_as.cpp:149