You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ha...@apache.org on 2016/08/04 05:29:30 UTC

[01/15] git commit: [flex-asjs] [refs/heads/refactor-sprite] - [Improvement] Numerous updates to BinaryData to get closer to flash IDataInput and IDataOutput interfaces. Endian now detects default Endianness. IBinaryDataInput and IBinaryDataOutput interf

Repository: flex-asjs
Updated Branches:
  refs/heads/refactor-sprite 184ef2d81 -> 7ac452972


[Improvement] Numerous updates to BinaryData to get closer to flash IDataInput and IDataOutput interfaces.
Endian now detects default Endianness. IBinaryDataInput and IBinaryDataOutput interfaces added


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/641301b0
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/641301b0
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/641301b0

Branch: refs/heads/refactor-sprite
Commit: 641301b0c5a070ebf65b69cbf0a1dee9dcdb6b72
Parents: 9636454
Author: greg-dove <gr...@gmail.com>
Authored: Fri Jul 22 20:01:38 2016 +1200
Committer: greg-dove <gr...@gmail.com>
Committed: Fri Jul 22 20:01:38 2016 +1200

----------------------------------------------------------------------
 .../flex/org/apache/flex/utils/BinaryData.as    | 1019 ++++++++++++------
 .../main/flex/org/apache/flex/utils/Endian.as   |   44 +-
 .../org/apache/flex/utils/IBinaryDataInput.as   |   47 +
 .../org/apache/flex/utils/IBinaryDataOutput.as  |   42 +
 4 files changed, 803 insertions(+), 349 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/641301b0/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
index 6aec4d2..1260dae 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
@@ -18,59 +18,60 @@
 ////////////////////////////////////////////////////////////////////////////////
 package org.apache.flex.utils
 {
+
 COMPILE::SWF
 {
     import flash.utils.ByteArray;
 }
 
-    
+
 /**
  *  The BinaryData class is a class that represents binary data.  The way
  *  browsers handle binary data varies.  This class abstracts those
- *  differences..  
- *  
+ *  differences..
+ *
  *  @langversion 3.0
  *  @playerversion Flash 10.2
  *  @playerversion AIR 2.6
  *  @productversion FlexJS 0.0
  */
-public class BinaryData
+public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
 {
     /**
      *  Constructor. The constructor takes an optional bytes argument.
      *  In Flash this should be a ByteArray. In JS this should be an ArrayBuffer
-     *  
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
     COMPILE::SWF
-	public function BinaryData(bytes:ByteArray = null)
-	{
+    public function BinaryData(bytes:ByteArray = null)
+    {
         ba = bytes ? bytes : new ByteArray();
     }
 
     COMPILE::JS
     public function BinaryData(bytes:ArrayBuffer = null)
-    {    
+    {
         ba = bytes ? bytes : new ArrayBuffer(0);
     }
-	
-	/**
-	 *  Utility method to create a BinaryData object from a string.
-	 *  
-	 *  @langversion 3.0
-	 *  @playerversion Flash 10.2
-	 *  @playerversion AIR 2.6
-	 *  @productversion FlexJS 0.7.0
-	 */        
-	public static function fromString(str:String):BinaryData
-	{
-		var bd:BinaryData = new BinaryData();
-		bd.writeUTFBytes(str);
-		return bd;
-	}
+
+    /**
+     *  Utility method to create a BinaryData object from a string.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.7.0
+     */
+    public static function fromString(str:String):BinaryData
+    {
+        var bd:BinaryData = new BinaryData();
+        bd.writeUTFBytes(str);
+        return bd;
+    }
 
     /**
      *  Gets a reference to the internal array of bytes.
@@ -78,408 +79,702 @@ public class BinaryData
      *  On the JS side, it's a Uint8Array.
      *  This is primarily used for indexed access to the bytes, and internally
      *  where the platform-specific implementation is significant.
-     *  
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.7.0
      */
-     COMPILE::SWF
-     public function get array():ByteArray
-     {
+    COMPILE::SWF
+    public function get array():ByteArray
+    {
         return ba;
-     }
+    }
 
     /**
      *  Gets a reference to the internal array of bytes.
      *  On the Flash side, this is  a ByteArray.
      *  On the JS side, it's a Uint8Array.
-     *  This is primarily used for indexed access to the bytes, and internally
-     *  where the platform-specific implementation is significant.
-     *  
+     *  This is primarily used for indexed (Array) access to the bytes, particularly
+     *  where platform-specific performance optimization is required.
+     *  To maintain cross-target consistency, you should not alter the length
+     *  of the ByteArray in any swf specific code, assume its length is fixed
+     *  (even though it is not).
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.7.0
      */
-     COMPILE::JS
-     public function get array():Uint8Array
-     {
+    COMPILE::JS
+    public function get array():Uint8Array
+    {
         return getTypedArray();
-     }
-
-	private var _endian:String = Endian.DEFAULT;
-
-	/**
-	 *  Indicates the byte order for the data.
-	 *  The default is "default" which in Javascript is machine dependent.
-	 *  To ensure portable bytes, set the endian to big or little as appropriate.
-	 *  
-	 *  @langversion 3.0
-	 *  @playerversion Flash 10.2
-	 *  @playerversion AIR 2.6
-	 *  @productversion FlexJS 0.7.0
-	 */        
-	public function get endian():String
-	{
-		return _endian;
-	}
-	
-	public function set endian(value:String):void
-	{
-		_endian = value;
-		
-		COMPILE::SWF
-		{
-			if(value == Endian.DEFAULT)
-				ba.endian = Endian.BIG_ENDIAN;
-			else
-				ba.endian = value;
-		}
-	}
+    }
+    COMPILE::JS
+    private var _endian:String = Endian.defaultEndian;
+
+    /**
+     *  Indicates the byte order for the data.
+     *  The default is the target default which in Javascript is machine dependent.
+     *  It is possible to check the default Endianness of the target platform at runtime with
+     *  <code>org.apache.flex.utils.Endian.defaultEndian</code>
+     *  To ensure portable bytes, set the endian to Endian.BIG_ENDIAN or Endian.LITTLE_ENDIAN as appropriate.
+     *  Setting to values other than Endian.BIG_ENDIAN or Endian.LITTLE_ENDIAN is ignored.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.7.0
+     */
+    public function get endian():String
+    {
+        COMPILE::SWF {
+            return ba.endian;
+        }
+        COMPILE::JS {
+            return _endian;
+        }
+    }
+
+    public function set endian(value:String):void
+    {
+        if (value == Endian.BIG_ENDIAN || Endian.LITTLE_ENDIAN) {
+            COMPILE::JS {
+                _endian = value;
+            }
+            COMPILE::SWF {
+                ba.endian = value;
+            }
+        }
+    }
 
     COMPILE::SWF
-	private var ba:ByteArray;
-	
+    private var ba:ByteArray;
+
     COMPILE::JS
     private var ba:ArrayBuffer;
-    
+
     COMPILE::JS
     private var _position:int = 0;
-    
-	/**
-	 * Get the platform-specific data for sending.
-	 * Generally only used by the network services.
-     *  
+
+    /**
+     * Get the platform-specific data for sending.
+     * Generally only used by the network services.
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
-	 */
-	public function get data():Object
-	{
-		return ba;
-	}
-	
+     */
+    public function get data():Object
+    {
+        return ba;
+    }
+
+    /**
+     *  Write a Boolean value (as a single byte) at the current position
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+    public function writeBoolean(value:Boolean):void
+    {
+        COMPILE::SWF
+        {
+            ba.writeBoolean(value);
+        }
+
+        COMPILE::JS
+        {
+            writeByte(value ? 1 :0);
+        }
+    }
+
     /**
      *  Write a byte of binary data at the current position
-     *  
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
-	public function writeByte(byte:int):void
-	{
+    public function writeByte(byte:int):void
+    {
         COMPILE::SWF
         {
-            ba.writeByte(byte);                
+            ba.writeByte(byte);
         }
         COMPILE::JS
         {
             var view:Uint8Array;
-            
-            growBuffer(1);
-            
+
+            ensureWritableBytes(1);
+
             view = new Uint8Array(ba, _position, 1);
             view[0] = byte;
             _position++;
         }
-	}
-	
+    }
+    /**
+     *  Writes a sequence of <code>length</code> bytes from the <code>source</code> BinaryData, starting
+     *  at <code>offset</code> (zero-based index) bytes into the source BinaryData. If length
+     *  is omitted or is zero, it will represent the entire length of the source
+     *  starting from offset. If offset is omitted also, it defaults to zero.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+    public function writeBytes(source:BinaryData, offset:uint = 0, length:uint = 0):void
+    {
+        COMPILE::SWF
+        {
+            ba.writeBytes(source.ba,offset,length);
+        }
+
+        COMPILE::JS
+        {
+
+            if (length == 0) length = source.length - offset ;
+
+            ensureWritableBytes(length);
+
+            var dest:Uint8Array = new Uint8Array(ba, _position, length);
+            var src:Uint8Array = new Uint8Array(source.ba, offset,length);
+            dest.set(src);
+            _position += length;
+        }
+
+    }
+
     /**
      *  Write a short integer of binary data at the current position
-     *  
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
-	public function writeShort(short:int):void
-	{
+    public function writeShort(short:int):void
+    {
         COMPILE::SWF
         {
-            ba.writeShort(short);                
+            ba.writeShort(short);
         }
         COMPILE::JS
         {
             var view:Int16Array;
-            
-            growBuffer(2);
-			if(_endian == Endian.DEFAULT)
-			{
-	            view = new Int16Array(ba, _position, 1);
-    	        view[0] = short;
-			}
-			else
-			{
-				var dv:DataView = new DataView(ba);
-				dv.setInt16(_position,short,_endian == Endian.LITTLE_ENDIAN);
-			}
+
+            ensureWritableBytes(2);
+            if(_endian == Endian.defaultEndian)
+            {
+                view = new Int16Array(ba, _position, 1);
+                view[0] = short;
+            }
+            else
+            {
+                var dv:DataView = new DataView(ba);
+                dv.setInt16(_position,short,_endian == Endian.LITTLE_ENDIAN);
+            }
             _position += 2;
         }
-	}
-	
+    }
+
     /**
-     *  Write an unsigned int of binary data at the current position
-     *  
+     *  Write an unsigned int (32 bits) of binary data at the current position
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
-	public function writeUnsignedInt(unsigned:uint):void
-	{
+    public function writeUnsignedInt(unsigned:uint):void
+    {
         COMPILE::SWF
         {
-            ba.writeUnsignedInt(unsigned);                
+            ba.writeUnsignedInt(unsigned);
         }
         COMPILE::JS
         {
             var view:Uint32Array;
-			
-            growBuffer(4);
-            if(_endian == Endian.DEFAULT)
-			{
-				view = new Uint32Array(ba, _position, 1);
-				view[0] = unsigned;
-			}
-			else
-			{
-				var dv:DataView = new DataView(ba);
-				dv.setUint32(_position,unsigned,_endian == Endian.LITTLE_ENDIAN);
-			}
-			_position += 4;
+
+            ensureWritableBytes(4);
+            if(_endian == Endian.defaultEndian)
+            {
+                view = new Uint32Array(ba, _position, 1);
+                view[0] = unsigned;
+            }
+            else
+            {
+                var dv:DataView = new DataView(ba);
+                dv.setUint32(_position,unsigned,_endian == Endian.LITTLE_ENDIAN);
+            }
+            _position += 4;
         }
-	}
+    }
 
     /**
-     *  Write a signed int of binary data at the current position
-     *  
+     *  Write a signed int (32 bits) of binary data at the current position
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
-	public function writeInt(integer:int):void
-	{
+    public function writeInt(integer:int):void
+    {
         COMPILE::SWF
         {
-            ba.writeInt(integer);                
+            ba.writeInt(integer);
         }
         COMPILE::JS
         {
             var view:Int32Array;
-			
-            growBuffer(4);
-			
-			if(_endian == Endian.DEFAULT)
-			{
-            	view = new Int32Array(ba, _position, 1);
-            	view[0] = integer;
-			}
-			else
-			{
-				var dv:DataView = new DataView(ba);
-				dv.setInt32(_position,integer,_endian == Endian.LITTLE_ENDIAN);
-			}
+
+            ensureWritableBytes(4);
+
+            if(_endian == Endian.defaultEndian)
+            {
+                view = new Int32Array(ba, _position, 1);
+                view[0] = integer;
+            }
+            else
+            {
+                var dv:DataView = new DataView(ba);
+                dv.setInt32(_position,integer,_endian == Endian.LITTLE_ENDIAN);
+            }
             _position += 4;
         }
-	}
+    }
 
     /**
-     *  Read a byte of binary data at the current position
-     *  
+     *  Writes an IEEE 754 single-precision (32-bit) floating-point number to the
+     *  BinaryData at the current position
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
-	public function readByte():int
-	{
+    public function writeFloat(value:Number):void
+    {
+        COMPILE::SWF {
+            return ba.writeFloat(value);
+        }
+        COMPILE::JS {
+            var view:Float32Array;
+
+            ensureWritableBytes(4);
+
+            if(_endian == Endian.defaultEndian)
+            {
+                view = new Float32Array(ba, _position, 1);
+                view[0] = value;
+            }
+            else
+            {
+                var dv:DataView = new DataView(ba);
+                dv.setFloat32(_position,value,_endian == Endian.LITTLE_ENDIAN);
+            }
+            _position += 4;
+        }
+    }
+    /**
+     *  Writes an IEEE 754 double-precision (64-bit) floating-point number to the
+     *  BinaryData at the current position
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+    public function writeDouble(value:Number):void
+    {
+        COMPILE::SWF {
+            return ba.writeDouble(value);
+        }
+        COMPILE::JS {
+            var view:Float64Array;
+
+            ensureWritableBytes(8);
+
+            if(_endian == Endian.defaultEndian)
+            {
+                view = new Float64Array(ba, _position, 1);
+                view[0] = value;
+            }
+            else
+            {
+                var dv:DataView = new DataView(ba);
+                dv.setFloat64(_position,value,_endian == Endian.LITTLE_ENDIAN);
+            }
+            _position += 8;
+        }
+    }
+    /**
+     *  Reads a Boolean value (as a single byte) at the current position.
+     *  returns true if the byte was non-zero, false otherwise
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+
+    public function readBoolean():Boolean
+    {
         COMPILE::SWF
         {
-            return ba.readByte();                
+            return ba.readBoolean();
+        }
+        COMPILE::JS
+        {
+            return Boolean(readUnsignedByte());
+        }
+    }
+
+    /**
+     *  Read a signed byte of binary data at the current position
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+    public function readByte():int
+    {
+        COMPILE::SWF
+        {
+            return ba.readByte();
+        }
+        COMPILE::JS
+        {
+
+            var view:Int8Array;
+
+            view = new Int8Array(ba, _position, 1);
+            _position++;
+            return view[0];
+        }
+    }
+    /**
+     *  Read an unsigned byte of binary data at the current position
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+    public function readUnsignedByte():uint {
+        COMPILE::SWF
+        {
+            return ba.readUnsignedByte();
         }
         COMPILE::JS
         {
             var view:Uint8Array;
-            
+
             view = new Uint8Array(ba, _position, 1);
             _position++;
             return view[0];
         }
-	}
-
-	/**
-	 *  Read a byte of binary data at the specified index. Does not change the <code>position</code> property.
-	 *  
-	 *  @langversion 3.0
-	 *  @playerversion Flash 10.2
-	 *  @playerversion AIR 2.6
-	 *  @productversion FlexJS 0.0
-	 */
-	public function readByteAt(idx:uint):int
-	{
-		COMPILE::SWF
-		{
-			return ba[idx];
-		}
-		COMPILE::JS
-		{
-			return getTypedArray()[idx];
-		}
-	}
-	COMPILE::JS
-	{
-		private var _typedArray:Uint8Array;
-	}
+    }
+
+    /**
+     *  Reads the number of data bytes, specified by the length parameter, from the BinaryData.
+     *  The bytes are read into the BinaryData object specified by the destination parameter,
+     *  and the bytes are written into the destination BinaryData starting at the position specified by offset.
+     *  If length is omitted or is zero, all bytes are read following offset to the end of this BinaryData.
+     *  If offset is also omitted, it defaults to zero.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+    public function readBytes(destination:BinaryData, offset:uint = 0, length:uint = 0):void
+    {
+        COMPILE::SWF
+        {
+            ba.readBytes(destination.ba,offset,length);
+        }
+
+        COMPILE::JS
+        {
+            //do we need to check offset and length and sanitize or throw an error?
+
+            if (length == 0) length = ba.byteLength - _position ;
+            //extend the destination length if necessary
+            var extra:int = offset + length - destination.ba.byteLength;
+            if (extra > 0)
+                destination.growBuffer(extra);
+            var src:Uint8Array = new Uint8Array(ba, _position,length);
+            var dest:Uint8Array = new Uint8Array(destination.ba, offset, length);
+
+            dest.set(src);
+            //todo: check position behavior vs. flash implementation (do either or both advance their internal position) :
+            _position+=length;
+        }
+
+    }
+
+    /**
+     *  Read a byte of binary data at the specified index. Does not change the <code>position</code> property.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+    public function readByteAt(idx:uint):int
+    {
+        COMPILE::SWF
+        {
+            return ba[idx];
+        }
+        COMPILE::JS
+        {
+            return getTypedArray()[idx];
+        }
+    }
+
+    COMPILE::JS
+    private var _typedArray:Uint8Array;
+
     COMPILE::JS
+    private function getTypedArray():Uint8Array
     {
-        private function getTypedArray():Uint8Array
-        {
-            if(_typedArray == null)
-                _typedArray = new Uint8Array(ba);
-                return _typedArray;
-        }
-    }
-
-	/**
-	 *  Writes a byte of binary data at the specified index. Does not change the <code>position</code> property.
-	 *  This is a method for optimzed writes with no range checking.
-	 *  If the specified index is out of range, it can throw an error.
-	 *  
-	 *  @langversion 3.0
-	 *  @playerversion Flash 10.2
-	 *  @playerversion AIR 2.6
-	 *  @productversion FlexJS 0.0
-	 */
-	public function writeByteAt(idx:uint,byte:int):void
-	{
-		COMPILE::SWF
-			{
-				ba[idx] = byte;
-			}
-			COMPILE::JS
-			{
-				getTypedArray()[idx] = byte;
-			}
-	}
-	
+        if(_typedArray == null)
+            _typedArray = new Uint8Array(ba);
+        return _typedArray;
+    }
+
+
+    /**
+     *  Writes a byte of binary data at the specified index. Does not change the <code>position</code> property.
+     *  This is a method for optimzed writes with no range checking.
+     *  If the specified index is out of range, it can throw an error.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+    public function writeByteAt(idx:uint,byte:int):void
+    {
+        COMPILE::SWF
+        {
+            ba[idx] = byte;
+        }
+        COMPILE::JS
+        {
+            if (idx >= ba.byteLength) {
+                setBufferSize(idx+1);
+            }
+            getTypedArray()[idx] = byte;
+        }
+    }
+
     /**
      *  Read a short int of binary data at the current position
-     *  
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
-	public function readShort():int
-	{
+    public function readShort():int
+    {
         COMPILE::SWF
         {
-            return ba.readShort();                
+            return ba.readShort();
         }
         COMPILE::JS
         {
             var view:Int16Array;
-            
-			if(_endian == Endian.DEFAULT)
-			{
-	            view = new Int16Array(ba, _position, 1);
-    	        _position += 2;
-				return view[0];
-			}
-			
-			var dv:DataView = new DataView(ba);
-			var i:int = dv.getInt16(_position,_endian == Endian.LITTLE_ENDIAN);
-			_position += 2;
-			return i;
-        }
-	}
-	
+
+            if(_endian == Endian.defaultEndian)
+            {
+                view = new Int16Array(ba, _position, 1);
+                _position += 2;
+                return view[0];
+            }
+
+            var dv:DataView = new DataView(ba);
+            var i:int = dv.getInt16(_position,_endian == Endian.LITTLE_ENDIAN);
+            _position += 2;
+            return i;
+        }
+    }
+
     /**
      *  Read an unsigned int of binary data at the current position
-     *  
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
-	public function readUnsignedInt():uint
-	{
+    public function readUnsignedInt():uint
+    {
         COMPILE::SWF
         {
-            return ba.readUnsignedInt();                
+            return ba.readUnsignedInt();
         }
         COMPILE::JS
         {
             var view:Uint32Array;
-            
-			if(_endian == Endian.DEFAULT)
-			{
-				view = new Uint32Array(ba, _position, 1);
-				_position += 4;
-				return view[0];
-			}
-			var dv:DataView = new DataView(ba);
-			var i:uint = dv.getUint32(_position,_endian == Endian.LITTLE_ENDIAN);
-			_position += 4;
-			return i;
-        }
-	}
-	
+
+            if(_endian == Endian.defaultEndian)
+            {
+                view = new Uint32Array(ba, _position, 1);
+                _position += 4;
+                return view[0];
+            }
+            var dv:DataView = new DataView(ba);
+            var i:uint = dv.getUint32(_position,_endian == Endian.LITTLE_ENDIAN);
+            _position += 4;
+            return i;
+        }
+    }
+
+    /**
+     *  Read an unsigned short (16bit) of binary data at the current position
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+    public function readUnsignedShort():uint {
+        COMPILE::SWF
+        {
+            return ba.readUnsignedShort();
+        }
+        COMPILE::JS
+        {
+            var view:Uint16Array;
+
+            if(_endian == Endian.defaultEndian)
+            {
+                view = new Uint16Array(ba, _position, 1);
+                _position += 2;
+                return view[0];
+            }
+            var dv:DataView = new DataView(ba);
+            var i:uint = dv.getUint16(_position,_endian == Endian.LITTLE_ENDIAN);
+            _position += 2;
+            return i;
+        }
+    }
+
     /**
      *  Read a signed int of binary data at the current position
-     *  
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
     public function readInt():int
-	{
+    {
         COMPILE::SWF
         {
-            return ba.readInt();                
+            return ba.readInt();
         }
         COMPILE::JS
         {
             var view:Int32Array;
-			
-			if(_endian == Endian.DEFAULT)
-			{
-				view = new Int32Array(ba, _position, 1);
-				_position += 4;
-				return view[0];
-			}
-			var dv:DataView = new DataView(ba);
-			var i:uint = dv.getInt32(_position,_endian == Endian.LITTLE_ENDIAN);
-			_position += 4;
-			return i;
 
+            if(_endian == Endian.defaultEndian)
+            {
+                view = new Int32Array(ba, _position, 1);
+                _position += 4;
+                return view[0];
+            }
+            var dv:DataView = new DataView(ba);
+            var i:uint = dv.getInt32(_position,_endian == Endian.LITTLE_ENDIAN);
+            _position += 4;
+            return i;
+
+        }
+    }
+
+    /**
+     *  Reads an IEEE 754 single-precision (32-bit) floating-point number from the BinaryData.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+    public function readFloat():Number
+    {
+        COMPILE::SWF {
+            return ba.readFloat();
+        }
+        COMPILE::JS {
+            var view:Float32Array;
+
+            if(_endian == Endian.defaultEndian)
+            {
+                view = new Float32Array(ba, _position, 1);
+                _position += 4;
+                return view[0];
+            }
+            var dv:DataView = new DataView(ba);
+            var i:Number = dv.getFloat32(_position,_endian == Endian.LITTLE_ENDIAN);
+            _position += 4;
+            return i;
         }
-	}
+
+    }
 
     /**
-     *  The total number of bytes of data.
-     *  
+     *  Reads an IEEE 754 double-precision (64-bit) floating-point number from the BinaryData.
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
-	public function get length():int
-	{
+    public function readDouble():Number
+    {
+        COMPILE::SWF {
+            return ba.readDouble();
+        }
+        COMPILE::JS {
+            var view:Float64Array;
+
+            if(_endian == Endian.defaultEndian)
+            {
+                view = new Float64Array(ba, _position, 1);
+                _position += 8;
+                return view[0];
+            }
+            var dv:DataView = new DataView(ba);
+            var i:Number = dv.getFloat64(_position,_endian == Endian.LITTLE_ENDIAN);
+            _position += 8;
+            return i;
+        }
+    }
+
+
+    public function get length():int
+    {
         COMPILE::SWF
         {
-            return ba.length;                
+            return ba.length;
         }
         COMPILE::JS
         {
             return ba.byteLength;
         }
-	}
+    }
 
     public function set length(value:int):void
     {
@@ -495,62 +790,69 @@ public class BinaryData
 
     }
 
-	COMPILE::JS
-    private function setBufferSize(newSize):void
+    COMPILE::JS
+    protected function setBufferSize(newSize):void
     {
-        var n:int = ba.byteLength;
-        var newBuffer:ArrayBuffer = new ArrayBuffer(newSize);
-        var newView:Uint8Array = new Uint8Array(newBuffer, 0, n);
-        var view:Uint8Array = new Uint8Array(ba, 0, Math.min(newSize,n));
-        newView.set(view);
-        ba = newBuffer;
-		_typedArray = null;
+        var n:uint = ba.byteLength;
+        if (n != newSize) {
+            //note: ArrayBuffer.slice could be better for buffer size reduction
+            //looks like it is only IE11+, so not using it here
+
+            var newView:Uint8Array = new Uint8Array(newSize);
+            var oldView:Uint8Array = new Uint8Array(ba, 0, Math.min(newSize,n));
+            newView.set(oldView);
+            ba = newView.buffer;
+            if (_position > newSize) _position = newSize;
+            _typedArray = newView;
+        }
     }
     /**
      *  The total number of bytes remaining to be read.
-     *  
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
-	public function get bytesAvailable():int
-	{
+    public function get bytesAvailable():uint
+    {
         COMPILE::SWF
         {
-            return ba.bytesAvailable;                
+            return ba.bytesAvailable;
         }
         COMPILE::JS
         {
-            return ba.byteLength - position;
+            return ba.byteLength - _position;
         }
-	}
+    }
 
     /**
-     *  The total number of bytes remaining to be read.
-     *  
+
+     *  Moves, or returns the current position, in bytes, of the pointer into the BinaryData object.
+     *  This is the point at which the next call to a read method starts reading or a write method starts writing.
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
-	public function get position():int
-	{
+    public function get position():uint
+    {
         COMPILE::SWF
         {
-            return ba.position;                
+            return ba.position;
         }
         COMPILE::JS
         {
             return _position;
         }
-	}
-	
+    }
+
     /**
      *  @private
      */
