flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject git commit: [flex-falcon] [refs/heads/develop] - FLEX-34897 maintain scope when assigning methods to vars
Date Mon, 29 Jun 2015 19:34:13 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop 7d2b63de7 -> e1256ced4


FLEX-34897 maintain scope when assigning methods to vars


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

Branch: refs/heads/develop
Commit: e1256ced41f66dc9e7bae1e4b887072a661cd137
Parents: 7d2b63d
Author: Alex Harui <aharui@apache.org>
Authored: Mon Jun 29 12:21:14 2015 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Mon Jun 29 12:25:46 2015 -0700

----------------------------------------------------------------------
 .../codegen/js/jx/IdentifierEmitter.java        | 45 ++++++++++++++++++++
 1 file changed, 45 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e1256ced/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java
index 9c5dcd9..c286c3e 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java
@@ -31,8 +31,12 @@ import org.apache.flex.compiler.internal.definitions.AccessorDefinition;
 import org.apache.flex.compiler.internal.definitions.FunctionDefinition;
 import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IExpressionNode;
+import org.apache.flex.compiler.tree.as.IFunctionCallNode;
 import org.apache.flex.compiler.tree.as.IFunctionObjectNode;
 import org.apache.flex.compiler.tree.as.IIdentifierNode;
+import org.apache.flex.compiler.tree.as.IMemberAccessExpressionNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
 import org.apache.flex.compiler.utils.NativeUtils;
 
 public class IdentifierEmitter extends JSSubEmitter implements
@@ -70,11 +74,15 @@ public class IdentifierEmitter extends JSSubEmitter implements
         else if (!NativeUtils.isNative(node.getName()))
         {
             // an instance method as a parameter or
+        	// an instance method assigned to a variable or
             // a local function
             boolean useGoogBind = (parentNodeId == ASTNodeID.ContainerID
                     && identifierIsPlainFunction && ((FunctionDefinition)
nodeDef)
                     .getFunctionClassification() == FunctionClassification.CLASS_MEMBER)
                     || (identifierIsPlainFunction && ((FunctionDefinition) nodeDef)
+                    .getFunctionClassification() == FunctionClassification.CLASS_MEMBER &&
+                       isBeingAssignedToVariable(node))
+                    || (identifierIsPlainFunction && ((FunctionDefinition) nodeDef)
                             .getFunctionClassification() == FunctionClassification.LOCAL);
 
             if (useGoogBind)
@@ -120,5 +128,42 @@ public class IdentifierEmitter extends JSSubEmitter implements
                 write(node.getName());
         }
     }
+    
+    private boolean isBeingAssignedToVariable(IIdentifierNode node)
+    {
+    	IVariableNode varNode = (IVariableNode) node
+        .getParent().getAncestorOfType(
+        		IVariableNode.class);
+    	if (varNode == null) return false;
+    	
+    	IExpressionNode avnode = varNode.getAssignedValueNode();
+    	IASNode parent = node.getParent();
+    	IMemberAccessExpressionNode parentMAE = null;
+        IFunctionCallNode fnNode = null;
+    	while (parent != varNode)
+    	{
+    		if (parent instanceof IMemberAccessExpressionNode)
+            {
+                parentMAE = (IMemberAccessExpressionNode) parent;
+            }
+    		else if (parent instanceof IFunctionCallNode)
+            {
+                fnNode = (IFunctionCallNode) parent;
+            }
+    		if (parent == avnode)
+    		{
+    			if (parentMAE != null)
+    			{
+                    // do one final check that this is the right node in
+                    // a member access expression
+    				return (node == parentMAE.getRightOperandNode());
+    			}
+    			return fnNode == null;
+    		}
+    		else     		
+    			parent = parent.getParent();
+    	}
+    	return false;
+    }
 
 }


Mime
View raw message