This is an automated email from the ASF dual-hosted git repository.

harbs pushed a commit to branch feature/ROYALE_INTERFACE_INFO
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git

commit 7ef5b009f8b5a012c8ed8daa15d29808ff821ed4
Author: Harbs <[email protected]>
AuthorDate: Sun Dec 26 19:30:42 2021 +0200

    This seems to pass all tests
---
 .../royale/org/apache/royale/utils/Language.as     | 45 ++++++++++++----------
 .../MXRoyale/src/main/royale/mx/modules/Module.as  |  2 +-
 .../org/apache/royale/reflection/TypeDefinition.as | 20 +++++++++-
 .../apache/royale/reflection/getDataInternal.as    | 35 +++++++++++------
 frameworks/projects/XML/src/main/royale/XML.as     | 24 ++++++------
 5 files changed, 79 insertions(+), 47 deletions(-)

diff --git 
a/frameworks/projects/Language/src/main/royale/org/apache/royale/utils/Language.as
 
b/frameworks/projects/Language/src/main/royale/org/apache/royale/utils/Language.as
index 7da7055..0345013 100644
--- 
a/frameworks/projects/Language/src/main/royale/org/apache/royale/utils/Language.as
+++ 
b/frameworks/projects/Language/src/main/royale/org/apache/royale/utils/Language.as
@@ -95,9 +95,14 @@ package org.apache.royale.utils
                 if (leftOperand == null) {
                     return null;
                 }
