Gnash  0.8.11dev
Public Member Functions | Protected Member Functions | List of all members
gnash::as_function Class Referenceabstract

ActionScript Function, either builtin or SWF-defined. More...

#include <as_function.h>

Inheritance diagram for gnash::as_function:
gnash::as_object gnash::GcResource gnash::abc::abc_function gnash::NativeFunction gnash::UserFunction gnash::builtin_function gnash::Function gnash::Function2

Public Member Functions

virtual ~as_function ()
 Destructor. More...
 
virtual as_functionto_function ()
 Return this as_object as an as_function. More...
 
virtual as_value call (const fn_call &fn)=0
 Function dispatch. More...
 
virtual std::string stringValue () const
 Return the string value of this as_object subclass. More...
 
as_objectconstruct (as_object &newobj, const as_environment &env, FunctionArgs< as_value > &args)
 Run this function as a constructor on an object. More...
 
virtual bool isBuiltin ()
 Return true if this is a built-in class. More...
 
- Public Member Functions inherited from gnash::as_object
DSOTEXPORT as_object (const Global_as &global)
 Construct an ActionScript object with no prototype associated. More...
 
virtual ~as_object ()
 The as_object dtor does nothing special. More...
 
PropertyfindProperty (const ObjectURI &uri, as_object **owner=nullptr)
 Find a property, scanning the inheritance chain. More...
 
VMvm () const
 Return a reference to this as_object's global object. More...
 
void dump_members ()
 Dump all properties using log_debug. More...
 
virtual bool set_member (const ObjectURI &uri, const as_value &val, bool ifFound=false)
 Set a member value. More...
 
void init_member (const std::string &name, const as_value &val, int flags=DefaultFlags)
 Initialize a member value by string. More...
 
void init_member (const ObjectURI &uri, const as_value &val, int flags=DefaultFlags)
 Initialize a member value by key. More...
 
void init_property (const std::string &key, as_function &getter, as_function &setter, int flags=DefaultFlags)
 Initialize a getter/setter property by name. More...
 
void init_property (const std::string &key, as_c_function_ptr getter, as_c_function_ptr setter, int flags=DefaultFlags)
 Initialize a getter/setter property by name. More...
 
void init_property (const ObjectURI &uri, as_function &getter, as_function &setter, int flags=DefaultFlags)
 Initialize a getter/setter property by key. More...
 
void init_property (const ObjectURI &uri, as_c_function_ptr getter, as_c_function_ptr setter, int flags=DefaultFlags)
 Initialize a getter/setter property by key. More...
 
bool init_destructive_property (const ObjectURI &uri, as_function &getter, int flags=PropFlags::dontEnum)
 Initialize a destructive getter property. More...
 
bool init_destructive_property (const ObjectURI &uri, as_c_function_ptr getter, int flags=PropFlags::dontEnum)
 Initialize a destructive getter property. More...
 
void init_readonly_property (const std::string &key, as_function &getter, int flags=DefaultFlags)
 Use this method for read-only properties. More...
 
void init_readonly_property (const std::string &key, as_c_function_ptr getter, int flags=DefaultFlags)
 Use this method for read-only properties. More...
 
bool watch (const ObjectURI &uri, as_function &trig, const as_value &cust)
 Add a watch trigger, overriding any other defined for same name. More...
 
bool unwatch (const ObjectURI &uri)
 Remove a watch trigger. More...
 
virtual bool get_member (const ObjectURI &uri, as_value *val)
 Get a property by name if it exists. More...
 
virtual as_objectget_super (const ObjectURI &fname)
 
as_objectget_super ()
 
DSOTEXPORT std::pair< bool, bool > delProperty (const ObjectURI &uri)
 Delete a property of this object, unless protected from deletion. More...
 
PropertygetOwnProperty (const ObjectURI &uri)
 Get this object's own named property, if existing. More...
 
void set_member_flags (const ObjectURI &uri, int setTrue, int setFalse=0)
 Set member flags (probably used by ASSetPropFlags) More...
 
virtual bool isSuper () const
 Return true if this is a 'super' object. More...
 
void addInterface (as_object *ctor)
 Add an interface to the list of interfaces. More...
 
bool instanceOf (as_object *ctor)
 Check whether this object is an instance of the given constructor. More...
 
bool prototypeOf (as_object &instance)
 Check whether this object is in another object's inheritance chain. More...
 
void setPropFlags (const as_value &props, int set_false, int set_true)
 Set property flags. More...
 
void copyProperties (const as_object &o)
 Copy properties from the given object. More...
 
void clearProperties ()
 Drop all properties from this object. More...
 
template<typename T >
void visitProperties (PropertyVisitor &visitor) const
 Visit the properties of this object by key/as_value pairs. More...
 
void visitKeys (KeyVisitor &visitor) const
 Visit all visible property identifiers. More...
 
void add_property (const std::string &key, as_function &getter, as_function *setter)
 Add a getter/setter property if no member already has that name. More...
 
as_objectget_prototype () const
 Return this object's proto member. More...
 
