Gnash
0.8.10
|
A simple SWF-defined Function. More...
#include <Function.h>
Classes | |
struct | Argument |
Public Types | |
typedef std::vector< as_object * > | ScopeStack |
Public Member Functions | |
Function (const action_buffer &ab, as_environment &env, size_t start, const ScopeStack &with_stack) | |
Create an ActionScript function as defined in an action_buffer starting at offset 'start'. | |
virtual | ~Function () |
const ScopeStack & | getScopeStack () const |
const action_buffer & | getActionBuffer () const |
size_t | getStartPC () const |
size_t | getLength () const |
virtual boost::uint8_t | registers () const |
Get the number of registers required for function execution. | |
void | add_arg (boost::uint8_t reg, const ObjectURI &name) |
Add an expected argument for the function. | |
void | setLength (size_t len) |
Set the length in bytes of the function code. | |
virtual as_value | call (const fn_call &fn) |
Dispatch. | |
virtual void | markReachableResources () const |
Mark reachable resources. Override from as_object. | |
Protected Attributes | |
std::vector< Argument > | _args |
as_environment & | _env |
@ might need some kind of ref count here, but beware cycles | |
const ConstantPool * | _pool |
The ConstantPool in effect at time of function definition. |
A simple SWF-defined Function.
This represents a callable Function defined in a SWF. The basic version creates a scope in which 'arguments' array, 'this', 'super', and the expected argument names are defined. For a more advanced function, see Function2.
typedef std::vector<as_object*> gnash::Function::ScopeStack |
gnash::Function::Function | ( | const action_buffer & | ab, |
as_environment & | env, | ||
size_t | start, | ||
const ScopeStack & | with_stack | ||
) |
Create an ActionScript function as defined in an action_buffer starting at offset 'start'.
References assert, and gnash::action_buffer::size().
virtual gnash::Function::~Function | ( | ) | [inline, virtual] |
void gnash::Function::add_arg | ( | boost::uint8_t | reg, |
const ObjectURI & | name | ||
) | [inline] |
Add an expected argument for the function.
For ordinary Functions the register is disregarded. This is only relevant for Function2s. All argument names are declared as variables in the function scope, whether the argument is passed or not.
reg | The register for the argument. |
name | The name of the argument. |
References _args.
Dispatch.
This is only needed for SWF5 (temp switch of target) We do always and base 'target' value on SWF version. TODO: simplify code by maybe using a custom as_environment instead, so to get an "original" target being the one set now (rather then the really original one) TODO: test scope when calling functions defined in another timeline (target, in particular).
Implements gnash::as_function.
Reimplemented in gnash::Function2.
References gnash::as_object::vm(), gnash::getVM(), gnash::VM::calling(), gnash::VM::currentCall(), gnash::CallFrame::function(), gnash::FrameGuard::callFrame(), _env, gnash::as_environment::target(), gnash::as_environment::get_original_target(), gnash::getSWFVersion(), gnash::fn_call::this_ptr, _pool, gnash::key::i, gnash::key::n, _args, assert, gnash::fn_call::nargs, gnash::setLocal(), gnash::fn_call::arg(), gnash::declareLocal(), gnash::NSV::PROP_THIS, gnash::fn_call::super, gnash::as_object::get_super(), gnash::NSV::PROP_SUPER, gnash::getGlobal(), gnash::Global_as::createArray(), gnash::NSV::PROP_ARGUMENTS, and gnash::getArguments().
const action_buffer& gnash::Function::getActionBuffer | ( | ) | const [inline] |
size_t gnash::Function::getLength | ( | ) | const [inline] |
const ScopeStack& gnash::Function::getScopeStack | ( | ) | const [inline] |
size_t gnash::Function::getStartPC | ( | ) | const [inline] |
void gnash::Function::markReachableResources | ( | ) | const [virtual] |
Mark reachable resources. Override from as_object.
Reachable resources from this object are its scope stack and the prototype.
Reimplemented from gnash::as_object.
References gnash::renderer::opengl::for_each(), gnash::GcResource::setReachable(), _env, and gnash::as_environment::markReachableResources().
virtual boost::uint8_t gnash::Function::registers | ( | ) | const [inline, virtual] |
Get the number of registers required for function execution.
For ordinary Functions this is always 0.
Implements gnash::UserFunction.
Reimplemented in gnash::Function2.
void gnash::Function::setLength | ( | size_t | len | ) |
Set the length in bytes of the function code.
References assert, and gnash::action_buffer::size().
std::vector<Argument> gnash::Function::_args [protected] |
Referenced by call(), add_arg(), and gnash::Function2::call().
as_environment& gnash::Function::_env [protected] |
@ might need some kind of ref count here, but beware cycles
Referenced by call(), markReachableResources(), and gnash::Function2::call().
const ConstantPool* gnash::Function::_pool [protected] |
The ConstantPool in effect at time of function definition.
Referenced by call(), and gnash::Function2::call().