Gnash
0.8.11dev
|
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_value & | operator= (const as_value &v) |
Assign to an as_value. More... | |
DSOEXPORT as_value & | operator= (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_object * | to_object (VM &vm) const |
Return value as an object, converting primitive values as needed. More... | |
as_object * | get_object () const |
Return the value as an as_object only if it is an as_object. More... | |
MovieClip * | toMovieClip (bool skipRebinding=false) const |
Returns value as a MovieClip if it is a MovieClip. More... | |
DisplayObject * | toDisplayObject (bool skipRebinding=false) const |
Return value as a DisplayObject or NULL if this is not possible. More... | |
as_function * | to_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... | |
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.
|
inline |
Construct an undefined value.
Referenced by gnash::doubleToString(), and to_primitive().
|
inline |
|
inline |
Construct a primitive String value.
|
inline |
Construct a primitive String value.
References gnash::key::T, and gnash::key::U.
|
inline |
Construct a primitive Boolean value.
|
inline |
Construct a primitive Number value.
|
inline |
Construct a null, Object, or DisplayObject value.
as_value::AsType gnash::as_value::defaultPrimitive | ( | int | version | ) | const |
References gnash::key::d, gnash::isNativeType(), NUMBER, OBJECT, and STRING.
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 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().
|
inline |
Referenced by gnash::SWF::SWFHandlers::execute().
as_object * gnash::as_value::get_object | ( | ) | const |
|
inline |
|
inline |
Referenced by gnash::ActionExec::operator()(), gnash::operator<<(), to_bool(), typeOf(), and writeAMF0().
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::doubleToString(), gnash::abc::Machine::execute(), gnash_view_call(), gnash::initObjectClass(), to_number(), to_string(), typeOf(), and writeAMF0().
|
inline |
Referenced by equals(), gnash::abc::Machine::execute(), gnash::externalinterface_class_init(), gnash::abc::Machine::findSuper(), gnash::initObjectClass(), gnash::rectangle_class_init(), gnash::registerMovieClipNative(), gnash::registerSelectionNative(), gnash::registerSoundNative(), gnash::registerTextFieldNative(), gnash::setIndexedProperty(), gnash::as_object::setPropFlags(), gnash::NetConnection_as::update(), and gnash::DisplayObject::MaskRenderer::~MaskRenderer().
|
inline |
Return true if this value is strictly a number.
Referenced by gnash::doubleToString(), equals(), gnash::externalinterface_class_init(), gnash::abc::Machine::findSuper(), and gnash::registerMovieClipNative().
|
inline |
Return true if this value is an object.
Both DisplayObjects and Objects count as Objects
Referenced by gnash::abc::abstractEquality(), gnash::abc::Class::addValue(), gnash::abc::Method::addValue(), gnash::as_function::construct(), gnash::doubleToString(), equals(), gnash::externalinterface_class_init(), gnash::abc::Machine::findSuper(), gnash::as_object::get_member(), gnash::abc::Machine::getMember(), gnash::getPathElement(), gnash::AsBroadcaster::init(), gnash::matrix_class_init(), gnash::newLessThan(), gnash::MovieClip::pathElement(), gnash::point_class_init(), gnash::registerBitmapDataNative(), gnash::registerXMLNative(), and gnash::abc::Machine::setMember().
|
inline |
Return true if this value is a DISPLAYOBJECT.
References DSOTEXPORT.
Referenced by gnash::SWF::SWFHandlers::execute(), gnash::newLessThan(), and gnash::MovieClip::pathElement().
|
inline |
Return true if this value is a string.
Referenced by gnash::doubleToString(), equals(), gnash::externalinterface_class_init(), gnash_view_call(), gnash::newAdd(), gnash::newLessThan(), gnash::registerLocalConnectionNative(), gnash::registerSelectionNative(), to_string(), and gnash::DisplayObject::MaskRenderer::~MaskRenderer().
|
inline |
Referenced by gnash::arrayLength(), gnash::VM::dumpState(), equals(), gnash::abc::Machine::execute(), gnash::externalinterface_class_init(), gnash::abc::Machine::findSuper(), gnash::initObjectClass(), gnash::invoke(), gnash::loadvars_class_init(), gnash::rectangle_class_init(), gnash::registerMovieClipNative(), gnash::registerSelectionNative(), gnash::registerSoundNative(), gnash::registerTextFieldNative(), gnash::registerXMLNative(), gnash::setIndexedProperty(), gnash::string_class_init(), gnash::NetConnection_as::update(), and gnash::DisplayObject::MaskRenderer::~MaskRenderer().
References gnash::key::o, and gnash::operator<<().
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().
void gnash::as_value::set_bool | ( | bool | val | ) |
Set to a primitive boolean.
References BOOLEAN.
Referenced by gnash::convertToBoolean(), gnash::SWF::SWFHandlers::execute(), gnash::abc::AbcBlock::locateClass(), and gnash::ExternalInterface::parseXML().
void gnash::as_value::set_double | ( | double | val | ) |
Set to a primitive number.
References NUMBER.
Referenced by gnash::convertToNumber(), gnash::SWF::SWFHandlers::execute(), gnash::abc::AbcBlock::locateClass(), gnash::matrix_class_init(), gnash::newAdd(), gnash::ExternalInterface::parseXML(), gnash::point_class_init(), gnash::setNaN(), mysqldb::size_method(), gnash::subtract(), and gnash::textformat_class_init().
void gnash::as_value::set_null | ( | ) |
Set this value to the NULL value.
References NULLTYPE.
Referenced by gnash::SWF::SWFHandlers::execute(), gnash::abc::Machine::execute(), gnash::externalinterface_class_init(), gnash::abc::AbcBlock::locateClass(), gnash::ExternalInterface::parseXML(), gnash::Global_as::registerClasses(), gnash::registerSelectionNative(), gnash::registerSharedObjectNative(), gnash::registerTextFieldNative(), set_as_object(), mysqldb::size_method(), gnash::textformat_class_init(), gnash::xmlnode_class_init(), and gnash::DisplayObject::MaskRenderer::~MaskRenderer().
void gnash::as_value::set_string | ( | const std::string & | str | ) |
Set to a primitive string.
References STRING.
Referenced by gnash::convertToString(), gnash::SWF::SWFHandlers::execute(), gnash::abc::AbcBlock::locateClass(), gnash::newAdd(), gnash::ExternalInterface::parseXML(), mysqldb::size_method(), and gnash::textformat_class_init().
void gnash::as_value::set_undefined | ( | ) |
Set to undefined.
References UNDEFINED.
Referenced by gnash::movie_root::callExternalCallback(), gnash::SWF::SWFHandlers::execute(), gnash::getIndexedProperty(), gnash::ExternalInterface::parseXML(), and mysqldb::size_method().
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().
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().
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().
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::contextmenuitem_class_init(), gnash::Global_as::createClass(), gnash::Global_as::createFunction(), gnash::createTextFieldObject(), gnash::doubleToString(), gnash::abc::Machine::execute(), gnash::getClassConstructor(), gnash::VM::getNative(), gnash::initObjectClass(), gnash::Global_as::makeObject(), gnash::matrix_class_init(), gnash::amf::Reader::operator()(), gnash::rectangle_class_init(), gnash::registerBitmapClass(), gnash::registerBitmapDataNative(), gnash::registerDateNative(), gnash::registerLocalConnectionNative(), gnash::registerSharedObjectNative(), gnash::registerTextFieldNative(), gnash::registerXMLSocketNative(), gnash::transform_class_init(), 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 BOOLEAN, gnash::key::d, DISPLAYOBJECT, gnash::key::e, is_function(), gnash::log_debug(), NULLTYPE, NUMBER, OBJECT, gnash::parseNonDecimalInt(), gnash::key::s, STRING, to_number(), to_primitive(), and UNDEFINED.
Referenced by gnash::convertToNumber(), gnash::doubleToString(), gnash::abc::Machine::execute(), to_bool(), to_number(), gnash::toInt(), and gnash::toNumber().
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 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().
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 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().
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 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().
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 gnash::MovieClip::pathElement(), to_object(), and typeOf().
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().
const char * gnash::as_value::typeOf | ( | ) | const |
Return the primitive type of this value as a string.
References gnash::key::a, gnash::key::b, BOOLEAN, DISPLAYOBJECT, is_exception(), is_function(), gnash::isNaN(), NULLTYPE, NUMBER, OBJECT, STRING, gnash::DisplayObject::to_movie(), toDisplayObject(), UNDEFINED, and test::v.
|
inline |
References gnash::key::d, gnash::doubleToString(), DSOEXPORT, DSOTEXPORT, gnash::equals(), gnash::operator!=(), gnash::operator<<(), gnash::operator==(), gnash::parseNonDecimalInt(), gnash::key::s, test::v, and test::w.
Referenced by gnash::ActionExec::operator()().
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 _, 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().
|
friend |
Stream operator.