Gnash
0.8.10
|
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. | |
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_value & | operator= (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_object * | to_object (VM &vm) const |
Return value as an object, converting primitive values as needed. | |
as_object * | get_object () const |
Return the value as an as_object only if it is an as_object. | |
MovieClip * | toMovieClip (bool skipRebinding=false) const |
Returns value as a MovieClip if it is a MovieClip. | |
DisplayObject * | toDisplayObject (bool skipRebinding=false) const |
Return value as a DisplayObject or NULL if this is not possible. | |
as_function * | to_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. |
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.
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.
gnash::as_value::as_value | ( | T | 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().
as_value::AsType gnash::as_value::defaultPrimitive | ( | int | version | ) | const |
References OBJECT, gnash::key::d, gnash::isNativeType(), STRING, and NUMBER.
Referenced by gnash::convertToPrimitive().
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
v | The 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 |
bool gnash::as_value::is_exception | ( | ) | const [inline] |
References UNDEFINED_EXCEPT, NULLTYPE_EXCEPT, BOOLEAN_EXCEPT, NUMBER_EXCEPT, OBJECT_EXCEPT, DISPLAYOBJECT_EXCEPT, and STRING_EXCEPT.
Referenced by gnash::ActionExec::operator()(), to_bool(), typeOf(), writeAMF0(), gnash::operator<<(), flag_exception(), and unflag_exception().
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] |
Return true if this value is an object.
Both DisplayObjects and Objects count as Objects
References OBJECT, and DISPLAYOBJECT.
Referenced by gnash::as_object::get_member(), gnash::getPathElement(), equals(), gnash::abc::Class::addValue(), gnash::abc::abstractEquality(), gnash::abc::Machine::getMember(), gnash::abc::Machine::setMember(), gnash::abc::Machine::findSuper(), gnash::abc::Method::addValue(), gnash::MovieClip::pathElement(), and gnash::newLessThan().
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] |
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 | ( | ) |
Set this value to the NULL value.
References NULLTYPE.
Referenced by set_as_object(), gnash::ExternalInterface::parseXML(), gnash::Global_as::registerClasses(), and gnash::abc::Machine::execute().
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 | ( | ) |
Set to undefined.
References UNDEFINED.
Referenced by gnash::abc::BoundValue::BoundValue(), gnash::getIndexedProperty(), and gnash::ExternalInterface::parseXML().
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 OBJECT, gnash::GcResource::setReachable(), DISPLAYOBJECT, and gnash::CharacterProxy::setReachable().
Referenced by gnash::Trigger::setReachable(), gnash::CallFrame::markReachableResources(), gnash::DelayedFunctionCall::setReachable(), gnash::FunctionArgs::setReachable(), gnash::GetterSetter::UserDefinedGetterSetter::markReachableResources(), gnash::Property::SetReachable::operator()(), and gnash::VM::markReachableResources().
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 |
Get a number representation for this value.
This function performs conversion if necessary.
References STRING, gnash::key::s, gnash::key::d, gnash::parseNonDecimalInt(), NULLTYPE, UNDEFINED, BOOLEAN, NUMBER, OBJECT, to_primitive(), to_number(), gnash::key::e, is_function(), and DISPLAYOBJECT.
Referenced by to_number(), to_bool(), gnash::abc::Machine::execute(), gnash::toNumber(), gnash::toInt(), and gnash::convertToNumber().
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.
global | The 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().
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).
hint | NUMBER or STRING, the preferred representation we're asking for. |
ActionTypeError | if 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 |
Get a std::string representation for this value.
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 STRING, DISPLAYOBJECT, gnash::CharacterProxy::get(), gnash::CharacterProxy::getTarget(), NUMBER, gnash::doubleToString(), UNDEFINED, NULLTYPE, BOOLEAN, OBJECT, gnash::key::s, gnash::isNativeType(), gnash::String_as::value(), to_primitive(), is_string(), gnash::key::e, and is_function().
Referenced by gnash::as_object::setPropFlags(), gnash::DisplayObject::blendMode(), gnash_view_call(), gnash::dump_callbacks(), gnash::gtkext_signal_connect(), gnash::abc::abstractEquality(), gnash::abc::Machine::execute(), gnash::MovieClip::get_frame_number(), gnash::MovieClip::setTextFieldVariables(), gnash::newAdd(), gnash::newLessThan(), and gnash::convertToString().
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.
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(), 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.
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 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().
std::ostream& operator<< | ( | std::ostream & | o, |
const as_value & | |||
) | [friend] |
Stream operator.