-	public function set position(value:int):void
-	{
+    public function set position(value:uint):void
+    {
         COMPILE::SWF
         {
             ba.position = value;
@@ -559,54 +861,48 @@ public class BinaryData
         {
             _position = value;
         }
-	}
-	
+    }
+
     /**
-     *  A method to extend the size of the binary data
-     *  so you can write more bytes to it.  Not all
+     *  A convenience method to extend the length of the BinaryData
+     *  so you can efficiently write more bytes to it. Not all
      *  browsers have a way to auto-resize a binary
      *  data as you write data to the binary data buffer
-     *  and resizing in large chunks in generally more
+     *  and resizing in large chunks is generally more
      *  efficient anyway.
-     * 
+     *
      *  @param extra The number of additional bytes.
-     *  
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
-	public function growBuffer(extra:int):void
-	{
-		// no need to do anything in AS
+    public function growBuffer(extra:uint):void
+    {
+        COMPILE::SWF
+        {
+            ba.length += extra;
+        }
+
         COMPILE::JS
         {
-            var newBuffer:ArrayBuffer;
-            var newView:Uint8Array;
-            var view:Uint8Array;
-            var i:int;
-            var n:int;
-            
-            if (_position >= ba.byteLength)
-            {
-                n = ba.byteLength;
-                newBuffer = new ArrayBuffer(n + extra);
-                newView = new Uint8Array(newBuffer, 0, n);
-                view = new Uint8Array(ba, 0, n);
-                for (i = 0; i < n; i++)
-                {
-                    newView[i] = view[i];
-                }
-                ba = newBuffer;
-				_typedArray = null;
-            }
+            setBufferSize(ba.byteLength + extra);
         }
-	}
+    }
+
+    COMPILE::JS
+    protected function ensureWritableBytes(len:uint):void{
+        if (_position + len > ba.byteLength) {
+            setBufferSize( _position + len );
+        }
+    }
+
 
     /**
      *  Reads a UTF-8 string from the byte stream.
      *  The string is assumed to be prefixed with an unsigned short indicating the length in bytes.
-     * 
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
@@ -618,19 +914,19 @@ public class BinaryData
         {
             return ba.readUTF();
         }
-        // no need to do anything in AS
+
         COMPILE::JS
         {
-            //TODO Doing nothing about the length for now
-            return this.readUTFBytes(ba.byteLength);
+            var bytes:uint = readUnsignedShort();
+            return this.readUTFBytes(bytes);
         }
     }
 
     /**
      *  Reads a sequence of UTF-8 bytes specified by the length parameter from the byte stream and returns a string.
-     * 
+     *
      *  @param An unsigned short indicating the length of the UTF-8 bytes.
-     *  
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
@@ -651,6 +947,7 @@ public class BinaryData
             if('TextDecoder' in window)
             {
                 var decoder:TextDecoder = new TextDecoder('utf-8');
+                _position += length;
                 return decoder.decode(bytes);
             }
 
@@ -689,18 +986,19 @@ public class BinaryData
                     out[c++] = String.fromCharCode((c1 & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
                 }
             }
+            _position += length;
             return out.join('');
         }
     }
 
-
+	
     /**
      *  Writes a UTF-8 string to the byte stream.
      *  The length of the UTF-8 string in bytes is written first, as a 16-bit integer,
-     *  followed by the bytes representing the characters of the string. 
-     * 
+     *  followed by the bytes representing the characters of the string.
+     *
      *  @param The string value to be written.
-     *  
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
@@ -710,22 +1008,22 @@ public class BinaryData
     {
         COMPILE::SWF
         {
-            return ba.writeUTF(value);
+            ba.writeUTF(value);
         }
 
         COMPILE::JS
         {
-            //TODO Doing nothing about the length for now
-            return this.writeUTFBytes(value);
+            var utcBytes:Uint8Array = getUTFBytes(value , true);
+            _position =  mergeInToArrayBuffer (_position,utcBytes);
         }
     }
 
     /**
      *  Writes a UTF-8 string to the byte stream. Similar to the writeUTF() method,
      *  but writeUTFBytes() does not prefix the string with a 16-bit length word.
-     * 
+     *
      *  @param The string value to be written.
-     *  
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
@@ -740,18 +1038,38 @@ public class BinaryData
 
         COMPILE::JS
         {
-            // Code taken from GC
-            // Use native implementations if/when available
-            var bytes:Uint8Array;
-            if('TextEncoder' in window)
-            {
-                var encoder:TextEncoder = new TextEncoder('utf-8');
-                bytes = encoder.encode(str);
-                ba = bytes.buffer;
-				_typedArray = null;
-                return;
-            }
+            var utcBytes:Uint8Array = getUTFBytes(str , false);
+            _position = mergeInToArrayBuffer (_position , utcBytes);
+        }
+    }
 
+    COMPILE::JS
+    private function mergeInToArrayBuffer(offset:uint, newBytes:Uint8Array):uint {
+        var newContentLength:uint = newBytes.length;
+        var dest:Uint8Array;
+        if (offset + newContentLength > ba.byteLength) {
+            dest = new Uint8Array(offset + newContentLength);
+            dest.set(new Uint8Array(ba, 0, offset));
+            dest.set(newBytes, offset);
+            ba = dest.buffer;
+            _typedArray = dest;
+        } else {
+            dest = new Uint8Array(ba, offset, newContentLength);
+            dest.set(newBytes);
+        }
+        return offset + newContentLength;
+    }
+
+    COMPILE::JS
+    private function getUTFBytes(str:String, prependLength:Boolean):Uint8Array {
+        // Code taken from GC
+        // Use native implementations if/when available
+        var bytes:Uint8Array;
+        if('TextEncoder' in window)
+        {
+            var encoder:TextEncoder = new TextEncoder('utf-8');
+            bytes = encoder.encode(str);
+        } else {
             var out:Array = [];
             var p:int = 0;
             var c:int;
@@ -765,10 +1083,12 @@ public class BinaryData
                 else if (c < 2048)
                 {
                     out[p++] = (c >> 6) | 192;
+
+
                     out[p++] = (c & 63) | 128;
                 }
                 else if (((c & 0xFC00) == 0xD800) && (i + 1) < str.length &&
-                    ((str.charCodeAt(i + 1) & 0xFC00) == 0xDC00))
+                        ((str.charCodeAt(i + 1) & 0xFC00) == 0xDC00))
                 {
                     // Surrogate Pair
                     c = 0x10000 + ((c & 0x03FF) << 10) + (str.charCodeAt(++i) & 0x03FF);
@@ -784,10 +1104,17 @@ public class BinaryData
                     out[p++] = (c & 63) | 128;
                 }
             }
+
             bytes = new Uint8Array(out);
-            ba = bytes.buffer;
-			_typedArray = null;
         }
+        if (prependLength) {
+            var temp:Uint8Array = new Uint8Array(bytes.length + 2);
+            temp.set(bytes , 2);
+            new Uint16Array(temp.buffer,0,2)[0] = bytes.length;
+            bytes = temp;
+        }
+        return bytes;
     }
+
 }
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/641301b0/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/Endian.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/Endian.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/Endian.as
index e33181c..289d363 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/Endian.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/Endian.as
@@ -49,14 +49,52 @@ package org.apache.flex.utils
 		public static const LITTLE_ENDIAN:String = "littleEndian";
 
 		/**
-		 *  Uses the default endianness on the system.
-		 *  
+		 *  Indicates an unknown default endianness (when using BinaryData).
+		 *  You cannot use this value to set the endian value of a BinaryData
+		 *  It is used to check the defaultEndian value for an unexpected result
+		 *
+		 *
 		 *  @langversion 3.0
 		 *  @playerversion Flash 10.2
 		 *  @playerversion AIR 2.6
 		 *  @productversion FlexJS 0.7.0
 		 */
-		public static const DEFAULT:String = "default";
+		public static const UNKNOWN_ENDIAN:String = "unknownEndian";
+
+
+
+		/**
+		 *  Indicates the default endianness on the system.
+		 *  In swf targets this is always BIG_ENDIAN. When targeting
+		 *  javascript it may differ depending on the target environment.
+		 *
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.7.0
+		 */
+		public static function get defaultEndian():String {
+			COMPILE::SWF {
+				return BIG_ENDIAN;
+			}
+			COMPILE::JS {
+				return _defaultEndian;
+			}
+		}
+
+
+		COMPILE::JS
+		private static function _detectDefaultEndian():String{
+            delete Endian["_detectDefaultEndian"];
+			var tester:Uint8Array = new Uint8Array([102,108,101,120]);
+			var checker:Uint32Array = new Uint32Array(tester.buffer);
+			var check:uint = checker[0];
+			return (check == 1718379896) ? BIG_ENDIAN : (check == 2019912806) ? LITTLE_ENDIAN : UNKNOWN_ENDIAN;
+		}
+
+		COMPILE::JS
+		private static var _defaultEndian:String = _detectDefaultEndian();
 
 	}
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/641301b0/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/IBinaryDataInput.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/IBinaryDataInput.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/IBinaryDataInput.as
new file mode 100644
index 0000000..49dda07
--- /dev/null
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/IBinaryDataInput.as
@@ -0,0 +1,47 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.utils {
+public interface IBinaryDataInput {
+
+    function readBytes(bytes:BinaryData, offset:uint = 0, length:uint = 0):void;
+
+    function readBoolean():Boolean;
+    function readByte():int;
+    function readUnsignedByte():uint;
+    function readShort():int;
+    function readUnsignedShort():uint;
+    function readInt():int;
+    function readUnsignedInt():uint;
+
+    function readFloat():Number;
+    function readDouble():Number;
+  //  function readMultiByte(length:uint, charSet:String):String;
+    function readUTF():String;
+    function readUTFBytes(length:uint):String;
+
+    function get bytesAvailable():uint;
+
+    // function readObject():*;
+    // function get objectEncoding():uint;
+    // function set objectEncoding(version:uint):void;
+
+    function get endian():String;
+    function set endian(type:String):void;
+}
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/641301b0/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/IBinaryDataOutput.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/IBinaryDataOutput.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/IBinaryDataOutput.as
new file mode 100644
index 0000000..2c447b0
--- /dev/null
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/IBinaryDataOutput.as
@@ -0,0 +1,42 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.utils {
+public interface IBinaryDataOutput {
+    function writeBytes(bytes:BinaryData,offset:uint = 0,length:uint = 0):void;
+
+    function writeBoolean(value:Boolean):void;
+    function writeByte(value:int):void;
+    function writeShort(value:int):void;
+    function writeInt(value:int):void;
+    function writeUnsignedInt(value:uint):void;
+
+    function writeFloat(value:Number):void;
+    function writeDouble(value:Number):void;
+  //  function writeMultiByte(value:String,charSet:String):void;
+    function writeUTF(value:String):void;
+    function writeUTFBytes(value:String):void;
+
+    // function writeObject(object:*):void;
+    // function get objectEncoding():uint;
+    // function set objectEncoding(version:uint):void;
+
+    function get endian():String;
+    function set endian(type:String):void;
+}
+}


[11/15] git commit: [flex-asjs] [refs/heads/refactor-sprite] - [Fix] Fixed integration of Endian changes with network classes.

Posted by ha...@apache.org.
[Fix] Fixed integration of Endian changes with network classes.


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/c8d147b9
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/c8d147b9
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/c8d147b9

Branch: refs/heads/refactor-sprite
Commit: c8d147b97f59d266ca58feec0aa3f305e0446998
Parents: 20f2611
Author: greg-dove <gr...@gmail.com>
Authored: Mon Aug 1 04:57:30 2016 +1200
Committer: greg-dove <gr...@gmail.com>
Committed: Mon Aug 1 04:57:30 2016 +1200

----------------------------------------------------------------------
 .../Network/src/main/flex/org/apache/flex/net/URLBinaryLoader.as   | 2 +-
 .../Network/src/main/flex/org/apache/flex/net/URLStream.as         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c8d147b9/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLBinaryLoader.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLBinaryLoader.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLBinaryLoader.as
index 4d5d293..5785c62 100644
--- a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLBinaryLoader.as
+++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLBinaryLoader.as
@@ -56,7 +56,7 @@ package org.apache.flex.net
 		 *  @playerversion AIR 2.6
 		 *  @productversion FlexJS 0.7.0
 		 */        
-		public var endian:String = Endian.DEFAULT;
+		public var endian:String = Endian.BIG_ENDIAN;
 		
 
         private var stream:URLStream;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c8d147b9/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLStream.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLStream.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLStream.as
index eeb6912..2ac8517 100644
--- a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLStream.as
+++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/URLStream.as
@@ -258,7 +258,7 @@ package org.apache.flex.net
 		 *  @playerversion AIR 2.6
 		 *  @productversion FlexJS 0.7.0
 		 */        
-		public var endian:String = Endian.DEFAULT;
+		public var endian:String = Endian.BIG_ENDIAN;
 
 		private function cleanupCallbacks():void
 		{


[03/15] git commit: [flex-asjs] [refs/heads/refactor-sprite] - Merge branch 'develop' into improvement_Binarydata

Posted by ha...@apache.org.
Merge branch 'develop' into improvement_Binarydata


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/3efcd719
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/3efcd719
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/3efcd719

Branch: refs/heads/refactor-sprite
Commit: 3efcd71991b1383107e5c9ae3e0566941aa26dcd
Parents: 8a9b91b cb5e88e
Author: greg-dove <gr...@gmail.com>
Authored: Fri Jul 22 20:05:10 2016 +1200
Committer: greg-dove <gr...@gmail.com>
Committed: Fri Jul 22 20:05:10 2016 +1200

----------------------------------------------------------------------
 .../Graphics/src/main/flex/org/apache/flex/core/graphics/Circle.as | 2 +-
 .../main/flex/org/apache/flex/core/graphics/GraphicsContainer.as   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------



[06/15] git commit: [flex-asjs] [refs/heads/refactor-sprite] - [Performance] instance level length var access adds a small speedup over requesting byteLength from the ArrayBuffer

Posted by ha...@apache.org.
[Performance] instance level length var access adds a small speedup over requesting byteLength from the ArrayBuffer


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/f791f02c
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/f791f02c
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/f791f02c

Branch: refs/heads/refactor-sprite
Commit: f791f02cf2f2cf4dcd25c6cae924923da20f0df1
Parents: 6288c2d
Author: greg-dove <gr...@gmail.com>
Authored: Mon Jul 25 18:14:17 2016 +1200
Committer: greg-dove <gr...@gmail.com>
Committed: Mon Jul 25 18:14:17 2016 +1200

----------------------------------------------------------------------
 .../flex/org/apache/flex/utils/BinaryData.as    | 23 ++++++++++++--------
 1 file changed, 14 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f791f02c/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
index 769b006..d44ac0e 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
@@ -56,6 +56,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
     public function BinaryData(bytes:ArrayBuffer = null)
     {
         ba = bytes ? bytes : new ArrayBuffer(0);
+        _len = ba.byteLength;
     }
 
     /**
@@ -481,9 +482,9 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         {
             //do we need to check offset and length and sanitize or throw an error?
 
-            if (length == 0) length = ba.byteLength - _position ;
+            if (length == 0) length = _len - _position ;
             //extend the destination length if necessary
-            var extra:int = offset + length - destination.ba.byteLength;
+            var extra:int = offset + length - destination._len;
             if (extra > 0)
                 destination.growBuffer(extra);
             var src:Uint8Array = new Uint8Array(ba, _position,length);
@@ -546,7 +547,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         }
         COMPILE::JS
         {
-            if (idx >= ba.byteLength) {
+            if (idx >= _len) {
                 setBufferSize(idx+1);
             }
             getTypedArray()[idx] = byte;
@@ -713,6 +714,9 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         }
     }
 
+    COMPILE::JS
+    private var _len:uint;
+
 
     public function get length():int
     {
@@ -722,7 +726,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         }
         COMPILE::JS
         {
-            return ba.byteLength;
+            return _len;;
         }
     }
 
@@ -743,7 +747,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
     COMPILE::JS
     protected function setBufferSize(newSize):void
     {
-        var n:uint = ba.byteLength;
+        var n:uint = _len;
         if (n != newSize) {
             //note: ArrayBuffer.slice could be better for buffer size reduction
             //looks like it is only IE11+, so not using it here
@@ -754,6 +758,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
             ba = newView.buffer;
             if (_position > newSize) _position = newSize;
             _typedArray = newView;
+            _len = newSize;
         }
     }
     /**
@@ -772,7 +777,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         }
         COMPILE::JS
         {
-            return ba.byteLength - _position;
+            return _len - _position;
         }
     }
 
@@ -837,13 +842,13 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
 
         COMPILE::JS
         {
-            setBufferSize(ba.byteLength + extra);
+            setBufferSize(_len + extra);
         }
     }
 
     COMPILE::JS
     protected function ensureWritableBytes(len:uint):void{
-        if (_position + len > ba.byteLength) {
+        if (_position + len > _len) {
             setBufferSize( _position + len );
         }
     }
@@ -998,7 +1003,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
     private function mergeInToArrayBuffer(offset:uint, newBytes:Uint8Array):uint {
         var newContentLength:uint = newBytes.length;
         var dest:Uint8Array;
-        if (offset + newContentLength > ba.byteLength) {
+        if (offset + newContentLength > _len) {
             dest = new Uint8Array(offset + newContentLength);
             dest.set(new Uint8Array(ba, 0, offset));
             dest.set(newBytes, offset);


[10/15] git commit: [flex-asjs] [refs/heads/refactor-sprite] - [Docs] Fixed endian doc comments, following change to BIG_ENDIAN as default for js

Posted by ha...@apache.org.
[Docs] Fixed endian doc comments, following change to BIG_ENDIAN as default for js


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/20f26116
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/20f26116
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/20f26116

Branch: refs/heads/refactor-sprite
Commit: 20f26116f097742808f390d9c74066a276b67e10
Parents: c7bb721
Author: greg-dove <gr...@gmail.com>
Authored: Wed Jul 27 07:58:37 2016 +1200
Committer: greg-dove <gr...@gmail.com>
Committed: Wed Jul 27 07:58:37 2016 +1200

----------------------------------------------------------------------
 .../Core/src/main/flex/org/apache/flex/utils/BinaryData.as    | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/20f26116/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
index 29e4e76..1b9cfda 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
@@ -133,10 +133,9 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
 
     /**
      *  Indicates the byte order for the data.
-     *  The default is the target default which in Javascript is machine dependent.
-     *  It is possible to check the default Endianness of the target platform at runtime with
-     *  <code>org.apache.flex.utils.Endian.defaultEndian</code>
-     *  To ensure portable bytes, set the endian to Endian.BIG_ENDIAN or Endian.LITTLE_ENDIAN as appropriate.
+     *  The default is Endian BIG_ENDIAN.
+     *  It is possible to check the default system Endianness of the target platform at runtime with
+     *  <code>org.apache.flex.utils.Endian.systemEndian</code>.
      *  Setting to values other than Endian.BIG_ENDIAN or Endian.LITTLE_ENDIAN is ignored.
      *
      *  @langversion 3.0


[14/15] git commit: [flex-asjs] [refs/heads/refactor-sprite] - Updated the TodoListExample so it works for both SWF and JS.

Posted by ha...@apache.org.
Updated the TodoListExample so it works for both SWF and JS.


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/3dea25a1
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/3dea25a1
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/3dea25a1

Branch: refs/heads/refactor-sprite
Commit: 3dea25a1f3c37ae383480523756d8a75fa070918
Parents: f57cfc4
Author: Peter Ent <pe...@apache.org>
Authored: Wed Aug 3 17:28:36 2016 -0400
Committer: Peter Ent <pe...@apache.org>
Committed: Wed Aug 3 17:28:36 2016 -0400

----------------------------------------------------------------------
 .../todo/controllers/TodoListController.as      |   3 +-
 .../src/sample/todo/models/TodoListItem.as      |  66 ++++++++++
 .../src/sample/todo/models/TodoListModel.as     |  88 ++++++++++++--
 .../sample/todo/renderers/TodoItemRenderer.as   |  21 ++++
 .../src/sample/todo/views/TodoListView.mxml     | 120 ++++++++++++-------
 5 files changed, 245 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/3dea25a1/examples/flexjs/TodoListSampleApp/src/sample/todo/controllers/TodoListController.as
----------------------------------------------------------------------
diff --git a/examples/flexjs/TodoListSampleApp/src/sample/todo/controllers/TodoListController.as b/examples/flexjs/TodoListSampleApp/src/sample/todo/controllers/TodoListController.as
index cbc4b1e..efd9168 100644
--- a/examples/flexjs/TodoListSampleApp/src/sample/todo/controllers/TodoListController.as
+++ b/examples/flexjs/TodoListSampleApp/src/sample/todo/controllers/TodoListController.as
@@ -57,6 +57,7 @@ package sample.todo.controllers {
 			// still need to change model a view get the changes
 			var todoModel:TodoListModel = app.model as TodoListModel;
 			//todoModel.todos.push({title: evt.todo, selected: false});
+			todoModel.addTodo(evt.todo);
 		}
 	}
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/3dea25a1/examples/flexjs/TodoListSampleApp/src/sample/todo/models/TodoListItem.as
----------------------------------------------------------------------
diff --git a/examples/flexjs/TodoListSampleApp/src/sample/todo/models/TodoListItem.as b/examples/flexjs/TodoListSampleApp/src/sample/todo/models/TodoListItem.as
new file mode 100644
index 0000000..4e10082
--- /dev/null
+++ b/examples/flexjs/TodoListSampleApp/src/sample/todo/models/TodoListItem.as
@@ -0,0 +1,66 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package sample.todo.models
+{
+	import org.apache.flex.events.Event;
+	import org.apache.flex.events.EventDispatcher;
+	
+	[Event("titleChanged","org.apache.flex.events.Event")]
+	[Event("selectedChanged","org.apache.flex.events.Event")]
+	[Event("removeItem","org.apache.flex.events.Event")]
+	
+	public class TodoListItem extends EventDispatcher
+	{
+		public function TodoListItem(title:String, selected:Boolean)
+		{
+			super();
+			_title = title;
+			_selected = selected;
+		}
+		
+		private var _title:String;
+		[Event("titleChanged")]
+		public function get title():String
+		{
+			return _title;
+		}
+		public function set title(value:String):void
+		{
+			_title = value;
+			dispatchEvent(new Event("titleChanged"));
+		}
+		
+		private var _selected:Boolean;
+		[Event("selectedChanged")]
+		public function get selected():Boolean
+		{
+			return _selected;
+		}
+		public function set selected(value:Boolean):void
+		{
+			_selected = value;
+			dispatchEvent(new Event("selectedChanged"));
+		}
+		
+		public function remove():void
+		{
+			dispatchEvent(new Event("removeItem"));
+		}
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/3dea25a1/examples/flexjs/TodoListSampleApp/src/sample/todo/models/TodoListModel.as
----------------------------------------------------------------------
diff --git a/examples/flexjs/TodoListSampleApp/src/sample/todo/models/TodoListModel.as b/examples/flexjs/TodoListSampleApp/src/sample/todo/models/TodoListModel.as
index e4d06b1..acf2104 100644
--- a/examples/flexjs/TodoListSampleApp/src/sample/todo/models/TodoListModel.as
+++ b/examples/flexjs/TodoListSampleApp/src/sample/todo/models/TodoListModel.as
@@ -17,26 +17,98 @@
 //
 ////////////////////////////////////////////////////////////////////////////////
 package sample.todo.models {
+    import org.apache.flex.events.Event;
     import org.apache.flex.events.EventDispatcher;
 
     public class TodoListModel extends EventDispatcher {
         public function TodoListModel() {
             super();
+			_filterFunction();
+			
+			addTodo("Get something").selected = true;
+			addTodo("Do this").selected = true;
+			addTodo("Do that");
         }
+		
+		private function titleChangeHandler(event:Event):void
+		{
+			dispatchEvent(new Event("todoListChanged"));
+		}
+		
+		private function selectChangeHandler(event:Event):void
+		{
+			dispatchEvent(new Event("todoListChanged"));
+		}
+		
+		private function removeHandler(event:Event):void
+		{
+			var item:TodoListItem = event.target as TodoListItem;
+			removeItem(item);
+		}
 
-        private var _todos:Array = [
-            {title: "Get something", selected: true},
-            {title: "Do this", selected: true},
-            {title: "Do that", selected: false}
-        ];
+        private var _todos:Array = [];
+		
+		private var _filteredList:Array = [];
+		private var _filterFunction:Function = showAllTodos;
 
-        [Bindable]
+        [Bindable("todoListChanged")]
         public function get todos():Array {
-            return _todos;
+			return _filteredList;
         }
 
         public function set todos(value:Array):void {
             _todos = value;
+			_filterFunction();
+			dispatchEvent(new Event("todoListChanged"));
         }
+
+        public function addTodo(value:String):TodoListItem
+        {
+			var item:TodoListItem = new TodoListItem(value, false);
+			item.addEventListener("titleChanged", titleChangeHandler);
+			item.addEventListener("selectedChanged", titleChangeHandler);
+			item.addEventListener("removeItem", removeHandler);
+			_todos.push(item);
+			
+			_filterFunction();
+			
+			return item;
+        }
+		
+		public function showAllTodos() : void {
+			_filteredList = _todos.slice();
+			dispatchEvent(new Event("todoListChanged"));
+			_filterFunction = showAllTodos;
+		}
+		
+		public function showActiveTodos() : void {
+			_filteredList = [];
+			for (var i:int=0; i < _todos.length; i++) {
+				if (!_todos[i].selected) {
+					_filteredList.push(_todos[i]);
+				}
+			}
+			dispatchEvent(new Event("todoListChanged"));
+			_filterFunction = showActiveTodos;
+		}
+		
+		public function showCompletedTodos() : void {
+			_filteredList = [];
+			for (var i:int=0; i < _todos.length; i++) {
+				if (_todos[i].selected) {
+					_filteredList.push(_todos[i]);
+				}
+			}
+			dispatchEvent(new Event("todoListChanged"));
+			_filterFunction = showCompletedTodos;
+		}
+		
+		public function removeItem(item:Object) : void {
+			var index:int = _todos.indexOf(item);
+			if (index >= 0) {
+				_todos.splice(index,1);
+			}
+			_filterFunction();
+		}
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/3dea25a1/examples/flexjs/TodoListSampleApp/src/sample/todo/renderers/TodoItemRenderer.as
----------------------------------------------------------------------
diff --git a/examples/flexjs/TodoListSampleApp/src/sample/todo/renderers/TodoItemRenderer.as b/examples/flexjs/TodoListSampleApp/src/sample/todo/renderers/TodoItemRenderer.as
index a4fa9f1..5e0dd50 100644
--- a/examples/flexjs/TodoListSampleApp/src/sample/todo/renderers/TodoItemRenderer.as
+++ b/examples/flexjs/TodoListSampleApp/src/sample/todo/renderers/TodoItemRenderer.as
@@ -17,14 +17,22 @@
 //
 ////////////////////////////////////////////////////////////////////////////////
 package sample.todo.renderers {
+
+    import org.apache.flex.events.Event;
+    import org.apache.flex.events.MouseEvent;
     import org.apache.flex.html.Button;
     import org.apache.flex.html.CheckBox;
     import org.apache.flex.html.Label;
     import org.apache.flex.html.supportClasses.DataItemRenderer;
 
+	[Event("checked","org.apache.flex.events.Event")]
+	[Event("remove","org.apache.flex.events.Event")]
+
     public class TodoItemRenderer extends DataItemRenderer {
+		
         public function TodoItemRenderer() {
             super();
+			className = "TodoItemRenderer";
         }
 
         private var checkbox:CheckBox;
@@ -36,12 +44,14 @@ package sample.todo.renderers {
 
             checkbox = new CheckBox();
             addElement(checkbox);
+			checkbox.addEventListener("change", checkBoxChange);
 
             title = new Label();
             addElement(title);
 
             removeButton = new Button();
             addElement(removeButton);
+			removeButton.addEventListener("click", removeClick);
         }
 
         override public function set data(value:Object):void {
@@ -52,6 +62,7 @@ package sample.todo.renderers {
         }
 
         override public function adjustSize():void {
+        	var hgt:Number = this.height;
             var cy:Number = this.height / 2;
 
             checkbox.x = 10;
@@ -65,5 +76,15 @@ package sample.todo.renderers {
 
             updateRenderer();
         }
+
+		private function checkBoxChange(event:Event):void
+		{
+			data.selected = !data.selected;
+		}
+
+		private function removeClick(event:MouseEvent):void
+		{
+			data.remove();
+		}
     }
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/3dea25a1/examples/flexjs/TodoListSampleApp/src/sample/todo/views/TodoListView.mxml
----------------------------------------------------------------------
diff --git a/examples/flexjs/TodoListSampleApp/src/sample/todo/views/TodoListView.mxml b/examples/flexjs/TodoListSampleApp/src/sample/todo/views/TodoListView.mxml
index 3a4c7e4..a1bd2c8 100644
--- a/examples/flexjs/TodoListSampleApp/src/sample/todo/views/TodoListView.mxml
+++ b/examples/flexjs/TodoListSampleApp/src/sample/todo/views/TodoListView.mxml
@@ -19,69 +19,100 @@ limitations under the License.
 -->
 <js:View xmlns:fx="http://ns.adobe.com/mxml/2009"
                 xmlns:js="library://ns.apache.org/flexjs/basic"
-                xmlns:svg="library://ns.apache.org/flexjs/svg">
+                xmlns:svg="library://ns.apache.org/flexjs/svg"
+				initComplete="setup()">
 
     <fx:Script>
 		<![CDATA[
-        import sample.todo.events.TodoListEvent;
-
-        /**
-         * add to the list the text entered by the user, in the text box,
-         * as a new todo list item
-         */
-        public function logTodo():void {
-            var logEvent:TodoListEvent = new TodoListEvent(TodoListEvent.LOG_TODO);
-            logEvent.todo = todoInput.text;
-            dispatchEvent(logEvent);
-
-            //todoList.width = Math.random() * 200; // to show changes v�a ENTER key
-        }
-
-        /**
-         * show all todos
-         */
-        private function showAll():void {
-        }
-
-        /**
-         * show active todos
-         */
-        private function showActive():void {
-        }
-
-        /**
-         * show completed todos
-         */
-        private function showCompleted():void {
-        }
+			import org.apache.flex.events.Event;
+			import org.apache.flex.html.beads.controllers.ItemRendererMouseController;
+			
+			import sample.todo.events.TodoListEvent;
+			import sample.todo.models.TodoListModel;
+			import sample.todo.renderers.TodoItemRenderer;
+			
+			private function setup():void {
+				// Listening for events on the model will update the UI. Functions like
+				// showActive() change the model which results in this event being
+				// dispatched.
+				(applicationModel as TodoListModel).addEventListener("todoListChanged", updateStatus);
+				updateStatus(null);
+			}
+			
+			/**
+			 * add to the list the text entered by the user, in the text box,
+			 * as a new todo list item
+			 */
+			public function logTodo():void {
+				var logEvent:TodoListEvent = new TodoListEvent(TodoListEvent.LOG_TODO);
+				logEvent.todo = todoInput.text;
+				dispatchEvent(logEvent);
+				
+				todoInput.text = "";
+			}
+			
+			private function updateStatus(event:org.apache.flex.events.Event):void {
+				var numberLeft:Number = 0;
+				
+				var model: TodoListModel = applicationModel as TodoListModel;
+				var list: Array = model.todos;
+				for (var i:int=0; i < list.length; i++) {
+					var item:Object = list[i];
+					numberLeft += item.selected ? 0 : 1;
+				}
+				
+				statusLabel.text = numberLeft + " items left";
+			}
+			
+			/**
+			 * show all todos
+			 */
+			private function showAll():void {
+				(applicationModel as TodoListModel).showAllTodos();
+			}
+			
+			/**
+			 * show active todos
+			 */
+			private function showActive():void {
+				(applicationModel as TodoListModel).showActiveTodos();
+			}
+			
+			/**
+			 * show completed todos
+			 */
+			private function showCompleted():void {
+				(applicationModel as TodoListModel).showCompletedTodos();
+			}
         ]]>
 	</fx:Script>
