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/04/11 00:49:00 UTC

[49/49] git commit: [flex-asjs] [refs/heads/develop] - XML Fixes More tests

XML Fixes
More 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/d4bce998
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/d4bce998
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/d4bce998

Branch: refs/heads/develop
Commit: d4bce998c9ab32eccd8ea0e76ec2e8d593655f46
Parents: 33d0c00
Author: Harbs <ha...@in-tools.com>
Authored: Mon Apr 11 01:46:58 2016 +0300
Committer: Harbs <ha...@in-tools.com>
Committed: Mon Apr 11 01:46:58 2016 +0300

----------------------------------------------------------------------
 frameworks/projects/XML/src/main/flex/XML.as    | 19 +++++-
 .../projects/XML/src/main/flex/XMLList.as       | 65 ++++++++++++--------
 manualtests/XMLTest/src/MyInitialView.mxml      |  4 ++
 3 files changed, 63 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d4bce998/frameworks/projects/XML/src/main/flex/XML.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/XML/src/main/flex/XML.as b/frameworks/projects/XML/src/main/flex/XML.as
index c3f212c..288fa35 100644
--- a/frameworks/projects/XML/src/main/flex/XML.as
+++ b/frameworks/projects/XML/src/main/flex/XML.as
@@ -1635,7 +1635,7 @@ package
 		}
 
 		COMPILE::JS
-		private function replaceChild(idx:int,v:*):void
+		public function replaceChildAt(idx:int,v:*):void
 		{
 			/*
 				When the [[Replace]] method of an XML object x is called with property name P and value V, the following steps are taken:
@@ -1681,6 +1681,19 @@ package
 				if(_children[idx])
 					_children[idx].setParent(null);
 
+				var len:int = v.length();
+				v[0].setParent(this);
+				_children[idx] = v[0];
+				var listIdx:int = 1;
+				var chld:XML = v[0];
+				while(listIdx < len)
+				{
+					chld = v[listIdx];
+					insertChildAt(chld,idx+listIdx);
+					listIdx++;
+
+				}
+
 			}
 			else
 			{
@@ -2258,6 +2271,10 @@ package
 				ns.prefix = "";
 				declarations.push(ns);
 			}
+			if(XML.prettyPrinting)
+			{
+				strArr.push(new Array(indentLevel).join(' '));
+			}
 			strArr.push("<");
 			if(ns.prefix)
 				strArr.push(ns.prefix+":");

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d4bce998/frameworks/projects/XML/src/main/flex/XMLList.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/XML/src/main/flex/XMLList.as b/frameworks/projects/XML/src/main/flex/XMLList.as
index ef16906..0f4b2ab 100644
--- a/frameworks/projects/XML/src/main/flex/XMLList.as
+++ b/frameworks/projects/XML/src/main/flex/XMLList.as
@@ -116,29 +116,10 @@ package
 				{
 					"get": function():* { return _xmlArray[idx]; },
 					"set": function(newValue:*):void {
-						var i:int;
-						if(newValue is XML)
-						{
-							_xmlArray[idx] = newValue;
-						}
-						else if(newValue is XMLList)
-						{
-							var len:int = newValue.length();
-							for(i=0;i<len;i++)
-							{
-								// replace the first one and add each additonal one.
-								if(i==0)
-									_xmlArray[idx] = newValue[i];
-								else
-									_xmlArray.splice(idx+i,0,newValue[i]);
-							}
-						}
-						// add indexes as necessary
-						while(idx++ < _xmlArray.length)
-						{
-							if(!this.hasOwnProperty(idx))
-								addIndex(idx);
-						}
+						if(idx >= _xmlArray.length)
+							appendChild(newValue);
+						else
+							replaceChildAt(idx,newValue);
 					},
 					enumerable: true,
 					configurable: true
@@ -149,8 +130,12 @@ package
 		COMPILE::JS
 		public function appendChild(child:XML):void
 		{
-			addIndex(_xmlArray.length);
 			_xmlArray[_xmlArray.length] = child;
+			addIndex(_xmlArray.length);
+			if(_targetObject)
+			{
+				_targetObject.appendChild(child);
+			}
 		}
 		
 		/**
@@ -565,6 +550,38 @@ package
 			if(idx >= 0 && idx < _xmlArray.length)
 				_xmlArray.splice(idx,1);
 		}
+		COMPILE::JS
+		private function replaceChildAt(idx:int,child:*):void
+		{
+			var i:int;
+			var childToReplace:XML = _xmlArray[idx];
+			if(childToReplace && _targetObject)
+			{
+				_targetObject.replaceChildAt(childToReplace.childIndex,child);
+			}
+			if(child is XML)
+			{
+				_xmlArray.splice(idx+i,0,child);
+			}
+			else if(child is XMLList)
+			{
+				var len:int = child.length();
+				for(i=0;i<len;i++)
+				{
+					// replace the first one and add each additonal one.
+					if(i==0)
+						_xmlArray[idx] = child[i];
+					else
+						_xmlArray.splice(idx+i,0,child[i]);
+				}
+			}
+			// add indexes as necessary
+			while(idx++ < _xmlArray.length)
+			{
+				if(!this.hasOwnProperty(idx))
+					addIndex(idx);
+			}
+		}
 
 		private var _targetObject:*;
 		/**

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/d4bce998/manualtests/XMLTest/src/MyInitialView.mxml
----------------------------------------------------------------------
diff --git a/manualtests/XMLTest/src/MyInitialView.mxml b/manualtests/XMLTest/src/MyInitialView.mxml
index 34de79a..6451996 100644
--- a/manualtests/XMLTest/src/MyInitialView.mxml
+++ b/manualtests/XMLTest/src/MyInitialView.mxml
@@ -56,6 +56,10 @@ limitations under the License.
                 xml1.appendChild(child);
                 trace(xml1.pop[0].toString());
                 trace(xml1.pop[1].toString());
+                var pop:XMLList = xml1.pop;
+                pop[pop.length()] = new XML('<pop><child name="Fred"/></pop>');
+                trace(pop.toString());
+                trace(xml1.toString());
             }
 		]]>
 	</fx:Script>