Gnash  0.8.10
Public Types | Public Member Functions | Friends
gnash::as_value Class Reference

ActionScript value type. More...

#include <as_value.h>

List of all members.

Public Types

enum  AsType {
  UNDEFINED, UNDEFINED_EXCEPT, NULLTYPE, NULLTYPE_EXCEPT,
  BOOLEAN, BOOLEAN_EXCEPT, STRING, STRING_EXCEPT,
  NUMBER, NUMBER_EXCEPT, OBJECT, OBJECT_EXCEPT,
  DISPLAYOBJECT, DISPLAYOBJECT_EXCEPT
}

Public Member Functions

DSOEXPORT as_value ()
 Construct an undefined value.
DSOEXPORT as_value (const as_value &v)
 Copy constructor.
 ~as_value ()
DSOEXPORT as_value (const char *str)
 Construct a primitive String value.
DSOEXPORT as_value (const std::string &str)
 Construct a primitive String value.
template<typename T >
 as_value (T val, typename boost::enable_if< boost::is_same< bool, T > >::type *dummy=0)
 Construct a primitive Boolean value.
 as_value (double num)
 Construct a primitive Number value.
 as_value (as_object *obj)
 Construct a null, Object, or DisplayObject value.
DSOEXPORT as_valueoperator= (const as_value &v)
 Assign to an as_value.
const char * typeOf () const
 Return the primitive type of this value as a string.
bool is_function () const
 Return true if this value is a function.
bool is_string () const
 Return true if this value is a string.
bool is_number () const
 Return true if this value is strictly a number.
bool is_object () const
 Return true if this value is an object.
bool is_sprite () const
 Return true if this value is a DISPLAYOBJECT.
std::string to_string (int version=7) const
 Get a std::string representation for this value.
double to_number (int version) const
 Get a number representation for this value.
bool to_bool (int version) const
 Conversion to boolean.
as_objectto_object (VM &vm) const
 Return value as an object, converting primitive values as needed.
as_objectget_object () const
 Return the value as an as_object only if it is an as_object.
MovieCliptoMovieClip (bool skipRebinding=false) const
 Returns value as a MovieClip if it is a MovieClip.
DisplayObjecttoDisplayObject (bool skipRebinding=false) const
 Return value as a DisplayObject or NULL if this is not possible.
as_functionto_function () const
 Return the value as a function only if it is a function.
AsType defaultPrimitive (int version) const
as_value to_primitive (AsType hint) const
 Return value as a primitive type, with a preference.
void set_string (const std::string &str)
 Set to a primitive string.
void set_double (double val)
 Set to a primitive number.
void set_bool (bool val)
 Set to a primitive boolean.
void set_as_object (as_object *obj)
 Make this value a NULL, OBJECT, DISPLAYOBJECT value.
void set_undefined ()
 Set to undefined.
void set_null ()
 Set this value to the NULL value.
bool is_undefined () const
bool is_null () const
bool is_bool () const
bool is_exception () const
void flag_exception ()
void unflag_exception ()
bool strictly_equals (const as_value &v) const
 Return true if this value is strictly equal to the given one.
bool equals (const as_value &v, int version) const
 Return true if this value is abstractly equal to the given one.
void setReachable () const
 Set any object value as reachable (for the GC)
bool writeAMF0 (amf::Writer &w) const
 Serialize value in AMF0 format.

Friends

std::ostream & operator<< (std::ostream &o, const as_value &)
 Stream operator.

Detailed Description

ActionScript value type.

The as_value class can store basic ActionScript types. These are the primitive types (Number, Boolean, String, null, and undefined), as well as complex types (Object and DisplayObject). Most type handling is hidden within the class. There are two different types of access to the as_value: converting and non-converting. Non-converting access Non-converting access is available for the complex types, for instance to_function() and toMovieClip(). In these cases, an object pointer is return only if the as_value is currently of the requested type. There are no ActionScript side-effects in such cases. Converting access The primitive types and Objects have converting access. This means that as_values of a different type are converted to the requested type. These functions may have ActionScript side-effects, for instance the calling of toString or valueOf, or construction of an object. It is possible to check the current type of an as_value using is_string(), is_number() etc. These functions have no ActionScript side effects.


Member Enumeration Documentation

Enumerator:
UNDEFINED 
UNDEFINED_EXCEPT 
NULLTYPE 
NULLTYPE_EXCEPT 
BOOLEAN 
BOOLEAN_EXCEPT 
STRING 
STRING_EXCEPT 
NUMBER 
NUMBER_EXCEPT 
OBJECT 
OBJECT_EXCEPT 
DISPLAYOBJECT 
DISPLAYOBJECT_EXCEPT 

Constructor & Destructor Documentation

DSOEXPORT gnash::as_value::as_value ( ) [inline]

Construct an undefined value.