+	
+	<js:beads>
+		<js:ViewDataBinding />
+	</js:beads>
 
     <js:Panel title="FlexJS TODO List" width="600">
         <js:beads>
             <js:VerticalLayout/>
         </js:beads>
 
-        <js:TextInput id="todoInput"
-                         width="300"
-                         change="logTodo()"/>
+		<js:HContainer width="100%">
+        	<js:TextInput id="todoInput"
+                         width="85%"/>
+            <js:TextButton text="Enter" click="logTodo()" width="15%" />
+        </js:HContainer>
 
         <js:List id="todoList"
                     itemRenderer="sample.todo.renderers.TodoItemRenderer"
-                    width="300" height="400">
-            <!-- dataProvider="{TodoListModel(applicationModel).todos}" -->
-            <js:beads>
-                <js:ConstantBinding sourceID="applicationModel"
-                                       sourcePropertyName="todos"
-                                       destinationPropertyName="dataProvider"/>
-            </js:beads>
+					dataProvider="{TodoListModel(applicationModel).todos}"
+                    width="100%" height="400">
         </js:List>
 
         <js:Container>
             <js:beads>
                 <js:HorizontalLayout/>
             </js:beads>
-            <js:Label id="statusLabel" text="N items left"/>
+            <js:Label id="statusLabel" text="N items left" width="295"/>
             <svg:TextButton text="All" width="100" height="30" click="showAll()" />
             <svg:TextButton text="Active" width="100" height="30" click="showActive()" />
             <svg:TextButton text="Completed" width="100" height="30" click="showCompleted()" />
