예제 #1
0
파일: Class.cpp 프로젝트: aopui/gnash
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;
}
예제 #2
0
	//TODO: we should use a switch() instead of string compares.
	bool	as_point::set_member(const tu_stringi& name, const as_value& val)
	{
		if( name == "x" )
		{
			m_point.m_x = val.to_float();
			return true;
		}
		else if( name == "y" )
		{
			m_point.m_y = val.to_float();
			return true;
		}

		return as_object::set_member( name, val );
	}
예제 #3
0
	void as_xmlsock::send(const as_value& val) const
	{
		if (m_ns)
		{
			m_ns->write_string(val.to_tu_string(), XML_TIMEOUT);
		}
	}
예제 #4
0
	void	as_environment::set_variable (
	    const tu_string &varname,
	    const as_value &val,
	    const array<with_stack_entry>& with_stack )
	// Given a path to variable, set its value.
	{
		IF_VERBOSE_ACTION ( log_msg ( "-------------- %s = %s\n", varname.c_str(), val.to_string() ) ); //xxxxxxxxxx
		// Path lookup rigamarole.
		character	*target = get_target();
		tu_string	path;
		tu_string	var;

		if ( parse_path ( varname, &path, &var ) )
		{
			target = cast_to<character> ( find_target ( path.c_str() ) );

			if ( target )
			{
				target->set_member ( var, val );
			}
		}

		else
		{
			set_variable_raw ( varname, val, with_stack );
		}
	}
예제 #5
0
void
test_bool(as_value boolval)
{
    if (boolval.is_bool()) {
        runtest.pass("as_value(bool)");
    } else {
        runtest.fail("as_value(bool)");
    }
}
예제 #6
0
void
test_int(as_value val)
{
    if (val.is_number()) {
        runtest.pass("as_value(int)");
    } else {
        runtest.fail("as_value(int)");
    }
}
예제 #7
0
void
test_string(as_value val)
{
    if (val.is_string()) {
        runtest.pass("as_value(string)");
    } else {
        runtest.fail("as_value(string)");
    }
}
예제 #8
0
	void	as_environment::set_variable_raw (
	    const tu_string &varname,
	    const as_value &val,
	    const array<with_stack_entry>& with_stack )
	// No path rigamarole.
	{
		// Check the with-stack.
		for ( int i = with_stack.size() - 1; i >= 0; i-- )
		{
			as_object	*obj = with_stack[i].m_object.get_ptr();
			as_value unused;

			if ( obj && obj->get_member ( varname, &unused ) )
			{
				// This object has the member; so set it here.
				obj->set_member ( varname, val );
				return;
			}
		}

		// Check locals.
		int	local_index = find_local ( varname, true );

		if ( local_index >= 0 )
		{
			// Set local var.
			m_local_frames[local_index].m_value = val;
			return;
		}

		if ( m_target != NULL )
		{
			m_target->set_member ( varname, val );
		}

		else
		{
			// assume local var
			// This case happens for example so
			// class myclass
			// {
			//		function myfunc()
			//		{
			//			for (i=0;...)		should be for (var i=0; ...)
			//			{
			//			}
			//		}
			//	}
			add_local ( varname, val );
			IF_VERBOSE_ACTION ( log_error ( "can't set_variable_raw %s=%s, target is NULL, it's assumed as local\n",
			                                varname.c_str(), val.to_string() ) );
			IF_VERBOSE_ACTION ( log_error ( "probably you forgot to declare variable '%s'\n", varname.c_str() ) );
		}
	}
예제 #9
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() ) );
	}
예제 #10
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)
		{
			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 == v.to_object();

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

			default:
				assert(0);
				return false;
		}
	}
예제 #11
0
	void	as_value::operator=(const as_value& v)
	{
		switch (v.m_type)
		{
			case UNDEFINED:
				set_undefined();
				break;

			case NUMBER:
				set_double(v.m_number);
				m_flags = v.m_flags;
				break;

			case BOOLEAN:
				set_bool(v.m_bool);
				m_flags = v.m_flags;
				break;

			case STRING:
				set_tu_string(v.m_string);
				m_flags = v.m_flags;
				break;

			case OBJECT:
				set_as_object(v.m_object);
				m_flags = v.m_flags;
				break;

			case PROPERTY:
				drop_refs(); 
				
				// is binded property ?
				if (v.m_property_target == NULL)
				{
					m_type = PROPERTY;
					m_property = v.m_property;
					m_property_target = NULL;
				}
				else
				{
					v.get_property(this);
				}
				m_flags = v.m_flags;

				break;

			default:
				assert(0);
		}
	}
