org.mozilla.javascript.debug.DebuggableObject Java Examples

The following examples show how to use org.mozilla.javascript.debug.DebuggableObject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JsValue.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private VMVariable[] getMembersImpl( Context cx )
{
	if ( reservedValueType != null )
	{
		return NO_CHILD;
	}

	Object valObj = value;

	if ( value instanceof NativeJavaObject )
	{
		valObj = ( (NativeJavaObject) value ).unwrap( );
	}

	if ( valObj == null || valObj.getClass( ).isPrimitive( ) || isPrimitive )
	{
		return NO_CHILD;
	}

	List children = new ArrayList( );

	if ( valObj.getClass( ).isArray( ) )
	{
		int len = Array.getLength( valObj );

		boolean primitive = valObj.getClass( )
				.getComponentType( )
				.isPrimitive( );

		for ( int i = 0; i < len; i++ )
		{
			Object aobj = Array.get( valObj, i );

			if ( isValidJsValue( aobj ) )
			{
				children.add( new JsVariable( aobj, "[" //$NON-NLS-1$
						+ children.size( )
						+ "]", primitive ) ); //$NON-NLS-1$
			}
		}
	}
	else if ( valObj instanceof Scriptable )
	{
		Object[] ids;

		if ( valObj instanceof DebuggableObject )
		{
			ids = ( (DebuggableObject) valObj ).getAllIds( );
		}
		else
		{
			ids = ( (Scriptable) valObj ).getIds( );
		}

		if ( ids == null || ids.length == 0 )
		{
			return NO_CHILD;
		}

		for ( int i = 0; i < ids.length; i++ )
		{
			if ( ids[i] instanceof String )
			{
				Object val = ScriptableObject.getProperty( (Scriptable) valObj,
						(String) ids[i] );

				if ( val instanceof NativeJavaObject )
				{
					val = ( (NativeJavaObject) val ).unwrap( );
				}

				if ( isValidJsValue( val ) )
				{
					children.add( new JsVariable( val, (String) ids[i] ) );
				}
			}
		}
	}
	else
	{
		// refelct native java objects
		reflectMembers( valObj, children );
	}

	if ( children.size( ) == 0 )
	{
		return NO_CHILD;
	}

	Collections.sort( children );

	return (VMVariable[]) children.toArray( new VMVariable[children.size( )] );
}