FLEX-35231 fix self/this in Language.closure
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/d66093a7 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/d66093a7 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/d66093a7 Branch: refs/heads/master Commit: d66093a732ad90b02b6199504db6829c4e28a16c Parents: d67fe9c Author: Alex Harui <[email protected]> Authored: Thu Dec 29 22:12:15 2016 -0800 Committer: Alex Harui <[email protected]> Committed: Thu Dec 29 22:12:15 2016 -0800 ---------------------------------------------------------------------- .../internal/codegen/js/jx/IdentifierEmitter.java | 12 +++++++++++- .../codegen/js/flexjs/TestFlexJSExpressions.java | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/d66093a7/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java index 5a464ad..75d8173 100644 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java @@ -207,6 +207,7 @@ public class IdentifierEmitter extends JSSubEmitter implements getEmitter().emitClosureStart(); } + boolean wroteSelf = false; if (EmitterUtils.writeThis(getProject(), getModel(), node)) { IFunctionObjectNode functionObjectNode = (IFunctionObjectNode) node @@ -222,9 +223,15 @@ public class IdentifierEmitter extends JSSubEmitter implements startMapping(node); if (functionObjectNode != null) + { write(JSGoogEmitterTokens.SELF); + wroteSelf = true; + } else if (functionNode != null && functionDef.getFunctionClassification() == FunctionClassification.LOCAL) + { write(JSGoogEmitterTokens.SELF); + wroteSelf = true; + } else write(ASEmitterTokens.THIS); @@ -247,7 +254,10 @@ public class IdentifierEmitter extends JSSubEmitter implements write(node.getName()); writeToken(ASEmitterTokens.COMMA); - write(ASEmitterTokens.THIS); + if (wroteSelf) + write(JSGoogEmitterTokens.SELF); + else + write(ASEmitterTokens.THIS); getEmitter().emitClosureEnd(node, nodeDef); emitName = false; } http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/d66093a7/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java index b50636f..29c6ff6 100644 --- a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java +++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java @@ -884,6 +884,16 @@ public class TestFlexJSExpressions extends TestGoogExpressions } @Test + public void testMethodAsParamInLocalFunction() + { + IFunctionNode node = (IFunctionNode) getNode( + "public class B {public function b() { function c(f:Function):void {c(d); }; } public function d() {}}", + IFunctionNode.class, WRAP_LEVEL_PACKAGE); + asBlockWalker.visitFunction(node); + assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n var self = this;\n function c(f) {\n c(org.apache.flex.utils.Language.closure(self.d, self, 'd'));\n };\n \n}"); + } + + @Test public void testNativeGetter() { IFunctionNode node = (IFunctionNode) getNode(
