Gnash  0.8.11dev
Public Types | Public Member Functions | Friends | List of all members
gnash::as_value Class Reference

ActionScript value type. More...

#include <as_value.h>

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

Friends

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

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

§ AsType

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

§ as_value() [1/8]

DSOEXPORT gnash::as_value::as_value ( )
inline

Construct an undefined value.

Referenced by gnash::doubleToString(), and to_primitive().

§ as_value() [2/8]

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

Copy constructor.

§ as_value() [3/8]

DSOEXPORT gnash::as_value::as_value ( as_value &&  other)
inline

Move constructor.

§ ~as_value()

gnash::as_value::~as_value ( )
inline

§ as_value() [4/8]

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

Construct a primitive String value.

§ as_value() [5/8]

DSOEXPORT gnash::as_value::as_value ( std::string  str)
inline

Construct a primitive String value.

References gnash::key::T, and gnash::key::U.

§ as_value() [6/8]

template<typename T , typename U = typename std::enable_if<std::is_same<bool, T>::value>::type>
gnash::as_value::as_value ( val)
inline

Construct a primitive Boolean value.

§ as_value() [7/8]

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

Construct a primitive Number value.

§ as_value() [8/8]

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

Construct a null, Object, or DisplayObject value.

Member Function Documentation

§ defaultPrimitive()

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

§ equals()

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 gnash::key::e, equals(), is_bool(), is_null(), is_number(), is_object(), is_string(), is_undefined(), NUMBER, gnash::key::p, strictly_equals(), to_primitive(), and test::v.

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

§ flag_exception()

void gnash::as_value::flag_exception ( )
inline

§ get_object()

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.

§ is_bool()

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

§ is_exception()

bool gnash::as_value::is_exception ( ) const
inline

§ is_function()

bool gnash::as_value::is_function ( ) const

§ is_null()

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

§ is_number()

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

§ is_object()

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

§ is_sprite()

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

Return true if this value is a DISPLAYOBJECT.

References DSOTEXPORT.

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

§ is_string()

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

§ is_undefined()

bool gnash::as_value::is_undefined ( ) const
inline

§ operator=() [1/2]

DSOEXPORT as_value& gnash::as_value::operator= ( const as_value v)
inline

Assign to an as_value.

§ operator=() [2/2]

DSOEXPORT as_value& gnash::as_value::operator= ( as_value &&  other)
inline

§ set_as_object()

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

Make this value a NULL, OBJECT, DISPLAYOBJECT value.

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

Referenced by gnash::parsePath().

§ set_bool()

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

§ set_double()

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

§ set_null()

void gnash::as_value::set_null ( )

§ set_string()

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

§ set_undefined()

void gnash::as_value::set_undefined ( )

§ setReachable()

void gnash::as_value::setReachable ( ) const

Set any object value as reachable (for the GC)

Object values are values stored by pointer (objects and functions)

References DISPLAYOBJECT, gnash::CharacterProxy::get(), OBJECT, gnash::GcResource::setReachable(), and gnash::CharacterProxy::setReachable().

Referenced by gnash::CallFrame::markReachableResources(), gnash::VM::markReachableResources(), and gnash::FunctionArgs< T >::setReachable().

§ strictly_equals()

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 gnash::abc::abstractEquality(), gnash::doubleToString(), and equals().

§ to_bool()

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

Conversion to boolean.

This function performs conversion if necessary.

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

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

§ to_function()

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

§ to_number()

double gnash::as_value::to_number ( int  version) const

§ to_object()

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 BOOLEAN, gnash::NSV::CLASS_BOOLEAN, gnash::NSV::CLASS_NUMBER, gnash::NSV::CLASS_STRING, DISPLAYOBJECT, gnash::getObject(), NUMBER, OBJECT, STRING, and toDisplayObject().

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

§ to_primitive()

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 as_value(), gnash::getVM(), gnash::invoke(), gnash::log_debug(), NUMBER, OBJECT, gnash::NSV::PROP_TO_STRING, gnash::NSV::PROP_VALUE_OF, and STRING.

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

§ to_string()

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

Get a std::string representation for this value.

Parameters
versionThe 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, gnash::key::s, STRING, to_primitive(), UNDEFINED, and gnash::String_as::value().

Referenced by gnash::abc::abstractEquality(), gnash::arrayKey(), gnash::XMLNode_as::clearChildren(), gnash::color_class_init(), gnash::convertToString(), gnash::dump_callbacks(), gnash::SWF::SWFHandlers::execute(), gnash::abc::Machine::execute(), gnash::externalinterface_class_init(), gnash::MovieClip::get_frame_number(), gnash::TextField::getDefinitionVersion(), gnash_view_call(), gnash::gtkext_signal_connect(), gnash::initObjectClass(), gnash::moviecliploader_class_init(), gnash::newAdd(), gnash::newLessThan(), gnash::amf::Reader::operator()(), gnash::movie_root::processInvoke(), gnash::registerLocalConnectionNative(), gnash::registerMovieClipNative(), gnash::registerSelectionNative(), gnash::registerSharedObjectNative(), gnash::registerTextFieldNative(), gnash::registerXMLNative(), gnash::registerXMLSocketNative(), gnash::as_object::setPropFlags(), gnash::MovieClip::setTextFieldVariables(), gnash::string_class_init(), gnash::NetConnection_as::update(), and gnash::DisplayObject::MaskRenderer::~MaskRenderer().

§ toDisplayObject()

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 gnash::MovieClip::pathElement(), to_object(), and typeOf().

§ toMovieClip()

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

Referenced by gnash::color_class_init().

§ typeOf()

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

§ unflag_exception()

void gnash::as_value::unflag_exception ( )
inline

§ writeAMF0()

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 _, BOOLEAN, DISPLAYOBJECT, is_exception(), is_function(), gnash::log_unimpl(), 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().

Friends And Related Function Documentation

§ operator<<

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

Stream operator.


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