flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [1/3] git commit: [flex-falcon] [refs/heads/develop] - replace goog.bind with Language.closure that generates the same closure every time
Date Fri, 21 Aug 2015 14:18:53 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop 29b522018 -> 1f9b06b4d


replace goog.bind with Language.closure that generates the same closure every time


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

Branch: refs/heads/develop
Commit: 3759e96d3a0af323bb31aaedac9a926983cbcfad
Parents: 29b5220
Author: Alex Harui <aharui@apache.org>
Authored: Thu Aug 20 16:31:38 2015 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Thu Aug 20 16:31:38 2015 -0700

----------------------------------------------------------------------
 .../codegen/js/flexjs/TestFlexJSClass.java      |  4 +-
 .../js/flexjs/TestFlexJSExpressions.java        | 72 ++++++++++++++++++--
 .../flexjs/files/LocalFunction_result.js        |  2 +-
 .../flexjs/files/MyInitialView_result.js        |  4 +-
 .../files/controllers/MyController_result.js    | 16 ++---
 .../flex/compiler/codegen/js/IJSEmitter.java    |  4 ++
 .../compiler/internal/codegen/js/JSEmitter.java |  9 +++
 .../codegen/js/flexjs/JSFlexJSEmitter.java      | 22 ++++++
 .../js/flexjs/JSFlexJSEmitterTokens.java        |  1 +
 .../internal/codegen/js/goog/JSGoogEmitter.java | 21 ++++--
 .../codegen/js/jx/BinaryOperatorEmitter.java    | 10 ++-
 .../codegen/js/jx/IdentifierEmitter.java        | 30 +++++---
 .../codegen/mxml/flexjs/MXMLFlexJSEmitter.java  |  4 +-
 13 files changed, 164 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3759e96d/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
index 24bff91..509e415 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
@@ -243,7 +243,7 @@ public class TestFlexJSClass extends TestGoogClass
                 + "public function foo2():Object{function bar2(param1:Object):Object {return
null;}; return bar2('foo');}"
                 + "}");
         asBlockWalker.visitClass(node);
-        assertOut("/**\n * @constructor\n */\norg.apache.flex.B = function() {\n};\n\n\n/**\n
* @export\n * @return {Object}\n */\norg.apache.flex.B.prototype.foo1 = function() {\n  function
bar1() {\n    return null;\n  };\n  return goog.bind(bar1, this)();\n};\n\n\n/**\n * @export\n
* @return {Object}\n */\norg.apache.flex.B.prototype.foo2 = function() {\n  function bar2(param1)
{\n    return null;\n  };\n  return goog.bind(bar2, this)('foo');\n};");
+        assertOut("/**\n * @constructor\n */\norg.apache.flex.B = function() {\n};\n\n\n/**\n
* @export\n * @return {Object}\n */\norg.apache.flex.B.prototype.foo1 = function() {\n  function
bar1() {\n    return null;\n  };\n  return org.apache.flex.utils.Language.closure(bar1, this,
'bar1')();\n};\n\n\n/**\n * @export\n * @return {Object}\n */\norg.apache.flex.B.prototype.foo2
= function() {\n  function bar2(param1) {\n    return null;\n  };\n  return org.apache.flex.utils.Language.closure(bar2,
this, 'bar2')('foo');\n};");
     }
 
     @Test
@@ -255,7 +255,7 @@ public class TestFlexJSClass extends TestGoogClass
                 + "public function foo2():String{function bar2(param1:String):String {return
param1 + baz1;}; return bar2('foo');}"
                 + "}");
         asBlockWalker.visitClass(node);