Referenced by to_primitive().

DSOEXPORT gnash::as_value::as_value ( const as_value v) [inline]

Copy constructor.

gnash::as_value::~as_value ( ) [inline]
DSOEXPORT gnash::as_value::as_value ( const char *  str) [inline]

Construct a primitive String value.

DSOEXPORT gnash::as_value::as_value ( const std::string &  str) [inline]

Construct a primitive String value.

template<typename T >
gnash::as_value::as_value ( val,
typename boost::enable_if< boost::is_same< bool, T > >::type *  dummy = 0 
) [inline]

Construct a primitive Boolean value.

References UNUSED.

gnash::as_value::as_value ( double  num) [inline]

Construct a primitive Number value.

gnash::as_value::as_value ( as_object obj) [inline]

Construct a null, Object, or DisplayObject value.

References set_as_object().


Member Function Documentation

as_value::AsType gnash::as_value::defaultPrimitive ( int  version) const
bool gnash::as_value::equals ( const as_value v,
int  version 
) const

Return true if this value is abstractly equal to the given one.

See ECMA-262 abstract equality comparison (sect 11.9.3)

NOTE: these invariants should hold

  • A != B is equivalent to ! ( A == B )
  • A == B is equivalent to B == A, except for order of evaluation of A and B.
Parameters:
vThe as_value to compare to

References is_bool(), is_object(), is_undefined(), is_null(), is_number(), is_string(), gnash::key::p, test::v, to_primitive(), NUMBER, gnash::key::e, strictly_equals(), and equals().

Referenced by equals(), gnash::DumpGui::run(), gnash::abc::abstractEquality(), gnash::abc::Machine::execute(), and gnash::equals().

void gnash::as_value::flag_exception ( ) [inline]

References is_exception().

as_object * gnash::as_value::get_object ( ) const

Return the value as an as_object only if it is an as_object.

Note that this performs no conversion, so returns 0 if the as_value is not an object.

References OBJECT.

bool gnash::as_value::is_bool ( ) const [inline]

References BOOLEAN.

Referenced by equals().

bool gnash::as_value::is_exception ( ) const [inline]
bool gnash::as_value::is_function ( ) const

Return true if this value is a function.

References OBJECT, and gnash::as_object::to_function().

Referenced by to_string(), to_number(), typeOf(), writeAMF0(), gnash_view_call(), and gnash::abc::Machine::execute().

bool gnash::as_value::is_null ( ) const [inline]
bool gnash::as_value::is_number ( ) const [inline]

Return true if this value is strictly a number.

References NUMBER.

Referenced by equals(), gnash::DisplayObject::blendMode(), and gnash::abc::Machine::findSuper().

bool gnash::as_value::is_object ( ) const [inline]
bool gnash::as_value::is_sprite ( ) const [inline]

Return true if this value is a DISPLAYOBJECT.

References DISPLAYOBJECT.

Referenced by gnash::MovieClip::pathElement(), and gnash::newLessThan().

bool gnash::as_value::is_string ( ) const [inline]

Return true if this value is a string.

References STRING.

Referenced by to_string(), equals(), gnash_view_call(), gnash::newAdd(), and gnash::newLessThan().

bool gnash::as_value::is_undefined ( ) const [inline]
DSOEXPORT as_value& gnash::as_value::operator= ( const as_value v) [inline]

Assign to an as_value.

void gnash::as_value::set_as_object ( as_object obj)

Make this value a NULL, OBJECT, DISPLAYOBJECT value.

References set_null(), gnash::as_object::displayObject(), DISPLAYOBJECT, gnash::getRoot(), and OBJECT.

Referenced by as_value().

void gnash::as_value::set_bool ( bool  val)

Set to a primitive boolean.

References BOOLEAN.

Referenced by gnash::ExternalInterface::parseXML(), and gnash::convertToBoolean().

void gnash::as_value::set_double ( double  val)

Set to a primitive number.

References NUMBER.

Referenced by gnash::ExternalInterface::parseXML(), gnash::newAdd(), gnash::subtract(), and gnash::convertToNumber().

void gnash::as_value::set_null ( )
void gnash::as_value::set_string ( const std::string &  str)

Set to a primitive string.

References STRING.

Referenced by gnash::ExternalInterface::parseXML(), gnash::newAdd(), and gnash::convertToString().

void gnash::as_value::set_undefined ( )
void gnash::as_value::setReachable ( ) const
bool gnash::as_value::strictly_equals ( const as_value v) const

Return true if this value is strictly equal to the given one.

Strict equality is defined as the two values being of the same type and the same value.

Referenced by equals(), and gnash::abc::abstractEquality().

bool gnash::as_value::to_bool ( int  version) const

Conversion to boolean.

This function performs conversion if necessary.