예제 #12
0
	bool	as_loadvars::set_member(const lfl_stringi& name, const as_value& val)
	{
		// todo: check for callbacks

		if( name == "onData"
			|| name == "onHTTPStatus"
			||name == "onLoad"
			)
		{
			return as_object::set_member( name, val );
		}

		m_values.set( name.to_lfl_string(), val.to_lfl_string() );

		return true;
	}
예제 #13
0
	bool	as_transform::set_member(const tu_stringi& name, const as_value& val)
	{
		as_transform_member	member = get_transform_member( name );

		switch (member)
		{
			case colorTransform:
			{
				m_color_transform = cast_to<as_color_transform>( val.to_object() );
				m_movie->set_cxform( m_color_transform->m_color_transform );
				return true;
			}
			case concatenatedColorTransform:
			{
				//read-only
				return true;
			}
			case matrix:
			{
				assert( false && "todo" );
				return true;
			}
			case concatenatedMatrix:
			{
				//read-only
				return true;
			}
			case pixelBounds:
			{
				assert( false && "todo" );
				return true;
			}
			default:
                                break;
		};

		return as_object::set_member( name, val );
	}
예제 #14
0
	// called from a object constructor only
	void	as_object::builtin_member(const tu_stringi& name, const as_value& val)
	{
		val.set_flags(as_value::DONT_ENUM);
		m_members.set(name, val);
	}
예제 #15
0
	void as_environment::set_register ( int reg, const as_value &val )
	{
		IF_VERBOSE_ACTION ( log_msg ( "-------------- set_register(%d): %s at %p\n",
		                              reg, val.to_string(), val.to_object() ) );
		*local_register_ptr ( reg ) = val;
	}
예제 #16
0
	bool	as_color_transform::set_member(const lfl_stringi& name, const as_value& val)
	{
		as_color_transform_member member = get_color_transform_member( name );

		switch( member )
		{
			case alphaOffset:
			{
				m_color_transform.m_[ 3 ][ 1 ] = val.to_float();
				return true;
			}

			case blueOffset:
			{
				m_color_transform.m_[ 2 ][ 1 ] = val.to_float();
				return true;
			}

			case greenOffset:
			{
				m_color_transform.m_[ 1 ][ 1 ] = val.to_float();
				return true;
			}

			case redOffset:
			{
				m_color_transform.m_[ 0 ][ 1 ] = val.to_float();
				return true;
			}

			case alphaMultiplier:
			{
				m_color_transform.m_[ 3 ][ 0 ] = val.to_float();
				return true;
			}

			case blueMultiplier:
			{
				m_color_transform.m_[ 2 ][ 0 ] = val.to_float();
				return true;
			}

			case greenMultiplier:
			{
				m_color_transform.m_[ 1 ][ 0 ] = val.to_float();
				return true;
			}

			case redMultiplier:
			{
				m_color_transform.m_[ 0 ][ 0 ] = val.to_float();
				return true;
			}

			case rgb:
			{
				int rgb;

				rgb = val.to_int();
				m_color_transform.m_[ 0 ][ 0 ] = 0.0f;
				m_color_transform.m_[ 1 ][ 0 ] = 0.0f;
				m_color_transform.m_[ 2 ][ 0 ] = 0.0f;
				m_color_transform.m_[ 3 ][ 0 ] = 0.0f;
				m_color_transform.m_[ 0 ][ 1 ] = static_cast<float>( ( rgb >> 16 ) & 0xFF );
				m_color_transform.m_[ 1 ][ 1 ] = static_cast<float>( ( rgb >> 8 ) & 0xFF );
				m_color_transform.m_[ 2 ][ 1 ] = static_cast<float>( rgb & 0xFF );
				m_color_transform.m_[ 3 ][ 1 ] = 255.0f;
				return true;
			}

			default:
				break;
		}

		return as_object::set_member( name, val );
	}
예제 #17
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();
}
예제 #18
0
 void operator()(const as_value& val) {
     _v.push_back(val.to_number());
 }
예제 #19
0
	as_property::as_property(const as_value& getter,	const as_value& setter)
	{
		m_getter = cast_to<as_function>(getter.to_object());
		m_setter = cast_to<as_function>(setter.to_object());
	}
예제 #20
0
	//ECMA-262 11.8.5
	as_value as_value::abstract_relational_comparison( const as_value & first, const as_value & second )
	{
		return as_value( first.to_number()  < second.to_number() );
		// todo
	}
예제 #21
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;
		}
	}