@@ -101,7 +132,8 @@ limitations under the License.
         }
 
         renderers|TodoItemRenderer {
-            height: 40;
+			backgroundColor: #FFFFFF;
+            height: 40px;
             IBeadController: ClassReference("org.apache.flex.html.beads.controllers.ItemRendererMouseController");
         }
     </fx:Style>


[04/15] git commit: [flex-asjs] [refs/heads/refactor-sprite] - Fix for UTC prepended short - respect endianness

Posted by ha...@apache.org.
Fix for UTC prepended short - respect endianness


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/d12bcddf
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/d12bcddf
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/d12bcddf

Branch: refs/heads/refactor-sprite
Commit: d12bcddf444da559931b351fd4d93d7648e1758f
Parents: 3efcd71
Author: greg-dove <gr...@gmail.com>
Authored: Sat Jul 23 16:23:49 2016 +1200
Committer: greg-dove <gr...@gmail.com>
Committed: Sat Jul 23 16:23:49 2016 +1200

----------------------------------------------------------------------
 .../Core/src/main/flex/org/apache/flex/utils/BinaryData.as     | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d12bcddf/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
index 1260dae..942b394 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
@@ -1110,7 +1110,11 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         if (prependLength) {
             var temp:Uint8Array = new Uint8Array(bytes.length + 2);
             temp.set(bytes , 2);
-            new Uint16Array(temp.buffer,0,2)[0] = bytes.length;
+            var len:uint = bytes.length;
+            //preconvert to alternate endian if needed
+            new Uint16Array(temp.buffer,0,2)[0] =
+                    (_endian == Endian.defaultEndian) ?
+                            len : ((len & 0xff) >> 8) | (len << 8);
             bytes = temp;
         }
         return bytes;


[15/15] git commit: [flex-asjs] [refs/heads/refactor-sprite] - Merge branch 'develop' into refactor-sprite

Posted by ha...@apache.org.
Merge branch 'develop' into refactor-sprite

* develop:
  Updated the TodoListExample so it works for both SWF and JS.
  Found a couple of minor bugs while fixing an example.
  [Fix] Fixed integration of Endian changes with network classes.
  [Docs] Fixed endian doc comments, following change to BIG_ENDIAN as default for js
  [Tests] Updated unit tests
  [Improvements] More performance tweaks, consistency tweaks, and doc improvements.
  [Performance] instance level length var access adds a small speedup over requesting byteLength from the ArrayBuffer
  [Consistency] Set default Endian to BIG ENDIAN in javascript to be consistent with flash [Performance] optimization of int/unit/short read/writes to avoid using DataView, substantial gains
  Fix for UTC prepended short - respect endianness
  [Test] Added swf-side unit tests for BinaryData changes (these also currently pass when mocked in the browser for the js version)
  [Improvement] Numerous updates to BinaryData to get closer to flash IDataInput and IDataOutput interfaces. Endian now detects default Endianness. IBinaryDataInput and IBinaryDataOutput interfaces added


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/7ac45297
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/7ac45297
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/7ac45297

Branch: refs/heads/refactor-sprite
Commit: 7ac45297235ab40508606a5b363ace9ffafdcac0
Parents: 184ef2d 3dea25a
Author: Harbs <ha...@in-tools.com>
Authored: Thu Aug 4 08:29:24 2016 +0300
Committer: Harbs <ha...@in-tools.com>
Committed: Thu Aug 4 08:29:24 2016 +0300

----------------------------------------------------------------------
 .../todo/controllers/TodoListController.as      |    3 +-
 .../src/sample/todo/models/TodoListItem.as      |   66 ++
 .../src/sample/todo/models/TodoListModel.as     |   88 +-
 .../sample/todo/renderers/TodoItemRenderer.as   |   21 +
 .../src/sample/todo/views/TodoListView.mxml     |  120 +-
 .../flex/org/apache/flex/utils/BinaryData.as    | 1089 ++++++++++++------
 .../main/flex/org/apache/flex/utils/Endian.as   |   31 +-
 .../org/apache/flex/utils/IBinaryDataInput.as   |   47 +
 .../org/apache/flex/utils/IBinaryDataOutput.as  |   42 +
 .../test/flex/FlexUnitFlexJSApplication.mxml    |    7 +-
 .../flex/flexUnitTests/BinaryDataTesterTest.as  |  565 +++++++++
 .../src/test/flex/flexUnitTests/CoreTester.as   |   28 +
 .../src/test/flex/flexUnitTests/StrandTester.as |   27 -
 .../flex/org/apache/flex/html/beads/ListView.as |    4 +-
 .../html/supportClasses/DataItemRenderer.as     |    6 +-
 .../flex/org/apache/flex/net/URLBinaryLoader.as |    2 +-
 .../main/flex/org/apache/flex/net/URLStream.as  |    2 +-
 17 files changed, 1685 insertions(+), 463 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7ac45297/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/DataItemRenderer.as
----------------------------------------------------------------------


[08/15] git commit: [flex-asjs] [refs/heads/refactor-sprite] - [Tests] Updated unit tests

Posted by ha...@apache.org.
[Tests] Updated unit tests


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/ae06cfdd
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/ae06cfdd
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/ae06cfdd

Branch: refs/heads/refactor-sprite
Commit: ae06cfddd63e0fae7197ba8c24bc74c8d5a3f383
Parents: febae6a
Author: greg-dove <gr...@gmail.com>
Authored: Tue Jul 26 15:10:50 2016 +1200
Committer: greg-dove <gr...@gmail.com>
Committed: Tue Jul 26 15:17:25 2016 +1200

----------------------------------------------------------------------
 .../flex/flexUnitTests/BinaryDataTesterTest.as  | 493 ++++++++++++++-----
 1 file changed, 375 insertions(+), 118 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/ae06cfdd/frameworks/projects/Core/src/test/flex/flexUnitTests/BinaryDataTesterTest.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/test/flex/flexUnitTests/BinaryDataTesterTest.as b/frameworks/projects/Core/src/test/flex/flexUnitTests/BinaryDataTesterTest.as
index 0fe68ce..6a8747f 100644
--- a/frameworks/projects/Core/src/test/flex/flexUnitTests/BinaryDataTesterTest.as
+++ b/frameworks/projects/Core/src/test/flex/flexUnitTests/BinaryDataTesterTest.as
@@ -43,68 +43,101 @@ package flexUnitTests {
         }
 
 
+        //util check functions
+        private static function bytesMatchExpectedData(bd:BinaryData,expected:Array,offset:int=0):Boolean{
+            var len:uint = expected.length;
+            var end:uint=offset+len;
+            for (var i:int=offset;i<end;i++) {
+                var check:uint = bd.readByteAt(i);
+                if (expected[i-offset]!=check) {
+                    // trace('failed at ',i,expected[i-offset],check);
+                    return false;
+                }
+            }
+            return true;
+        }
+
+        private static function reversedBytesMatch(bd1:BinaryData,bd2:BinaryData,len:uint,offset:int=0):Boolean{
+            var end:uint=offset+len;
+            for (var i:int=offset;i<end;i++) {
+                if (bd1.readByteAt(i) != bd2.readByteAt(end-1-i)) return false;
+            }
+            return true;
+
+        }
+
+
         [Test]
