You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flex.apache.org by Alex Harui <ah...@adobe.com> on 2013/04/19 23:17:55 UTC

[FalconJX][FlexJS] Local Functions code gen

Erik,

It looks like you took the ³var self=this² out.  How are you supposed to
call local functions?  For example, this AS:

Class A
{
    public var foo:String;
    public function bar():String
    {
        return foobar();
        function foobar():String
        {
            return foo;
        }
    }
}

Should the output JS use goog.bind to call foobar?  Is there ever a time
when goog.bind is not used to call a local function?

A.prototype.bar = function()
{
    return goog.bind(foobar, this)();
    function foobar():String
    {
        return this.foo;
    }
}
-- 
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui


Re: [FalconJX][FlexJS] Local Functions code gen

Posted by Nimai <ni...@beecavegames.com>.
Shoot!  That "internal" was just a leftover from my last test.  Same thing
happens with "public", though.
In any case, I will at least add to JIRA.  We are becoming more familiar
with the compiler code each day, with the hope to be submitting patches and
test cases for sure.

Thank you.



--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/FalconJX-FlexJS-Local-Functions-code-gen-tp24890p52186.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: [FalconJX][FlexJS] Local Functions code gen

Posted by Alex Harui <ah...@adobe.com>.
I'm pretty sure we haven't deal with "internal" keyword yet.

Patches are welcome, or file a JIRA issue?

Thanks,
-Alex

On 4/4/16, 8:06 PM, "Nimai" <ni...@beecavegames.com> wrote:

>I hope it's OK etiquette to add onto this old thread, but it appears
>related
>to this issue.  Please see the source AS3 and resulting JS below.  The
>"self" var is emitted but not used.  If I manually add "self." in front of
>the reference to "bar", it does work!
>
>
>///// ACTIONSCRIPT /////
>
>package {
>public class foo {
>	internal var bar:String = "baz";
>	public function foo() {
>
>		function localFunction(i:int) {
>			if (i==0) {
>				trace( bar );
>			}
>		}
>
>		localFunction(0);
>	}
>}
>}
>
>
>///// JAVASCRIPT /////
>
>foo = function() {
>  var self = this;
>  function localFunction(i) {
>    if (i == 0) {
>      org.apache.flex.utils.Language.trace(bar); // Uncaught
>ReferenceError:
>bar is not defined
>    }
>  };
>  localFunction(0);
>};
>
>
>
>
>
>--
>View this message in context:
>http://apache-flex-development.2333347.n4.nabble.com/FalconJX-FlexJS-Local
>-Functions-code-gen-tp24890p52183.html
>Sent from the Apache Flex Development mailing list archive at Nabble.com.


Re: [FalconJX][FlexJS] Local Functions code gen

Posted by Nimai <ni...@beecavegames.com>.
I hope it's OK etiquette to add onto this old thread, but it appears related
to this issue.  Please see the source AS3 and resulting JS below.  The
"self" var is emitted but not used.  If I manually add "self." in front of
the reference to "bar", it does work!


///// ACTIONSCRIPT /////

package {
public class foo {
	internal var bar:String = "baz";
	public function foo() {

		function localFunction(i:int) {
			if (i==0) {
				trace( bar );
			}
		}

		localFunction(0);
	}
}
}


///// JAVASCRIPT /////

foo = function() {
  var self = this;
  function localFunction(i) {
    if (i == 0) {
      org.apache.flex.utils.Language.trace(bar); // Uncaught ReferenceError:
bar is not defined
    }
  };
  localFunction(0);
};





--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/FalconJX-FlexJS-Local-Functions-code-gen-tp24890p52183.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: [FalconJX][FlexJS] Local Functions code gen

Posted by Erik de Bruin <er...@ixsoftware.nl>.
Ah, I see you've hidden your solution in the excellently commented
"fix more bugs in compiler and add more tests for them" commit...
Didn't know JSFlexJSEmitter was part of the compiler :-) Maybe make
your commits a little bit more granular and descriptive, please?

Since I already wrote a test for it before I noticed you'd already
tackled this, I'm committing that. More tests never hurt ;-)

EdB



On Sat, Apr 20, 2013 at 10:02 AM, Erik de Bruin <er...@ixsoftware.nl> wrote:
> "Just when you think you're out... they pull you back in!"
>
> I'm on it, expect to have solution this weekend.
>
> EdB
>
>
>
> On Fri, Apr 19, 2013 at 11:17 PM, Alex Harui <ah...@adobe.com> wrote:
>> Erik,
>>
>> It looks like you took the ³var self=this² out.  How are you supposed to
>> call local functions?  For example, this AS:
>>
>> Class A
>> {
>>     public var foo:String;
>>     public function bar():String
>>     {
>>         return foobar();
>>         function foobar():String
>>         {
>>             return foo;
>>         }
>>     }
>> }
>>
>> Should the output JS use goog.bind to call foobar?  Is there ever a time
>> when goog.bind is not used to call a local function?
>>
>> A.prototype.bar = function()
>> {
>>     return goog.bind(foobar, this)();
>>     function foobar():String
>>     {
>>         return this.foo;
>>     }
>> }
>> --
>> Alex Harui
>> Flex SDK Team
>> Adobe Systems, Inc.
>> http://blogs.adobe.com/aharui
>>
>
>
>
> --
> Ix Multimedia Software
>
> Jan Luykenstraat 27
> 3521 VB Utrecht
>
> T. 06-51952295
> I. www.ixsoftware.nl



-- 
Ix Multimedia Software

Jan Luykenstraat 27
3521 VB Utrecht

T. 06-51952295
I. www.ixsoftware.nl

Re: [FalconJX][FlexJS] Local Functions code gen

Posted by Erik de Bruin <er...@ixsoftware.nl>.
"Just when you think you're out... they pull you back in!"

I'm on it, expect to have solution this weekend.

EdB



On Fri, Apr 19, 2013 at 11:17 PM, Alex Harui <ah...@adobe.com> wrote:
> Erik,
>
> It looks like you took the ³var self=this² out.  How are you supposed to
> call local functions?  For example, this AS:
>
> Class A
> {
>     public var foo:String;
>     public function bar():String
>     {
>         return foobar();
>         function foobar():String
>         {
>             return foo;
>         }
>     }
> }
>
> Should the output JS use goog.bind to call foobar?  Is there ever a time
> when goog.bind is not used to call a local function?
>
> A.prototype.bar = function()
> {
>     return goog.bind(foobar, this)();
>     function foobar():String
>     {
>         return this.foo;
>     }
> }
> --
> Alex Harui
> Flex SDK Team
> Adobe Systems, Inc.
> http://blogs.adobe.com/aharui
>



-- 
Ix Multimedia Software

Jan Luykenstraat 27
3521 VB Utrecht

T. 06-51952295
I. www.ixsoftware.nl