Public Types | Public Member Functions

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 char *str)
 Construct a primitive String value.
DSOEXPORT as_value (const std::string &str)
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 val)
 Construct a primitive Number value.
 as_value (as_object *obj)
 Construct a null, Object, or DisplayObject value.
DSOEXPORT as_value (const as_value &value)
 Copy constructor.
const char * typeOf () const
 Return the primitive type of this value as a string.
primitive_types ptype () const
 Get the primitive type of this value.
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 () const
 Get a number representation for this value.
bool to_bool () const
 Conversion to boolean.
as_objectto_object (Global_as &global) const
 Return value as an object, converting primitive values as needed.
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.
DSOEXPORT std::string toDebugString () const
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.
DSOEXPORT void operator= (const as_value &v)
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) 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.

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

gnash::as_value::as_value (  ) 

Construct an undefined value.

Referenced by to_primitive().

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

Construct a primitive String value.

gnash::as_value::as_value ( const std::string &  str  ) 
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  val  ) 

Construct a primitive Number value.

gnash::as_value::as_value ( as_object obj  ) 

Construct a null, Object, or DisplayObject value.

References set_as_object().

gnash::as_value::as_value ( const as_value value  ) 

Copy constructor.


Member Function Documentation

as_value::AsType gnash::as_value::defaultPrimitive ( int  version  )  const

References s2x::d, gnash::isNativeType(), and OBJECT.

bool gnash::as_value::equals ( const as_value v  )  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:
v The as_value to compare to

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

Referenced by equals().

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

References is_exception().

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

References BOOLEAN.

Referenced by equals(), main(), and gnash::ExternalInterface::toXML().

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 gnash_view_call(), to_number(), to_string(), gnash::ExternalInterface::toXML(), typeOf(), and writeAMF0().

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

References NULLTYPE.

Referenced by equals(), and gnash::ExternalInterface::toXML().

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

Return true if this value is strictly a number.

Referenced by gnash::DisplayObject::blendMode(), equals(), and gnash::ExternalInterface::toXML().

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

Return true if this value is an object.

Both DisplayObjects and Objects count as Objects

References OBJECT.

Referenced by gnash::abc::Method::addValue(), gnash::abc::Class::addValue(), equals(), and gnash::ExternalInterface::toXML().

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

Return true if this value is a DISPLAYOBJECT.

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

Return true if this value is a string.

Referenced by equals(), gnash_view_call(), to_string(), and gnash::ExternalInterface::toXML().

bool gnash::as_value::is_undefined (  )  const [inline]
void gnash::as_value::operator= ( const as_value v  ) 
primitive_types gnash::as_value::ptype (  )  const

Get the primitive type of this value.

This is only used in AVM2.

Only used in AVM2

References BOOLEAN, DISPLAYOBJECT, NULLTYPE, NUMBER, OBJECT, STRING, and UNDEFINED.

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

Make this value a NULL, OBJECT, DISPLAYOBJECT value.

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

Referenced by as_value().

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

Set to a primitive boolean.

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

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

Set to a primitive string.

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

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 main().

bool gnash::as_value::to_bool (  )  const
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::DisplayObject::hasEventHandler().

double gnash::as_value::to_number (  )  const

Get a number representation for this value.

This function performs conversion if necessary.

References _, BOOLEAN, s2x::d, DISPLAYOBJECT, gnash::key::e, gnash::get(), is_function(), NULLTYPE, NUMBER, OBJECT, gnash::parseNonDecimalInt(), s, STRING, to_number(), to_primitive(), and UNDEFINED.

Referenced by gnash::DisplayObject::blendMode(), main(), gnash::setHeight(), to_bool(), and to_number().

as_object * gnash::as_value::to_object ( Global_as global  )  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:
global The global object object for the conversion. This contains the prototypes or constructors necessary for conversion.

References BOOLEAN, gnash::Global_as::createBoolean(), gnash::Global_as::createNumber(), gnash::Global_as::createString(), DISPLAYOBJECT, gnash::getObject(), NUMBER, OBJECT, STRING, and toDisplayObject().

Referenced by gnash::abc::Method::addValue(), gnash::abc::Class::addValue(), gnash::AVM1Global::createArray(), gnash::invoke(), and gnash::XMLNode_as::object().

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:
hint NUMBER or STRING, the preferred representation we're asking for.
Exceptions:
ActionTypeError if an object can't be converted to a primitive

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

Referenced by equals(), to_number(), and to_string().

std::string gnash::as_value::to_string ( int  version = 7  )  const

Get a std::string representation for this value.

Parameters:
version The SWF version to use to transform the string. This only affects undefined values, which trace "undefined" for version 7 and above, nothing for lower versions. TODO: drop the default argument.

References BOOLEAN, DISPLAYOBJECT, gnash::doubleToString(), gnash::key::e, gnash::CharacterProxy::get(), gnash::CharacterProxy::getTarget(), is_function(), is_string(), gnash::isNativeType(), NULLTYPE, NUMBER, OBJECT, s, STRING, to_primitive(), UNDEFINED, and gnash::String_as::value().

Referenced by gnash::DisplayObject::blendMode(), gnash::dump_callbacks(), gnash_view_call(), gnash::gtkext_signal_connect(), main(), and gnash::ExternalInterface::toXML().

std::string gnash::as_value::toDebugString (  )  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:
skipRebinding If 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().

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 BOOLEAN, DISPLAYOBJECT, is_exception(), is_function(), NULLTYPE, NUMBER, OBJECT, STRING, gnash::DisplayObject::to_movie(), and UNDEFINED.

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:
buf The buffer to append serialized version of this value to.
offsetTable A map of already-parsed objects, pass an empty map on first call as it will be used internally.
vm Virtual machine to use for serialization of property names (string_table)
allowStrictArray If true strict arrays will be encoded a STRICT_ARRAY types.

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


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