2 // Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "ClassHierarchy.h"
21 #include <boost/bind.hpp>
23 #include "as_object.h"
24 #include "PropFlags.h"
26 #include "namedStrings.h"
27 #include "as_function.h"
28 #include "Global_as.h"
29 #include "extension.h"
33 // anonymous namespace
37 addVisibilityFlag(int& flags
, int version
)
39 // TODO: more visibility for swf10+?
45 flags
|= PropFlags::onlySWF9Up
;
48 flags
|= PropFlags::onlySWF8Up
;
51 flags
|= PropFlags::onlySWF7Up
;
54 flags
|= PropFlags::onlySWF6Up
;
59 class declare_extension_function
: public as_function
62 ClassHierarchy::ExtensionClass _decl
;
64 Extension
*mExtension
;
67 bool isBuiltin() { return true; }
69 declare_extension_function(ClassHierarchy::ExtensionClass
&c
, as_object
*g
,
72 as_function(getGlobal(*g
)),
79 virtual as_value
call(const fn_call
& fn
)
81 string_table
& st
= getStringTable(fn
);
82 log_debug("Loading extension class %s", st
.value(getName(_decl
.uri
)));
84 if (mExtension
->initModuleWithFunc(_decl
.file_name
,
85 _decl
.init_name
, *mTarget
))
87 // Successfully loaded it, now find it, set its proto, and return.
89 mTarget
->get_member(_decl
.uri
, &us
);
92 // Error here -- not successful in loading.
93 log_error("Could not load class %s", st
.value(getName(_decl
.uri
)));
98 class declare_native_function
: public as_function
103 bool isBuiltin() { return true; }
105 declare_native_function(const ClassHierarchy::NativeClass
&c
, as_object
*g
)
107 as_function(getGlobal(*g
)),
113 virtual as_value
call(const fn_call
& fn
)
115 string_table
& st
= getStringTable(fn
);
116 log_debug("Loading native class %s", st
.value(getName(_decl
.uri
)));
118 _decl
.initializer(*mTarget
, _decl
.uri
);
119 // Successfully loaded it, now find it, set its proto, and return.
121 if (mTarget
->get_member(_decl
.uri
, &us
)) {
122 if (!toObject(us
, getVM(fn
))) {
123 log_error("Native class %s is not an object after "
124 "initialization (%s)",
125 st
.value(getName(_decl
.uri
)), us
);
130 log_error("Native class %s is not found after initialization",
131 st
.value(getName(_decl
.uri
)));
138 ClassHierarchy::NativeClass _decl
;
143 } // end anonymous namespace
145 ClassHierarchy::~ClassHierarchy()
150 ClassHierarchy::declareClass(ExtensionClass
& c
)
152 if (!mExtension
) return false;
154 as_function
* getter(new declare_extension_function(c
, mGlobal
, mExtension
));
156 int flags
= PropFlags::dontEnum
;
157 addVisibilityFlag(flags
, c
.version
);
158 return mGlobal
->init_destructive_property(c
.uri
, *getter
, flags
);
162 ClassHierarchy::declareClass(const NativeClass
& c
)
164 as_function
* getter
= new declare_native_function(c
, mGlobal
);
166 int flags
= PropFlags::dontEnum
;
167 addVisibilityFlag(flags
, c
.version
);
168 return mGlobal
->init_destructive_property(c
.uri
, *getter
, flags
);
173 ClassHierarchy::declareAll(const NativeClasses
& classes
)
175 // This is necessary to resolve the overload...
176 bool(ClassHierarchy::*nf
)(const NativeClass
& f
) =
177 &ClassHierarchy::declareClass
;
179 std::for_each(classes
.begin(), classes
.end(), boost::bind(nf
, this, _1
));
182 } // end of namespace gnash
186 // indent-tabs-mode: t