Пример #1
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();
}
Пример #2
0
bool
Class::addValue(string_table::key name, Namespace *ns,
        std::uint32_t slotId, Class *type, as_value& val, bool isconst,
        bool isstatic)
{
    Global_as* g = VM::get().getGlobal();

    if (val.is_object()) {
		val.to_object(*g)->set_member(NSV::INTERNAL_TYPE, type->getName());
    }

	string_table::key nsname = ns ? ns->getURI() : string_table::key(0);

	int flags = PropFlags::dontDelete;
	if (isconst)
		flags |= PropFlags::readOnly;
	if (isstatic)
		flags |= PropFlags::staticProp;

    const ObjectURI uri(name, nsname);

	if (slotId == 0) {
		_prototype->init_member(uri, val, flags);
	}
	else {
		_prototype->init_member(uri, val, flags, slotId);
	}
	return true;
}
Пример #3
0
	void as_environment::set_target ( as_value &target, character *original_target )
	{
		if ( target.is_string() )
		{
			tu_string path = target.to_tu_string();
			IF_VERBOSE_ACTION ( log_msg ( "-------------- ActionSetTarget2: %s", path.c_str() ) );

			if ( path.size() > 0 )
			{
				character *tar = cast_to<character> ( find_target ( path.c_str() ) );

				if ( tar )
				{
					set_target ( tar );
					return;
				}
			}

			else
			{
				set_target ( original_target );
				return;
			}
		}

		else if ( target.is_object() )
		{
			IF_VERBOSE_ACTION ( log_msg ( "-------------- ActionSetTarget2: %s", target.to_string() ) );
			character *tar = cast_to<character> ( find_target ( target ) );

			if ( tar )
			{
				set_target ( tar );
				return;
			}
		}

		IF_VERBOSE_ACTION ( log_msg ( "can't set target %s\n", target.to_string() ) );
	}