-        assertOut("/**\n * @constructor\n */\norg.apache.flex.B = function() {\n};\n\n\n/**\n
* @export\n * @type {string}\n */\norg.apache.flex.B.prototype.baz1;\n\n\n/**\n * @export\n
* @return {string}\n */\norg.apache.flex.B.prototype.foo1 = function() {\n  function bar1()
{\n    return this.baz1;\n  };\n  return goog.bind(bar1, this)();\n};\n\n\n/**\n * @export\n
* @return {string}\n */\norg.apache.flex.B.prototype.foo2 = function() {\n  function bar2(param1)
{\n    return param1 + this.baz1;\n  };\n  return goog.bind(bar2, this)('foo');\n};");
+        assertOut("/**\n * @constructor\n */\norg.apache.flex.B = function() {\n};\n\n\n/**\n
* @export\n * @type {string}\n */\norg.apache.flex.B.prototype.baz1;\n\n\n/**\n * @export\n
* @return {string}\n */\norg.apache.flex.B.prototype.foo1 = function() {\n  function bar1()
{\n    return this.baz1;\n  };\n  return org.apache.flex.utils.Language.closure(bar1, this,
'bar1')();\n};\n\n\n/**\n * @export\n * @return {string}\n */\norg.apache.flex.B.prototype.foo2
= function() {\n  function bar2(param1) {\n    return param1 + this.baz1;\n  };\n  return
org.apache.flex.utils.Language.closure(bar2, this, 'bar2')('foo');\n};");
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3759e96d/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
index a1246a6..eea2525 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
@@ -552,7 +552,7 @@ public class TestFlexJSExpressions extends TestGoogExpressions
                 "public class B {public function b() { function c(f:Function):void {}; function
d():void {}; c(d); }}",
                 IFunctionNode.class, WRAP_LEVEL_PACKAGE);
         asBlockWalker.visitFunction(node);
-        assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n  function c(f) {\n
 };\n  function d() {\n  };\n  goog.bind(c, this)(goog.bind(d, this));\n}");
+        assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n  function c(f) {\n
 };\n  function d() {\n  };\n  org.apache.flex.utils.Language.closure(c, this, 'c')(org.apache.flex.utils.Language.closure(d,
this, 'd'));\n}");
     }
 
     @Test
@@ -562,7 +562,7 @@ public class TestFlexJSExpressions extends TestGoogExpressions
                 "public class B {public function b() { function c(s:String, f:Function):void
{}; function d():void {}; c('foo', d); }}",
                 IFunctionNode.class, WRAP_LEVEL_PACKAGE);
         asBlockWalker.visitFunction(node);
-        assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n  function c(s, f)
{\n  };\n  function d() {\n  };\n  goog.bind(c, this)('foo', goog.bind(d, this));\n}");
+        assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n  function c(s, f)
{\n  };\n  function d() {\n  };\n  org.apache.flex.utils.Language.closure(c, this, 'c')('foo',
org.apache.flex.utils.Language.closure(d, this, 'd'));\n}");
     }
 
     @Test
@@ -572,7 +572,7 @@ public class TestFlexJSExpressions extends TestGoogExpressions
                 "public class B {public function b() {  c('foo', d); function c(s:String,
f:Function):void {}; function d():void {};}}",
                 IFunctionNode.class, WRAP_LEVEL_PACKAGE);
         asBlockWalker.visitFunction(node);
-        assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n  goog.bind(c, this)('foo',
goog.bind(d, this));\n  function c(s, f) {\n  };\n  function d() {\n  };\n}");
+        assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n  org.apache.flex.utils.Language.closure(c,
this, 'c')('foo', org.apache.flex.utils.Language.closure(d, this, 'd'));\n  function c(s,
f) {\n  };\n  function d() {\n  };\n}");
     }
 
     @Test
@@ -582,7 +582,7 @@ public class TestFlexJSExpressions extends TestGoogExpressions
                 "public class B {public function b() { function d():void {}; c('foo', d);
} public function c(s:String, f:Function):void {};}",
                 IFunctionNode.class, WRAP_LEVEL_PACKAGE);
         asBlockWalker.visitFunction(node);
