Gnash
0.8.11dev
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
libcore
vm
fn_call.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_FN_CALL_H
20
#define GNASH_FN_CALL_H
21
22
#include <string>
23
#include <vector>
24
#include <cassert>
25
#include <ostream>
26
#include <algorithm>
27
28
#include "
utility.h
"
// for typeName
29
#include "
as_object.h
"
30
#include "
as_value.h
"
31
#include "
VM.h
"
32
#include "
GnashException.h
"
33
#include "
as_environment.h
"
34
35
36
// Forward declarations
37
namespace
gnash {
38
class
movie_definition;
39
}
40
41
namespace
gnash {
42
44
//
46
//
48
//
51
//
55
template
<
typename
T>
56
class
FunctionArgs
57
{
58
public
:
59
60
typedef
typename
std::vector<T>::size_type
size_type
;
61
typedef
std::vector<T>
container_type
;
62
typedef
T
value_type
;
63
64
FunctionArgs
() {}
65
67
FunctionArgs
(
const
FunctionArgs
& other)
68
:
69
_v(other._v)
70
{}
71
72
FunctionArgs
&
operator+=
(
const
T
&
t
) {
73
_v.push_back(t);
74
return
*
this
;
75
}
76
77
FunctionArgs
&
operator,
(
const
T
&
t
) {
78
_v.push_back(t);
79
return
*
this
;
80
}
81
83
//
86
void
setReachable
()
const
{
87
std::for_each
(_v.begin(), _v.end(),
88
std::mem_fun_ref(&
as_value::setReachable
));
89
}
90
91
void
swap
(std::vector<T>& to) {
92
std::swap(_v, to);
93
}
94
95
size_type
size
()
const
{
96
return
_v.size();
97
}
98
99
private
:
100
std::vector<T> _v;
101
};
102
103
107
class
fn_call
108
{
109
public
:
110
111
typedef
FunctionArgs<as_value>
Args
;
112
114
//
121
fn_call
(
as_object
* this_in,
const
as_environment
& env_in,
122
Args
& args,
as_object
* sup = 0,
bool
isNew =
false
)
123
:
124
this_ptr
(this_in),
125
super
(sup),
126
nargs
(args.size()),
127
callerDef
(0),
128
_env(env_in),
129
_new(isNew)
130
{
131
args.
swap
(_args);
132
}
133
134
fn_call
(
as_object
* this_in,
const
as_environment
& env_in)
135
:
136
this_ptr
(this_in),
137
super
(0),
138
nargs
(0),
139
callerDef
(0),
140
_env(env_in),
141
_new(false)
142
{
143
}
144
146
fn_call
(
const
fn_call
& fn)
147
:
148
this_ptr
(fn.
this_ptr
),
149
super
(fn.
super
),
150
nargs
(fn.
nargs
),
151
callerDef
(fn.
callerDef
),
152
_env(fn._env),
153
_args(fn._args),
154
_new(false)
155
{
156
}
157
160
as_object
*
this_ptr
;
161
163
//
165
as_object
*
super
;
166
168
Args::size_type
nargs
;
169
171
const
movie_definition
*
callerDef
;
172
174
VM
&
getVM
()
const
{
175
return
_env.
getVM
();
176
}
177
179
bool
isInstantiation
()
const
{
180
return
_new;
181
}
182
184
const
Args::value_type
&
arg
(
unsigned
int
n
)
const
{
185
assert(n <
nargs
);
186
return
_args[
n
];
187
}
188
189
const
Args::container_type
&
getArgs
()
const
{
190
return
_args;
191
}
192
193
void
drop_bottom
() {
194
assert(!_args.empty());
195
_args.erase(_args.begin());
196
--
nargs
;
197
}
198
199
const
as_environment
&
env
()
const
{
200
return
_env;
201
}
202
204
void
dump_args
(std::ostream& os)
const
{
205
for
(
size_t
i
= 0;
i
<
nargs
; ++
i
) {
206
if
(
i
) os <<
", "
;
207
os <<
arg
(
i
);
208
}
209
}
210
211
void
resetArgs
() {
212
nargs
= 0;
213
_args.clear();
214
}
215
216
void
pushArg
(
const
Args::value_type
&
arg
) {
217
++
nargs
;
218
_args.push_back(arg);
219
}
220
221
private
:
222
225
const
as_environment
& _env;
226
228
Args::container_type
_args;
229
230
bool
_new;
231
232
};
233
234
236
//
238
template
<
typename
T>
239
struct
ThisIsNative
240
{
241
typedef
T
value_type
;
242
value_type
*
operator()
(
const
as_object
*
o
)
const
{
243
return
dynamic_cast<
value_type
*
>
(o->
relay
());
244
}
245
};
246
248
//
250
template
<
typename
T = DisplayObject>
251
struct
IsDisplayObject
252
{
253
typedef
T
value_type
;
254
value_type
*
operator()
(
const
as_object
*
o
)
const
{
255
if
(!o)
return
0;
256
return
dynamic_cast<
T
*
>
(o->
displayObject
());
257
}
258
};
259
261
struct
ValidThis
262
{
263
typedef
as_object
value_type
;
264
value_type
*
operator()
(
as_object
*
o
)
const
{
265
return
o
;
266
}
267
};
268
270
//
274
//
279
//
287
template
<
typename
T>
288
typename
T::value_type*
289
ensure
(
const
fn_call
& fn)
290
{
291
as_object
* obj = fn.
this_ptr
;
292
if
(!obj)
throw
ActionTypeError
();
293
294
typename
T::value_type* ret =
T
()(obj);
295
296
if
(!ret) {
297
std::string target =
typeName
(ret);
298
std::string
source
=
typeName
(obj);
299
300
std::string msg =
"Function requiring "
+ target +
" as 'this' "
301
"called from "
+ source +
" instance."
;
302
303
throw
ActionTypeError
(msg);
304
}
305
return
ret;
306
}
307
308
inline
string_table&
309
getStringTable
(
const
fn_call
& fn)
310
{
311
return
fn.
getVM
().
getStringTable
();
312
}
313
314
inline
movie_root&
315
getRoot
(
const
fn_call
& fn)
316
{
317
return
fn.
getVM
().
getRoot
();
318
}
319
320
inline
int
321
getSWFVersion
(
const
fn_call
& fn)
322
{
323
return
fn.
getVM
().
getSWFVersion
();
324
}
325
326
inline
VM&
327
getVM
(
const
fn_call
& fn)
328
{
329
return
fn.
getVM
();
330
}
331
332
inline
Global_as&
333
getGlobal
(
const
fn_call
& fn)
334
{
335
return
*fn.
getVM
().
getGlobal
();
336
}
337
338
}
// namespace gnash
339
340
341
#endif
342
343
344
// Local Variables:
345
// mode: C++
346
// indent-tabs-mode: nil
347
// End:
Generated on Wed Mar 2 2016 01:37:24 for Gnash by
1.8.4