You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2021/03/16 21:07:19 UTC

[royale-compiler] branch develop updated (3b1f473 -> bf016f1)

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

joshtynjala pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git.


    from 3b1f473  playerglobalc: accidentally put into REST_METHODS instead of ANY_METHODS
     new bd27efe  playerglobalc: various methods on Date need parameters typed as * and null defaults
     new fb068a0  playerglobalc: special case for global constants: undefined, NaN, and Infinity
     new 605a138  playerglobalc: some extra members on flash.display.Graphics
     new aa3264a  playerglobalc: member variables that should be typed as any
     new cbeda50  playerglobalc: some more constructors that need parameters typed as any
     new a43bc6b  playerglobalc: some missing members
     new a426d80  playerglobalc: Array.splice() should be a ...rest method
     new 62ecb0f  playerglobalc: Function is missing prototype property
     new 9b3ff46  playerglobalc: some refinements to the Object prototype methods
     new e0e24b4  playerglobalc: Function missing APIs
     new d3285e0  playerglobalc: Date.parse should accept any
     new bf016f1  playerglobalc: constants that should be read/write variables

The 12 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../royale/compiler/clients/PLAYERGLOBALC.java     | 356 +++++++++++++--------
 1 file changed, 221 insertions(+), 135 deletions(-)


[royale-compiler] 08/12: playerglobalc: Function is missing prototype property

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit 62ecb0f6b45b7335da35c79c0b387b0cc2a43ec1
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Mar 16 12:02:57 2021 -0700

    playerglobalc: Function is missing prototype property
---
 .../src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java  | 1 +
 1 file changed, 1 insertion(+)

diff --git a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
index 6a3cfa5..dd85cf7 100644
--- a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
+++ b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
@@ -108,6 +108,7 @@ class PLAYERGLOBALC implements FlexTool {
 	}
 	private static final Map<String, List<String>> EXTRA_MEMBERS = new HashMap<String, List<String>>();
 	{
+		EXTRA_MEMBERS.put("Function", Arrays.asList("public var prototype:Object"));
 		EXTRA_MEMBERS.put("flash.display.DisplayObjectContainer", Arrays
 				.asList("public native function removeChildren(beginIndex:int = 0, endIndex:int = 0x7fffffff):void"));
 		EXTRA_MEMBERS.put("flash.display.Graphics", Arrays.asList(


[royale-compiler] 05/12: playerglobalc: some more constructors that need parameters typed as any

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit cbeda507779a82f304a1ded3bc57ddbbd5a7cf88
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Mar 16 10:54:10 2021 -0700

    playerglobalc: some more constructors that need parameters typed as any
---
 .../main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java  | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
index dd9ae50..6948f41 100644
--- a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
+++ b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
@@ -65,8 +65,9 @@ class PLAYERGLOBALC implements FlexTool {
 	// Object's prototype.
 	private static final List<String> OBJECT_PROTOTYPE_METHODS = Arrays.asList("hasOwnProperty", "isPrototypeOf",
 			"propertyIsEnumerable", "setPropertyIsEnumerable", "toString", "toLocaleString", "valueOf");
-	private static final List<String> ANY_CONSTRUCTORS = Arrays.asList("Boolean", "Date", "int", "Number", "RegExp",
-			"String", "uint", "XML", "XMLList");
+	private static final List<String> ANY_CONSTRUCTORS = Arrays.asList("ArgumentError", "Boolean", "Date",
+			"DefinitionError", "Error", "EvalError", "int", "Number", "RangeError", "ReferenceError", "RegExp",
+			"SecurityError", "String", "SyntaxError", "TypeError", "uint", "URIError", "VerifyError", "XML", "XMLList");
 	private static final Map<String, String> GLOBAL_CONSTANTS = new HashMap<String, String>();
 	{
 		GLOBAL_CONSTANTS.put("Infinity", "1 / 0");


[royale-compiler] 07/12: playerglobalc: Array.splice() should be a ...rest method

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit a426d80979d3422f03807963236fce4142b6f96d
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Mar 16 11:59:34 2021 -0700

    playerglobalc: Array.splice() should be a ...rest method
---
 .../src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java  | 1 +
 1 file changed, 1 insertion(+)

diff --git a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
index 885d957..6a3cfa5 100644
--- a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
+++ b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
@@ -76,6 +76,7 @@ class PLAYERGLOBALC implements FlexTool {
 	}
 	private static final Map<String, List<String>> REST_METHODS = new HashMap<String, List<String>>();
 	{
+		REST_METHODS.put("Array", Arrays.asList("splice"));
 		REST_METHODS.put("__AS3__.vec.Vector$object", Arrays.asList("sort"));
 		REST_METHODS.put("__AS3__.vec.Vector$double", Arrays.asList("sort"));
 		REST_METHODS.put("__AS3__.vec.Vector$int", Arrays.asList("sort"));


[royale-compiler] 11/12: playerglobalc: Date.parse should accept any

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit d3285e002c499e024019ac30c431602feb006a78
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Mar 16 13:20:48 2021 -0700

    playerglobalc: Date.parse should accept any
---
 .../src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
index 925a4cc..d164b41 100644
--- a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
+++ b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
@@ -97,7 +97,7 @@ class PLAYERGLOBALC implements FlexTool {
 		ANY_METHODS.put("Date",
 				Arrays.asList("setFullYear", "setMonth", "setDate", "setHours", "setMinutes", "setSeconds",
 						"setMilliseconds", "setUTCFullYear", "setUTCMonth", "setUTCDate", "setUTCHours",
-						"setUTCMinutes", "setUTCSeconds", "setUTCMilliseconds", "setTime", "UTC"));
+						"setUTCMinutes", "setUTCSeconds", "setUTCMilliseconds", "setTime", "UTC", "parse"));
 		ANY_METHODS.put("Object", Arrays.asList("hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable"));
 		ANY_METHODS.put("XML", Arrays.asList("addNamespace", "appendChild", "attribute", "child", "contains",
 				"descendants", "elements", "insertChildAfter", "insertChildBefore", "namespace", "prependChild",


[royale-compiler] 04/12: playerglobalc: member variables that should be typed as any

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit aa3264a32a43937aae333b9d1c2f1f853d1ad293
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Mar 16 10:47:08 2021 -0700

    playerglobalc: member variables that should be typed as any
---
 .../royale/compiler/clients/PLAYERGLOBALC.java     | 42 +++++++++++++++++-----
 1 file changed, 33 insertions(+), 9 deletions(-)

diff --git a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
index af7fdc5..dd9ae50 100644
--- a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
+++ b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
@@ -100,6 +100,10 @@ class PLAYERGLOBALC implements FlexTool {
 				"descendants", "elements", "insertChildAfter", "insertChildBefore", "namespace", "prependChild",
 				"processingInstructions", "removeNamespace", "replace", "setChildren", "setName", "setNamespace"));
 	}
+	private static final Map<String, List<String>> ANY_VARIABLES = new HashMap<String, List<String>>();
+	{
+		ANY_VARIABLES.put("Object", Arrays.asList("constructor"));
+	}
 	private static final Map<String, List<String>> EXTRA_MEMBERS = new HashMap<String, List<String>>();
 	{
 		EXTRA_MEMBERS.put("flash.display.Graphics", Arrays.asList(
@@ -444,7 +448,7 @@ class PLAYERGLOBALC implements FlexTool {
 			parseFunction(apiOperationElement, fullyQualifiedName, false, classBuilder);
 		}
 		for (Element apiValueElement : apiValueElements) {
-			parseVariable(apiValueElement, false, false, classBuilder);
+			parseVariable(apiValueElement, fullyQualifiedName, false, classBuilder);
 		}
 		if (EXTRA_MEMBERS.containsKey(fullyQualifiedName)) {
 			for (String member : EXTRA_MEMBERS.get(fullyQualifiedName)) {
@@ -549,7 +553,7 @@ class PLAYERGLOBALC implements FlexTool {
 			parseFunction(apiOperationElement, null, true, interfaceBuilder);
 		}
 		for (Element apiValueElement : apiValueElements) {
-			parseVariable(apiValueElement, true, false, interfaceBuilder);
+			parseVariable(apiValueElement, fullyQualifiedName, true, interfaceBuilder);
 		}
 		interfaceBuilder.append("\t");
 		interfaceBuilder.append("}");
@@ -647,14 +651,14 @@ class PLAYERGLOBALC implements FlexTool {
 		variableBuilder.append("{");
 		variableBuilder.append("\n");
 		writeImports(importFullyQualifiedNames, variableBuilder);
-		parseVariable(apiValueElement, false, true, variableBuilder);
+		parseVariable(apiValueElement, null, false, variableBuilder);
 		variableBuilder.append("}");
 		variableBuilder.append("\n");
 
 		writeFileForDefinition(fullyQualifiedName, isAIROnly, variableBuilder.toString());
 	}
 
-	private void parseVariable(Element apiValueElement, boolean forInterface, boolean isInPackage,
+	private void parseVariable(Element apiValueElement, String contextClassName, boolean forInterface,
 			StringBuilder variableBuilder) throws Exception {
 		boolean isAIROnly = isAIROnly(apiValueElement.element("prolog"));
 		if (isAIROnly && !configuration.getAir()) {
@@ -669,6 +673,7 @@ class PLAYERGLOBALC implements FlexTool {
 		boolean isStatic = false;
 		boolean isOverride = false;
 		String variableType = "*";
+		boolean forceAnyType = isVariableTypedAsAny(contextClassName, variableName);
 		String access = null;
 
 		Element apiValueDetailElement = apiValueElement.element("apiValueDetail");
@@ -743,7 +748,11 @@ class PLAYERGLOBALC implements FlexTool {
 			variableBuilder.append("(");
 			variableBuilder.append(")");
 			variableBuilder.append(":");
-			variableBuilder.append(variableType);
+			if (forceAnyType) {
+				variableBuilder.append("*");
+			} else {
+				variableBuilder.append(variableType);
+			}
 			variableBuilder.append(";");
 			variableBuilder.append("\n");
 		}
@@ -769,7 +778,11 @@ class PLAYERGLOBALC implements FlexTool {
 			variableBuilder.append("(");
 			variableBuilder.append("value");
 			variableBuilder.append(":");
-			variableBuilder.append(variableType);
+			if (forceAnyType) {
+				variableBuilder.append("*");
+			} else {
+				variableBuilder.append(variableType);
+			}
 			variableBuilder.append(")");
 			variableBuilder.append(":");
 			variableBuilder.append("void");
@@ -786,15 +799,19 @@ class PLAYERGLOBALC implements FlexTool {
 			if (isStatic) {
 				variableBuilder.append("static ");
 			}
-			if (isConst || (isInPackage && GLOBAL_CONSTANTS.containsKey(variableName))) {
+			if (isConst || (contextClassName == null && GLOBAL_CONSTANTS.containsKey(variableName))) {
 				variableBuilder.append("const ");
 			} else {
 				variableBuilder.append("var ");
 			}
 			variableBuilder.append(variableName);
 			variableBuilder.append(":");
-			variableBuilder.append(variableType);
-			if (isInPackage && GLOBAL_CONSTANTS.containsKey(variableName)) {
+			if (forceAnyType) {
+				variableBuilder.append("*");
+			} else {
+				variableBuilder.append(variableType);
+			}
+			if (contextClassName == null && GLOBAL_CONSTANTS.containsKey(variableName)) {
 				variableBuilder.append(" = ");
 				variableBuilder.append(GLOBAL_CONSTANTS.get(variableName));
 			} else if (apiDataElement != null) {
@@ -1126,6 +1143,13 @@ class PLAYERGLOBALC implements FlexTool {
 		return REST_METHODS.get(contextClassName).contains(contextFunctionName);
 	}
 
+	private boolean isVariableTypedAsAny(String contextClassName, String contextVariableName) {
+		if (!ANY_VARIABLES.containsKey(contextClassName)) {
+			return false;
+		}
+		return ANY_VARIABLES.get(contextClassName).contains(contextVariableName);
+	}
+
 	private void parseParameters(List<Element> apiParamElements, String contextClassName, String contextFunctionName,
 			StringBuilder functionBuilder) throws Exception {
 		boolean forceOptionalConstructor = isConstructorThatNeedsParamsTypedAsAny(contextClassName,


[royale-compiler] 12/12: playerglobalc: constants that should be read/write variables

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit bf016f17cdd67b0cd8ce40fdfc3ffb27f7292e6d
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Mar 16 14:06:38 2021 -0700

    playerglobalc: constants that should be read/write variables
---
 .../org/apache/royale/compiler/clients/PLAYERGLOBALC.java   | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
index d164b41..bfb13b9 100644
--- a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
+++ b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
@@ -76,6 +76,10 @@ class PLAYERGLOBALC implements FlexTool {
 		GLOBAL_CONSTANTS.put("NaN", "0 / 0");
 		GLOBAL_CONSTANTS.put("undefined", "void 0");
 	}
+	private static final Map<String, List<String>> WRITABLE_VARIABLES = new HashMap<String, List<String>>();
+	{
+		WRITABLE_VARIABLES.put("flash.external.ExternalInterface", Arrays.asList("marshallExceptions"));
+	}
 	private static final Map<String, List<String>> REST_METHODS = new HashMap<String, List<String>>();
 	{
 		REST_METHODS.put("Array", Arrays.asList("splice"));
@@ -685,7 +689,7 @@ class PLAYERGLOBALC implements FlexTool {
 
 		boolean isGetter = false;
 		boolean isSetter = false;
-		boolean isConst = true;
+		boolean isConst = !isVariableThatShouldBeWritable(contextClassName, variableName);
 		boolean isStatic = false;
 		boolean isOverride = false;
 		String variableType = "*";
@@ -1173,6 +1177,13 @@ class PLAYERGLOBALC implements FlexTool {
 		return ANY_VARIABLES.get(contextClassName).contains(contextVariableName);
 	}
 
+	private boolean isVariableThatShouldBeWritable(String contextClassName, String contextVariableName) {
+		if (!WRITABLE_VARIABLES.containsKey(contextClassName)) {
+			return false;
+		}
+		return WRITABLE_VARIABLES.get(contextClassName).contains(contextVariableName);
+	}
+
 	private void parseParameters(List<Element> apiParamElements, String contextClassName, String contextFunctionName,
 			StringBuilder functionBuilder) throws Exception {
 		boolean forceOptionalConstructor = isConstructorThatNeedsParamsTypedAsAny(contextClassName,


[royale-compiler] 06/12: playerglobalc: some missing members

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit a43bc6be2d3711c3a89eb7646f42d2727b71def2
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Mar 16 11:52:02 2021 -0700

    playerglobalc: some missing members
---
 .../main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java  | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
index 6948f41..885d957 100644
--- a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
+++ b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
@@ -107,9 +107,14 @@ class PLAYERGLOBALC implements FlexTool {
 	}
 	private static final Map<String, List<String>> EXTRA_MEMBERS = new HashMap<String, List<String>>();
 	{
+		EXTRA_MEMBERS.put("flash.display.DisplayObjectContainer", Arrays
+				.asList("public native function removeChildren(beginIndex:int = 0, endIndex:int = 0x7fffffff):void"));
 		EXTRA_MEMBERS.put("flash.display.Graphics", Arrays.asList(
 				"public native function cubicCurveTo(controlX1:Number, controlY1:Number, controlX2:Number, controlY2:Number, anchorX:Number, anchorY:Number):void",
 				"public native function drawRoundRectComplex(x:Number, y:Number, width:Number, height:Number, topLeftRadius:Number, topRightRadius:Number, bottomLeftRadius:Number, bottomRightRadius:Number):void"));
+		EXTRA_MEMBERS.put("flash.events.EventDispatcher", Arrays.asList("public native function toString():String"));
+		EXTRA_MEMBERS.put("flash.media.Camera",
+				Arrays.asList("public native function copyToByteArray(rect:Rectangle, destination:ByteArray):void"));
 	}
 
 	protected ProblemQuery problems;


[royale-compiler] 03/12: playerglobalc: some extra members on flash.display.Graphics

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit 605a138bb9bcae5fd49a693da39845e1ec6048cb
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Mar 16 10:33:36 2021 -0700

    playerglobalc: some extra members on flash.display.Graphics
---
 .../org/apache/royale/compiler/clients/PLAYERGLOBALC.java  | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
index 1f23f42..af7fdc5 100644
--- a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
+++ b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
@@ -100,6 +100,12 @@ class PLAYERGLOBALC implements FlexTool {
 				"descendants", "elements", "insertChildAfter", "insertChildBefore", "namespace", "prependChild",
 				"processingInstructions", "removeNamespace", "replace", "setChildren", "setName", "setNamespace"));
 	}
+	private static final Map<String, List<String>> EXTRA_MEMBERS = new HashMap<String, List<String>>();
+	{
+		EXTRA_MEMBERS.put("flash.display.Graphics", Arrays.asList(
+				"public native function cubicCurveTo(controlX1:Number, controlY1:Number, controlX2:Number, controlY2:Number, anchorX:Number, anchorY:Number):void",
+				"public native function drawRoundRectComplex(x:Number, y:Number, width:Number, height:Number, topLeftRadius:Number, topRightRadius:Number, bottomLeftRadius:Number, bottomRightRadius:Number):void"));
+	}
 
 	protected ProblemQuery problems;
 	protected Configurator projectConfigurator;
@@ -440,6 +446,14 @@ class PLAYERGLOBALC implements FlexTool {
 		for (Element apiValueElement : apiValueElements) {
 			parseVariable(apiValueElement, false, false, classBuilder);
 		}
+		if (EXTRA_MEMBERS.containsKey(fullyQualifiedName)) {
+			for (String member : EXTRA_MEMBERS.get(fullyQualifiedName)) {
+				classBuilder.append("\t");
+				classBuilder.append(member);
+				classBuilder.append(";");
+				classBuilder.append("\n");
+			}
+		}
 		classBuilder.append("\t");
 		classBuilder.append("}");
 		classBuilder.append("\n");


[royale-compiler] 09/12: playerglobalc: some refinements to the Object prototype methods

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit 9b3ff46af078f9fd1501479a188ae5e0598c1e44
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Mar 16 12:13:40 2021 -0700

    playerglobalc: some refinements to the Object prototype methods
---
 .../org/apache/royale/compiler/clients/PLAYERGLOBALC.java | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
index dd85cf7..2a692c1 100644
--- a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
+++ b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
@@ -63,8 +63,10 @@ class PLAYERGLOBALC implements FlexTool {
 	private static final List<String> VECTOR_SUFFIXES = Arrays.asList("$double", "$int", "$uint", "$object");
 	// From the docs: Methods of the Object class are dynamically created on
 	// Object's prototype.
-	private static final List<String> OBJECT_PROTOTYPE_METHODS = Arrays.asList("hasOwnProperty", "isPrototypeOf",
-			"propertyIsEnumerable", "setPropertyIsEnumerable", "toString", "toLocaleString", "valueOf");
+	private static final List<String> OBJECT_PROTOTYPE_METHODS = Arrays.asList("setPropertyIsEnumerable", "toString",
+			"toLocaleString", "valueOf");
+	private static final List<String> OBJECT_AS3_METHODS = Arrays.asList("hasOwnProperty", "isPrototypeOf",
+			"propertyIsEnumerable");
 	private static final List<String> ANY_CONSTRUCTORS = Arrays.asList("ArgumentError", "Boolean", "Date",
 			"DefinitionError", "Error", "EvalError", "int", "Number", "RangeError", "ReferenceError", "RegExp",
 			"SecurityError", "String", "SyntaxError", "TypeError", "uint", "URIError", "VerifyError", "XML", "XMLList");
@@ -88,6 +90,7 @@ class PLAYERGLOBALC implements FlexTool {
 				Arrays.asList("setFullYear", "setMonth", "setDate", "setHours", "setMinutes", "setSeconds",
 						"setMilliseconds", "setUTCFullYear", "setUTCMonth", "setUTCDate", "setUTCHours",
 						"setUTCMinutes", "setUTCSeconds", "setUTCMilliseconds", "setTime"));
+		NULL_DEFAULT_METHODS.put("Object", Arrays.asList("hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable"));
 	}
 	private static final Map<String, List<String>> ANY_METHODS = new HashMap<String, List<String>>();
 	{
@@ -95,6 +98,7 @@ class PLAYERGLOBALC implements FlexTool {
 				Arrays.asList("setFullYear", "setMonth", "setDate", "setHours", "setMinutes", "setSeconds",
 						"setMilliseconds", "setUTCFullYear", "setUTCMonth", "setUTCDate", "setUTCHours",
 						"setUTCMinutes", "setUTCSeconds", "setUTCMilliseconds", "setTime", "UTC"));
+		ANY_METHODS.put("Object", Arrays.asList("hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable"));
 		ANY_METHODS.put("XML", Arrays.asList("addNamespace", "appendChild", "attribute", "child", "contains",
 				"descendants", "elements", "insertChildAfter", "insertChildBefore", "namespace", "prependChild",
 				"processingInstructions", "removeNamespace", "replace", "setChildren", "setName", "setNamespace"));
@@ -887,6 +891,13 @@ class PLAYERGLOBALC implements FlexTool {
 
 		List<Element> apiParamElements = apiOperationDefElement.elements("apiParam");
 
+		if (OBJECT_AS3_METHODS.contains(functionName)) {
+			if ("Object".equals(contextClassName)) {
+				access = "AS3";
+			} else {
+				return;
+			}
+		}
 		if ("Object".equals(contextClassName) && OBJECT_PROTOTYPE_METHODS.contains(functionName)) {
 			return;
 		}


[royale-compiler] 02/12: playerglobalc: special case for global constants: undefined, NaN, and Infinity

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit fb068a0a625be4a1d80ae168e97a9eba6f171620
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Mar 16 10:23:19 2021 -0700

    playerglobalc: special case for global constants: undefined, NaN, and Infinity
---
 .../royale/compiler/clients/PLAYERGLOBALC.java     | 23 +++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
index aae41b4..1f23f42 100644
--- a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
+++ b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
@@ -67,6 +67,12 @@ class PLAYERGLOBALC implements FlexTool {
 			"propertyIsEnumerable", "setPropertyIsEnumerable", "toString", "toLocaleString", "valueOf");
 	private static final List<String> ANY_CONSTRUCTORS = Arrays.asList("Boolean", "Date", "int", "Number", "RegExp",
 			"String", "uint", "XML", "XMLList");
+	private static final Map<String, String> GLOBAL_CONSTANTS = new HashMap<String, String>();
+	{
+		GLOBAL_CONSTANTS.put("Infinity", "1 / 0");
+		GLOBAL_CONSTANTS.put("NaN", "0 / 0");
+		GLOBAL_CONSTANTS.put("undefined", "void 0");
+	}
 	private static final Map<String, List<String>> REST_METHODS = new HashMap<String, List<String>>();
 	{
 		REST_METHODS.put("__AS3__.vec.Vector$object", Arrays.asList("sort"));
@@ -432,7 +438,7 @@ class PLAYERGLOBALC implements FlexTool {
 			parseFunction(apiOperationElement, fullyQualifiedName, false, classBuilder);
 		}
 		for (Element apiValueElement : apiValueElements) {
-			parseVariable(apiValueElement, false, classBuilder);
+			parseVariable(apiValueElement, false, false, classBuilder);
 		}
 		classBuilder.append("\t");
 		classBuilder.append("}");
@@ -529,7 +535,7 @@ class PLAYERGLOBALC implements FlexTool {
 			parseFunction(apiOperationElement, null, true, interfaceBuilder);
 		}
 		for (Element apiValueElement : apiValueElements) {
-			parseVariable(apiValueElement, true, interfaceBuilder);
+			parseVariable(apiValueElement, true, false, interfaceBuilder);
 		}
 		interfaceBuilder.append("\t");
 		interfaceBuilder.append("}");
@@ -627,15 +633,15 @@ class PLAYERGLOBALC implements FlexTool {
 		variableBuilder.append("{");
 		variableBuilder.append("\n");
 		writeImports(importFullyQualifiedNames, variableBuilder);
-		parseVariable(apiValueElement, false, variableBuilder);
+		parseVariable(apiValueElement, false, true, variableBuilder);
 		variableBuilder.append("}");
 		variableBuilder.append("\n");
 
 		writeFileForDefinition(fullyQualifiedName, isAIROnly, variableBuilder.toString());
 	}
 
-	private void parseVariable(Element apiValueElement, boolean forInterface, StringBuilder variableBuilder)
-			throws Exception {
+	private void parseVariable(Element apiValueElement, boolean forInterface, boolean isInPackage,
+			StringBuilder variableBuilder) throws Exception {
 		boolean isAIROnly = isAIROnly(apiValueElement.element("prolog"));
 		if (isAIROnly && !configuration.getAir()) {
 			return;
@@ -766,7 +772,7 @@ class PLAYERGLOBALC implements FlexTool {
 			if (isStatic) {
 				variableBuilder.append("static ");
 			}
-			if (isConst) {
+			if (isConst || (isInPackage && GLOBAL_CONSTANTS.containsKey(variableName))) {
 				variableBuilder.append("const ");
 			} else {
 				variableBuilder.append("var ");
@@ -774,7 +780,10 @@ class PLAYERGLOBALC implements FlexTool {
 			variableBuilder.append(variableName);
 			variableBuilder.append(":");
 			variableBuilder.append(variableType);
-			if (apiDataElement != null) {
+			if (isInPackage && GLOBAL_CONSTANTS.containsKey(variableName)) {
+				variableBuilder.append(" = ");
+				variableBuilder.append(GLOBAL_CONSTANTS.get(variableName));
+			} else if (apiDataElement != null) {
 				writeVariableOrParameterValue(apiDataElement, variableType, variableBuilder);
 			}
 			variableBuilder.append(";");


[royale-compiler] 01/12: playerglobalc: various methods on Date need parameters typed as * and null defaults

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit bd27efee2c7353c27a089d36190048c38741b8a5
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Mar 16 09:57:52 2021 -0700

    playerglobalc: various methods on Date need parameters typed as * and null defaults
---
 .../royale/compiler/clients/PLAYERGLOBALC.java     | 245 +++++++++++----------
 1 file changed, 125 insertions(+), 120 deletions(-)

diff --git a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
index d61d0a8..aae41b4 100644
--- a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
+++ b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
@@ -50,24 +50,19 @@ import org.dom4j.io.SAXReader;
  */
 class PLAYERGLOBALC implements FlexTool {
 
-    static enum ExitCode
-    {
-        SUCCESS(0),
-        PRINT_HELP(1),
-        FAILED_WITH_PROBLEMS(2),
-        FAILED_WITH_EXCEPTIONS(3),
-        FAILED_WITH_CONFIG_PROBLEMS(4);
-
-        ExitCode(int code)
-        {
-            this.code = code;
-        }
-
-        final int code;
-    }
+	static enum ExitCode {
+		SUCCESS(0), PRINT_HELP(1), FAILED_WITH_PROBLEMS(2), FAILED_WITH_EXCEPTIONS(3), FAILED_WITH_CONFIG_PROBLEMS(4);
+
+		ExitCode(int code) {
+			this.code = code;
+		}
+
+		final int code;
+	}
 
 	private static final List<String> VECTOR_SUFFIXES = Arrays.asList("$double", "$int", "$uint", "$object");
-	//From the docs: Methods of the Object class are dynamically created on Object's prototype.
+	// From the docs: Methods of the Object class are dynamically created on
+	// Object's prototype.
 	private static final List<String> OBJECT_PROTOTYPE_METHODS = Arrays.asList("hasOwnProperty", "isPrototypeOf",
 			"propertyIsEnumerable", "setPropertyIsEnumerable", "toString", "toLocaleString", "valueOf");
 	private static final List<String> ANY_CONSTRUCTORS = Arrays.asList("Boolean", "Date", "int", "Number", "RegExp",
@@ -79,104 +74,102 @@ class PLAYERGLOBALC implements FlexTool {
 		REST_METHODS.put("__AS3__.vec.Vector$int", Arrays.asList("sort"));
 		REST_METHODS.put("__AS3__.vec.Vector$uint", Arrays.asList("sort"));
 	}
+	private static final Map<String, List<String>> NULL_DEFAULT_METHODS = new HashMap<String, List<String>>();
+	{
+		NULL_DEFAULT_METHODS.put("Date",
+				Arrays.asList("setFullYear", "setMonth", "setDate", "setHours", "setMinutes", "setSeconds",
+						"setMilliseconds", "setUTCFullYear", "setUTCMonth", "setUTCDate", "setUTCHours",
+						"setUTCMinutes", "setUTCSeconds", "setUTCMilliseconds", "setTime"));
+	}
 	private static final Map<String, List<String>> ANY_METHODS = new HashMap<String, List<String>>();
 	{
-		ANY_METHODS.put("XML", Arrays.asList("addNamespace", "appendChild", "attribute",
-			"child", "contains", "descendants", "elements", "insertChildAfter", "insertChildBefore", "namespace",
-			"prependChild", "processingInstructions", "removeNamespace", "replace", "setChildren", "setName",
-			"setNamespace"));
-		ANY_METHODS.put("XMLList", Arrays.asList("addNamespace", "appendChild", "attribute",
-			"child", "contains", "descendants", "elements", "insertChildAfter", "insertChildBefore", "namespace",
-			"prependChild", "processingInstructions", "removeNamespace", "replace", "setChildren", "setName",
-			"setNamespace"));
+		ANY_METHODS.put("Date",
+				Arrays.asList("setFullYear", "setMonth", "setDate", "setHours", "setMinutes", "setSeconds",
+						"setMilliseconds", "setUTCFullYear", "setUTCMonth", "setUTCDate", "setUTCHours",
+						"setUTCMinutes", "setUTCSeconds", "setUTCMilliseconds", "setTime", "UTC"));
+		ANY_METHODS.put("XML", Arrays.asList("addNamespace", "appendChild", "attribute", "child", "contains",
+				"descendants", "elements", "insertChildAfter", "insertChildBefore", "namespace", "prependChild",
+				"processingInstructions", "removeNamespace", "replace", "setChildren", "setName", "setNamespace"));
+		ANY_METHODS.put("XMLList", Arrays.asList("addNamespace", "appendChild", "attribute", "child", "contains",
+				"descendants", "elements", "insertChildAfter", "insertChildBefore", "namespace", "prependChild",
+				"processingInstructions", "removeNamespace", "replace", "setChildren", "setName", "setNamespace"));
 	}
 
-    protected ProblemQuery problems;
-    protected Configurator projectConfigurator;
+	protected ProblemQuery problems;
+	protected Configurator projectConfigurator;
 	protected PlayerglobalcConfiguration configuration;
 	private File sourceFolder;
 	private File targetFolder;
 	private File currentFile;
 
-    /**
-     * Java program entry point.
-     * 
-     * @param args command line arguments
-     */
-    public static void main(final String[] args)
-    {
+	/**
+	 * Java program entry point.
+	 * 
+	 * @param args command line arguments
+	 */
+	public static void main(final String[] args) {
 		PLAYERGLOBALC compiler = new PLAYERGLOBALC();
-        int exitCode = compiler.execute(args);
-        System.exit(exitCode);
-    }
+		int exitCode = compiler.execute(args);
+		System.exit(exitCode);
+	}
 
 	public PLAYERGLOBALC() {
 
 	}
 
-    @Override
-    public String getName() {
-        // TODO: Change this to a flex-tool-api constant ...
-        return "PLAYERGLOBALC";
-    }
-
-    /**
-     * Create a new Configurator. This method may be overridden to allow
-     * Configurator subclasses to be created that have custom configurations.
-     * 
-     * @return a new instance or subclass of {@link Configurator}.
-     */
-    protected Configurator createConfigurator()
-    {
-        return new PlayerglobalcConfigurator(PlayerglobalcConfiguration.class);
-    }
-
-    protected boolean configure(String[] args)
-    {
+	@Override
+	public String getName() {
+		// TODO: Change this to a flex-tool-api constant ...
+		return "PLAYERGLOBALC";
+	}
+
+	/**
+	 * Create a new Configurator. This method may be overridden to allow
+	 * Configurator subclasses to be created that have custom configurations.
+	 * 
+	 * @return a new instance or subclass of {@link Configurator}.
+	 */
+	protected Configurator createConfigurator() {
+		return new PlayerglobalcConfigurator(PlayerglobalcConfiguration.class);
+	}
+
+	protected boolean configure(String[] args) {
 		projectConfigurator = createConfigurator();
-        projectConfigurator.setConfiguration(args, "asdoc-root", false);
-        projectConfigurator.getTargetSettings(TargetType.SWC);
-        configuration = ((PlayerglobalcConfiguration) projectConfigurator.getConfiguration());
-        problems = new ProblemQuery(
-                projectConfigurator.getCompilerProblemSettings());
-        problems.addAll(projectConfigurator.getConfigurationProblems());
-        if (problems.hasErrors() || configuration == null)
-        {
-            return false;
-        }
-        return true;
-    }
-
-    @Override
-    public int execute(String[] args) {
-        ExitCode exitCode = ExitCode.SUCCESS;
+		projectConfigurator.setConfiguration(args, "asdoc-root", false);
+		projectConfigurator.getTargetSettings(TargetType.SWC);
+		configuration = ((PlayerglobalcConfiguration) projectConfigurator.getConfiguration());
+		problems = new ProblemQuery(projectConfigurator.getCompilerProblemSettings());
+		problems.addAll(projectConfigurator.getConfigurationProblems());
+		if (problems.hasErrors() || configuration == null) {
+			return false;
+		}
+		return true;
+	}
+
+	@Override
+	public int execute(String[] args) {
+		ExitCode exitCode = ExitCode.SUCCESS;
 		try {
 			boolean continueGeneration = configure(args);
 			if (continueGeneration) {
 				sourceFolder = configuration.getASDocRoot();
 				targetFolder = configuration.getAsRoot();
 				generateSources();
+			} else if (problems.hasFilteredProblems()) {
+				exitCode = ExitCode.FAILED_WITH_CONFIG_PROBLEMS;
+			} else {
+				exitCode = ExitCode.PRINT_HELP;
 			}
-            else if (problems.hasFilteredProblems())
-            {
-                exitCode = ExitCode.FAILED_WITH_CONFIG_PROBLEMS;
-            }
-            else
-            {
-                exitCode = ExitCode.PRINT_HELP;
-            }
 		} catch (Exception e) {
 			System.err.println(e.getMessage());
-            exitCode = ExitCode.FAILED_WITH_EXCEPTIONS;
+			exitCode = ExitCode.FAILED_WITH_EXCEPTIONS;
+		} finally {
+			final ProblemFormatter formatter = new ProblemFormatter();
+			final ProblemPrinter printer = new ProblemPrinter(formatter, System.err);
+			printer.printProblems(problems.getFilteredProblems());
 		}
-        finally
-        {
-            final ProblemFormatter formatter = new ProblemFormatter();
-            final ProblemPrinter printer = new ProblemPrinter(formatter, System.err);
-            printer.printProblems(problems.getFilteredProblems());
-        }
 
-        return exitCode.code;
+		return exitCode.code;
 	}
 
 	public void generateSources() throws Exception {
@@ -296,7 +289,7 @@ class PLAYERGLOBALC implements FlexTool {
 			fullyQualifiedName = fullyQualifiedName.substring(17);
 		}
 		if (fullyQualifiedName.equals("Vector")) {
-			//special case in the compiler that doesn't get exposed in docs
+			// special case in the compiler that doesn't get exposed in docs
 			fullyQualifiedName = "__AS3__.vec:Vector";
 			StringBuilder vectorBuilder = new StringBuilder();
 			vectorBuilder.append("// generated from: ");
@@ -329,7 +322,8 @@ class PLAYERGLOBALC implements FlexTool {
 		}
 
 		boolean isAIROnly = isAIROnly(apiClassifierElement.element("prolog"));
-		if(isAIROnly && !configuration.getAir() && !fullyQualifiedName.equals("flash.display.NativeMenu") && !fullyQualifiedName.equals("flash.display.NativeMenuItem")) {
+		if (isAIROnly && !configuration.getAir() && !fullyQualifiedName.equals("flash.display.NativeMenu")
+				&& !fullyQualifiedName.equals("flash.display.NativeMenuItem")) {
 			return;
 		}
 
@@ -465,7 +459,7 @@ class PLAYERGLOBALC implements FlexTool {
 		}
 
 		boolean isAIROnly = isAIROnly(apiClassifierElement.element("prolog"));
-		if(isAIROnly && !configuration.getAir()) {
+		if (isAIROnly && !configuration.getAir()) {
 			return;
 		}
 
@@ -552,7 +546,7 @@ class PLAYERGLOBALC implements FlexTool {
 			fullyQualifiedName = fullyQualifiedName.substring(16);
 		}
 		if (fullyQualifiedName.equals("Vector")) {
-			//special case in the compiler that doesn't get exposed in docs
+			// special case in the compiler that doesn't get exposed in docs
 			return;
 		}
 
@@ -564,7 +558,7 @@ class PLAYERGLOBALC implements FlexTool {
 		}
 
 		boolean isAIROnly = isAIROnly(apiOperationElement.element("prolog"));
-		if(isAIROnly && !configuration.getAir()) {
+		if (isAIROnly && !configuration.getAir()) {
 			return;
 		}
 
@@ -607,13 +601,13 @@ class PLAYERGLOBALC implements FlexTool {
 		}
 
 		if (variableName.startsWith("-")) {
-			//nothing to do here
-			//it's just a negative value getting documented (like -Infinity)
+			// nothing to do here
+			// it's just a negative value getting documented (like -Infinity)
 			return;
 		}
 
 		boolean isAIROnly = isAIROnly(apiValueElement.element("prolog"));
-		if(isAIROnly && !configuration.getAir()) {
+		if (isAIROnly && !configuration.getAir()) {
 			return;
 		}
 
@@ -643,10 +637,10 @@ class PLAYERGLOBALC implements FlexTool {
 	private void parseVariable(Element apiValueElement, boolean forInterface, StringBuilder variableBuilder)
 			throws Exception {
 		boolean isAIROnly = isAIROnly(apiValueElement.element("prolog"));
-		if(isAIROnly && !configuration.getAir()) {
+		if (isAIROnly && !configuration.getAir()) {
 			return;
 		}
-	
+
 		String variableName = apiValueElement.element("apiName").getTextTrim();
 
 		boolean isGetter = false;
@@ -701,8 +695,8 @@ class PLAYERGLOBALC implements FlexTool {
 
 		if (!forInterface && isGetter && isSetter && !isOverride
 				&& apiValueElement.attributeValue("id").endsWith(":set")) {
-			//skip the getter because it is already defined on the base class
-			//example: flash.text.engine.TextElement.text
+			// skip the getter because it is already defined on the base class
+			// example: flash.text.engine.TextElement.text
 			isGetter = false;
 		}
 
@@ -791,7 +785,7 @@ class PLAYERGLOBALC implements FlexTool {
 	private void parseFunction(Element apiOperationElement, String contextClassName, boolean forInterface,
 			StringBuilder functionBuilder) throws Exception {
 		boolean isAIROnly = isAIROnly(apiOperationElement.element("prolog"));
-		if(isAIROnly && !configuration.getAir()) {
+		if (isAIROnly && !configuration.getAir()) {
 			return;
 		}
 
@@ -814,7 +808,8 @@ class PLAYERGLOBALC implements FlexTool {
 		Element apiIsOverrideElement = apiOperationDefElement.element("apiIsOverride");
 		if (apiIsOverrideElement != null) {
 			isOverride = true;
-			if(!configuration.getAir() && "clone".equals(functionName) && "flash.ui.ContextMenuItem".equals(contextClassName)) {
+			if (!configuration.getAir() && "clone".equals(functionName)
+					&& "flash.ui.ContextMenuItem".equals(contextClassName)) {
 				isOverride = false;
 			}
 		}
@@ -961,7 +956,7 @@ class PLAYERGLOBALC implements FlexTool {
 				}
 				result.add(apiParamElement2);
 				if (isRest) {
-					//nothing after rest
+					// nothing after rest
 					break;
 				}
 				continue;
@@ -995,7 +990,7 @@ class PLAYERGLOBALC implements FlexTool {
 				}
 				result.add(apiParamElement1);
 				if (isRest) {
-					//nothing after rest
+					// nothing after rest
 					break;
 				}
 				continue;
@@ -1010,7 +1005,7 @@ class PLAYERGLOBALC implements FlexTool {
 					isRest = true;
 					Element apiItemNameElement1 = apiParamElement1.element("apiItemName");
 					if (apiItemNameElement1 != null) {
-						//keep the existing name
+						// keep the existing name
 						paramName = apiItemNameElement1.getTextTrim();
 					}
 				}
@@ -1022,7 +1017,7 @@ class PLAYERGLOBALC implements FlexTool {
 					isRest = true;
 					Element apiItemNameElement2 = apiParamElement2.element("apiItemName");
 					if (apiItemNameElement2 != null) {
-						//keep the existing name
+						// keep the existing name
 						paramName = apiItemNameElement2.getTextTrim();
 					}
 				}
@@ -1045,7 +1040,7 @@ class PLAYERGLOBALC implements FlexTool {
 			}
 			result.add(newApiParamElement);
 			if (isRest) {
-				//nothing after rest
+				// nothing after rest
 				break;
 			}
 		}
@@ -1070,7 +1065,8 @@ class PLAYERGLOBALC implements FlexTool {
 			String[] parts = apiTypeValue.split("\\$");
 			String vectorItemType = parts[1];
 			vectorItemType = vectorItemType.replace(":", ".");
-			if (contextClassName != null && contextClassName.startsWith("__AS3__.vec.Vector$") && vectorItemType.equals("T")) {
+			if (contextClassName != null && contextClassName.startsWith("__AS3__.vec.Vector$")
+					&& vectorItemType.equals("T")) {
 				return contextClassName;
 			}
 			return "Vector.<" + vectorItemType + ">";
@@ -1087,14 +1083,21 @@ class PLAYERGLOBALC implements FlexTool {
 	}
 
 	private boolean isMethodThatNeedsParamsTypedAsAny(String contextClassName, String contextFunctionName) {
-		if(!ANY_METHODS.containsKey(contextClassName)) {
+		if (!ANY_METHODS.containsKey(contextClassName)) {
 			return false;
 		}
 		return ANY_METHODS.get(contextClassName).contains(contextFunctionName);
 	}
 
+	private boolean isMethodThatNeedsParamsWithDefaultNull(String contextClassName, String contextFunctionName) {
+		if (!NULL_DEFAULT_METHODS.containsKey(contextClassName)) {
+			return false;
+		}
+		return NULL_DEFAULT_METHODS.get(contextClassName).contains(contextFunctionName);
+	}
+
 	private boolean isMethodThatNeedsRestParamOnly(String contextClassName, String contextFunctionName) {
-		if(!REST_METHODS.containsKey(contextClassName)) {
+		if (!REST_METHODS.containsKey(contextClassName)) {
 			return false;
 		}
 		return REST_METHODS.get(contextClassName).contains(contextFunctionName);
@@ -1106,6 +1109,7 @@ class PLAYERGLOBALC implements FlexTool {
 				contextFunctionName);
 		boolean forceRest = isMethodThatNeedsRestParamOnly(contextClassName, contextFunctionName);
 		boolean forceAnyType = isMethodThatNeedsParamsTypedAsAny(contextClassName, contextFunctionName);
+		boolean forceNullDefault = isMethodThatNeedsParamsWithDefaultNull(contextClassName, contextFunctionName);
 		for (int i = 0; i < apiParamElements.size(); i++) {
 			if (i > 0) {
 				functionBuilder.append(", ");
@@ -1113,11 +1117,10 @@ class PLAYERGLOBALC implements FlexTool {
 			Element apiParamElement = apiParamElements.get(i);
 			Element apiTypeElement = apiParamElement.element("apiType");
 			String paramType = null;
-			if(forceRest) {
+			if (forceRest) {
 				functionBuilder.append("...args");
 				break;
-			}
-			else {
+			} else {
 				if (apiTypeElement != null) {
 					String apiTypeValue = apiTypeElement.attributeValue("value");
 					if ("restParam".equals(apiTypeValue)) {
@@ -1131,7 +1134,7 @@ class PLAYERGLOBALC implements FlexTool {
 				}
 				functionBuilder.append(apiItemNameElement.getTextTrim());
 				if (forceOptionalConstructor) {
-					//workaround for missing data in asdoc dita
+					// workaround for missing data in asdoc dita
 					functionBuilder.append(":* = null");
 				} else {
 					Element apiOperationClassifierElement = apiParamElement.element("apiOperationClassifier");
@@ -1147,10 +1150,12 @@ class PLAYERGLOBALC implements FlexTool {
 						functionBuilder.append(paramType);
 					}
 					Element apiDataElement = apiParamElement.element("apiData");
-					if (apiDataElement != null) {
+					if (forceNullDefault) {
+						functionBuilder.append(" = null");
+					} else if (apiDataElement != null) {
 						writeVariableOrParameterValue(apiDataElement, paramType, functionBuilder);
-					}
-					else if(("int".equals(contextClassName) || "uint".equals(contextClassName)) && "toString".equals(contextFunctionName)) {
+					} else if (("int".equals(contextClassName) || "uint".equals(contextClassName))
+							&& "toString".equals(contextFunctionName)) {
 						functionBuilder.append(" = 10");
 					}
 				}
@@ -1179,12 +1184,12 @@ class PLAYERGLOBALC implements FlexTool {
 	private void collectImport(String fullyQualifiedName, String forPackage, Set<String> result) throws Exception {
 		String[] parts = fullyQualifiedName.split(":");
 		if (parts.length == 1) {
-			//top-level package
+			// top-level package
 			return;
 		}
 		String packageName = parts[0];
 		if (packageName.equals(forPackage)) {
-			//same package
+			// same package
 			return;
 		}
 		result.add(packageName + "." + parts[1]);
@@ -1233,7 +1238,7 @@ class PLAYERGLOBALC implements FlexTool {
 		}
 		if ("apiOperation".equals(elementName)) {
 			boolean isAIROnly = isAIROnly(element.element("prolog"));
-			if(isAIROnly && !configuration.getAir()) {
+			if (isAIROnly && !configuration.getAir()) {
 				return;
 			}
 
@@ -1316,7 +1321,7 @@ class PLAYERGLOBALC implements FlexTool {
 		}
 		if ("apiValue".equals(elementName)) {
 			boolean isAIROnly = isAIROnly(element.element("prolog"));
-			if(isAIROnly && !configuration.getAir()) {
+			if (isAIROnly && !configuration.getAir()) {
 				return;
 			}
 


[royale-compiler] 10/12: playerglobalc: Function missing APIs

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit e0e24b43f323ceacc5c451102816c6e5c8324566
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Mar 16 13:20:27 2021 -0700

    playerglobalc: Function missing APIs
---
 .../main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
index 2a692c1..925a4cc 100644
--- a/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
+++ b/compiler-playerglobalc/src/main/java/org/apache/royale/compiler/clients/PLAYERGLOBALC.java
@@ -112,12 +112,16 @@ class PLAYERGLOBALC implements FlexTool {
 	}
 	private static final Map<String, List<String>> EXTRA_MEMBERS = new HashMap<String, List<String>>();
 	{
-		EXTRA_MEMBERS.put("Function", Arrays.asList("public var prototype:Object"));
+		EXTRA_MEMBERS.put("Function", Arrays.asList("public native function get prototype():*",
+				"public native function set prototype(value:*):void", "public native function get length():int;"));
+		EXTRA_MEMBERS.put("String", Arrays.asList("AS3 native function toString():String"));
 		EXTRA_MEMBERS.put("flash.display.DisplayObjectContainer", Arrays
 				.asList("public native function removeChildren(beginIndex:int = 0, endIndex:int = 0x7fffffff):void"));
 		EXTRA_MEMBERS.put("flash.display.Graphics", Arrays.asList(
 				"public native function cubicCurveTo(controlX1:Number, controlY1:Number, controlX2:Number, controlY2:Number, anchorX:Number, anchorY:Number):void",
 				"public native function drawRoundRectComplex(x:Number, y:Number, width:Number, height:Number, topLeftRadius:Number, topRightRadius:Number, bottomLeftRadius:Number, bottomRightRadius:Number):void"));
+		EXTRA_MEMBERS.put("flash.display.MovieClip",
+				Arrays.asList("public native function addFrameScript(...args):void"));
 		EXTRA_MEMBERS.put("flash.events.EventDispatcher", Arrays.asList("public native function toString():String"));
 		EXTRA_MEMBERS.put("flash.media.Camera",
 				Arrays.asList("public native function copyToByteArray(rect:Rectangle, destination:ByteArray):void"));