-        assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n  function d() {\n
 };\n  this.c('foo', goog.bind(d, this));\n}");
+        assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n  function d() {\n
 };\n  this.c('foo', org.apache.flex.utils.Language.closure(d, this, 'd'));\n}");
     }
 
     @Test
@@ -592,7 +592,7 @@ public class TestFlexJSExpressions extends TestGoogExpressions
                 "public class B {public function b() { function c(f:Function):void {}; c(b);
}}",
                 IFunctionNode.class, WRAP_LEVEL_PACKAGE);
         asBlockWalker.visitFunction(node);
-        assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n  function c(f) {\n
 };\n  goog.bind(c, this)(goog.bind(this.b, this));\n}");
+        assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n  function c(f) {\n
 };\n  org.apache.flex.utils.Language.closure(c, this, 'c')(org.apache.flex.utils.Language.closure(this.b,
this, 'b'));\n}");
     }
 
     @Test
@@ -602,10 +602,70 @@ public class TestFlexJSExpressions extends TestGoogExpressions
                 "public class B {static public function b() { function c(f:Function):void
{}; c(b); }}",
                 IFunctionNode.class, WRAP_LEVEL_PACKAGE, true);
         asBlockWalker.visitFunction(node);
-        assertOut("/**\n * @export\n */\nfoo.bar.B.b = function() {\n  function c(f) {\n
 };\n  goog.bind(c, this)(foo.bar.B.b);\n}");
+        assertOut("/**\n * @export\n */\nfoo.bar.B.b = function() {\n  function c(f) {\n
 };\n  org.apache.flex.utils.Language.closure(c, this, 'c')(foo.bar.B.b);\n}");
     }
 
     @Test