-        public function testBasicPositionAndLength():void {
+        public function testBasicPositionAndLength():void
+        {
             var ba:BinaryData = new BinaryData();
 
             Assert.assertEquals("new Instance, position", ba.position, 0);
             Assert.assertEquals("new Instance, length", ba.length, 0);
 
-            ba.position = 100;
-            Assert.assertEquals("position change, position", ba.position, 100);
+            ba.position=100;
+            Assert.assertEquals("position change, position", ba.position,100);
             Assert.assertEquals("position change, length", ba.length, 0);
+            Assert.assertEquals("position change, length", ba.bytesAvailable, 0);
 
-            ba.length = 100;
-            Assert.assertEquals("length change, position", ba.position, 100);
+            ba.length=100;
+            Assert.assertEquals("length change, position", ba.position,100);
             Assert.assertEquals("length change, length", ba.length, 100);
 
-            ba.length = 50;
-            Assert.assertEquals("length change, position", ba.position, 50);
+            ba.length=50;
+            Assert.assertEquals("length change, position", ba.position,50);
             Assert.assertEquals("length change, length", ba.length, 50);
+
+
         }
 
         [Test]
-        public function testAdvancedPositionAndLength():void {
+        public function testAdvancedPositionAndLength():void
+        {
             var ba:BinaryData = new BinaryData();
 
-            ba.position = 100;
-            ba.length = 100;
+            ba.position=100;
+            ba.length=100;
 
-            ba.writeByteAt(49, 255);
-            Assert.assertEquals("writeByteAt does not affect position", ba.position, 100);
-            Assert.assertEquals("writeByteAt (internal) does not affect length", ba.length, 100);
+            ba.writeByteAt(49,255);
+            Assert.assertEquals("writeByteAt does not affect position", ba.position,100);
+            Assert.assertEquals("writeByteAt (internal) does not affect length", ba.length,100);
 
             ba.readByteAt(48);
-            Assert.assertEquals("readByteAt does not affect position", ba.position, 100);
-            Assert.assertEquals("readByteAt does not affect length", ba.length, 100);
+            Assert.assertEquals("readByteAt does not affect position", ba.position,100);
+            Assert.assertEquals("readByteAt does not affect length", ba.length,100);
+
+            ba.writeByteAt(199,255);
+            Assert.assertEquals("writeByteAt (beyond length) does affect length", ba.length,200);
+            Assert.assertEquals("writeByteAt (beyond length) does not affect position", ba.position,100);
 
-            ba.writeByteAt(199, 255);
-            Assert.assertEquals("writeByteAt (beyond length) does affect length", ba.length, 200);
-            Assert.assertEquals("writeByteAt (beyond length) does not affect position", ba.position, 100);
+            Assert.assertStrictlyEquals("out of range byte read request",ba.readByteAt(205),0);
 
         }
 
 
         [Test]
-        public function testUTFWritePosition():void {
+        public function testUTFWritePosition():void
+        {
             var ba:BinaryData = new BinaryData();
             ba.writeUTF('This is a test');
             //writeUTF
             Assert.assertEquals("basic post-writeUTF position", ba.position, 16);
-            ba = new BinaryData();
+            ba=new BinaryData();
             ba.writeUTFBytes('This is a test');
             //writeUTFBytes
             Assert.assertEquals("basic post-writeUTFBytes position", ba.position, 14);
 
             //overlapping
-            ba.position = 5;
+            ba.position=5;
             ba.writeUTFBytes('This is a test');
             Assert.assertEquals("Advanced post-writeUTFBytes position (overlap)", ba.position, 19);
 
         }
 
         [Test]
-        public function testBooleanRoundTripping():void {
+        public function testBooleanRoundTripping():void
+        {
             var ba:BinaryData = new BinaryData();
             ba.writeBoolean(true);
             ba.writeBoolean(false);
@@ -114,195 +147,419 @@ package flexUnitTests {
         }
 
         [Test]
-        public function testByteRoundTripping():void {
+        public function testByteRoundTripping():void
+        {
             var ba:BinaryData = new BinaryData();
             ba.writeByte(255);
+            ba.writeByte(256);
+            ba.writeByte(-256);
             ba.writeByte(-257);
+            ba.writeByte(-128);
+            ba.writeByte(128);
+            ba.writeByte(127);
             ba.writeByte(-50);
             ba.writeByte(50);
             ba.position = 0;
 
 
-            Assert.assertEquals("Error testing post writeByte/readByte roundtripping", ba.readByte(), -1);
-            Assert.assertEquals("Error testing post writeByte/readByte roundtripping", ba.readByte(), -1);
-            Assert.assertEquals("Error testing post writeByte/readByte roundtripping", ba.readByte(), -50);
-            Assert.assertEquals("Error testing post writeByte/readByte roundtripping", ba.readByte(), 50);
+            Assert.assertEquals("Error testing post writeByte/readByte round-tripping", ba.readByte(), -1);
+            Assert.assertEquals("Error testing post writeByte/readByte round-tripping", ba.readByte(), 0);
+            Assert.assertEquals("Error testing post writeByte/readByte round-tripping", ba.readByte(), 0);
+            Assert.assertEquals("Error testing post writeByte/readByte round-tripping", ba.readByte(), -1);
+            Assert.assertEquals("Error testing post writeByte/readByte round-tripping", ba.readByte(), -128);
+            Assert.assertEquals("Error testing post writeByte/readByte round-tripping", ba.readByte(), -128);
+            Assert.assertEquals("Error testing post writeByte/readByte round-tripping", ba.readByte(), 127);
+            Assert.assertEquals("Error testing post writeByte/readByte round-tripping", ba.readByte(), -50);
+            Assert.assertEquals("Error testing post writeByte/readByte round-tripping", ba.readByte(), 50);
         }
 
 
         [Test]
-        public function testUnsignedByteRoundTripping():void {
+        public function testUnsignedByteRoundTripping():void
+        {
             var ba:BinaryData = new BinaryData();
             ba.writeByte(255);
+            ba.writeByte(256);
+            ba.writeByte(-256);
             ba.writeByte(-257);
+            ba.writeByte(-128);
+            ba.writeByte(128);
+            ba.writeByte(127);
             ba.writeByte(-50);
             ba.writeByte(50);
             ba.position = 0;
             //check read values
-            Assert.assertEquals("Error testing post writeByte/readByte roundtripping", ba.readUnsignedByte(), 255);
-            Assert.assertEquals("Error testing post writeByte/readByte roundtripping", ba.readUnsignedByte(), 255);
-            Assert.assertEquals("Error testing post writeByte/readByte roundtripping", ba.readUnsignedByte(), 206);
-            Assert.assertEquals("Error testing post writeByte/readByte roundtripping", ba.readUnsignedByte(), 50);
+
+            Assert.assertEquals("Error testing post writeByte/readUnsignedByte round-tripping", ba.readUnsignedByte(), 255);
+            Assert.assertEquals("Error testing post writeByte/readUnsignedByte round-tripping", ba.readUnsignedByte(), 0);
+            Assert.assertEquals("Error testing post writeByte/readUnsignedByte round-tripping", ba.readUnsignedByte(), 0);
+            Assert.assertEquals("Error testing post writeByte/readUnsignedByte round-tripping", ba.readUnsignedByte(), 255);
+            Assert.assertEquals("Error testing post writeByte/readUnsignedByte round-tripping", ba.readUnsignedByte(), 128);
+            Assert.assertEquals("Error testing post writeByte/readUnsignedByte round-tripping", ba.readUnsignedByte(), 128);
+            Assert.assertEquals("Error testing post writeByte/readUnsignedByte round-tripping", ba.readUnsignedByte(), 127);
+            Assert.assertEquals("Error testing post writeByte/readUnsignedByte round-tripping", ba.readUnsignedByte(), 206);
+            Assert.assertEquals("Error testing post writeByte/readUnsignedByte round-tripping", ba.readUnsignedByte(), 50);
         }
 
 
         [Test]
-        public function testBasicEndian():void {
-            var defaultEndian:String = Endian.defaultEndian;
-            //check we have a decisive default
-            Assert.assertTrue(defaultEndian != null && defaultEndian != Endian.UNKNOWN_ENDIAN);
-            var alternateEndian:String = (defaultEndian == Endian.BIG_ENDIAN) ? Endian.LITTLE_ENDIAN : Endian.BIG_ENDIAN;
+        public function testBasicEndian():void
+        {
+
+            var systemEndian:String = Endian.systemEndian;
+            //check we have a decisive systemEndian detection
+            Assert.assertNotNull(systemEndian );
+
 
             var ba:BinaryData = new BinaryData();
-            var expected:Object = {};
-            expected[Endian.BIG_ENDIAN] = 1718379896;
-            expected[Endian.LITTLE_ENDIAN] = 2019912806;
-            var bytes:Array = [102, 108, 101, 120];
+            var defaultEndian:String = ba.endian;
+
+            var alternateEndian:String = (defaultEndian == Endian.BIG_ENDIAN) ? Endian.LITTLE_ENDIAN : Endian.BIG_ENDIAN;
+            var expected:Object ={};
+            expected[Endian.BIG_ENDIAN] = 218038271;
+            expected[Endian.LITTLE_ENDIAN] = 4294966796;
+            var bytes:Array = [12, 254, 255, 255];
             for each(var byte:uint in bytes) ba.writeByte(byte);
             ba.position = 0;
 
-            Assert.assertEquals("testing endian:" + defaultEndian, ba.readUnsignedInt(), expected[defaultEndian]);
+            Assert.assertEquals("testing endian:"+defaultEndian, ba.readUnsignedInt(), expected[defaultEndian]);
+
+            ba.position = 0;
+            ba.endian = alternateEndian;
+            var result:uint =  ba.readUnsignedInt();
+
+            Assert.assertEquals("testing endian:"+alternateEndian, result, expected[alternateEndian]);
+
+            ba.position = 0;
+            ba.endian = defaultEndian;
+            Assert.assertEquals("testing endian:"+defaultEndian, ba.readInt(), int(expected[defaultEndian]));
 
             ba.position = 0;
             ba.endian = alternateEndian;
-            Assert.assertEquals("testing endian:" + alternateEndian, ba.readUnsignedInt(), expected[alternateEndian]);
+            Assert.assertEquals("testing endian:"+alternateEndian, ba.readInt(), int(expected[alternateEndian]));
+
+            var leBA:BinaryData = new BinaryData();
+            leBA.endian = Endian.LITTLE_ENDIAN;
+            var beBA:BinaryData = new BinaryData();
+            beBA.endian = Endian.BIG_ENDIAN;
+            //int writing
+            beBA.writeInt(-500);
+            leBA.writeInt(-500);
+            //check they represent reversed byte sequence
+            Assert.assertTrue(reversedBytesMatch(beBA,leBA,4));
+            beBA.position=0;
+            leBA.position=0;
+            //check they each read back to the same uint value
+            Assert.assertEquals('big endian',beBA.readUnsignedInt(),4294966796);
+            Assert.assertEquals('little endian',leBA.readUnsignedInt(),4294966796);
+
+            beBA.position=0;
+            leBA.position=0;
+            //uint writing
+            beBA.writeUnsignedInt(4294966796);
+            leBA.writeUnsignedInt(4294966796);
+            //check they represent reversed byte sequence
+            Assert.assertTrue(reversedBytesMatch(beBA,leBA,4));
+            beBA.position=0;
+            leBA.position=0;
+            //check they each read back to the same uint value
+            Assert.assertEquals('big endian',beBA.readUnsignedInt(),4294966796);
+            Assert.assertEquals('little endian',leBA.readUnsignedInt(),4294966796);
+
+
+            beBA.position=0;
+            leBA.position=0;
+
+            //check they each read back to the same int value
+            Assert.assertEquals('big endian',beBA.readInt(),-500);
+            Assert.assertEquals('little endian',leBA.readInt(),-500);
+
+
+            beBA.position=0;
+            leBA.position=0;
+
+            //short writing
+            beBA.writeShort(-500);
+            leBA.writeShort(-500);
+            //check they represent reversed byte sequence
+            Assert.assertTrue(reversedBytesMatch(beBA,leBA,2));
+            beBA.position=0;
+            leBA.position=0;
+            //check they each read back to the same uint value
+            Assert.assertEquals('big endian',beBA.readUnsignedShort(),65036);
+            Assert.assertEquals('little endian',leBA.readUnsignedShort(),65036);
+
+
+            beBA.position=0;
+            leBA.position=0;
+
+            //check they each read back to the same int value
+            Assert.assertEquals('big endian',beBA.readShort(),-500);
+            Assert.assertEquals('little endian',leBA.readShort(),-500);
+
+        }
+
+
+        [Test]
+        public function testUTFRoundtripping():void
+        {
+
+            //test big-endian round-tripping
+            var ba:BinaryData = new BinaryData();
+            ba.endian = Endian.BIG_ENDIAN;
+            ba.writeUTF('This is a test');
+            //writeUTF
+            Assert.assertEquals("basic post-writeUTF position", ba.position, 16);
+            ba.position = 0;
+            Assert.assertEquals("utf big endian round-tripping", ba.readUTF(), 'This is a test');
+
+            ba = new BinaryData();
+            //test little-endian round-tripping
+            ba.endian = Endian.LITTLE_ENDIAN;
+            ba.writeUTF('This is a test');
+            //writeUTF
+            Assert.assertEquals("basic post-writeUTF position", ba.position, 16);
+            ba.position = 0;
+            Assert.assertEquals("utf big endian round-tripping", ba.readUTF(), 'This is a test');
+
         }
 
+
         [Test]
-        public function testShortRoundTripping():void {
+        public function testShortRoundTripping():void
+        {
             var ba:BinaryData = new BinaryData();
+            //test LITTLE_ENDIAN round-tripping
+            ba.endian = Endian.LITTLE_ENDIAN;
+            ba.writeShort(255);
+            ba.writeShort(-50);
+            ba.writeShort(50);
+            ba.position = 0;
+
+            Assert.assertEquals("Error testing post writeShort/readShort round-tripping", ba.length, 6);
+            Assert.assertEquals("Error testing post writeShort/readShort round-tripping", ba.readShort(), 255);
+            Assert.assertEquals("Error testing post writeShort/readShort round-tripping", ba.readShort(), -50);
+            Assert.assertEquals("Error testing post writeShort/readShort round-tripping", ba.readShort(), 50);
+
+            //test BIG_ENDIAN round-tripping
+
+            ba.position = 0;
+            ba.endian = Endian.BIG_ENDIAN ;
             ba.writeShort(255);
             ba.writeShort(-50);
             ba.writeShort(50);
             ba.position = 0;
 
-            Assert.assertEquals("Error testing post writeShort/readShort roundtripping", ba.length, 6);
-            Assert.assertEquals("Error testing post writeShort/readShort roundtripping", ba.readShort(), 255);
-            Assert.assertEquals("Error testing post writeShort/readShort roundtripping", ba.readShort(), -50);
-            Assert.assertEquals("Error testing post writeShort/readShort roundtripping", ba.readShort(), 50);
+            Assert.assertEquals("Error testing post writeShort/readShort round-tripping", ba.length, 6);
+            Assert.assertEquals("Error testing post writeShort/readShort round-tripping", ba.readShort(), 255);
+            Assert.assertEquals("Error testing post writeShort/readShort round-tripping", ba.readShort(), -50);
+            Assert.assertEquals("Error testing post writeShort/readShort round-tripping", ba.readShort(), 50);
         }
 
 
         [Test]
-        public function testcShortRoundTripping():void {
+        public function testUnsignedShortRoundTripping():void
+        {
             var ba:BinaryData = new BinaryData();
+            //test LITTLE_ENDIAN round-tripping
+            ba.endian = Endian.LITTLE_ENDIAN;
             ba.writeShort(255);
             ba.writeShort(-50);
             ba.writeShort(50);
             ba.position = 0;
 
-            Assert.assertEquals("Error testing post unsigned writeShort/readShort roundtripping", ba.length, 6);
-            Assert.assertEquals("Error testing post unsigned writeShort/readShort roundtripping", ba.readUnsignedShort(), 255);
-            Assert.assertEquals("Error testing post unsigned writeShort/readShort roundtripping", ba.readUnsignedShort(), 65486);
-            Assert.assertEquals("Error testing post unsigned writeShort/readShort roundtripping", ba.readUnsignedShort(), 50);
+            Assert.assertEquals("Error testing post unsigned writeShort/readShort round-tripping", ba.length, 6);
+            Assert.assertEquals("Error testing post unsigned writeShort/readShort round-tripping", ba.readUnsignedShort(), 255);
+            Assert.assertEquals("Error testing post unsigned writeShort/readShort round-tripping", ba.readUnsignedShort(), 65486);
+            Assert.assertEquals("Error testing post unsigned writeShort/readShort round-tripping", ba.readUnsignedShort(), 50);
+
+            //test BIG_ENDIAN round-tripping
+
+            ba.position = 0;
+            ba.endian = Endian.BIG_ENDIAN ;
+            ba.writeShort(255);
+            ba.writeShort(-50);
+            ba.writeShort(50);
+            ba.position = 0;
+
+            Assert.assertEquals("Error testing post unsigned writeShort/readShort round-tripping", ba.length, 6);
+            Assert.assertEquals("Error testing post unsigned writeShort/readShort round-tripping", ba.readUnsignedShort(), 255);
+            Assert.assertEquals("Error testing post unsigned writeShort/readShort round-tripping", ba.readUnsignedShort(), 65486);
+            Assert.assertEquals("Error testing post unsigned writeShort/readShort round-tripping", ba.readUnsignedShort(), 50);
         }
 
         [Test]
-        public function testIntRoundTripping():void {
+        public function testIntRoundTripping():void
+        {
             var ba:BinaryData = new BinaryData();
+            //test LITTLE_ENDIAN round-tripping
+            ba.endian = Endian.LITTLE_ENDIAN;
+            ba.writeInt(65536);
+            ba.writeInt(-50);
+            ba.writeInt(50);
+            ba.position = 0;
+
+            Assert.assertEquals("Error testing post writeInt/readInt round-tripping", ba.length, 12);
+            Assert.assertEquals("Error testing post writeInt/readInt round-tripping", ba.readInt(), 65536);
+            Assert.assertEquals("Error testing post writeInt/readInt round-tripping", ba.readInt(), -50);
+            Assert.assertEquals("Error testing post writeInt/readInt round-tripping", ba.readInt(), 50);
+
+            //test BIG_ENDIAN round-tripping
+
+            ba.position = 0;
+            ba.endian = Endian.BIG_ENDIAN ;
             ba.writeInt(65536);
             ba.writeInt(-50);
             ba.writeInt(50);
             ba.position = 0;
 
-            Assert.assertEquals("Error testing post writeInt/readInt roundtripping", ba.length, 12);
-            Assert.assertEquals("Error testing post writeInt/readInt roundtripping", ba.readInt(), 65536);
-            Assert.assertEquals("Error testing post writeInt/readInt roundtripping", ba.readInt(), -50);
-            Assert.assertEquals("Error testing post writeInt/readInt roundtripping", ba.readInt(), 50);
+            Assert.assertEquals("Error testing post writeInt/readInt round-tripping", ba.length, 12);
+            Assert.assertEquals("Error testing post writeInt/readInt round-tripping", ba.readInt(), 65536);
+            Assert.assertEquals("Error testing post writeInt/readInt round-tripping", ba.readInt(), -50);
+            Assert.assertEquals("Error testing post writeInt/readInt round-tripping", ba.readInt(), 50);
         }
 
 
         [Test]
-        public function testUnsignedIntRoundTripping():void {
+        public function testUnsignedIntRoundTripping():void
+        {
             var ba:BinaryData = new BinaryData();
+            //test LITTLE_ENDIAN round-tripping
+            ba.endian = Endian.LITTLE_ENDIAN;
             ba.writeUnsignedInt(65536);
             ba.writeUnsignedInt(-50);
             ba.writeUnsignedInt(50);
             ba.position = 0;
 
-            Assert.assertEquals("Error testing post writeInt/readInt roundtripping", ba.length, 12);
-            Assert.assertEquals("Error testing post writeInt/readInt roundtripping", ba.readUnsignedInt(), 65536);
-            Assert.assertEquals("Error testing post writeInt/readInt roundtripping", ba.readUnsignedInt(), 4294967246);
-            Assert.assertEquals("Error testing post writeInt/readInt roundtripping", ba.readUnsignedInt(), 50);
-        }
+            Assert.assertEquals("Error testing post writeInt/readInt round-tripping", ba.length, 12);
+            Assert.assertEquals("Error testing post writeInt/readInt round-tripping", ba.readUnsignedInt(),65536);
+            Assert.assertEquals("Error testing post writeInt/readInt round-tripping", ba.readUnsignedInt(), 4294967246);
+            Assert.assertEquals("Error testing post writeInt/readInt round-tripping", ba.readUnsignedInt(), 50);
 
-        [Test]
-        public function testFloatRoundTripping():void {
-            var ba:BinaryData = new BinaryData();
+            //test BIG_ENDIAN round-tripping
 
-            ba.writeFloat(86.54);
-            ba.writeFloat(-50.5);
-            ba.writeFloat(0);
             ba.position = 0;
+            ba.endian = Endian.BIG_ENDIAN ;
+            ba.writeUnsignedInt(65536);
+            ba.writeUnsignedInt(-50);
+            ba.writeUnsignedInt(50);
+            ba.position = 0;
+
+            Assert.assertEquals("Error testing post writeInt/readInt round-tripping", ba.length, 12);
+            Assert.assertEquals("Error testing post writeInt/readInt round-tripping", ba.readUnsignedInt(),65536);
+            Assert.assertEquals("Error testing post writeInt/readInt round-tripping", ba.readUnsignedInt(), 4294967246);
+            Assert.assertEquals("Error testing post writeInt/readInt round-tripping", ba.readUnsignedInt(), 50);
+        }
+
+        [Test]
+        public function testFloatRoundTripping():void
+        {
+            var ble:BinaryData = new BinaryData();
+            //test LITTLE_ENDIAN round-tripping
+            ble.endian = Endian.LITTLE_ENDIAN;
+            ble.writeFloat(86.54);
 
-            Assert.assertEquals("Error testing post writeFloat/readFloat roundtripping", ba.length, 12);
 
+            Assert.assertEquals("Error testing post writeFloat/readFloat round-tripping", ble.length, 4);
+            Assert.assertEquals("Error testing post writeFloat/readFloat round-tripping", ble.position, 4);
             //check bytes to account for precision loss between double and float comparisons
-            var expected:Array = [66, 173, 20, 123];
-            if (ba.endian == Endian.LITTLE_ENDIAN) expected = expected.reverse();
+            Assert.assertTrue("Error testing post writeFloat/readFloat round-tripping", bytesMatchExpectedData(ble,[123,20,173,66]));
 
-            for (var i:int = 0; i < 4; i++) {
-                Assert.assertEquals("Error testing post writeFloat/readFloat roundtripping", ba.readUnsignedByte(), expected[i]);
-            }
+            var bbe:BinaryData = new BinaryData();
+            //test BIG_ENDIAN round-tripping
+            bbe.endian = Endian.BIG_ENDIAN;
+            bbe.writeFloat(86.54);
+
+
+            Assert.assertEquals("Error testing post writeFloat/readFloat round-tripping", bbe.length, 4);
+            Assert.assertEquals("Error testing post writeFloat/readFloat round-tripping", bbe.position, 4);
+            //check bytes to account for precision loss between double and float comparisons
+            Assert.assertTrue("Error testing post writeFloat/readFloat round-tripping", bytesMatchExpectedData(bbe,[66,173,20,123]));
 
 
-            Assert.assertEquals("Error testing post writeFloat/readFloat roundtripping", ba.readFloat(), -50.5);
-            Assert.assertEquals("Error testing post writeFloat/readFloat roundtripping", ba.readFloat(), 0);
         }
 
 
-        [Test]
-        public function testDoubleRoundTripping():void {
-            var ba:BinaryData = new BinaryData();
-            ba.writeDouble(86.54);
-            ba.writeDouble(-50.5);
-            ba.writeDouble(0);
-            ba.position = 0;
+    [Test]
+    public function testDoubleRoundTripping():void
+    {
 
-            Assert.assertEquals("Error testing post writeDouble/readDouble roundtripping", ba.length, 24);
-            Assert.assertEquals("Error testing post writeDouble/readDouble roundtripping", ba.readDouble(), 86.54);
-            Assert.assertEquals("Error testing post writeDouble/readDouble roundtripping", ba.readDouble(), -50.5);
-            Assert.assertEquals("Error testing post writeDouble/readDouble roundtripping", ba.readDouble(), 0);
-        }
+        var ble:BinaryData = new BinaryData();
+        //test LITTLE_ENDIAN round-tripping
+        ble.endian = Endian.LITTLE_ENDIAN;
+        ble.writeDouble(86.54);
 
 
-        [Test]
-        public function testWriteBytes():void {
-            var ba:BinaryData = new BinaryData();
-            for (var i:int = 0; i < 50; i++) ba.writeByte(i);
+        Assert.assertEquals("Error testing post writeDouble/readDouble round-tripping", ble.length, 8);
+        Assert.assertEquals("Error testing post writeDouble/readDouble round-tripping", ble.position, 8);
 
+        //check bytes
+        Assert.assertTrue("Error testing post writeDouble/readDouble round-tripping", bytesMatchExpectedData(ble,[195,245,40,92,143,162,85,64]));
 
-            var newBa:BinaryData = new BinaryData();
-            newBa.writeBytes(ba);
+        var bbe:BinaryData = new BinaryData();
+        //test BIG_ENDIAN round-tripping
+        bbe.endian = Endian.BIG_ENDIAN;
+        bbe.writeDouble(86.54);
 
-            Assert.assertEquals("BinaryData writeBytes: length", 50, newBa.length);
-            Assert.assertEquals("BinaryData writeBytes: position", 50, newBa.position);
 
-            for (i = 0; i < 50; i++) {
-                Assert.assertEquals("BinaryData writeBytes: content check", i, newBa.array[i]);
-            }
+        Assert.assertEquals("Error testing post writeDouble/readDouble round-tripping", bbe.length, 8);
+        Assert.assertEquals("Error testing post writeDouble/readDouble round-tripping", bbe.position, 8);
+        //check bytes
 
-            newBa = new BinaryData();
+        Assert.assertTrue("Error testing post writeDouble/readDouble round-tripping", bytesMatchExpectedData(bbe,[64,85,162,143,92,40,245,195]));
 
-        }
 
-        [Test]
-        public function testReadBytes():void {
-            var ba:BinaryData = new BinaryData();
-            for (var i:int = 0; i < 50; i++) ba.writeByte(i);
-            ba.position = 0;
-            var newBa:BinaryData = new BinaryData();
-
-            ba.readBytes(newBa, 5, 10);
-            Assert.assertEquals("BinaryData readBytes: position", 10, ba.position);
-            Assert.assertEquals("BinaryData readBytes: length", 15, newBa.length);
-            Assert.assertEquals("BinaryData readBytes: position", 0, newBa.position);
-            var expected:Array = [0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
-            for (i = 5; i < 15; i++) {
-                Assert.assertEquals("BinaryData readBytes: content check", expected[i], newBa.array[i]);
-            }
+        ble.position = 0;
+        bbe.position = 0;
+        Assert.assertEquals("Error testing post writeDouble/readDouble round-tripping", bbe.readDouble(), 86.54);
+        Assert.assertEquals("Error testing post writeDouble/readDouble round-tripping", ble.readDouble(), 86.54);
+
+        Assert.assertEquals("Error testing post writeDouble/readDouble round-tripping", bbe.position, 8);
+        Assert.assertEquals("Error testing post writeDouble/readDouble round-tripping", ble.position, 8);
+
+    }
+
+
+
+    [Test]
+    public function testWriteBytes():void
+    {
+        var ba:BinaryData = new BinaryData();
+        for (var i:int=0;i<50;i++) ba.writeByte(i);
+
+
+        var newBa:BinaryData = new BinaryData();
+        newBa.writeBytes(ba);
+
+        Assert.assertEquals("BinaryData writeBytes: length", 50, newBa.length);
+        Assert.assertEquals("BinaryData writeBytes: position", 50, newBa.position);
+
+        for (i=0;i<50;i++) {
+            Assert.assertEquals("BinaryData writeBytes: content check", i, newBa.array[i]);
         }
 
 
+
     }
+
+    [Test]
+    public function testReadBytes():void
+    {
+        var ba:BinaryData = new BinaryData();
+        for (var i:int=0;i<50;i++) ba.writeByte(i);
+        ba.position=0;
+        var newBa:BinaryData = new BinaryData();
+
+        ba.readBytes(newBa,5,10);
+        Assert.assertEquals("BinaryData readBytes: position", 10, ba.position);
+        Assert.assertEquals("BinaryData readBytes: length", 15, newBa.length);
+        Assert.assertEquals("BinaryData readBytes: position", 0, newBa.position);
+        var expected:Array = [0,0,0,0,0,0,1,2,3,4,5,6,7,8,9];
+        for (i=5;i<15;i++) {
+            Assert.assertEquals("BinaryData readBytes: content check", expected[i], newBa.array[i]);
+        }
+    }
+
+
+}
 }


[07/15] git commit: [flex-asjs] [refs/heads/refactor-sprite] - [Improvements] More performance tweaks, consistency tweaks, and doc improvements.

Posted by ha...@apache.org.
[Improvements] More performance tweaks, consistency tweaks, and doc improvements.


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/febae6a6
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/febae6a6
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/febae6a6

Branch: refs/heads/refactor-sprite
Commit: febae6a6e2237abee1da67d14f98bce71e3f1792
Parents: f791f02
Author: greg-dove <gr...@gmail.com>
Authored: Tue Jul 26 15:02:27 2016 +1200
Committer: greg-dove <gr...@gmail.com>
Committed: Tue Jul 26 15:02:27 2016 +1200

----------------------------------------------------------------------
 .../flex/org/apache/flex/utils/BinaryData.as    | 235 ++++++++++++-------
 .../main/flex/org/apache/flex/utils/Endian.as   |  20 +-
 2 files changed, 156 insertions(+), 99 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/febae6a6/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
index d44ac0e..29e4e76 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
@@ -62,6 +62,9 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
     /**
      *  Utility method to create a BinaryData object from a string.
      *
+     *  @param {String} str The string to convert to BinaryData as UTF-8 bytes.
+     *  @return {BinaryData} The BinaryData instance from the UTF-8 bytes of the string.     *
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
@@ -78,13 +81,19 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
      *  Gets a reference to the internal array of bytes.
      *  On the Flash side, this is  a ByteArray.
      *  On the JS side, it's a Uint8Array.
-     *  This is primarily used for indexed access to the bytes, and internally
-     *  where the platform-specific implementation is significant.
+     *  This is primarily used for indexed access to the bytes, and particularly
+     *  where platform-specific performance optimization is required.
+     *  To maintain cross-target consistency, you should not alter the length
+     *  of the ByteArray in any swf specific code, you should assume its length is fixed
+     *  (even though it is not).
+     *
+     *  @return {ByteArray} The BinaryData backing array as ByteArray on flash.
      *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.7.0
+
      */
     COMPILE::SWF
     public function get array():ByteArray
@@ -102,6 +111,8 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
      *  of the ByteArray in any swf specific code, assume its length is fixed
      *  (even though it is not).
      *
+     *  @return {Uint8Array} The BinaryData backing array as Uint8Array in javascript.
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
@@ -112,6 +123,8 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
     {
         return getTypedArray();
     }
+
+
     COMPILE::JS
     private var _endian:String = Endian.BIG_ENDIAN;
 
@@ -180,6 +193,8 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
     /**
      *  Write a Boolean value (as a single byte) at the current position
      *
+     *  @param {Boolean} value The boolean value to write into the BinaryData at the current position
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
@@ -201,6 +216,8 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
     /**
      *  Write a byte of binary data at the current position
      *
+     *  @param {int} byte The value to write into the BinaryData at the current position
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
@@ -214,12 +231,10 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         }
         COMPILE::JS
         {
-            var view:Uint8Array;
-
-            ensureWritableBytes(1);
-
-            view = new Uint8Array(ba, _position, 1);
-            view[0] = byte;
+            if (_position + 1 > _len) {
+                setBufferSize(_position + 1);
+            }
+            new Uint8Array(ba, _position, 1)[0] = byte;
             _position++;
         }
     }
@@ -229,6 +244,10 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
      *  is omitted or is zero, it will represent the entire length of the source
      *  starting from offset. If offset is omitted also, it defaults to zero.
      *
+     *  @param {BinaryData} source The source BinaryData to write from at the current position
+     *  @param {uint} offset The optional offset value of the starting bytes to write inside source
+     *  @param {uint} length The optional length value of the bytes to write from offset in source
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
@@ -245,9 +264,9 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         {
 
             if (length == 0) length = source.length - offset ;
-
-            ensureWritableBytes(length);
-
+            if (_position + length > _len) {
+                setBufferSize(_position + length);
+            }
             var dest:Uint8Array = new Uint8Array(ba, _position, length);
             var src:Uint8Array = new Uint8Array(source.ba, offset,length);
             dest.set(src);
@@ -257,7 +276,10 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
     }
 
     /**
-     *  Write a short integer of binary data at the current position
+     *  Write a short integer (16 bits, typically represented by a 32 bit int parameter between -32768 and 65535)
+     *  of binary data at the current position
+     *
+     *  @param {int} short The value to write into the BinaryData at the current position
      *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
@@ -275,7 +297,9 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
             if (!_sysEndian) {
                 short = (((short & 0xff00) >>> 8) | ((short & 0xff) <<8 ));
             }
-            ensureWritableBytes(2);
+            if (_position + 2 > _len) {
+                setBufferSize(_position + 2);
+            }
             new Int16Array(ba, _position, 1)[0] = short;
             _position += 2;
         }
@@ -284,24 +308,28 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
     /**
      *  Write an unsigned int (32 bits) of binary data at the current position
      *
+     *  @param {uint} val The value to write into the BinaryData at the current position
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
-    public function writeUnsignedInt(unsigned:uint):void
+    public function writeUnsignedInt(val:uint):void
     {
         COMPILE::SWF
         {
-            ba.writeUnsignedInt(unsigned);
+            ba.writeUnsignedInt(val);
         }
         COMPILE::JS
         {
             if (!_sysEndian) {
-                unsigned = ((unsigned & 0xff000000) >>> 24) | ((unsigned & 0x00ff0000) >> 8) | ((unsigned & 0x0000ff00) << 8) | (unsigned << 24);
+                val = ((val & 0xff000000) >>> 24) | ((val & 0x00ff0000) >> 8) | ((val & 0x0000ff00) << 8) | (val << 24);
+            }
+            if (_position + 4 > _len) {
+                setBufferSize(_position + 4);
             }
-            ensureWritableBytes(4);
-            new Uint32Array(ba, _position, 1)[0] = unsigned;
+            new Uint32Array(ba, _position, 1)[0] = val;
             _position += 4;
         }
     }
@@ -309,6 +337,8 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
     /**
      *  Write a signed int (32 bits) of binary data at the current position
      *
+     *  @param {int} val The value to write into the BinaryData at the current position
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
@@ -325,7 +355,9 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
             if (!_sysEndian) {
                 val = (((val & 0xff000000) >>> 24) | ((val & 0x00ff0000) >> 8) | ((val & 0x0000ff00) << 8) | (val << 24)) >> 0;
             }
-            ensureWritableBytes(4);
+            if (_position + 4 > _len) {
+                setBufferSize(_position + 4);
+            }
             new Int32Array(ba, _position, 1)[0] = val;
             _position += 4;
         }
@@ -335,30 +367,30 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
      *  Writes an IEEE 754 single-precision (32-bit) floating-point number to the
      *  BinaryData at the current position
      *
+     *  @param {Number} val The value to write into the BinaryData at the current position
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
-    public function writeFloat(value:Number):void
+    public function writeFloat(val:Number):void
     {
         COMPILE::SWF {
-            return ba.writeFloat(value);
+            return ba.writeFloat(val);
         }
         COMPILE::JS {
-            var view:Float32Array;
-
-            ensureWritableBytes(4);
+            if (_position + 4 > _len) {
+                setBufferSize(_position + 4);
+            }
 
             if(_sysEndian)
             {
-                view = new Float32Array(ba, _position, 1);
-                view[0] = value;
+                new Float32Array(ba, _position, 1)[0] = val;
             }
             else
             {
-                var dv:DataView = new DataView(ba);
-                dv.setFloat32(_position,value,_endian == Endian.LITTLE_ENDIAN);
+                new DataView(ba).setFloat32(_position,val,_endian == Endian.LITTLE_ENDIAN);
             }
             _position += 4;
         }
@@ -367,31 +399,26 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
      *  Writes an IEEE 754 double-precision (64-bit) floating-point number to the
      *  BinaryData at the current position
      *
+     *  @param {Number} val The value to write into the BinaryData at the current position
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
-    public function writeDouble(value:Number):void
+    public function writeDouble(val:Number):void
     {
         COMPILE::SWF {
-            return ba.writeDouble(value);
+            return ba.writeDouble(val);
         }
         COMPILE::JS {
-            var view:Float64Array;
-
-            ensureWritableBytes(8);
-
-            if(_sysEndian)
-            {
-                view = new Float64Array(ba, _position, 1);
-                view[0] = value;
+            if (_position + 8 > _len) {
+                setBufferSize(_position + 8);
             }
+            if(_sysEndian)
+                new Float64Array(ba, _position, 1)[0] = val;
             else
-            {
-                var dv:DataView = new DataView(ba);
-                dv.setFloat64(_position,value,_endian == Endian.LITTLE_ENDIAN);
-            }
+                new DataView(ba).setFloat64(_position,val,_endian == Endian.LITTLE_ENDIAN);
             _position += 8;
         }
     }
@@ -399,6 +426,8 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
      *  Reads a Boolean value (as a single byte) at the current position.
      *  returns true if the byte was non-zero, false otherwise
      *
+     *  @return {Boolean} The boolean value read from the current position
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
@@ -420,6 +449,8 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
     /**
      *  Read a signed byte of binary data at the current position
      *
+     *  @return {int} An int value in the range -128 to 127, read from the current position
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
@@ -441,6 +472,8 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
     /**
      *  Read an unsigned byte of binary data at the current position
      *
+     *  @return {uint} An uint value in the range 0 to 255, read from the current position
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
@@ -463,8 +496,12 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
      *  Reads the number of data bytes, specified by the length parameter, from the BinaryData.
      *  The bytes are read into the BinaryData object specified by the destination parameter,
      *  and the bytes are written into the destination BinaryData starting at the position specified by offset.
-     *  If length is omitted or is zero, all bytes are read following offset to the end of this BinaryData.
-     *  If offset is also omitted, it defaults to zero.
+     *  If length is omitted or is zero, all bytes are read following the current position to the end
+     *  of this BinaryData. If offset is also omitted, it defaults to zero.
+     *
+     *  @param {BinaryData} destination The destination BinaryData to write bytes into from the current position
+     *  @param {uint} offset The optional offset value of the starting bytes to write inside destination
+     *  @param {uint} length The optional length value of the bytes to read
      *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
@@ -499,13 +536,16 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
 
     /**
      *  Read a byte of binary data at the specified index. Does not change the <code>position</code> property.
+     *  If an index is out of range (beyond the current length) this will return zero.
+     *
+     *  @return {uint} A byte value in the range 0-255 from the index
      *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
-    public function readByteAt(idx:uint):int
+    public function readByteAt(idx:uint):uint
     {
         COMPILE::SWF
         {
@@ -513,7 +553,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         }
         COMPILE::JS
         {
-            return getTypedArray()[idx];
+            return getTypedArray()[idx] >> 0;
         }
     }
 
@@ -557,6 +597,8 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
     /**
      *  Read a short int of binary data at the current position
      *
+     *  @return {int} An int value in the range -32768 to 32767, read from the current position
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
@@ -581,7 +623,9 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
     }
 
     /**
-     *  Read an unsigned int of binary data at the current position
+     *  Read an unsigned int (32bit) of binary data at the current position
+     *
+     *  @return {uint} A uint value, read from the current position
      *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
@@ -608,6 +652,8 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
     /**
      *  Read an unsigned short (16bit) of binary data at the current position
      *
+     *  @return {uint} A uint value in the range 0 to 65535, read from the current position
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
@@ -631,7 +677,9 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
     }
 
     /**
-     *  Read a signed int of binary data at the current position
+     *  Read a signed int (32bit) of binary data at the current position
+     *
+     *  @return {int} An int value, read from the current position
      *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
@@ -658,6 +706,8 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
     /**
      *  Reads an IEEE 754 single-precision (32-bit) floating-point number from the BinaryData.
      *
+     *  @return {Number} A Number value, read from the current position
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
@@ -669,18 +719,13 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
             return ba.readFloat();
         }
         COMPILE::JS {
-            var view:Float32Array;
-
+            var ret :Number;
             if(_sysEndian)
             {
-                view = new Float32Array(ba, _position, 1);
-                _position += 4;
-                return view[0];
-            }
-            var dv:DataView = new DataView(ba);
-            var i:Number = dv.getFloat32(_position,_endian == Endian.LITTLE_ENDIAN);
+                ret = new Float32Array(ba, _position, 1)[0];
+            }  else ret = new DataView(ba).getFloat32(_position,_endian == Endian.LITTLE_ENDIAN);
             _position += 4;
-            return i;
+            return ret;
         }
 
     }
@@ -688,6 +733,8 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
     /**
      *  Reads an IEEE 754 double-precision (64-bit) floating-point number from the BinaryData.
      *
+     *  @return {Number} A Number value, read from the current position
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
@@ -699,25 +746,29 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
             return ba.readDouble();
         }
         COMPILE::JS {
-            var view:Float64Array;
-
+            var ret : Number;
             if(_sysEndian)
-            {
-                view = new Float64Array(ba, _position, 1);
-                _position += 8;
-                return view[0];
-            }
-            var dv:DataView = new DataView(ba);
-            var i:Number = dv.getFloat64(_position,_endian == Endian.LITTLE_ENDIAN);
+                ret = new Float64Array(ba, _position, 1)[0];
+            else ret = new DataView(ba).getFloat64(_position,_endian == Endian.LITTLE_ENDIAN);
             _position += 8;
-            return i;
+            return ret;
         }
     }
 
     COMPILE::JS
     private var _len:uint;
 
-
+    /**
+     *  The length of this BinaryData, in bytes.
+     *  If the length is set to a value that is larger than the current length, the right side
+     *  of the BinaryData is filled with zeros.
+     *  If the length is set to a value that is smaller than the current length, the BinaryData is truncated.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.7.0
+     */
     public function get length():int
     {
         COMPILE::SWF
@@ -762,7 +813,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         }
     }
     /**
-     *  The total number of bytes remaining to be read.
+     *  The total number of bytes available to read from the current position.
      *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
@@ -777,7 +828,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         }
         COMPILE::JS
         {
-            return _len - _position;
+            return _position < _len ? _len - _position : 0;
         }
     }
 
@@ -786,6 +837,9 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
      *  Moves, or returns the current position, in bytes, of the pointer into the BinaryData object.
      *  This is the point at which the next call to a read method starts reading or a write method starts writing.
      *
+     *  Setting the position beyond the end of the current length value is possible and will increase the length
+     *  during write operations, but will throw an error during read operations.
+     *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
@@ -824,7 +878,8 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
      *  browsers have a way to auto-resize a binary
      *  data as you write data to the binary data buffer
      *  and resizing in large chunks is generally more
-     *  efficient anyway.
+     *  efficient anyway. Preallocating bytes to write into
+     *  is also more efficient on the swf target.
      *
      *  @param extra The number of additional bytes.
      *
@@ -846,17 +901,13 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         }
     }
 
-    COMPILE::JS
-    protected function ensureWritableBytes(len:uint):void{
-        if (_position + len > _len) {
-            setBufferSize( _position + len );
-        }
-    }
-
 
     /**
-     *  Reads a UTF-8 string from the byte stream.
+     *  Reads a UTF-8 string from the BinaryData.
      *  The string is assumed to be prefixed with an unsigned short indicating the length in bytes.
+     *  The <code>position</code> is advanced to the first byte following the string's bytes.
+     *
+     *  @return {String} The utf-8 decoded string
      *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
@@ -878,9 +929,11 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
     }
 
     /**
-     *  Reads a sequence of UTF-8 bytes specified by the length parameter from the byte stream and returns a string.
+     *  Reads a sequence of UTF-8 bytes specified by the length parameter
+     *  from the BinaryData and returns a string.
+     *  The <code>position</code> is advanced to the first byte following the string's bytes.
      *
-     *  @param An unsigned short indicating the length of the UTF-8 bytes.
+     *  @param {uint} length An unsigned short indicating the length of the UTF-8 bytes.
      *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
@@ -949,36 +1002,40 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
 
     /**
      *  Writes a UTF-8 string to the byte stream.
-     *  The length of the UTF-8 string in bytes is written first, as a 16-bit integer,
+     *  The length of the UTF-8 string in bytes is written first, as a 16-bit unsigned integer,
      *  followed by the bytes representing the characters of the string.
      *  If the byte length of the string is larger than 65535 this will throw a RangeError
+     *  The <code>position</code> is advanced to the first byte following the string's bytes.
      *
-     *  @param The string value to be written.
+     *  @param {String} str The string value to be written.
      *
      *  @langversion 3.0
      *  @playerversion Flash 10.2
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.7.0
      */
-    public function writeUTF(value:String):void
+    public function writeUTF(str:String):void
     {
         COMPILE::SWF
         {
-            ba.writeUTF(value);
+            ba.writeUTF(str);
         }
 
         COMPILE::JS
         {
-            var utcBytes:Uint8Array = getUTFBytes(value , true);
+            var utcBytes:Uint8Array = getUTFBytes(str , true);
             _position =  mergeInToArrayBuffer (_position,utcBytes);
         }
     }
 
     /**
-     *  Writes a UTF-8 string to the byte stream. Similar to the writeUTF() method,
-     *  but writeUTFBytes() does not prefix the string with a 16-bit length word.
+     *  Writes a UTF-8 string to the BinaryData. Similar to the writeUTF() method,
+     *  but writeUTFBytes() does not prefix the string with a 16-bit length word, and
+     *  therefore also permits strings longer than 65535 bytes (note: byte length will not
+     *  necessarily be the same as string length because some characters can be
+     *  multibyte characters).
      *
-     *  @param The string value to be written.
+     *  @param {String} str The string value to be written.
      *
      *  @langversion 3.0
      *  @playerversion Flash 10.2

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/febae6a6/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/Endian.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/Endian.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/Endian.as
index 5d7a595..53a0bf2 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/Endian.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/Endian.as
@@ -54,6 +54,9 @@ package org.apache.flex.utils
 		 *  In swf targets this is always BIG_ENDIAN. When targeting
 		 *  javascript it may differ depending on the target environment,
 		 *  but is Endian.LITTLE_ENDIAN for most machines/browsers.
+		 *  In theory, the native support classes for javascript should
+		 *  have better performance when working with binary data
+		 *  for integers and numbers represented with this endianness.
 		 *
 		 *
 		 *  @langversion 3.0
@@ -72,16 +75,13 @@ package org.apache.flex.utils
 
 
 		COMPILE::JS
-		private static function _detectSystemEndian():String{
-            delete Endian["_detectSystemEndian"];
-			var tester:Uint8Array = new Uint8Array([102,108,101,120]);
-			var checker:Uint32Array = new Uint32Array(tester.buffer);
-			var check:uint = checker[0];
-			return (check == 1718379896) ? BIG_ENDIAN : LITTLE_ENDIAN ;
-		}
-
-		COMPILE::JS
-		private static var _sysEndian:String = _detectSystemEndian();
+		private static var _sysEndian:String =
+				function():String {
+					var tester:Uint8Array = new Uint8Array([102,108,101,120]);
+					var checker:Uint32Array = new Uint32Array(tester.buffer);
+					var check:uint = checker[0];
+					return (check == 1718379896) ? BIG_ENDIAN : LITTLE_ENDIAN ;
+				}();
 
 	}
 }
\ No newline at end of file


[05/15] git commit: [flex-asjs] [refs/heads/refactor-sprite] - [Consistency] Set default Endian to BIG ENDIAN in javascript to be consistent with flash [Performance] optimization of int/unit/short read/writes to avoid using DataView, substantial gains

Posted by ha...@apache.org.
[Consistency] Set default Endian to BIG ENDIAN in javascript to be consistent with flash
[Performance] optimization of int/unit/short read/writes to avoid using DataView, substantial gains


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/6288c2dd
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/6288c2dd
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/6288c2dd

Branch: refs/heads/refactor-sprite
Commit: 6288c2ddff4872464faa9bc6ce327e77730a47e1
Parents: d12bcdd
Author: greg-dove <gr...@gmail.com>
Authored: Mon Jul 25 15:20:33 2016 +1200
Committer: greg-dove <gr...@gmail.com>
Committed: Mon Jul 25 15:20:33 2016 +1200

----------------------------------------------------------------------
 .../flex/org/apache/flex/utils/BinaryData.as    | 151 +++++++------------
 .../main/flex/org/apache/flex/utils/Endian.as   |  29 +---
 2 files changed, 61 insertions(+), 119 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/6288c2dd/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
index 942b394..769b006 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as
@@ -112,7 +112,10 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         return getTypedArray();
     }
     COMPILE::JS
-    private var _endian:String = Endian.defaultEndian;
+    private var _endian:String = Endian.BIG_ENDIAN;
+
+    COMPILE::JS
+    private var _sysEndian:Boolean = _endian == Endian.systemEndian;
 
     /**
      *  Indicates the byte order for the data.
@@ -142,6 +145,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         if (value == Endian.BIG_ENDIAN || Endian.LITTLE_ENDIAN) {
             COMPILE::JS {
                 _endian = value;
+                _sysEndian = value == Endian.systemEndian;
             }
             COMPILE::SWF {
                 ba.endian = value;
@@ -267,19 +271,11 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         }
         COMPILE::JS
         {
-            var view:Int16Array;
-
-            ensureWritableBytes(2);
-            if(_endian == Endian.defaultEndian)
-            {
-                view = new Int16Array(ba, _position, 1);
-                view[0] = short;
-            }
-            else
-            {
-                var dv:DataView = new DataView(ba);
-                dv.setInt16(_position,short,_endian == Endian.LITTLE_ENDIAN);
+            if (!_sysEndian) {
+                short = (((short & 0xff00) >>> 8) | ((short & 0xff) <<8 ));
             }
+            ensureWritableBytes(2);
+            new Int16Array(ba, _position, 1)[0] = short;
             _position += 2;
         }
     }
@@ -300,19 +296,11 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         }
         COMPILE::JS
         {
-            var view:Uint32Array;
-
-            ensureWritableBytes(4);
-            if(_endian == Endian.defaultEndian)
-            {
-                view = new Uint32Array(ba, _position, 1);
-                view[0] = unsigned;
-            }
-            else
-            {
-                var dv:DataView = new DataView(ba);
-                dv.setUint32(_position,unsigned,_endian == Endian.LITTLE_ENDIAN);
+            if (!_sysEndian) {
+                unsigned = ((unsigned & 0xff000000) >>> 24) | ((unsigned & 0x00ff0000) >> 8) | ((unsigned & 0x0000ff00) << 8) | (unsigned << 24);
             }
+            ensureWritableBytes(4);
+            new Uint32Array(ba, _position, 1)[0] = unsigned;
             _position += 4;
         }
     }
@@ -325,28 +313,19 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
      *  @playerversion AIR 2.6
      *  @productversion FlexJS 0.0
      */
-    public function writeInt(integer:int):void
+    public function writeInt(val:int):void
     {
         COMPILE::SWF
         {
-            ba.writeInt(integer);
+            ba.writeInt(val);
         }
         COMPILE::JS
         {
-            var view:Int32Array;
-
-            ensureWritableBytes(4);
-
-            if(_endian == Endian.defaultEndian)
-            {
-                view = new Int32Array(ba, _position, 1);
-                view[0] = integer;
-            }
-            else
-            {
-                var dv:DataView = new DataView(ba);
-                dv.setInt32(_position,integer,_endian == Endian.LITTLE_ENDIAN);
+            if (!_sysEndian) {
+                val = (((val & 0xff000000) >>> 24) | ((val & 0x00ff0000) >> 8) | ((val & 0x0000ff00) << 8) | (val << 24)) >> 0;
             }
+            ensureWritableBytes(4);
+            new Int32Array(ba, _position, 1)[0] = val;
             _position += 4;
         }
     }
@@ -370,7 +349,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
 
             ensureWritableBytes(4);
 
-            if(_endian == Endian.defaultEndian)
+            if(_sysEndian)
             {
                 view = new Float32Array(ba, _position, 1);
                 view[0] = value;
@@ -402,7 +381,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
 
             ensureWritableBytes(8);
 
-            if(_endian == Endian.defaultEndian)
+            if(_sysEndian)
             {
                 view = new Float64Array(ba, _position, 1);
                 view[0] = value;
@@ -453,10 +432,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         }
         COMPILE::JS
         {
-
-            var view:Int8Array;
-
-            view = new Int8Array(ba, _position, 1);
+            var view:Int8Array = new Int8Array(ba, _position, 1);
             _position++;
             return view[0];
         }
@@ -476,9 +452,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         }
         COMPILE::JS
         {
-            var view:Uint8Array;
-
-            view = new Uint8Array(ba, _position, 1);
+            var view:Uint8Array = new Uint8Array(ba, _position, 1);
             _position++;
             return view[0];
         }
@@ -595,19 +569,13 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         }
         COMPILE::JS
         {
-            var view:Int16Array;
-
-            if(_endian == Endian.defaultEndian)
-            {
-                view = new Int16Array(ba, _position, 1);
-                _position += 2;
-                return view[0];
+            var ret:int = new Int16Array(ba, _position, 1)[0];
+            if (!_sysEndian) {
+                //special case conversion for short int return value to 32 bit int
+                ret = ((((ret & 0xff00) >> 8) | ((ret & 0xff) << 8)) << 16) >> 16;
             }
-
-            var dv:DataView = new DataView(ba);
-            var i:int = dv.getInt16(_position,_endian == Endian.LITTLE_ENDIAN);
             _position += 2;
-            return i;
+            return ret;
         }
     }
 
@@ -627,18 +595,12 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         }
         COMPILE::JS
         {
-            var view:Uint32Array;
-
-            if(_endian == Endian.defaultEndian)
-            {
-                view = new Uint32Array(ba, _position, 1);
-                _position += 4;
-                return view[0];
+            var ret:uint = new Uint32Array(ba, _position, 1)[0];
+            if (!_sysEndian) {
+                ret = (((ret & 0xff000000) >>> 24) | ((ret & 0x00ff0000) >>> 8) | ((ret & 0x0000ff00) << 8) | (ret << 24)) >>> 0;
             }
-            var dv:DataView = new DataView(ba);
-            var i:uint = dv.getUint32(_position,_endian == Endian.LITTLE_ENDIAN);
             _position += 4;
-            return i;
+            return ret;
         }
     }
 
@@ -657,18 +619,13 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         }
         COMPILE::JS
         {
-            var view:Uint16Array;
 
-            if(_endian == Endian.defaultEndian)
-            {
-                view = new Uint16Array(ba, _position, 1);
-                _position += 2;
-                return view[0];
+            var ret:uint = new Uint16Array(ba, _position, 1)[0];
+            if (!_sysEndian) {
+                ret = ((ret & 0xff00) >> 8 ) | ((ret & 0xff) << 8);
             }
-            var dv:DataView = new DataView(ba);
-            var i:uint = dv.getUint16(_position,_endian == Endian.LITTLE_ENDIAN);
             _position += 2;
-            return i;
+            return ret;
         }
     }
 
@@ -688,19 +645,12 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         }
         COMPILE::JS
         {
-            var view:Int32Array;
-
-            if(_endian == Endian.defaultEndian)
-            {
-                view = new Int32Array(ba, _position, 1);
-                _position += 4;
-                return view[0];
+            var ret:int = new Int32Array(ba, _position, 1)[0];
+            if (!_sysEndian) {
+                ret = (((ret & 0xff000000) >>> 24) | ((ret & 0x00ff0000) >>> 8) | ((ret & 0x0000ff00) << 8) | (ret << 24)) >> 0;
             }
-            var dv:DataView = new DataView(ba);
-            var i:uint = dv.getInt32(_position,_endian == Endian.LITTLE_ENDIAN);
             _position += 4;
-            return i;
-
+            return ret;
         }
     }
 
@@ -720,7 +670,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         COMPILE::JS {
             var view:Float32Array;
 
-            if(_endian == Endian.defaultEndian)
+            if(_sysEndian)
             {
                 view = new Float32Array(ba, _position, 1);
                 _position += 4;
@@ -750,7 +700,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         COMPILE::JS {
             var view:Float64Array;
 
-            if(_endian == Endian.defaultEndian)
+            if(_sysEndian)
             {
                 view = new Float64Array(ba, _position, 1);
                 _position += 8;
@@ -991,11 +941,12 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         }
     }
 
-	
+
     /**
      *  Writes a UTF-8 string to the byte stream.
      *  The length of the UTF-8 string in bytes is written first, as a 16-bit integer,
      *  followed by the bytes representing the characters of the string.
+     *  If the byte length of the string is larger than 65535 this will throw a RangeError
      *
      *  @param The string value to be written.
      *
@@ -1108,13 +1059,17 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
             bytes = new Uint8Array(out);
         }
         if (prependLength) {
+            var len:uint = bytes.length;
+            if (len > 0xffff) {
+                //throw error, similar to swf ByteArray behavior:
+                throw new RangeError("UTF max string length of 65535 bytes exceeded : BinaryData.writeUTF");
+            }
             var temp:Uint8Array = new Uint8Array(bytes.length + 2);
             temp.set(bytes , 2);
-            var len:uint = bytes.length;
-            //preconvert to alternate endian if needed
-            new Uint16Array(temp.buffer,0,2)[0] =
-                    (_endian == Endian.defaultEndian) ?
-                            len : ((len & 0xff) >> 8) | (len << 8);
+            //pre-convert to alternate endian if needed
+            new Uint16Array(temp.buffer,0,1)[0] =
+                    _sysEndian ? len : (((len & 0xff00) >> 8) | ((len & 0xff) << 8));
+
             bytes = temp;
         }
         return bytes;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/6288c2dd/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/Endian.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/Endian.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/Endian.as
index 289d363..5d7a595 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/Endian.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/Endian.as
@@ -48,25 +48,12 @@ package org.apache.flex.utils
 		 */
 		public static const LITTLE_ENDIAN:String = "littleEndian";
 
-		/**
-		 *  Indicates an unknown default endianness (when using BinaryData).
-		 *  You cannot use this value to set the endian value of a BinaryData
-		 *  It is used to check the defaultEndian value for an unexpected result
-		 *
-		 *
-		 *  @langversion 3.0
-		 *  @playerversion Flash 10.2
-		 *  @playerversion AIR 2.6
-		 *  @productversion FlexJS 0.7.0
-		 */
-		public static const UNKNOWN_ENDIAN:String = "unknownEndian";
-
-
 
 		/**
 		 *  Indicates the default endianness on the system.
 		 *  In swf targets this is always BIG_ENDIAN. When targeting
-		 *  javascript it may differ depending on the target environment.
+		 *  javascript it may differ depending on the target environment,
+		 *  but is Endian.LITTLE_ENDIAN for most machines/browsers.
 		 *
 		 *
 		 *  @langversion 3.0
@@ -74,27 +61,27 @@ package org.apache.flex.utils
 		 *  @playerversion AIR 2.6
 		 *  @productversion FlexJS 0.7.0
 		 */
-		public static function get defaultEndian():String {
+		public static function get systemEndian():String {
 			COMPILE::SWF {
 				return BIG_ENDIAN;
 			}
 			COMPILE::JS {
-				return _defaultEndian;
+				return _sysEndian;
 			}
 		}
 
 
 		COMPILE::JS
-		private static function _detectDefaultEndian():String{
-            delete Endian["_detectDefaultEndian"];
+		private static function _detectSystemEndian():String{
+            delete Endian["_detectSystemEndian"];
 			var tester:Uint8Array = new Uint8Array([102,108,101,120]);
 			var checker:Uint32Array = new Uint32Array(tester.buffer);
 			var check:uint = checker[0];
-			return (check == 1718379896) ? BIG_ENDIAN : (check == 2019912806) ? LITTLE_ENDIAN : UNKNOWN_ENDIAN;
+			return (check == 1718379896) ? BIG_ENDIAN : LITTLE_ENDIAN ;
 		}
 
 		COMPILE::JS
-		private static var _defaultEndian:String = _detectDefaultEndian();
+		private static var _sysEndian:String = _detectSystemEndian();
 
 	}
 }
\ No newline at end of file


[09/15] git commit: [flex-asjs] [refs/heads/refactor-sprite] - Merge branch 'develop' into improvement_Binarydata

Posted by ha...@apache.org.
Merge branch 'develop' into improvement_Binarydata


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/c7bb721c
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/c7bb721c
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/c7bb721c

Branch: refs/heads/refactor-sprite
Commit: c7bb721cd76985529b4dc0bb033ef5f2e96c5210
Parents: ae06cfd c383fa7
Author: greg-dove <gr...@gmail.com>
Authored: Tue Jul 26 18:20:01 2016 +1200
Committer: greg-dove <gr...@gmail.com>
Committed: Tue Jul 26 18:20:01 2016 +1200

----------------------------------------------------------------------
 .gitignore                                      |    1 +
 distribution/pom.xml                            |  213 ++-
 .../src/main/assembly/component-air.xml         |  103 ++
 .../src/main/assembly/component-fontkit.xml     |   30 +
 distribution/src/main/assembly/component.xml    |    9 +-
 distribution/src/main/assembly/dir.xml          |    1 +
 .../src/main/assembly/filter.properties         |   21 +
 distribution/src/main/resources/air/adt         |   24 +
 distribution/src/main/resources/air/adt.bat     |   22 +
 .../frameworks/air-config-template.xml          |    6 +-
 .../main/resources/frameworks/air-config.xml    |    6 +-
 .../frameworks/flex-config-template.xml         |    6 +-
 .../main/resources/frameworks/flex-config.xml   |    6 +-
 frameworks/build.xml                            |    4 +-
 frameworks/flex-config-template.xml             |   12 +
 frameworks/flex-config.xml                      |   12 +
 .../flex/binding/ApplicationDataBinding.as      |   20 +-
 .../apache/flex/binding/ContainerDataBinding.as |   20 +-
 .../flex/binding/MXMLBeadViewDataBinding.as     |   20 +-
 .../org/apache/flex/binding/ViewDataBinding.as  |   16 +-
 .../apache/flex/charts/beads/AxisBaseBead.as    |   15 +-
 .../flex/charts/beads/layouts/PieChartLayout.as |    4 +-
 .../org/apache/flex/charts/core/IAxisBead.as    |    2 +-
 .../org/apache/flex/charts/core/IAxisGroup.as   |    4 +-
 .../flex/charts/optimized/SVGBoxItemRenderer.as |   12 +-
 .../flex/charts/optimized/SVGChartAxisGroup.as  |   10 +-
 .../flex/charts/optimized/SVGChartDataGroup.as  |    4 +-
 .../optimized/SVGLineSegmentItemRenderer.as     |   12 +-
 .../charts/optimized/SVGWedgeItemRenderer.as    |   12 +-
 .../charts/supportClasses/BoxItemRenderer.as    |   10 +-
 .../charts/supportClasses/ChartAxisGroup.as     |    6 +-
 .../supportClasses/ILineSegmentItemRenderer.as  |    2 +-
 .../charts/supportClasses/IWedgeItemRenderer.as |    4 +-
 .../supportClasses/LineSegmentItemRenderer.as   |    4 +-
 .../charts/supportClasses/WedgeItemRenderer.as  |   10 +-
 .../projects/Core/src/main/flex/CoreClasses.as  |    1 +
 .../main/flex/org/apache/flex/utils/CSSUtils.as |  145 +-
 .../flex/org/apache/flex/utils/StringPadder.as  |   69 +
 .../src/main/config/compile-as-config.xml       |    1 +
 .../flex/org/apache/flex/createjs/CheckBox.as   |    4 +-
 .../main/flex/org/apache/flex/createjs/Label.as |    4 +-
 .../flex/org/apache/flex/createjs/TextButton.as |    4 +-
 .../apache/flex/createjs/core/CreateJSBase.as   |    6 +-
 .../org/apache/flex/createjs/core/UIBase.as     |   12 +-
 .../org/apache/flex/createjs/graphics/Circle.as |   10 +-
 .../flex/createjs/graphics/GraphicShape.as      |    8 +-
 .../org/apache/flex/createjs/graphics/Rect.as   |   10 +-
 .../org/apache/flex/createjs/tween/Sequence.as  |   52 +
 .../org/apache/flex/createjs/tween/Tween.as     |   45 +-
 .../CreateJS/src/main/resources/defaults.css    |    6 +
 frameworks/projects/Graphics/pom.xml            |    4 +
 .../Graphics/src/main/flex/GraphicsClasses.as   |   32 +-
 .../org/apache/flex/core/graphics/Circle.as     |  102 --
 .../org/apache/flex/core/graphics/Ellipse.as    |   94 -
 .../apache/flex/core/graphics/GradientBase.as   |  229 ---
 .../apache/flex/core/graphics/GradientEntry.as  |  133 --
 .../apache/flex/core/graphics/GraphicShape.as   |  213 ---
 .../flex/core/graphics/GraphicsContainer.as     |  302 ---
 .../flex/org/apache/flex/core/graphics/IFill.as |   32 -
 .../org/apache/flex/core/graphics/IStroke.as    |   29 -
 .../apache/flex/core/graphics/LinearGradient.as |  123 --
 .../flex/org/apache/flex/core/graphics/Path.as  |  100 -
 .../flex/org/apache/flex/core/graphics/Rect.as  |   90 -
 .../org/apache/flex/core/graphics/SolidColor.as |  136 --
 .../flex/core/graphics/SolidColorStroke.as      |  130 --
 .../flex/org/apache/flex/core/graphics/Text.as  |  147 --
 .../graphics/utils/AdvancedLayoutFeatures.as    | 1140 ------------
 .../core/graphics/utils/CompoundTransform.as    |  777 --------
 .../core/graphics/utils/IAssetLayoutFeatures.as |  371 ----
 .../flex/core/graphics/utils/MatrixUtil.as      | 1605 ----------------
 .../flex/core/graphics/utils/PathHelper.as      | 1712 ------------------
 .../core/graphics/utils/TransformOffsets.as     |  367 ----
 .../flex/org/apache/flex/graphics/CubicCurve.as |   56 +
 .../org/apache/flex/graphics/GradientBase.as    |  229 +++
 .../org/apache/flex/graphics/GradientEntry.as   |  133 ++
 .../apache/flex/graphics/ICompoundGraphic.as    |   30 +
 .../main/flex/org/apache/flex/graphics/IFill.as |   32 +
 .../org/apache/flex/graphics/IGraphicShape.as   |   30 +
 .../org/apache/flex/graphics/IPathCommand.as    |   16 +
 .../flex/org/apache/flex/graphics/IStroke.as    |   38 +
 .../flex/org/apache/flex/graphics/LineStyle.as  |   59 +
 .../flex/org/apache/flex/graphics/LineTo.as     |   47 +
 .../flex/org/apache/flex/graphics/MoveTo.as     |   47 +
 .../org/apache/flex/graphics/PathBuilder.as     |  292 +++
 .../org/apache/flex/graphics/QuadraticCurve.as  |   51 +
 .../flex/org/apache/flex/graphics/SolidColor.as |  134 ++
 .../apache/flex/graphics/SolidColorStroke.as    |  251 +++
 .../graphics/utils/AdvancedLayoutFeatures.as    | 1140 ++++++++++++
 .../flex/graphics/utils/CompoundTransform.as    |  777 ++++++++
 .../flex/graphics/utils/IAssetLayoutFeatures.as |  371 ++++
 .../apache/flex/graphics/utils/MatrixUtil.as    | 1605 ++++++++++++++++
 .../apache/flex/graphics/utils/PathHelper.as    | 1712 ++++++++++++++++++
 .../flex/graphics/utils/TransformOffsets.as     |  367 ++++
 .../src/main/flex/org/apache/flex/svg/Circle.as |  102 ++
 .../flex/org/apache/flex/svg/CompoundGraphic.as |  528 ++++++
 .../main/flex/org/apache/flex/svg/DOMWrapper.as |   56 +
 .../main/flex/org/apache/flex/svg/Ellipse.as    |   94 +
 .../org/apache/flex/svg/GraphicContainer.as     |   79 +
 .../flex/org/apache/flex/svg/GraphicShape.as    |  225 +++
 .../flex/org/apache/flex/svg/LinearGradient.as  |  126 ++
 .../src/main/flex/org/apache/flex/svg/Path.as   |  100 +
 .../src/main/flex/org/apache/flex/svg/Rect.as   |   90 +
 .../src/main/flex/org/apache/flex/svg/Text.as   |  149 ++
 .../src/main/resources/basic-manifest.xml       |   14 +-
 .../src/main/resources/svg-manifest.xml         |   30 +
 .../src/main/flex/org/apache/flex/html/Label.as |   27 +
 .../apache/flex/html/beads/DataGridLinesBead.as |   14 +-
 .../flex/html/beads/DecrementButtonView.as      |    8 +-
 .../flex/html/beads/IncrementButtonView.as      |    8 +-
 .../apache/flex/html/beads/RangeStepperView.as  |    4 +-
 .../html/supportClasses/GraphicsItemRenderer.as |    4 +-
 .../flex/mobile/beads/ToggleSwitchView.as       |    6 +-
 manualtests/.gitignore                          |    1 +
 .../FlexJSTest_SVG/src/GraphicsView.mxml        |   24 +-
 manualtests/FlexJSTest_SVG/src/SkinsView.mxml   |   15 +-
 115 files changed, 9922 insertions(+), 8107 deletions(-)
----------------------------------------------------------------------



[02/15] git commit: [flex-asjs] [refs/heads/refactor-sprite] - [Test] Added swf-side unit tests for BinaryData changes (these also currently pass when mocked in the browser for the js version)

Posted by ha...@apache.org.
[Test] Added swf-side unit tests for BinaryData changes (these also currently pass when mocked in the browser for the js version)


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/8a9b91b4
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/8a9b91b4
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/8a9b91b4

Branch: refs/heads/refactor-sprite
Commit: 8a9b91b4bb3e8d56590546455704631de16bcdac
Parents: 641301b
Author: greg-dove <gr...@gmail.com>
Authored: Fri Jul 22 20:03:03 2016 +1200
Committer: greg-dove <gr...@gmail.com>
Committed: Fri Jul 22 20:03:03 2016 +1200

----------------------------------------------------------------------
 .../test/flex/FlexUnitFlexJSApplication.mxml    |   7 +-
 .../flex/flexUnitTests/BinaryDataTesterTest.as  | 308 +++++++++++++++++++
 .../src/test/flex/flexUnitTests/CoreTester.as   |  28 ++
 .../src/test/flex/flexUnitTests/StrandTester.as |  27 --
 4 files changed, 340 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8a9b91b4/frameworks/projects/Core/src/test/flex/FlexUnitFlexJSApplication.mxml
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/test/flex/FlexUnitFlexJSApplication.mxml b/frameworks/projects/Core/src/test/flex/FlexUnitFlexJSApplication.mxml
index a97b086..db99af7 100644
--- a/frameworks/projects/Core/src/test/flex/FlexUnitFlexJSApplication.mxml
+++ b/frameworks/projects/Core/src/test/flex/FlexUnitFlexJSApplication.mxml
@@ -24,8 +24,8 @@ limitations under the License.
                    >
     <fx:Script>
         <![CDATA[
-            import flexUnitTests.StrandTesterTest;
-            import flexUnitTests.StrandTester;
+
+			import flexUnitTests.CoreTester;
             
             import org.flexunit.listeners.CIListener;
             import org.flexunit.runner.FlexUnitCore;
@@ -34,7 +34,8 @@ limitations under the License.
             {
                 var core : FlexUnitCore = new FlexUnitCore();
                 core.addListener(new CIListener());
-                core.run(StrandTester);
+                core.run(CoreTester);
+
             }
             
         ]]>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8a9b91b4/frameworks/projects/Core/src/test/flex/flexUnitTests/BinaryDataTesterTest.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/test/flex/flexUnitTests/BinaryDataTesterTest.as b/frameworks/projects/Core/src/test/flex/flexUnitTests/BinaryDataTesterTest.as
new file mode 100644
index 0000000..0fe68ce
--- /dev/null
+++ b/frameworks/projects/Core/src/test/flex/flexUnitTests/BinaryDataTesterTest.as
@@ -0,0 +1,308 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package flexUnitTests {
+
+
+    import org.apache.flex.utils.Endian;
+    import flexunit.framework.Assert;
+    import org.apache.flex.utils.BinaryData
+
+
+    public class BinaryDataTesterTest {
+
+        [Before]
+        public function setUp():void {
+        }
+
+        [After]
+        public function tearDown():void {
+        }
+
+        [BeforeClass]
+        public static function setUpBeforeClass():void {
+        }
+
+        [AfterClass]
+        public static function tearDownAfterClass():void {
+        }
+
+
+        [Test]
+        public function testBasicPositionAndLength():void {
+            var ba:BinaryData = new BinaryData();
+
+            Assert.assertEquals("new Instance, position", ba.position, 0);
+            Assert.assertEquals("new Instance, length", ba.length, 0);
+
+            ba.position = 100;
+            Assert.assertEquals("position change, position", ba.position, 100);
+            Assert.assertEquals("position change, length", ba.length, 0);
+
+            ba.length = 100;
+            Assert.assertEquals("length change, position", ba.position, 100);
+            Assert.assertEquals("length change, length", ba.length, 100);
+
+            ba.length = 50;
+            Assert.assertEquals("length change, position", ba.position, 50);
+            Assert.assertEquals("length change, length", ba.length, 50);
+        }
+
+        [Test]
+        public function testAdvancedPositionAndLength():void {
+            var ba:BinaryData = new BinaryData();
+
+            ba.position = 100;
+            ba.length = 100;
+
+            ba.writeByteAt(49, 255);
+            Assert.assertEquals("writeByteAt does not affect position", ba.position, 100);
+            Assert.assertEquals("writeByteAt (internal) does not affect length", ba.length, 100);
+
+            ba.readByteAt(48);
+            Assert.assertEquals("readByteAt does not affect position", ba.position, 100);
+            Assert.assertEquals("readByteAt does not affect length", ba.length, 100);
+
+            ba.writeByteAt(199, 255);
+            Assert.assertEquals("writeByteAt (beyond length) does affect length", ba.length, 200);
+            Assert.assertEquals("writeByteAt (beyond length) does not affect position", ba.position, 100);
+
+        }
+
+
+        [Test]
+        public function testUTFWritePosition():void {
+            var ba:BinaryData = new BinaryData();
+            ba.writeUTF('This is a test');
+            //writeUTF
+            Assert.assertEquals("basic post-writeUTF position", ba.position, 16);
+            ba = new BinaryData();
+            ba.writeUTFBytes('This is a test');
+            //writeUTFBytes
+            Assert.assertEquals("basic post-writeUTFBytes position", ba.position, 14);
+
+            //overlapping
+            ba.position = 5;
+            ba.writeUTFBytes('This is a test');
+            Assert.assertEquals("Advanced post-writeUTFBytes position (overlap)", ba.position, 19);
+
+        }
+
+        [Test]
+        public function testBooleanRoundTripping():void {
+            var ba:BinaryData = new BinaryData();
+            ba.writeBoolean(true);
+            ba.writeBoolean(false);
+            ba.position = 0;
+            Assert.assertTrue(ba.readBoolean());
+            Assert.assertFalse(ba.readBoolean());
+        }
+
+        [Test]
+        public function testByteRoundTripping():void {
+            var ba:BinaryData = new BinaryData();
+            ba.writeByte(255);
+            ba.writeByte(-257);
+            ba.writeByte(-50);
+            ba.writeByte(50);
+            ba.position = 0;
+
+
+            Assert.assertEquals("Error testing post writeByte/readByte roundtripping", ba.readByte(), -1);
+            Assert.assertEquals("Error testing post writeByte/readByte roundtripping", ba.readByte(), -1);
+            Assert.assertEquals("Error testing post writeByte/readByte roundtripping", ba.readByte(), -50);
+            Assert.assertEquals("Error testing post writeByte/readByte roundtripping", ba.readByte(), 50);
+        }
+
+
+        [Test]
+        public function testUnsignedByteRoundTripping():void {
+            var ba:BinaryData = new BinaryData();
+            ba.writeByte(255);
+            ba.writeByte(-257);
+            ba.writeByte(-50);
+            ba.writeByte(50);
+            ba.position = 0;
+            //check read values
+            Assert.assertEquals("Error testing post writeByte/readByte roundtripping", ba.readUnsignedByte(), 255);
+            Assert.assertEquals("Error testing post writeByte/readByte roundtripping", ba.readUnsignedByte(), 255);
+            Assert.assertEquals("Error testing post writeByte/readByte roundtripping", ba.readUnsignedByte(), 206);
+            Assert.assertEquals("Error testing post writeByte/readByte roundtripping", ba.readUnsignedByte(), 50);
+        }
+
+
+        [Test]
+        public function testBasicEndian():void {
+            var defaultEndian:String = Endian.defaultEndian;
+            //check we have a decisive default
+            Assert.assertTrue(defaultEndian != null && defaultEndian != Endian.UNKNOWN_ENDIAN);
+            var alternateEndian:String = (defaultEndian == Endian.BIG_ENDIAN) ? Endian.LITTLE_ENDIAN : Endian.BIG_ENDIAN;
+
+            var ba:BinaryData = new BinaryData();
+            var expected:Object = {};
+            expected[Endian.BIG_ENDIAN] = 1718379896;
+            expected[Endian.LITTLE_ENDIAN] = 2019912806;
+            var bytes:Array = [102, 108, 101, 120];
+            for each(var byte:uint in bytes) ba.writeByte(byte);
+            ba.position = 0;
+
+            Assert.assertEquals("testing endian:" + defaultEndian, ba.readUnsignedInt(), expected[defaultEndian]);
+
+            ba.position = 0;
+            ba.endian = alternateEndian;
+            Assert.assertEquals("testing endian:" + alternateEndian, ba.readUnsignedInt(), expected[alternateEndian]);
+        }
+
+        [Test]
+        public function testShortRoundTripping():void {
+            var ba:BinaryData = new BinaryData();
+            ba.writeShort(255);
+            ba.writeShort(-50);
+            ba.writeShort(50);
+            ba.position = 0;
+
+            Assert.assertEquals("Error testing post writeShort/readShort roundtripping", ba.length, 6);
+            Assert.assertEquals("Error testing post writeShort/readShort roundtripping", ba.readShort(), 255);
+            Assert.assertEquals("Error testing post writeShort/readShort roundtripping", ba.readShort(), -50);
+            Assert.assertEquals("Error testing post writeShort/readShort roundtripping", ba.readShort(), 50);
+        }
+
+
+        [Test]
+        public function testcShortRoundTripping():void {
+            var ba:BinaryData = new BinaryData();
+            ba.writeShort(255);
+            ba.writeShort(-50);
+            ba.writeShort(50);
+            ba.position = 0;
+
+            Assert.assertEquals("Error testing post unsigned writeShort/readShort roundtripping", ba.length, 6);
+            Assert.assertEquals("Error testing post unsigned writeShort/readShort roundtripping", ba.readUnsignedShort(), 255);
+            Assert.assertEquals("Error testing post unsigned writeShort/readShort roundtripping", ba.readUnsignedShort(), 65486);
+            Assert.assertEquals("Error testing post unsigned writeShort/readShort roundtripping", ba.readUnsignedShort(), 50);
+        }
+
+        [Test]
+        public function testIntRoundTripping():void {
+            var ba:BinaryData = new BinaryData();
+            ba.writeInt(65536);
+            ba.writeInt(-50);
+            ba.writeInt(50);
+            ba.position = 0;
+
+            Assert.assertEquals("Error testing post writeInt/readInt roundtripping", ba.length, 12);
+            Assert.assertEquals("Error testing post writeInt/readInt roundtripping", ba.readInt(), 65536);
+            Assert.assertEquals("Error testing post writeInt/readInt roundtripping", ba.readInt(), -50);
+            Assert.assertEquals("Error testing post writeInt/readInt roundtripping", ba.readInt(), 50);
+        }
+
+
+        [Test]
+        public function testUnsignedIntRoundTripping():void {
+            var ba:BinaryData = new BinaryData();
+            ba.writeUnsignedInt(65536);
+            ba.writeUnsignedInt(-50);
+            ba.writeUnsignedInt(50);
+            ba.position = 0;
+
+            Assert.assertEquals("Error testing post writeInt/readInt roundtripping", ba.length, 12);
+            Assert.assertEquals("Error testing post writeInt/readInt roundtripping", ba.readUnsignedInt(), 65536);
+            Assert.assertEquals("Error testing post writeInt/readInt roundtripping", ba.readUnsignedInt(), 4294967246);
+            Assert.assertEquals("Error testing post writeInt/readInt roundtripping", ba.readUnsignedInt(), 50);
+        }
+
+        [Test]
+        public function testFloatRoundTripping():void {
+            var ba:BinaryData = new BinaryData();
+
+            ba.writeFloat(86.54);
+            ba.writeFloat(-50.5);
+            ba.writeFloat(0);
+            ba.position = 0;
+
+            Assert.assertEquals("Error testing post writeFloat/readFloat roundtripping", ba.length, 12);
+
+            //check bytes to account for precision loss between double and float comparisons
+            var expected:Array = [66, 173, 20, 123];
+            if (ba.endian == Endian.LITTLE_ENDIAN) expected = expected.reverse();
+
+            for (var i:int = 0; i < 4; i++) {
+                Assert.assertEquals("Error testing post writeFloat/readFloat roundtripping", ba.readUnsignedByte(), expected[i]);
+            }
+
+
+            Assert.assertEquals("Error testing post writeFloat/readFloat roundtripping", ba.readFloat(), -50.5);
+            Assert.assertEquals("Error testing post writeFloat/readFloat roundtripping", ba.readFloat(), 0);
+        }
+
+
+        [Test]
+        public function testDoubleRoundTripping():void {
+            var ba:BinaryData = new BinaryData();
+            ba.writeDouble(86.54);
+            ba.writeDouble(-50.5);
+            ba.writeDouble(0);
+            ba.position = 0;
+
+            Assert.assertEquals("Error testing post writeDouble/readDouble roundtripping", ba.length, 24);
+            Assert.assertEquals("Error testing post writeDouble/readDouble roundtripping", ba.readDouble(), 86.54);
+            Assert.assertEquals("Error testing post writeDouble/readDouble roundtripping", ba.readDouble(), -50.5);
+            Assert.assertEquals("Error testing post writeDouble/readDouble roundtripping", ba.readDouble(), 0);
+        }
+
+
+        [Test]
+        public function testWriteBytes():void {
+            var ba:BinaryData = new BinaryData();
+            for (var i:int = 0; i < 50; i++) ba.writeByte(i);
+
+
+            var newBa:BinaryData = new BinaryData();
+            newBa.writeBytes(ba);
+
+            Assert.assertEquals("BinaryData writeBytes: length", 50, newBa.length);
+            Assert.assertEquals("BinaryData writeBytes: position", 50, newBa.position);
+
+            for (i = 0; i < 50; i++) {
+                Assert.assertEquals("BinaryData writeBytes: content check", i, newBa.array[i]);
+            }
+
+            newBa = new BinaryData();
+
+        }
+
+        [Test]
+        public function testReadBytes():void {
+            var ba:BinaryData = new BinaryData();
+            for (var i:int = 0; i < 50; i++) ba.writeByte(i);
+            ba.position = 0;
+            var newBa:BinaryData = new BinaryData();
+
+            ba.readBytes(newBa, 5, 10);
+            Assert.assertEquals("BinaryData readBytes: position", 10, ba.position);
+            Assert.assertEquals("BinaryData readBytes: length", 15, newBa.length);
+            Assert.assertEquals("BinaryData readBytes: position", 0, newBa.position);
+            var expected:Array = [0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
+            for (i = 5; i < 15; i++) {
+                Assert.assertEquals("BinaryData readBytes: content check", expected[i], newBa.array[i]);
+            }
+        }
+
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8a9b91b4/frameworks/projects/Core/src/test/flex/flexUnitTests/CoreTester.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/test/flex/flexUnitTests/CoreTester.as b/frameworks/projects/Core/src/test/flex/flexUnitTests/CoreTester.as
new file mode 100644
index 0000000..098a6a9
--- /dev/null
+++ b/frameworks/projects/Core/src/test/flex/flexUnitTests/CoreTester.as
@@ -0,0 +1,28 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package flexUnitTests
+{
+    [Suite]
+    [RunWith("org.flexunit.runners.Suite")]
+    public class CoreTester
+    {
+        public var strandTesterTest:StrandTesterTest;
+		public var binaryDataTesterTest:BinaryDataTesterTest;
+    }
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8a9b91b4/frameworks/projects/Core/src/test/flex/flexUnitTests/StrandTester.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/test/flex/flexUnitTests/StrandTester.as b/frameworks/projects/Core/src/test/flex/flexUnitTests/StrandTester.as
deleted file mode 100644
index 06d673b..0000000
--- a/frameworks/projects/Core/src/test/flex/flexUnitTests/StrandTester.as
+++ /dev/null
@@ -1,27 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////
-//
-//  Licensed to the Apache Software Foundation (ASF) under one or more
-//  contributor license agreements.  See the NOTICE file distributed with
-//  this work for additional information regarding copyright ownership.
-//  The ASF licenses this file to You under the Apache License, Version 2.0
-//  (the "License"); you may not use this file except in compliance with
-//  the License.  You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-//  Unless required by applicable law or agreed to in writing, software
-//  distributed under the License is distributed on an "AS IS" BASIS,
-//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//  See the License for the specific language governing permissions and
-//  limitations under the License.
-//
-////////////////////////////////////////////////////////////////////////////////
-package flexUnitTests
-{
-    [Suite]
-    [RunWith("org.flexunit.runners.Suite")]
-    public class StrandTester
-    {
-        public var strandTesterTest:StrandTesterTest;
-    }
-}


[12/15] git commit: [flex-asjs] [refs/heads/refactor-sprite] - Merge branch 'BinaryData_improvement' of https://github.com/greg-dove/flex-asjs into develop

Posted by ha...@apache.org.
Merge branch 'BinaryData_improvement' of https://github.com/greg-dove/flex-asjs into develop


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/6e9672b5
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/6e9672b5
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/6e9672b5

Branch: refs/heads/refactor-sprite
Commit: 6e9672b55ef5538f56c76a36e76637f462a55ebc
Parents: 13323e6 c8d147b
Author: Harbs <ha...@in-tools.com>
Authored: Wed Aug 3 10:38:20 2016 +0300
Committer: Harbs <ha...@in-tools.com>
Committed: Wed Aug 3 10:38:20 2016 +0300

----------------------------------------------------------------------
 .../flex/org/apache/flex/utils/BinaryData.as    | 1089 ++++++++++++------
 .../main/flex/org/apache/flex/utils/Endian.as   |   31 +-
 .../org/apache/flex/utils/IBinaryDataInput.as   |   47 +
 .../org/apache/flex/utils/IBinaryDataOutput.as  |   42 +
 .../test/flex/FlexUnitFlexJSApplication.mxml    |    7 +-
 .../flex/flexUnitTests/BinaryDataTesterTest.as  |  565 +++++++++
 .../src/test/flex/flexUnitTests/CoreTester.as   |   28 +
 .../src/test/flex/flexUnitTests/StrandTester.as |   27 -
 .../flex/org/apache/flex/net/URLBinaryLoader.as |    2 +-
 .../main/flex/org/apache/flex/net/URLStream.as  |    2 +-
 10 files changed, 1434 insertions(+), 406 deletions(-)
----------------------------------------------------------------------



[13/15] git commit: [flex-asjs] [refs/heads/refactor-sprite] - Found a couple of minor bugs while fixing an example.

Posted by ha...@apache.org.
Found a couple of minor bugs while fixing an example.


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/f57cfc42
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/f57cfc42
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/f57cfc42

Branch: refs/heads/refactor-sprite
Commit: f57cfc42ea8a18772940b95668e13ea7cb8b2f87
Parents: 6e9672b
Author: Peter Ent <pe...@apache.org>
Authored: Wed Aug 3 17:27:27 2016 -0400
Committer: Peter Ent <pe...@apache.org>
Committed: Wed Aug 3 17:27:27 2016 -0400

----------------------------------------------------------------------
 .../HTML/src/main/flex/org/apache/flex/html/beads/ListView.as  | 4 ++--
 .../org/apache/flex/html/supportClasses/DataItemRenderer.as    | 6 ++++--
 2 files changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f57cfc42/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/ListView.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/ListView.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/ListView.as
index cab97f8..3018600 100644
--- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/ListView.as
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/ListView.as
@@ -165,12 +165,12 @@ package org.apache.flex.html.beads
 			if (lastSelectedIndex != -1)
 			{
 				var ir:ISelectableItemRenderer = dataGroup.getItemRendererForIndex(lastSelectedIndex) as ISelectableItemRenderer;
-                ir.selected = false;
+                if (ir != null) ir.selected = false;
 			}
 			if (listModel.selectedIndex != -1)
 			{
 	            ir = dataGroup.getItemRendererForIndex(listModel.selectedIndex) as ISelectableItemRenderer;
-	            ir.selected = true;
+	            if (ir != null) ir.selected = true;
 			}
             lastSelectedIndex = listModel.selectedIndex;
 		}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f57cfc42/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/DataItemRenderer.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/DataItemRenderer.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/DataItemRenderer.as
index 796e6b7..71d534a 100644
--- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/DataItemRenderer.as
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/supportClasses/DataItemRenderer.as
@@ -148,10 +148,12 @@ package org.apache.flex.html.supportClasses
 			COMPILE::JS
 			{
 				if (selected) {
-					element.className = "StringItemRenderer selected";
+					element.className = element.className + " selected";
 				}
 				else {
-					element.className = "StringItemRenderer";
+					if (element.className.endsWith(" selected")) {
+						element.className = element.className.replace(" selected", "");
+					}
 				}
 			}
 		}