Repository: flex-asjs Updated Branches: refs/heads/develop 5ae65eabc -> ef320f796
throwError More fixes to XMLList XMLList.toXML() Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/ef320f79 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/ef320f79 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/ef320f79 Branch: refs/heads/develop Commit: ef320f796b96d3fcd3cf00e6d78a700f363ae5b5 Parents: 5ae65ea Author: Harbs <ha...@in-tools.com> Authored: Mon Jul 17 19:42:16 2017 +0300 Committer: Harbs <ha...@in-tools.com> Committed: Mon Jul 17 19:42:16 2017 +0300 ---------------------------------------------------------------------- .../projects/Core/src/main/flex/CoreClasses.as | 1 + .../org/apache/flex/debugging/throwError.as | 43 ++++++++++++++++++++ .../projects/XML/src/main/flex/XMLList.as | 26 +++++++++++- 3 files changed, 68 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/ef320f79/frameworks/projects/Core/src/main/flex/CoreClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/CoreClasses.as b/frameworks/projects/Core/src/main/flex/CoreClasses.as index 4bb65e7..e062a8b 100644 --- a/frameworks/projects/Core/src/main/flex/CoreClasses.as +++ b/frameworks/projects/Core/src/main/flex/CoreClasses.as @@ -118,6 +118,7 @@ internal class CoreClasses import org.apache.flex.debugging.check; check; // import org.apache.flex.debugging.conditionalBreak; conditionalBreak; import org.apache.flex.debugging.notNull; notNull; + import org.apache.flex.debugging.throwError; throwError; import org.apache.flex.core.StyleChangeNotifier; StyleChangeNotifier; import org.apache.flex.events.CustomEvent; CustomEvent; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/ef320f79/frameworks/projects/Core/src/main/flex/org/apache/flex/debugging/throwError.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/debugging/throwError.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/debugging/throwError.as new file mode 100644 index 0000000..da528a0 --- /dev/null +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/debugging/throwError.as @@ -0,0 +1,43 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.debugging +{ + COMPILE::JS + { + import goog.DEBUG; + } + + /** + * assert throws an error if the condition is not met. + */ + public function throwError(errorMessage:String):void + { + COMPILE::SWF + { + throw new Error(errorMessage); + } + COMPILE::JS + { + if(goog.DEBUG) + { + throw new Error(errorMessage); + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/ef320f79/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 17c2e33..e6394f8 100644 --- a/frameworks/projects/XML/src/main/flex/XMLList.as +++ b/frameworks/projects/XML/src/main/flex/XMLList.as @@ -21,6 +21,7 @@ package COMPILE::JS public class XMLList { + import org.apache.flex.debugging.throwError; public function XMLList() { addIndex(0); @@ -665,8 +666,9 @@ package removeChildAt(i); return; } - - if(child is XMLList) + if (isSingle()) + _xmlArray[0].removeChild(child); + else if(child is XMLList) { len = child.length(); for(i=0;i<len;i++) @@ -691,6 +693,8 @@ package public function removeChildAt(idx:int):void { + if (isSingle()) + _xmlArray[0].removeChildAt(idx); if(idx >= 0 && idx < _xmlArray.length) { var child:XML = _xmlArray[idx]; @@ -701,6 +705,12 @@ package } private function replaceChildAt(idx:int,child:*):void { + if (isSingle()) + { + _xmlArray[0].replaceChildAt(idx,child); + return; + } + var i:int; var childToReplace:XML = _xmlArray[idx]; if(childToReplace && _targetObject) @@ -1065,6 +1075,18 @@ package { return _xmlArray.length == 1; } + + /** + * This coerces single-item XMLList objects to XML for cases where the type is expected to be XML + */ + public function toXML():XML + { + if (isSingle()) + return _xmlArray[0]; + + throwError("Incompatible assignment of XMLList to XML"); + return null; + } } }