References STRING, to_number(), gnash::isNaN(), NUMBER, gnash::key::d, BOOLEAN, OBJECT, DISPLAYOBJECT, assert, UNDEFINED, NULLTYPE, and is_exception().

Referenced by gnash::abc::Machine::execute(), gnash::toBool(), and gnash::convertToBoolean().

as_function * gnash::as_value::to_function ( ) const

Return the value as a function only if it is a function.

Note that this performs no conversion, so returns 0 if the as_value is not a function.

References OBJECT, and gnash::as_object::to_function().

Referenced by gnash::registerBitmapClass(), gnash::getClassConstructor(), gnash::abc::Machine::execute(), gnash::createTextFieldObject(), gnash::VM::getNative(), and gnash::xml_class_init().

double gnash::as_value::to_number ( int  version) const
as_object * gnash::as_value::to_object ( VM vm) const

Return value as an object, converting primitive values as needed.

This function performs conversion where necessary. string values are converted to String objects numeric values are converted to Number objects boolean values are converted to Boolean objects

If you want to avoid the conversion, check with is_object() before calling this function.

Parameters:
globalThe global object object for the conversion. This contains the prototypes or constructors necessary for conversion.

References OBJECT, DISPLAYOBJECT, gnash::getObject(), toDisplayObject(), STRING, gnash::NSV::CLASS_STRING, NUMBER, gnash::NSV::CLASS_NUMBER, BOOLEAN, and gnash::NSV::CLASS_BOOLEAN.

Referenced by gnash::abc::Class::addValue(), gnash::abc::Machine::execute(), gnash::abc::Method::addValue(), and gnash::toObject().

as_value gnash::as_value::to_primitive ( AsType  hint) const

Return value as a primitive type, with a preference.

This function performs no conversion. Primitive types are: undefined, null, boolean, string, number. See ECMA-2.6.2 (sections 4.3.2 and 8.6.2.6).

Parameters:
hintNUMBER or STRING, the preferred representation we're asking for.
Exceptions:
ActionTypeErrorif an object can't be converted to a primitive

References OBJECT, NUMBER, assert, gnash::NSV::PROP_VALUE_OF, as_value(), STRING, gnash::NSV::PROP_TO_STRING, gnash::getVM(), and gnash::invoke().

Referenced by to_string(), to_number(), equals(), gnash::newLessThan(), and gnash::convertToPrimitive().

std::string gnash::as_value::to_string ( int  version = 7) const
DisplayObject * gnash::as_value::toDisplayObject ( bool  skipRebinding = false) const

Return value as a DisplayObject or NULL if this is not possible.

Note that this function performs no conversion, so returns 0 if the as_value is not a DisplayObject. If the value is a DisplayObject value, the stored DisplayObject target is evaluated using the root movie's environment. If the target points to something that doesn't cast to a DisplayObject, 0 is returned.

Parameters:
skipRebindingIf true a reference to a destroyed DisplayObject is still returned, rather than attempting to resolve it as a soft-reference. Main use for this is during paths resolution, to avoid infinite loops. See bug #21647.

References DISPLAYOBJECT.

Referenced by to_object(), and gnash::MovieClip::pathElement().

MovieClip * gnash::as_value::toMovieClip ( bool  skipRebinding = false) const

Returns value as a MovieClip if it is a MovieClip.

This function performs no conversion, so returns 0 if the as_value is not a MovieClip. This is just a wrapper around toDisplayObject() performing an additional final cast.

References DISPLAYOBJECT, and gnash::DisplayObject::to_movie().

const char * gnash::as_value::typeOf ( ) const

Return the primitive type of this value as a string.

References UNDEFINED, STRING, NUMBER, BOOLEAN, OBJECT, is_function(), DISPLAYOBJECT, gnash::DisplayObject::to_movie(), NULLTYPE, and is_exception().

void gnash::as_value::unflag_exception ( ) [inline]

References is_exception().

bool gnash::as_value::writeAMF0 ( amf::Writer w) const

Serialize value in AMF0 format.

Parameters:
bufThe buffer to append serialized version of this value to.
offsetTableA map of already-parsed objects, pass an empty map on first call as it will be used internally.
vmVirtual machine to use for serialization of property names (string_table)
allowStrictArrayIf true strict arrays will be encoded a STRICT_ARRAY types.

References assert, is_exception(), _, OBJECT, is_function(), gnash::amf::Writer::writeObject(), STRING, gnash::amf::Writer::writeString(), NUMBER, gnash::amf::Writer::writeNumber(), DISPLAYOBJECT, UNDEFINED, gnash::amf::Writer::writeUndefined(), NULLTYPE, gnash::amf::Writer::writeNull(), BOOLEAN, and gnash::amf::Writer::writeBoolean().

Referenced by gnash::amf::Writer::writeObject().


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  o,
const as_value  
) [friend]

Stream operator.


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