25
25
#include "as_environment.h" // for inlines (arg)
26
26
#include "as_object.h" // for dtor visibility by boost::intrusive_ptr
27
27
#include "smart_ptr.h"
29
30
#include <cassert> // for inlines (arg)
30
31
#include <ostream> // for inlines (dump_args)
45
/// A class to contain transferable arguments for a fn_call.
47
/// The operators += and , are implemented for intuitive syntax:
49
/// FunctionArgs<as_value> args; args += 0.0, "string", NaN.
51
/// This may have unexpected side effects if it is used in unexpected ways,
52
/// so stick to using such lists, or use operator += repeatedly.
54
/// The arguments can be moved to another container, and this happens when
55
/// the FunctionArgs object is passed to fn_call. It will still be valid
56
/// afterwards, but will contain no arguments.
62
typedef typename std::vector<T>::size_type size_type;
63
typedef std::vector<T> container_type;
68
FunctionArgs& operator+=(const T& t) {
73
FunctionArgs& operator,(const T& t) {
78
void swap(std::vector<T>& to) {
82
size_type size() const {
46
92
/// Parameters/environment for builtin or user-defined functions
97
typedef FunctionArgs<as_value> Args;
51
99
/// The as_object (or a pointer derived thereof) on which this call
52
100
/// is taking place.
53
boost::intrusive_ptr<as_object> this_ptr;
55
103
/// The "super" object in this function call context
58
106
/// Number of arguments to this ActionScript function call.
107
Args::size_type nargs;
61
109
/// Definition containing caller code. 0 if spontaneous (system event).
62
110
const movie_definition* callerDef;
82
129
callerDef(fn.callerDef),
86
_args.reset(new std::vector<as_value>(*fn._args));
90
fn_call(as_object* this_in, as_environment& env_in,
136
fn_call(as_object* this_in, const as_environment& env_in,
91
137
int nargs_in, size_t first_in, as_object* sup = 0)
93
139
this_ptr(this_in),
99
146
assert(first_in + 1 == env_in.stack_size());
100
147
readArgs(env_in, first_in, nargs);
103
fn_call(as_object* this_in, as_environment& env_in,
104
std::auto_ptr<std::vector<as_value> > args, as_object* sup = 0)
150
fn_call(as_object* this_in, const as_environment& env_in,
151
Args& args, as_object* sup = 0, bool isNew = false)
106
153
this_ptr(this_in),
115
fn_call(as_object* this_in, as_environment& env_in)
163
fn_call(as_object* this_in, const as_environment& env_in)
117
165
this_ptr(this_in),
138
186
// For the future, we might use an explicit flag instead
139
187
// as I belive there are some cases in which 'this' is
140
188
// undefined even in a normal function call.
141
return (this_ptr == 0);
144
192
/// Access a particular argument.
145
const as_value& arg(unsigned int n) const
193
const Args::value_type& arg(unsigned int n) const
147
195
assert(n < nargs);
151
const std::vector<as_value>& getArgs() const {
199
const Args::container_type& getArgs() const {
155
203
void drop_bottom()
157
assert(_args.get() && !(*_args).empty());
158
for (size_t i=0; i<(*_args).size()-1; ++i)
160
(*_args)[i] = (*_args)[i+1];
205
assert(!_args.empty());
206
_args.erase(_args.begin());
166
as_environment& env() const
210
const as_environment& env() const
171
215
/// Dump arguments to given output stream
172
216
void dump_args(std::ostream& os) const
174
for (unsigned int i=0; i<nargs; ++i)
218
for (size_t i = 0; i < nargs; ++i)
176
220
if ( i ) os << ", ";
177
221
os << arg(i).toDebugString();
195
void pushArg(const as_value& arg)
239
void pushArg(const Args::value_type& arg)
198
_args->push_back(arg);
242
_args.push_back(arg);
203
249
/// The ActionScript environment in which the function call is taking
204
250
/// place. This contains, among other things, the function arguments.
205
as_environment& _env;
251
const as_environment& _env;
207
253
/// The actual arguments
208
std::auto_ptr< std::vector<as_value> > _args;
254
Args::container_type _args;
210
void readArgs(as_environment& env, int first_in, int nargs)
256
void readArgs(const as_environment& env, int first_in, size_t nargs)
212
_args.reset(new std::vector<as_value>);
213
for (int i=0; i<nargs; ++i)
214
_args->push_back(env.bottom(first_in - i));
259
for (size_t i = 0; i < nargs; ++i) {
260
_args.push_back(env.bottom(first_in - i));
219
/// Signature of a builtin function callable from ActionScript
220
typedef as_value (*as_c_function_ptr)(const fn_call& fn);
266
/// Check whether the currently executing code is AS3 (ABC)
268
/// This is a non-member, non-friend function for better encapsulation.
269
/// TODO: drop these when there is a better design!
271
isAS3(const fn_call& fn)
273
return fn.getVM().getAVMVersion() == VM::AVM2;
277
getStringTable(const fn_call& fn)
279
return fn.getVM().getStringTable();
283
getRoot(const fn_call& fn)
285
return fn.getVM().getRoot();
289
getSWFVersion(const fn_call& fn)
291
return fn.getVM().getSWFVersion();
295
getVM(const fn_call& fn)
301
getGlobal(const fn_call& fn)
303
return fn.getVM().getGlobal();
223
306
} // namespace gnash
226
#endif // _GNASH_FN_CALL_H_
229
312
// Local Variables: