Gnash
0.8.11dev
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
libcore
asobj
Global_as.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
20
#ifndef GNASH_GLOBAL_H
21
#define GNASH_GLOBAL_H
22
23
#include <string>
24
#include <boost/preprocessor/arithmetic/inc.hpp>
25
#include <boost/preprocessor/repetition/enum_params.hpp>
26
#include <boost/preprocessor/repetition/repeat.hpp>
27
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
28
#include <boost/preprocessor/seq/for_each.hpp>
29
#include <boost/preprocessor/facilities/empty.hpp>
30
#include <boost/scoped_ptr.hpp>
31
32
#include "
as_object.h
"
33
#include "
fn_call.h
"
34
#include "
log.h
"
35
#include "
ClassHierarchy.h
"
36
#include "
dsodefs.h
"
// for DSOTEXPORT
37
38
// Forward declarations
39
namespace
gnash {
40
class
as_value;
41
class
VM;
42
class
Extension;
43
}
44
45
namespace
gnash {
46
48
//
52
//
55
class
Global_as
:
public
as_object
56
{
57
public
:
58
59
typedef
as_value
(*
ASFunction
)(
const
fn_call
& fn);
60
typedef
void(*
Properties
)(
as_object
&);
61
62
explicit
Global_as
(
VM
&
vm
);
63
virtual
~Global_as
();
64
65
void
registerClasses
();
66
67
as_object
*
createArray
();
68
69
VM
&
getVM
()
const
{
70
return
vm
();
71
}
72
74
as_function
*
createFunction
(
Global_as::ASFunction
function
);
75
77
//
80
as_object
*
createClass
(
Global_as::ASFunction
ctor,
81
as_object
* prototype);
82
83
void
makeObject
(
as_object
&
o
)
const
;
84
85
protected
:
86
87
virtual
void
markReachableResources
()
const
;
88
89
private
:
90
91
void
loadExtensions();
92
boost::scoped_ptr<Extension> _et;
93
94
ClassHierarchy
_classes;
95
96
as_object
* _objectProto;
97
98
};
99
100
DSOTEXPORT
as_object*
createObject
(
const
Global_as& gl);
101
102
104
//
106
//
109
//
112
//
119
inline
as_object*
120
registerBuiltinObject
(
as_object
& where,
Global_as::Properties
p
,
121
const
ObjectURI
& uri)
122
{
123
Global_as
& gl =
getGlobal
(where);
124
as_object
* obj =
createObject
(gl);
125
if
(p)
p
(*obj);
126
127
where.
init_member
(uri, obj,
as_object::DefaultFlags
);
128
129
return
obj;
130
}
131
133
//
135
//
139
//
149
inline
as_object*
150
registerBuiltinClass
(
as_object
& where,
Global_as::ASFunction
ctor,
151
Global_as::Properties
p
,
Global_as::Properties
c
,
const
ObjectURI
& uri)
152
{
153
Global_as
& gl =
getGlobal
(where);
154
as_object
* proto =
createObject
(gl);
155
as_object
* cl = gl.
createClass
(ctor, proto);
156
157
// Attach class properties to class
158
if
(c)
c
(*cl);
159
160
// Attach prototype properties to prototype
161
if
(p)
p
(*proto);
162
163
// Register class with specified object.
164
where.
init_member
(uri, cl,
as_object::DefaultFlags
);
165
return
cl;
166
}
167
169
//
171
inline
DSOEXPORT
as_value
172
invoke
(
const
as_value
& method,
const
as_environment
& env,
as_object
* this_ptr,
173
fn_call::Args
& args,
as_object
* super = 0,
174
const
movie_definition
* callerDef = 0)
175
{
176
177
as_value
val;
178
fn_call
call(this_ptr, env, args);
179
call.
super
= super;
180
call.
callerDef
= callerDef;
181
182
try
{
183
if
(
as_object
* func =
toObject
(method,
getVM
(env))) {
184
// Call function.
185
val = func->call(call);
186
}
187
else
{
188
IF_VERBOSE_ASCODING_ERRORS
(
189
log_aserror(
"Attempt to call a value which is not "
190
"a function (%s)"
, method);
191
);
192
return
val;
193
}
194
}
195
catch
(
ActionTypeError
&
e
) {
196
assert(val.
is_undefined
());
197
IF_VERBOSE_ASCODING_ERRORS
(
198
log_aserror(
"%s"
, e.what());
199
);
200
}
201
return
val;
202
}
203
205
#define FUNC_PARAM(z, n, t) BOOST_PP_COMMA_IF(n) t arg##n
206
#define VALUE_ARG(z, n, t) BOOST_PP_COMMA_IF(n) arg##n
207
209
//
212
//
215
//
218
//
227
#define CALL_METHOD(x, n, t) \
228
inline as_value \
229
callMethod(as_object* obj, const ObjectURI& uri BOOST_PP_COMMA_IF(n)\
230
BOOST_PP_REPEAT(n, FUNC_PARAM, const as_value&)) {\
231
if (!obj) return as_value();\
232
as_value func;\
233
if (!obj->get_member(uri, &func)) return as_value();\
234
fn_call::Args args;\
235
BOOST_PP_EXPR_IF(n, (args += BOOST_PP_REPEAT(n, VALUE_ARG, BOOST_PP_EMPTY));)\
236
return invoke(func, as_environment(getVM(*obj)), obj, args);\
237
}
238
240
#define MAX_ARGS 4
241
BOOST_PP_REPEAT(BOOST_PP_INC(
MAX_ARGS
),
CALL_METHOD
, BOOST_PP_EMPTY)
242
243
#undef VALUE_ARG
244
#undef FUNC_PARAM
245
#undef MAX_ARGS
246
#undef CALL_METHOD
247
249
//
251
inline
as_function*
252
getClassConstructor
(
const
fn_call
& fn,
const
std::string&
s
)
253
{
254
const
as_value
ctor(
findObject
(fn.
env
(),
s
));
255
return
ctor.
to_function
();
256
}
257
258
inline
as_value
259
emptyFunction
(
const
fn_call
&)
260
{
261
return
as_value
();
262
}
263
264
}
// namespace gnash
265
266
#endif
Generated on Wed Mar 2 2016 01:37:24 for Gnash by
1.8.4