+    public void testMethodAsVariable()
+    {
+        IFunctionNode node = (IFunctionNode) getNode(
+                "public class B {public function b() { function c(f:Function):void {}; var
f:Function = b; c(f); }}",
+                IFunctionNode.class, WRAP_LEVEL_PACKAGE);
+        asBlockWalker.visitFunction(node);
+        assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n  function c(f) {\n
 };\n  var /** @type {Function} */ f = org.apache.flex.utils.Language.closure(this.b, this,
'b');\n  org.apache.flex.utils.Language.closure(c, this, 'c')(f);\n}");
+    }
+    
+    @Test
+    public void testStaticMethodAsVariable()
+    {
+        IFunctionNode node = (IFunctionNode) getNode(
+                "public class B {static public function b() { function c(f:Function):void
{}; var f:Function = b; c(f); }}",
+                IFunctionNode.class, WRAP_LEVEL_PACKAGE, true);
+        asBlockWalker.visitFunction(node);
+        assertOut("/**\n * @export\n */\nfoo.bar.B.b = function() {\n  function c(f) {\n
 };\n  var /** @type {Function} */ f = foo.bar.B.b;\n  org.apache.flex.utils.Language.closure(c,
this, 'c')(f);\n}");
+    }
+    
+    @Test
+    public void testMethodAsAssign()
+    {
+        IFunctionNode node = (IFunctionNode) getNode(
+                "public class B {public function b() { function c(f:Function):void {}; var
f:Function; f = b; c(f); }}",
+                IFunctionNode.class, WRAP_LEVEL_PACKAGE);
+        asBlockWalker.visitFunction(node);
+        assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n  function c(f) {\n
 };\n  var /** @type {Function} */ f;\n  f = org.apache.flex.utils.Language.closure(this.b,
this, 'b');\n  org.apache.flex.utils.Language.closure(c, this, 'c')(f);\n}");
+    }
+    
+    @Test
+    public void testStaticMethodAsAssign()
+    {
+        IFunctionNode node = (IFunctionNode) getNode(
+                "public class B {static public function b() { function c(f:Function):void
{}; var f:Function; f = b; c(f); }}",
+                IFunctionNode.class, WRAP_LEVEL_PACKAGE, true);
+        asBlockWalker.visitFunction(node);
+        assertOut("/**\n * @export\n */\nfoo.bar.B.b = function() {\n  function c(f) {\n
 };\n  var /** @type {Function} */ f;\n  f = foo.bar.B.b;\n  org.apache.flex.utils.Language.closure(c,
this, 'c')(f);\n}");
+    }
+    
+    @Test
+    public void testMethodAsValue()
+    {
+        IFunctionNode node = (IFunctionNode) getNode(
+                "public class B {public function b() { function c(f:Function):void {}; var
f:Array = [b]; c(f[0]); }}",
+                IFunctionNode.class, WRAP_LEVEL_PACKAGE);
+        asBlockWalker.visitFunction(node);
+        assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n  function c(f) {\n
 };\n  var /** @type {Array} */ f = [org.apache.flex.utils.Language.closure(this.b, this,
'b')];\n  org.apache.flex.utils.Language.closure(c, this, 'c')(f[0]);\n}");
+    }
+    
+    @Test
+    public void testStaticMethodAsValue()
+    {
+        IFunctionNode node = (IFunctionNode) getNode(
+                "public class B {static public function b() { function c(f:Function):void
{}; var f:Array = [b]; c(f); }}",
+                IFunctionNode.class, WRAP_LEVEL_PACKAGE, true);
+        asBlockWalker.visitFunction(node);
+        assertOut("/**\n * @export\n */\nfoo.bar.B.b = function() {\n  function c(f) {\n
 };\n  var /** @type {Array} */ f = [foo.bar.B.b];\n  org.apache.flex.utils.Language.closure(c,
this, 'c')(f);\n}");
+    }
+    
+    @Test
     public void testNativeGetter()
     {
         IFunctionNode node = (IFunctionNode) getNode(

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3759e96d/compiler.jx.tests/test-files/flexjs/files/LocalFunction_result.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/flexjs/files/LocalFunction_result.js b/compiler.jx.tests/test-files/flexjs/files/LocalFunction_result.js
index edc507f..3a502cd 100644
--- a/compiler.jx.tests/test-files/flexjs/files/LocalFunction_result.js
+++ b/compiler.jx.tests/test-files/flexjs/files/LocalFunction_result.js
@@ -45,7 +45,7 @@ LocalFunction.prototype.myMemberMethod = function(value) {
   function myLocalFunction(value) {
     return this.myMemberProperty + value;
   };
-  org.apache.flex.utils.Language.trace("WOW! :: " + goog.bind(myLocalFunction, this)(value
+ 42));
+  org.apache.flex.utils.Language.trace("WOW! :: " + org.apache.flex.utils.Language.closure(myLocalFunction,
this, 'myLocalFunction')(value + 42));
 };
 
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3759e96d/compiler.jx.tests/test-files/flexjs/files/MyInitialView_result.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/flexjs/files/MyInitialView_result.js b/compiler.jx.tests/test-files/flexjs/files/MyInitialView_result.js
index e1ef0fb..006de46 100644
--- a/compiler.jx.tests/test-files/flexjs/files/MyInitialView_result.js
+++ b/compiler.jx.tests/test-files/flexjs/files/MyInitialView_result.js
@@ -233,7 +233,7 @@ MyInitialView.prototype.timer;
  */
 MyInitialView.prototype.startTimer = function(event) {
   this.timer = new org.apache.flex.utils.Timer(1000);
-  this.timer.addEventListener('timer', goog.bind(this.timerHandler, this));
+  this.timer.addEventListener('timer', org.apache.flex.utils.Language.closure(this.timerHandler,
this, 'timerHandler'));
   this.timer.start();
 };
 
@@ -287,7 +287,7 @@ MyInitialView.prototype.$EH0 = function(event)
  */
 MyInitialView.prototype.$EH1 = function(event)
 {
-  this.timer.removeEventListener('timer', goog.bind(this.timerHandler, this));
+  this.timer.removeEventListener('timer', org.apache.flex.utils.Language.closure(this.timerHandler,
this, 'timerHandler'));
   this.timer.stop();
 };
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3759e96d/compiler.jx.tests/test-files/flexjs/files/controllers/MyController_result.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/flexjs/files/controllers/MyController_result.js
b/compiler.jx.tests/test-files/flexjs/files/controllers/MyController_result.js
index b792358..dfc3cfb 100644
--- a/compiler.jx.tests/test-files/flexjs/files/controllers/MyController_result.js
+++ b/compiler.jx.tests/test-files/flexjs/files/controllers/MyController_result.js
@@ -32,7 +32,7 @@ controllers.MyController = function(app) {
   app = typeof app !== 'undefined' ? app : null;
   if (app) {
     this.app = org.apache.flex.utils.Language.as(app, FlexJSTest_again);
-    app.addEventListener("viewChanged", goog.bind(this.viewChangeHandler, this));
+    app.addEventListener("viewChanged", org.apache.flex.utils.Language.closure(this.viewChangeHandler,
this, 'viewChangeHandler'));
   }
 };
 
@@ -63,11 +63,11 @@ controllers.MyController.prototype.app;
  * @param {org.apache.flex.events.Event} event
  */
 controllers.MyController.prototype.viewChangeHandler = function(event) {
-  this.app.initialView.addEventListener("buttonClicked", goog.bind(this.buttonClickHandler,
this));
-  this.app.initialView.addEventListener("listChanged", goog.bind(this.listChangedHandler,
this));
-  this.app.initialView.addEventListener("cityListChanged", goog.bind(this.cityListChangeHandler,
this));
-  this.app.initialView.addEventListener("transferClicked", goog.bind(this.transferClickHandler,
this));
-  this.app.initialView.addEventListener("comboBoxChanged", goog.bind(this.comboBoxChangeHandler,
this));
+  this.app.initialView.addEventListener("buttonClicked", org.apache.flex.utils.Language.closure(this.buttonClickHandler,
this, 'buttonClickHandler'));
+  this.app.initialView.addEventListener("listChanged", org.apache.flex.utils.Language.closure(this.listChangedHandler,
this, 'listChangedHandler'));
+  this.app.initialView.addEventListener("cityListChanged", org.apache.flex.utils.Language.closure(this.cityListChangeHandler,
this, 'cityListChangeHandler'));
+  this.app.initialView.addEventListener("transferClicked", org.apache.flex.utils.Language.closure(this.transferClickHandler,
this, 'transferClickHandler'));
+  this.app.initialView.addEventListener("comboBoxChanged", org.apache.flex.utils.Language.closure(this.comboBoxChangeHandler,
this, 'comboBoxChangeHandler'));
 };
 
 
@@ -79,7 +79,7 @@ controllers.MyController.prototype.buttonClickHandler = function(event)
{
   var /** @type {string} */ sym = org.apache.flex.utils.Language.as(this.app.initialView,
MyInitialView, true).symbol;
   this.app.service.url = this.queryBegin + sym + this.queryEnd;
   this.app.service.send();
-  this.app.service.addEventListener("complete", goog.bind(this.completeHandler, this));
+  this.app.service.addEventListener("complete", org.apache.flex.utils.Language.closure(this.completeHandler,
this, 'completeHandler'));
 };
 
 
@@ -136,7 +136,7 @@ controllers.MyController.prototype.comboBoxChangeHandler = function(event)
{
 controllers.MyController.prototype.setDocument = function(document, id) {
   id = typeof id !== 'undefined' ? id : null;
   this.app = org.apache.flex.utils.Language.as(document, FlexJSTest_again);
-  this.app.addEventListener("viewChanged", goog.bind(this.viewChangeHandler, this));
+  this.app.addEventListener("viewChanged", org.apache.flex.utils.Language.closure(this.viewChangeHandler,
this, 'viewChangeHandler'));
 };
 
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3759e96d/compiler.jx/src/org/apache/flex/compiler/codegen/js/IJSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/codegen/js/IJSEmitter.java b/compiler.jx/src/org/apache/flex/compiler/codegen/js/IJSEmitter.java
index 5a83ec6..4972b39 100644
--- a/compiler.jx/src/org/apache/flex/compiler/codegen/js/IJSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/codegen/js/IJSEmitter.java
@@ -23,6 +23,7 @@ import java.io.Writer;
 
 import org.apache.flex.compiler.codegen.as.IASEmitter;
 import org.apache.flex.compiler.internal.codegen.js.JSSessionModel;
+import org.apache.flex.compiler.tree.as.IASNode;
 import org.apache.flex.compiler.visitor.IASNodeStrategy;
 
 /**
@@ -36,4 +37,7 @@ public interface IJSEmitter extends IASEmitter
     JSSessionModel getModel();
     
     String formatQualifiedName(String name);
+    
+    void emitClosureStart();
+    void emitClosureEnd(IASNode node);
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3759e96d/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java
index 1c55dcd..c5d3e2b 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java
@@ -25,6 +25,7 @@ import org.apache.flex.compiler.codegen.js.IJSEmitter;
 import org.apache.flex.compiler.internal.codegen.as.ASEmitter;
 import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
 import org.apache.flex.compiler.internal.tree.as.FunctionNode;
+import org.apache.flex.compiler.tree.as.IASNode;
 import org.apache.flex.compiler.tree.as.IFunctionNode;
 import org.apache.flex.compiler.tree.as.IFunctionObjectNode;
 
@@ -74,6 +75,14 @@ public class JSEmitter extends ASEmitter implements IJSEmitter
         emitFunctionScope(fnode.getScopedNode());
     }
 
+    public void emitClosureStart()
+    {
+    	
+    }
 
+    public void emitClosureEnd(IASNode node)
+    {
+    	
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3759e96d/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
index eb301e5..0d451d9 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
@@ -158,6 +158,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
         selfReferenceEmitter = new SelfReferenceEmitter(this);
         objectDefinePropertyEmitter = new ObjectDefinePropertyEmitter(this);
         definePropertyFunctionEmitter = new DefinePropertyFunctionEmitter(this);
+        
     }
 
     @Override
@@ -403,4 +404,25 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
         setBufferWrite(false);
         return result;
     }
+
+    @Override
+	public void emitClosureStart()
+    {
+        write(JSFlexJSEmitterTokens.CLOSURE_FUNCTION_NAME);
+        write(ASEmitterTokens.PAREN_OPEN);
+    }
+
+    @Override
+	public void emitClosureEnd(IASNode node)
+    {
+    	write(ASEmitterTokens.COMMA);
+    	write(ASEmitterTokens.SPACE);
+    	write(ASEmitterTokens.SINGLE_QUOTE);
+    	if (node.getNodeID() == ASTNodeID.IdentifierID)
+    		write(((IIdentifierNode)node).getName());
+    	else
+    		System.out.println("unexpected node in emitClosureEnd");
+    	write(ASEmitterTokens.SINGLE_QUOTE);
+        write(ASEmitterTokens.PAREN_CLOSE);
+    }
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3759e96d/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitterTokens.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitterTokens.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitterTokens.java
index 0d8b002..e9db7db 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitterTokens.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitterTokens.java
@@ -42,6 +42,7 @@ public enum JSFlexJSEmitterTokens implements IEmitterTokens
     POSTDECREMENT("postdecrement"),
     SUPERGETTER("superGetter"),
     SUPERSETTER("superSetter"),
+    CLOSURE_FUNCTION_NAME("org.apache.flex.utils.Language.closure"),
     ;
 
     private String token;

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3759e96d/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogEmitter.java
index c45cb3f..b3b0f04 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/goog/JSGoogEmitter.java
@@ -39,6 +39,7 @@ import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.JSEmitter;
 import org.apache.flex.compiler.internal.codegen.js.JSEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.JSSessionModel;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
 import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
 import org.apache.flex.compiler.internal.definitions.AccessorDefinition;
 import org.apache.flex.compiler.internal.definitions.FunctionDefinition;
@@ -88,7 +89,7 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
     public ICompilerProject project;
 
     private JSGoogDocEmitter docEmitter;
-
+    
     // TODO (mschmalle) Fix; this is not using the backend doc strategy for replacement
     @Override
     public IJSGoogDocEmitter getDocEmitter()
@@ -868,16 +869,17 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
             }
             else
             {
+        		// AJH need Language.bind here and maybe not require
+            	// that the node is a MemberAccessExpression
             	if (definition instanceof FunctionDefinition &&
             			(!(definition instanceof AccessorDefinition)) &&
             			node instanceof MemberAccessExpressionNode)
             	{
-                    write(JSGoogEmitterTokens.GOOG_BIND);
-                    write(ASEmitterTokens.PAREN_OPEN);
+                    emitClosureStart();
             		getWalker().walk(node);
                     writeToken(ASEmitterTokens.COMMA);
             		getWalker().walk(((MemberAccessExpressionNode)node).getLeftOperandNode());
-                    write(ASEmitterTokens.PAREN_CLOSE);
+                    emitClosureEnd(((MemberAccessExpressionNode)node).getLeftOperandNode());
             	}
             	else
             		getWalker().walk(node);
@@ -1086,4 +1088,15 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
         if (ASNodeUtils.hasParenOpen(node))
             write(ASEmitterTokens.PAREN_CLOSE);
     }
+    
+    protected void emitClosureStart(FunctionNode node)
+    {
+        write(JSGoogEmitterTokens.GOOG_BIND);
+        write(ASEmitterTokens.PAREN_OPEN);
+    }
+    
+    protected void emitClosureEnd(FunctionNode node)
+    {
+        write(ASEmitterTokens.PAREN_CLOSE);
+    }
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3759e96d/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
index 7509907..a12ac6d 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
@@ -27,6 +27,7 @@ import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
 import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
 import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitterTokens;
 import org.apache.flex.compiler.internal.definitions.AccessorDefinition;
+import org.apache.flex.compiler.internal.definitions.FunctionDefinition;
 import org.apache.flex.compiler.internal.projects.FlexJSProject;
 import org.apache.flex.compiler.projects.ICompilerProject;
 import org.apache.flex.compiler.tree.ASTNodeID;
@@ -270,7 +271,14 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements
 
             write(ASEmitterTokens.SPACE);
 
-            getWalker().walk(node.getRightOperandNode());
+            /*
+            IDefinition definition = node.getRightOperandNode().resolve(getProject());
+        	if (definition instanceof FunctionDefinition &&
+        			(!(definition instanceof AccessorDefinition)))
+        	{
+        	}
+        	else */
+        		getWalker().walk(node.getRightOperandNode());
         }
 
         if (ASNodeUtils.hasParenOpen(node))

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3759e96d/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..9266e7c 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
@@ -25,10 +25,12 @@ import org.apache.flex.compiler.definitions.IDefinition;
 import org.apache.flex.compiler.definitions.IFunctionDefinition.FunctionClassification;
 import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
 import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
 import org.apache.flex.compiler.internal.definitions.AccessorDefinition;
 import org.apache.flex.compiler.internal.definitions.FunctionDefinition;
+import org.apache.flex.compiler.internal.tree.as.FunctionNode;
 import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IASNode;
 import org.apache.flex.compiler.tree.as.IFunctionObjectNode;
@@ -55,7 +57,6 @@ public class IdentifierEmitter extends JSSubEmitter implements
         boolean identifierIsAccessorFunction = nodeDef instanceof AccessorDefinition;
         boolean identifierIsPlainFunction = nodeDef instanceof FunctionDefinition
                 && !identifierIsAccessorFunction;
-
         boolean emitName = true;
 
         if (nodeDef != null && nodeDef.isStatic())
@@ -69,18 +70,28 @@ public class IdentifierEmitter extends JSSubEmitter implements
         }
         else if (!NativeUtils.isNative(node.getName()))
         {
+            boolean identifierIsLocalOrInstanceFunctionAsValue = false;
+            if (identifierIsPlainFunction)
+            {
+            	FunctionClassification fc = ((FunctionDefinition)nodeDef).getFunctionClassification();
+            	identifierIsLocalOrInstanceFunctionAsValue = 
+            		fc == FunctionClassification.LOCAL || 
+            		(fc == FunctionClassification.CLASS_MEMBER && 
+            				// not a value if parent is a function call or member access expression
+            				(!(parentNodeId == ASTNodeID.MemberAccessExpressionID ||
+            				   parentNodeId == ASTNodeID.FunctionCallID)));
+            	
+            }
             // an instance method as a parameter or
             // a local function
-            boolean useGoogBind = (parentNodeId == ASTNodeID.ContainerID
+            boolean generateClosure = (parentNodeId == ASTNodeID.ContainerID
                     && identifierIsPlainFunction && ((FunctionDefinition)
nodeDef)
                     .getFunctionClassification() == FunctionClassification.CLASS_MEMBER)
-                    || (identifierIsPlainFunction && ((FunctionDefinition) nodeDef)
-                            .getFunctionClassification() == FunctionClassification.LOCAL);
+                    || identifierIsLocalOrInstanceFunctionAsValue;
 
-            if (useGoogBind)
+            if (generateClosure)
             {
-                write(JSGoogEmitterTokens.GOOG_BIND);
-                write(ASEmitterTokens.PAREN_OPEN);
+            	getEmitter().emitClosureStart();
             }
 
             if (EmitterUtils.writeThis(getProject(), getModel(), node))
@@ -97,14 +108,13 @@ public class IdentifierEmitter extends JSSubEmitter implements
                 write(ASEmitterTokens.MEMBER_ACCESS);
             }
 
-            if (useGoogBind)
+            if (generateClosure)
             {
                 write(node.getName());
 
                 writeToken(ASEmitterTokens.COMMA);
                 write(ASEmitterTokens.THIS);
-                write(ASEmitterTokens.PAREN_CLOSE);
-
+            	getEmitter().emitClosureEnd(node);
                 emitName = false;
             }
         }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3759e96d/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
index 69975a0..a7bf8b8 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
@@ -1290,9 +1290,11 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
         handler.isProperty = true;
         handler.name = "handlerFunction";
         handler.parent = setEvent;
-        handler.value = JSGoogEmitterTokens.GOOG_BIND.getToken() + ASEmitterTokens.PAREN_OPEN.getToken()
+ 
+        handler.value = JSFlexJSEmitterTokens.CLOSURE_FUNCTION_NAME.getToken() + ASEmitterTokens.PAREN_OPEN.getToken()
+ 
         		ASEmitterTokens.THIS.getToken() + ASEmitterTokens.MEMBER_ACCESS.getToken() + eventHandler
+
         		ASEmitterTokens.COMMA.getToken() + ASEmitterTokens.SPACE.getToken() + ASEmitterTokens.THIS.getToken()
+
+        		ASEmitterTokens.COMMA.getToken() + ASEmitterTokens.SPACE.getToken() + ASEmitterTokens.SINGLE_QUOTE.getToken()
+
+        			eventHandler + ASEmitterTokens.SINGLE_QUOTE.getToken() +
         		ASEmitterTokens.PAREN_CLOSE.getToken();
         setEvent.propertySpecifiers.add(handler);
         


Mime
View raw message