flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [46/50] git commit: [flex-falcon] [refs/heads/master] - get compiler to redirect Array.sortOn
Date Wed, 06 Apr 2016 15:02:55 GMT
get compiler to redirect Array.sortOn


Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/e736a120
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/e736a120
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/e736a120

Branch: refs/heads/master
Commit: e736a1209ae642903da24182975f27ca272bf34b
Parents: 69eb3d5
Author: Alex Harui <aharui@apache.org>
Authored: Mon Mar 21 12:14:40 2016 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Mon Mar 21 21:01:45 2016 -0700

----------------------------------------------------------------------
 .../js/flexjs/TestFlexJSGlobalClasses.java      | 18 +++++++++++++++
 .../codegen/js/jx/FunctionCallEmitter.java      | 23 ++++++++++++++++++++
 externs/js/missing.js                           |  6 +++++
 3 files changed, 47 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e736a120/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
index 96a9a0a..df663af 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
@@ -141,6 +141,24 @@ public class TestFlexJSGlobalClasses extends TestGoogGlobalClasses
     }
 
     @Test
+    public void testArraySortOn()
+    {
+        IBinaryOperatorNode node = getBinaryNode("var a:Array = new Array(); a.sortOn('foo')");
+        IFunctionCallNode parentNode = (IFunctionCallNode)(node.getParent());
+        asBlockWalker.visitFunctionCall(parentNode);
+        assertOut("org.apache.flex.utils.Language.sortOn(a, 'foo')");
+    }
+
+    @Test
+    public void testArraySortOnTwoArgs()
+    {
+        IBinaryOperatorNode node = getBinaryNode("var a:Array = new Array(); a.sortOn('foo',
10)");
+        IFunctionCallNode parentNode = (IFunctionCallNode)(node.getParent());
+        asBlockWalker.visitFunctionCall(parentNode);
+        assertOut("org.apache.flex.utils.Language.sortOn(a, 'foo', 10)");
+    }
+
+    @Test
     public void testIntConstMaxValue()
     {
         IVariableNode node = getVariable("var a:Number = int.MAX_VALUE");

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e736a120/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
index c38d820..475541e 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
@@ -33,6 +33,9 @@ import org.apache.flex.compiler.internal.definitions.ClassDefinition;
 import org.apache.flex.compiler.internal.definitions.InterfaceDefinition;
 import org.apache.flex.compiler.internal.projects.FlexJSProject;
 import org.apache.flex.compiler.internal.tree.as.ContainerNode;
+import org.apache.flex.compiler.internal.tree.as.IdentifierNode;
+import org.apache.flex.compiler.internal.tree.as.MemberAccessExpressionNode;
+import org.apache.flex.compiler.internal.tree.as.NumericLiteralNode;
 import org.apache.flex.compiler.internal.tree.as.VectorLiteralNode;
 import org.apache.flex.compiler.projects.ICompilerProject;
 import org.apache.flex.compiler.tree.ASTNodeID;
@@ -139,6 +142,26 @@ public class FunctionCallEmitter extends JSSubEmitter implements ISubEmitter<IFu
                         if (isInt)
                             write(JSFlexJSEmitterTokens.UNDERSCORE);
                     }
+                    else if (def != null && def.getBaseName().equals("sortOn"))
+                	{
+                		if (def.getParent() != null &&
+                    		def.getParent().getQualifiedName().equals("Array"))
+                		{
+                            ICompilerProject project = this.getProject();
+                            if (project instanceof FlexJSProject)
+                                ((FlexJSProject) project).needLanguage = true;
+                            write(JSFlexJSEmitterTokens.LANGUAGE_QNAME);
+                            write(ASEmitterTokens.MEMBER_ACCESS);
+                            write("sortOn");
+                            write(ASEmitterTokens.PAREN_OPEN);
+                            write(((IdentifierNode)cnode).getName());  // will this always
be an indentifer node
+                            writeToken(ASEmitterTokens.COMMA);
+                            fjs.walkArguments(node.getArgumentNodes());
+                            write(ASEmitterTokens.PAREN_CLOSE);
+                            return;
+            			}
+            		}
+
                     else if (def instanceof AppliedVectorDefinition)
                     {
                         fjs.walkArguments(node.getArgumentNodes());

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e736a120/externs/js/missing.js
----------------------------------------------------------------------
diff --git a/externs/js/missing.js b/externs/js/missing.js
index aedd69f..d3e6d3c 100644
--- a/externs/js/missing.js
+++ b/externs/js/missing.js
@@ -217,6 +217,12 @@ Array.prototype.insertAt = function(index, element) {};
  */
 Array.prototype.removeAt = function(index) {};
 
+/**
+ * @param {Object} fieldName The field name or array of field names.
+ * @param {Object=} opt_options The bitmask of options.
+ * @return {Array} The sorted Array.
+ */
+Array.prototype.sortOn = function(fieldName, opt_options) {};
 
 
 /**


Mime
View raw message