-                const leftType:String = '' + (leftOperand.ROYALE_CLASS_INFO ? 
leftOperand.ROYALE_CLASS_INFO.names[0].qName : String(leftOperand));
-                const rightType:String = '' + (rightOperand.prototype && 
rightOperand.prototype.ROYALE_CLASS_INFO ? 
rightOperand.prototype.ROYALE_CLASS_INFO.names[0].qName: String(rightOperand));
-                throw new TypeError('Error #1034: Type Coercion failed: cannot 
convert ' + leftType + ' to ' + rightType);
+                if(goog.DEBUG)
+                {
+                    const leftType:String = '' + 
(leftOperand.ROYALE_CLASS_INFO ? leftOperand.ROYALE_CLASS_INFO.names[0].qName : 
String(leftOperand));
+                    const rightType:String = '' + (rightOperand.prototype && 
rightOperand.prototype.ROYALE_CLASS_INFO ? 
rightOperand.prototype.ROYALE_CLASS_INFO.names[0].qName: String(rightOperand));
+                    throw new TypeError('Error #1034: Type Coercion failed: 
cannot convert ' + leftType + ' to ' + rightType);
+                } else {
+                    throw new TypeError('Type Coercion failed.');
+                }
             }
             
             return itIs ? leftOperand : null;
@@ -176,7 +181,7 @@ package org.apache.royale.utils
             if (rightOperand.constructor === _synthType)
                 return rightOperand['checkIs'](leftOperand);
             
-            if (leftOperand.ROYALE_CLASS_INFO === undefined)
+            if (leftOperand.ROYALE_INTERFACE_INFO === undefined)
                 return false; // could be a function but not an instance
 
             if (!isInitInterfaceMap)
@@ -191,25 +196,25 @@ package org.apache.royale.utils
             var classInterfaceMap:Object;
 
             // check interface check cache
-            if (interfaceMap && 
interfaceMap.has(leftOperand.ROYALE_CLASS_INFO))
+            if (interfaceMap && 
interfaceMap.has(leftOperand.ROYALE_INTERFACE_INFO))
             {
-                classInterfaceMap = 
interfaceMap.get(leftOperand.ROYALE_CLASS_INFO);
+                classInterfaceMap = 
interfaceMap.get(leftOperand.ROYALE_INTERFACE_INFO);
                 if (classInterfaceMap && classInterfaceMap.has(rightOperand))
                     return classInterfaceMap.get(rightOperand);
             }
             
-            if (leftOperand.ROYALE_CLASS_INFO && 
leftOperand.ROYALE_CLASS_INFO.interfaces)
+            if (leftOperand.ROYALE_INTERFACE_INFO && 
leftOperand.ROYALE_INTERFACE_INFO.interfaces)
             {
                 if (checkInterfaces(leftOperand, rightOperand))
                 {
                     // update interface check cache
                     if (interfaceMap)
                     {
-                        if (!interfaceMap.has(leftOperand.ROYALE_CLASS_INFO))
+                        if 
(!interfaceMap.has(leftOperand.ROYALE_INTERFACE_INFO))
                         {
-                            interfaceMap.set(leftOperand.ROYALE_CLASS_INFO, 
new WeakMap());
+                            
interfaceMap.set(leftOperand.ROYALE_INTERFACE_INFO, new WeakMap());
                         }
-                        classInterfaceMap = 
interfaceMap.get(leftOperand.ROYALE_CLASS_INFO);
+                        classInterfaceMap = 
interfaceMap.get(leftOperand.ROYALE_INTERFACE_INFO);
                         classInterfaceMap.set(rightOperand, true);
                     }
                     return true;
@@ -220,20 +225,20 @@ package org.apache.royale.utils
             
             if (superClass)
             {
-                while (superClass && superClass.ROYALE_CLASS_INFO)
+                while (superClass && superClass.ROYALE_INTERFACE_INFO)
                 {
-                    if (superClass.ROYALE_CLASS_INFO.interfaces)
+                    if (superClass.ROYALE_INTERFACE_INFO.interfaces)
                     {
                         if (checkInterfaces(superClass, rightOperand))
                         {
                             // update interface check cache
                             if (interfaceMap)
                             {
-                                if 
(!interfaceMap.has(leftOperand.ROYALE_CLASS_INFO))
+                                if 
(!interfaceMap.has(leftOperand.ROYALE_INTERFACE_INFO))
                                 {
-                                    
interfaceMap.set(leftOperand.ROYALE_CLASS_INFO, new WeakMap());
+                                    
interfaceMap.set(leftOperand.ROYALE_INTERFACE_INFO, new WeakMap());
                                 }
-                                classInterfaceMap = 
interfaceMap.get(leftOperand.ROYALE_CLASS_INFO);
+                                classInterfaceMap = 
interfaceMap.get(leftOperand.ROYALE_INTERFACE_INFO);
                                 classInterfaceMap.set(rightOperand, true);
                             }
                             return true;
@@ -246,11 +251,11 @@ package org.apache.royale.utils
             // update interface check cache
             if (interfaceMap)
             {
-                if (!interfaceMap.has(leftOperand.ROYALE_CLASS_INFO))
+                if (!interfaceMap.has(leftOperand.ROYALE_INTERFACE_INFO))
                 {
-                    interfaceMap.set(leftOperand.ROYALE_CLASS_INFO, new 
WeakMap());
+                    interfaceMap.set(leftOperand.ROYALE_INTERFACE_INFO, new 
WeakMap());
                 }
-                classInterfaceMap = 
interfaceMap.get(leftOperand.ROYALE_CLASS_INFO);
+                classInterfaceMap = 
interfaceMap.get(leftOperand.ROYALE_INTERFACE_INFO);
                 classInterfaceMap.set(rightOperand, false);
             }
             return false;
@@ -263,7 +268,7 @@ package org.apache.royale.utils
         {
             var i:int, interfaces:Array;
             
-            interfaces = leftOperand.ROYALE_CLASS_INFO.interfaces;
+            interfaces = leftOperand.ROYALE_INTERFACE_INFO.interfaces;
             for (i = interfaces.length - 1; i > -1; i--)
             {
                 var theInterface:* = interfaces[i];
@@ -272,7 +277,7 @@ package org.apache.royale.utils
                     return true;
                 }
                 
-                if (theInterface.prototype.ROYALE_CLASS_INFO && 
theInterface.prototype.ROYALE_CLASS_INFO.interfaces)
+                if (theInterface.prototype.ROYALE_INTERFACE_INFO && 
theInterface.prototype.ROYALE_INTERFACE_INFO.interfaces)
                 {
                     var isit:Boolean = checkInterfaces(theInterface.prototype, 
rightOperand);
                     if (isit) return true;
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/modules/Module.as 
b/frameworks/projects/MXRoyale/src/main/royale/mx/modules/Module.as
index ce3b493..491c290 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/modules/Module.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/modules/Module.as
@@ -198,7 +198,7 @@ public class Module extends Container implements IModule, 
IFlexInfo //extends La
         if (obj.cssData)
             return obj.cssData;
         
-        return obj.ROYALE_CLASS_INFO;
+        return obj.ROYALE_CLASS_INFO || obj.ROYALE_INTERFACE_INFO;
     }
 
     /**
diff --git 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/TypeDefinition.as
 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/TypeDefinition.as
index f53d5cd..9dd5aa2 100755
--- 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/TypeDefinition.as
+++ 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/TypeDefinition.as
@@ -289,6 +289,13 @@ COMPILE::SWF {
                     _rawData = def.prototype.ROYALE_CLASS_INFO;
                     if (_rawData == null) {
                         _rawData = ExtraData.hasData(def) ? 
ExtraData.getData(def)['ROYALE_CLASS_INFO'] : null;
+                        if(_rawData) {
+                            var interfaceInfo:Object = 
ExtraData.getData(def)['ROYALE_INTERFACE_INFO'];
+                            _rawData.interfaces = interfaceInfo ? 
interfaceInfo.interfaces : [];
+                        }
+                    } else {
+                        interfaceInfo = def.prototype.ROYALE_INTERFACE_INFO;
+                        _rawData.interfaces = interfaceInfo ? 
interfaceInfo.interfaces : [];
                     }
                 }
             }
@@ -428,14 +435,23 @@ COMPILE::SWF {
                     if ((_kind || kind) == "interface") {
                         //collect.length can expand during the loop below
                         for (i = 0; i < collect.length; i++) {
-                            collect.push.apply(collect, 
(collect[i].prototype.ROYALE_CLASS_INFO.interfaces || []));
+                            var info:Object = 
collect[i].prototype.ROYALE_INTERFACE_INFO;
+                            var interfaces:Array;
+                            if(info && info.interfaces)
+                            {
+                                interfaces = info.interfaces;
+                            } else {
+                                interfaces = [];
+                            }                            
+                            collect.push.apply(collect, interfaces);
                         }
                     } else {
                         var superClass:Object = def.superClass_;
                         while (superClass && superClass.ROYALE_CLASS_INFO !== 
undefined)
                         {
                             data = superClass.ROYALE_CLASS_INFO;
-                            var latest:Array = data.interfaces;
+                            var interfaceData:Object = 
superClass.ROYALE_INTERFACE_INFO;
+                            var latest:Array = interfaceData ? 
interfaceData.interfaces : null;
                             if (latest) {
                                 n = latest.length;
                                 for (i=0;i<n;i++) if 
(collect.indexOf(latest[i])==-1) collect.push(latest[i]);
diff --git 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getDataInternal.as
 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getDataInternal.as
index 66ffc05..d3b9d2c 100644
--- 
a/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getDataInternal.as
+++ 
b/frameworks/projects/Reflection/src/main/royale/org/apache/royale/reflection/getDataInternal.as
@@ -51,20 +51,33 @@ package org.apache.royale.reflection
      */
     COMPILE::JS
     internal function getDataInternal(value:Object, qName:String):Object {
-        var data:Object = value.ROYALE_CLASS_INFO || (value.prototype ? 
value.prototype.ROYALE_CLASS_INFO : null);
-        if (!data) {
+        var classValue:Object = value.ROYALE_CLASS_INFO ? value : 
value.prototype;
+        var data:Object = classValue ? classValue.ROYALE_CLASS_INFO : null;
+        do{
+            if(data)break;
             if (ExtraData.hasData(qName)) {
-                data = ExtraData.getData(qName)['ROYALE_CLASS_INFO'];
-            } else {
-                var key:* = (value.constructor && value.constructor != 
Function && !Language.isSynthType(value)) ? value.constructor : value;
-                data = ExtraData.hasData(key) ? 
ExtraData.getData(key)['ROYALE_CLASS_INFO'] : null;
-                if (!data) {
-                    key = getDefinitionByName(qName);
-                    data = ExtraData.hasData(key) ? 
ExtraData.getData(key)['ROYALE_CLASS_INFO'] : null;
-                }
+                classValue = ExtraData.getData(qName)
+                data = classValue['ROYALE_CLASS_INFO'];
             }
+            if(data)break;
+            var key:* = (value.constructor && value.constructor != Function && 
!Language.isSynthType(value)) ? value.constructor : value;
+            if(ExtraData.hasData(key)){
+                classValue = ExtraData.getData(key);
+                data = classValue['ROYALE_CLASS_INFO'];
+            }
+            if(data)break;
+            key = getDefinitionByName(qName);
+            if(ExtraData.hasData(key)) {
+                classValue = ExtraData.getData(key);
+                data = classValue['ROYALE_CLASS_INFO'];
+            }
+
+        }while(false);
+        if(data && classValue.ROYALE_INTERFACE_INFO)
+        {
+            data.interfaces = classValue.ROYALE_INTERFACE_INFO.interfaces;
         }
-        return data;
+        return data ? data : null;
     }
 
 }
diff --git a/frameworks/projects/XML/src/main/royale/XML.as 
b/frameworks/projects/XML/src/main/royale/XML.as
index 6586ebf..60daa44 100644
--- a/frameworks/projects/XML/src/main/royale/XML.as
+++ b/frameworks/projects/XML/src/main/royale/XML.as
@@ -572,19 +572,17 @@ package
                                //as3 docs say this is a TypeError, but it is 
actually not (in AVM), return an empty text node
                                return new XML();
                        }
-                       else if (xml.ROYALE_CLASS_INFO != null)
-                       {
-                               var className:String = 
xml.ROYALE_CLASS_INFO.names[0].name;
-                               switch(className){
-                                       case "XML":
-                                               return xml;
-                                       case "XMLList":
-                                               var xmlList:XMLList = xml as 
XMLList;
-                                               if (xmlList.length() == 1)
-                                                       return xmlList[0];
-                                               // throw TypeError
-                                               return null;
-                               }
+                       else if(xml is XML)
+                       {
+                               return xml;
+                       }
+                       else if(xml is XMLList)
+                       {
+                               var xmlList:XMLList = xml as XMLList;
+                               if (xmlList.length() == 1)
+                                       return xmlList[0];
+                               // throw TypeError
+                               return null;
 
                        }
                        if (defaultNS !== undefined) {

Reply via email to