예제 #1
0
	bool as_value::abstract_equality_comparison( const as_value & first, const as_value & second )
	{
		if (first.type_of() == second.type_of())
		{
			if( first.is_undefined() ) return true;
			if( first.is_null() ) return true;

			if( first.is_number() )
			{
				double first_number = first.to_number();
				double second_number = second.to_number();
				if( first_number == get_nan() || second_number == get_nan() )
				{
					return false;
				}

				return first_number == second_number;
			}
			else if( first.is_string() )
			{
				return first.to_tu_string() == second.to_tu_string();
			}
			else if( first.is_bool() )
			{
				return first.to_bool() == second.to_bool();
			}

			//13.Return true if x and y refer to the same object or if they refer to objects joined to each other (see
			//13.1.2). Otherwise, return false.
			// TODO: treat joined object

			return first.to_object() == second.to_object();
		}
		else
		{

			if( first.is_null() && second.is_undefined() ) return true;
			if( second.is_null() && first.is_undefined() ) return true;

			if( ( first.is_number() && second.is_string() ) 
				|| (second.is_number() && first.is_string() ) )
			{
				return first.to_number() == second.to_number();
			}

			if( first.is_bool() || second.is_bool() ) return first.to_number() == second.to_number();

			// TODO:20.If Type(x) is either String or Number and Type(y) is Object,
			//return the result of the comparison x == ToPrimitive(y).
			//21.If Type(x) is Object and Type(y) is either String or Number,
			//return the result of the comparison ToPrimitive(x) == y.

			return false;
		}
	}
예제 #2
0
/// Convert an AS object to an XML string.
std::string
ExternalInterface::_toXML(const as_value &val)
{
    // GNASH_REPORT_FUNCTION;
    
    std::stringstream ss;
    
    if (val.is_string()) {
        ss << "<string>" << val.to_string() << "</string>";
    } else if (val.is_number()) {
        ss << "<number>" << val.to_string() << "</number>";
    } else if (val.is_undefined()) {
        ss << "<void/>";
    } else if (val.is_null()) {
        ss << "<null/>";
        // Exception isn't listed in any docs, but we'll use it for
        // marshallExceptions.
    } else if (val.is_exception()) {
        ss << "<exception>" << val.to_string()<< "</exception>";
    } else if (val.is_bool()) {
        ss << (val.to_bool(8) ? "<true/>" : "<false/>");
        // Function also isn't listed, but it's the only other type
        // supported by as_value, so leaving it out doesn't seem right.
    } else if (val.is_function()) {
        ss << "<function>" << val.to_string() << "</function>";
    } else if (val.is_object()) {
        as_object *obj = val.get_object();
        ss << _objectToXML(obj);
    } else {
        log_error(_("Can't convert unknown type %d"), val.to_string());
    }

    return ss.str();
}
예제 #3
0
	bool	as_value::operator==(const as_value& v) const
	// Return true if operands are equal.
	{
		// types don't match
		if (m_type != PROPERTY && v.m_type != PROPERTY && m_type != v.m_type)
		{
			if ((is_undefined() && v.is_null()) || (is_null() && v.is_undefined()))
			{
				return true;
			}
			return false;
		}

		switch (m_type)
		{
			case UNDEFINED:
				return v.m_type == UNDEFINED;

			case STRING:
				return m_string == v.to_tu_string();

			case NUMBER:
				return m_number == v.to_number();

			case BOOLEAN:
				return m_bool == v.to_bool();

			case OBJECT:
				return m_object.get() == v.to_object();

			case PROPERTY:
			{
				as_value prop;
				get_property(&prop);
				return prop == v;
			}

			default:
				assert(0);
				return false;
		}
	}