void set_prototype (const as_value &proto)
 Set this object's proto member. More...
 
void setRelay (Relay *p)
 Set the as_object's Relay object. More...
 
Relayrelay () const
 Access the as_object's Relay object. More...
 
bool array () const
 Return true if this object should be treated as an array. More...
 
void setArray (bool array=true)
 Set whether this object should be treated as an array. More...
 
DisplayObjectdisplayObject () const
 Return the DisplayObject associated with this object. More...
 
void setDisplayObject (DisplayObject *d)
 Set the DisplayObject associated with this as_object. More...
 
- Public Member Functions inherited from gnash::GcResource
 GcResource (GC &gc)
 Create a Garbage-collected resource associated with a GC. More...
 
void setReachable () const
 Mark this resource as being reachable. More...
 
bool isReachable () const
 Return true if this object is marked as reachable. More...
 
void clearReachable () const
 Clear the reachable flag. More...
 

Protected Member Functions

 as_function (Global_as &gl)
 Construct a function. More...
 
- Protected Member Functions inherited from gnash::as_object
 as_object (VM &vm)
 Construct an as_object associated with a VM. More...
 
virtual void markReachableResources () const
 Mark all reachable resources, override from GcResource. More...
 
- Protected Member Functions inherited from gnash::GcResource
virtual ~GcResource ()
 Delete this resource. More...
 

Additional Inherited Members

- Static Public Attributes inherited from gnash::as_object
static const int DefaultFlags
 The most common flags for built-in properties. More...
 

Detailed Description

ActionScript Function, either builtin or SWF-defined.

In ActionScript, every Function is also a class. The exported interface of the class is defined as a 'prototype' member of the function object.

Any instance of the class defined by this function will inherit any member of the class 'prototype'. To have an object inherit from a class you can set its proto member so to point to the class prototype, ie:

function MyClass() {} MyClass.prototype.doit = function() { trace("doing it"; }

var myobj = new Object; myobj.__proto__ = MyClass.prototype;

The 'prototype' of a class must provide a 'constructor' member, which would point back to the Function object itself, which is used as the constructor, so given the code above you can assert that:

myobj.__proto__.constructor == MyClass

This class will automatically setup the 'prototype' member if not explicitly provided (ie: will set 'constructor' so that it points to the instance).

Constructor & Destructor Documentation

§ ~as_function()

virtual gnash::as_function::~as_function ( )
inlinevirtual

Destructor.

§ as_function()

gnash::as_function::as_function ( Global_as gl)
protected

Construct a function.

Referenced by isBuiltin().

Member Function Documentation

§ call()

virtual as_value gnash::as_function::call ( const fn_call fn)
pure virtual

Function dispatch.

Override from as_object, although as_objects cannot generally be called.

Reimplemented from gnash::as_object.

Implemented in gnash::Function, gnash::Function2, gnash::builtin_function, gnash::NativeFunction, and gnash::abc::abc_function.

Referenced by construct(), and to_function().

§ construct()

as_object * gnash::as_function::construct ( as_object newobj,
const as_environment env,
FunctionArgs< as_value > &  args 
)

Run this function as a constructor on an object.

This function assigns various constructor properties and runs the constructor. NB: This function does not make the object an 'instance of' the constructor, i.e. it does not assign a proto property. For ActionScript compatibility, callers should ensure this is already done.

Parameters
newobjThe object to construct. This will be used as the 'this' object in the constructor.
envThe environment to use for stack, local variables, registers and scope chain.
argsArguments for the constructor invocation
Returns
The constructed object. TODO: return void; currently there is a hack to cope with some remaining bogus constructors, which necessitates returning a different object from the passed 'this' pointer.

References _, call(), gnash::PropFlags::dontEnum, gnash::getSWFVersion(), gnash::getVM(), gnash::as_object::init_member(), gnash::as_value::is_object(), isBuiltin(), gnash::log_error(), gnash::PropFlags::onlySWF6Up, gnash::NSV::PROP_CONSTRUCTOR, gnash::NSV::PROP_uuCONSTRUCTORuu, and gnash::toObject().

Referenced by gnash::MovieClip::constructAsScriptObject(), gnash::constructInstance(), and to_function().

§ isBuiltin()

virtual bool gnash::as_function::isBuiltin ( )
inlinevirtual

Return true if this is a built-in class.

Reimplemented in gnash::builtin_function, and gnash::NativeFunction.

References as_function(), and gnash::constructInstance().

Referenced by construct(), and gnash::abc::Machine::pushCall().

§ stringValue()

std::string gnash::as_function::stringValue ( ) const
virtual

Return the string value of this as_object subclass.

It's "function".

Reimplemented from gnash::as_object.

Referenced by to_function().

§ to_function()

virtual as_function* gnash::as_function::to_function ( )
inlinevirtual

Return this as_object as an as_function.

Reimplemented from gnash::as_object.

References call(), construct(), and stringValue().

Referenced by gnash::registerMovieClipNative().


The documentation for this class was generated from the following files: