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 a6c8e592719f57d3d23e29321ac12fd3aff7ea7d
Author: Josh Tynjala <[email protected]>
AuthorDate: Tue Jan 20 15:07:44 2026 -0800

    FunctionCallEmitter: fix Vector.<Foo>() global function when using custom 
vector emulation class
---
 .../codegen/js/jx/FunctionCallEmitter.java         | 68 ++++++++++++++++------
 .../js/royale/TestRoyaleGlobalFunctions.java       | 42 +++++++++++++
 2 files changed, 91 insertions(+), 19 deletions(-)

diff --git 
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
 
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
index a4210d385..b5d9f389f 100644
--- 
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
+++ 
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
@@ -632,32 +632,62 @@ public class FunctionCallEmitter extends JSSubEmitter 
implements ISubEmitter<IFu
                        }
                        else
                        {
+                            String vectorEmulationClass = null;
+                            String vectorEmulationLiteralFunction = null;
+                            boolean vectorEmulationElementTypes = true;
+                            if (project instanceof RoyaleJSProject)
+                            {
+                                RoyaleJSProject royaleProject = 
(RoyaleJSProject) project;
+                                if (royaleProject.config != null)
+                                {
+                                    vectorEmulationClass = 
royaleProject.config.getJsVectorEmulationClass();
+                                    vectorEmulationLiteralFunction = 
royaleProject.config.getJsVectorEmulationLiteralFunction();
+                                    vectorEmulationElementTypes = 
royaleProject.config.getJsVectorEmulationElementTypes();
+                                }
+                            }
                             String elementClassName = 
getEmitter().formatQualifiedName(((TypedExpressionNode)nameNode).getTypeNode().resolve(getProject()).getQualifiedName());
-                           if (getProject() instanceof RoyaleJSProject
-                                && ((RoyaleJSProject) 
getProject()).config.getJsVectorEmulationClass()!= null) {
-                               String vectorEmulationClass = 
((RoyaleJSProject) getProject()).config.getJsVectorEmulationClass();
-                               if 
(vectorEmulationClass.equals(IASLanguageConstants.Array)) {
-                                   //just do a slice copy of the array which 
is the first argument
-                                    
getWalker().walk(node.getArgumentsNode().getChild(0));
-                                    write(ASEmitterTokens.MEMBER_ACCESS);
-                                    write("slice");
-                                    write(ASEmitterTokens.PAREN_OPEN);
-                                    write(ASEmitterTokens.PAREN_CLOSE);
-                                } else {
-                                   //assume the emulation class can handle an 
array or numeric value for first constructor arg...
-                                    writeToken(ASEmitterTokens.NEW);
-                                    startMapping(node.getNameNode());
-                                    write(vectorEmulationClass);
-                                    endMapping(node.getNameNode());
-                                    write(ASEmitterTokens.PAREN_OPEN);
-                                    
getWalker().walk(node.getArgumentsNode().getChild(0));
+                            if 
(IASLanguageConstants.Array.equals(vectorEmulationClass))
+                            {
+                                //just do a slice copy of the array which is 
the first argument
+                                
getWalker().walk(node.getArgumentsNode().getChild(0));
+                                write(ASEmitterTokens.MEMBER_ACCESS);
+                                write("slice");
+                                write(ASEmitterTokens.PAREN_OPEN);
+                                write(ASEmitterTokens.PAREN_CLOSE);
+                            }
+                            else if (vectorEmulationLiteralFunction != null)
+                            {
+                                write(vectorEmulationLiteralFunction);
+                                write(ASEmitterTokens.PAREN_OPEN);
+                                
getWalker().walk(node.getArgumentsNode().getChild(0));
+                                if (vectorEmulationElementTypes)
+                                {
                                     writeToken(ASEmitterTokens.COMMA);
                                     write(ASEmitterTokens.SINGLE_QUOTE);
                                     //the element type of the Vector:
                                     write(elementClassName);
                                     write(ASEmitterTokens.SINGLE_QUOTE);
-                                    write(ASEmitterTokens.PAREN_CLOSE);
                                 }
+                                write(ASEmitterTokens.PAREN_CLOSE);
+                            }
+                            else if (vectorEmulationClass != null) 
+                            {
+                                //assume the emulation class can handle an 
array or numeric value for first constructor arg...
+                                writeToken(ASEmitterTokens.NEW);
+                                startMapping(node.getNameNode());
+                                write(vectorEmulationClass);
+                                endMapping(node.getNameNode());
+                                write(ASEmitterTokens.PAREN_OPEN);
+                                
getWalker().walk(node.getArgumentsNode().getChild(0));
+                                if (vectorEmulationElementTypes)
+                                {
+                                    writeToken(ASEmitterTokens.COMMA);
+                                    write(ASEmitterTokens.SINGLE_QUOTE);
+                                    //the element type of the Vector:
+                                    write(elementClassName);
+                                    write(ASEmitterTokens.SINGLE_QUOTE);
+                                }
+                                write(ASEmitterTokens.PAREN_CLOSE);
                             } else {
                                //default Vector implementation
                                 startMapping(node.getNameNode());
diff --git 
a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalFunctions.java
 
b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalFunctions.java
index e80fcb4f3..cfee3656c 100644
--- 
a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalFunctions.java
+++ 
b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalFunctions.java
@@ -298,6 +298,37 @@ public class TestRoyaleGlobalFunctions extends 
TestGlobalFunctions
         assertOut("var /** @type {CustomVector} */ a = new 
CustomVector(['Hello', 'World'], 'String')");
     }
     
+    @Test
+    public void testCustomVectorNoElementTypes()
+    {
+        project.config.setJsVectorEmulationClass(null, "CustomVector");
+        project.config.setJsVectorEmulationElementTypes(null, false);
+        IVariableNode node = getVariable("var a:Vector.<String> = 
Vector.<String>(['Hello', 'World']);");
+        asBlockWalker.visitVariable(node);
+        assertOut("var /** @type {CustomVector} */ a = new 
CustomVector(['Hello', 'World'])");
+    }
+    
+    @Test
+    public void testCustomVectorLiteralFunction()
+    {
+        project.config.setJsVectorEmulationClass(null, "CustomVector");
+        project.config.setJsVectorEmulationLiteralFunction(null, 
"createVectorLiteral");
+        IVariableNode node = getVariable("var a:Vector.<String> = 
Vector.<String>(['Hello', 'World']);");
+        asBlockWalker.visitVariable(node);
+        assertOut("var /** @type {CustomVector} */ a = 
createVectorLiteral(['Hello', 'World'], 'String')");
+    }
+    
+    @Test
+    public void testCustomVectorLiteralFunctionNoElementTypes()
+    {
+        project.config.setJsVectorEmulationClass(null, "CustomVector");
+        project.config.setJsVectorEmulationLiteralFunction(null, 
"createVectorLiteral");
+        project.config.setJsVectorEmulationElementTypes(null, false);
+        IVariableNode node = getVariable("var a:Vector.<String> = 
Vector.<String>(['Hello', 'World']);");
+        asBlockWalker.visitVariable(node);
+        assertOut("var /** @type {CustomVector} */ a = 
createVectorLiteral(['Hello', 'World'])");
+    }
+    
     @Test
     public void testCustomVectorAsArray()
     {
@@ -342,6 +373,17 @@ public class TestRoyaleGlobalFunctions extends 
TestGlobalFunctions
         assertOut("var /** @type {CustomVector} */ a = new CustomVector(30, 
'String')");
     }
     
+    @Test
+    public void testCustomVectorSizeArgNoElementTypes()
+    {
+        project.config.setJsVectorEmulationClass(null, "CustomVector");
+        project.config.setJsVectorEmulationElementTypes(null, false);
+        IVariableNode node = getVariable("var a:Vector.<String> = 
Vector.<String>(30);");
+        asBlockWalker.visitVariable(node);
+        // MXMLC doesn't report an error either.  Maybe we should.
+        assertOut("var /** @type {CustomVector} */ a = new CustomVector(30)");
+    }
+    
     @Test
     public void testCustomVectorAsArraySizeArg()
     {

Reply via email to