You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flex.apache.org by OmPrakash Muppirala <bi...@gmail.com> on 2016/03/15 20:17:31 UTC

Re: [2/2] git commit: [flex-falcon] [refs/heads/develop] - apparently, parseInt in JS should always specify the radix

>
> apparently, parseInt in JS should always specify the radix


I don't think that is the case.  ParseInt does this by default [1] :

If the radix parameter is omitted, JavaScript assumes the following:

   - If the string begins with "0x", the radix is 16 (hexadecimal)
   - If the string begins with "0", the radix is 8 (octal). This feature is
   deprecated
   - If the string begins with any other value, the radix is 10 (decimal)


[1] http://www.w3schools.com/jsref/jsref_parseint.asp

On Tue, Mar 15, 2016 at 10:22 AM, <ah...@apache.org> wrote:

> apparently, parseInt in JS should always specify the radix
>
>
> Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
> Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/46d54f82
> Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/46d54f82
> Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/46d54f82
>
> Branch: refs/heads/develop
> Commit: 46d54f829d026f55359e652038d5135dd08378e4
> Parents: aa6de08
> Author: Alex Harui <ah...@apache.org>
> Authored: Tue Mar 15 10:22:29 2016 -0700
> Committer: Alex Harui <ah...@apache.org>
> Committed: Tue Mar 15 10:22:29 2016 -0700
>
> ----------------------------------------------------------------------
>  .../codegen/js/flexjs/TestFlexJSGlobalFunctions.java | 15 +++++++++++++++
>  .../internal/codegen/js/flexjs/JSFlexJSEmitter.java  | 11 +++++++++++
>  2 files changed, 26 insertions(+)
> ----------------------------------------------------------------------
>
>
>
> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/46d54f82/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalFunctions.java
> ----------------------------------------------------------------------
> diff --git
> a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalFunctions.java
> b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalFunctions.java
> index aaa9c92..f1be070 100644
> ---
> a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalFunctions.java
> +++
> b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalFunctions.java
> @@ -90,6 +90,21 @@ public class TestFlexJSGlobalFunctions extends
> TestGoogGlobalFunctions
>          assertOut("var /** @type {Array} */ a = Array(['Hello',
> 'World'])");
>      }
>
> +    @Test
> +    public void testParseInt()
> +    {
> +        IVariableNode node = getVariable("var a:int = parseInt('1.8');");
> +        asBlockWalker.visitVariable(node);
> +        assertOut("var /** @type {number} */ a = parseInt('1.8', 10)");
> +    }
> +
> +    @Test
> +    public void testParseIntTwoArgs()
> +    {
> +        IVariableNode node = getVariable("var a:int = parseInt('1.8',
> 16);");
> +        asBlockWalker.visitVariable(node);
> +        assertOut("var /** @type {number} */ a = parseInt('1.8', 16)");
> +    }
>
>      @Override
>      @Test
>
>
> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/46d54f82/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 d4325a7..c4c72da 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
> @@ -573,6 +573,17 @@ public class JSFlexJSEmitter extends JSGoogEmitter
> implements IJSFlexJSEmitter
>                         }
>                         }
>                 }
> +               else if (def != null &&
> def.getBaseName().equals("parseInt"))
> +               {
> +                       IDefinition parentDef = def.getParent();
> +                       if (parentDef == null)
> +                       {
> +                       if (nameNode instanceof IdentifierNode)
> +                       {
> +                               write(", 10");
> +                       }
> +                       }
> +               }
>         }
>      }
>
>
>

Re: [2/2] git commit: [flex-falcon] [refs/heads/develop] - apparently, parseInt in JS should always specify the radix

Posted by Carlos Rovira <ca...@codeoscopic.com>.
Hi Alex,

AFAIK, most javascript frameworks out there doesn't support IE9. I think
IE10 is the lowest version supported.
People wanting IE7-8-9 should go Flex (Flash) way.

Just my thoughts.

Carlos



2016-03-17 6:13 GMT+01:00 Alex Harui <ah...@adobe.com>:

>
>
> On 3/16/16, 7:09 PM, "omuppi1@gmail.com on behalf of OmPrakash Muppirala"
> <omuppi1@gmail.com on behalf of bigosmallm@gmail.com> wrote:
>
> >On Wed, Mar 16, 2016 at 7:03 PM, Andy Dufilie <an...@gmail.com>
> >wrote:
> >
> >> The latest browsers do not support the octal case anymore so I'm
> >>inclined
> >> to say it should be left alone.  I doubt it would ever be an issue.
> >>
> >
> >In that case, Alex's option 2 will ensure that it will work the same way
> >across Flash, older browsers and newer browsers.
>
> Yes, but we've set a baseline for FlexJS as IE9.  Most older browsers run
> Flash so you can deploy the SWF version for them.  So if this is only an
> issue for really old browsers, it may not be worth doing #2.
>
> I don't have an opinion either way.
>
> -Alex
>
>


-- 

Carlos Rovira
Director General
M: +34 607 22 60 05
http://www.codeoscopic.com
http://www.avant2.es


Este mensaje se dirige exclusivamente a su destinatario y puede contener
información privilegiada o confidencial. Si ha recibido este mensaje por
error, le rogamos que nos lo comunique inmediatamente por esta misma vía y
proceda a su destrucción.

De la vigente Ley Orgánica de Protección de Datos (15/1999), le comunicamos
que sus datos forman parte de un fichero cuyo responsable es CODEOSCOPIC
S.A. La finalidad de dicho tratamiento es facilitar la prestación del
servicio o información solicitados, teniendo usted derecho de acceso,
rectificación, cancelación y oposición de sus datos dirigiéndose a nuestras
oficinas c/ Paseo de la Habana 9-11, 28036, Madrid con la documentación
necesaria.

Re: [2/2] git commit: [flex-falcon] [refs/heads/develop] - apparently, parseInt in JS should always specify the radix

Posted by Alex Harui <ah...@adobe.com>.

On 3/16/16, 7:09 PM, "omuppi1@gmail.com on behalf of OmPrakash Muppirala"
<omuppi1@gmail.com on behalf of bigosmallm@gmail.com> wrote:

>On Wed, Mar 16, 2016 at 7:03 PM, Andy Dufilie <an...@gmail.com>
>wrote:
>
>> The latest browsers do not support the octal case anymore so I'm
>>inclined
>> to say it should be left alone.  I doubt it would ever be an issue.
>>
>
>In that case, Alex's option 2 will ensure that it will work the same way
>across Flash, older browsers and newer browsers.

Yes, but we've set a baseline for FlexJS as IE9.  Most older browsers run
Flash so you can deploy the SWF version for them.  So if this is only an
issue for really old browsers, it may not be worth doing #2.

I don't have an opinion either way.

-Alex


Re: [2/2] git commit: [flex-falcon] [refs/heads/develop] - apparently, parseInt in JS should always specify the radix

Posted by OmPrakash Muppirala <bi...@gmail.com>.
On Wed, Mar 16, 2016 at 7:03 PM, Andy Dufilie <an...@gmail.com>
wrote:

> The latest browsers do not support the octal case anymore so I'm inclined
> to say it should be left alone.  I doubt it would ever be an issue.
>

In that case, Alex's option 2 will ensure that it will work the same way
across Flash, older browsers and newer browsers.

Thanks,
Om


>
> On Tue, Mar 15, 2016 at 7:55 PM, Alex Harui <ah...@adobe.com> wrote:
>
> >
> >
> > On 3/15/16, 3:57 PM, "omuppi1@gmail.com on behalf of OmPrakash
> Muppirala"
> > <omuppi1@gmail.com on behalf of bigosmallm@gmail.com> wrote:
> >
> > >I think the problematic part is where strings start with "0".  There
> might
> > >be some browsers adding a radix of 8.  This is a supposedly deprecated
> > >feature.  There is no way of knowing what the browser would do by
> default
> > >in this case.
> >
> > OK, so this is all about radix=8?
> >
> > I guess that leaves us two choices:
> > 1) Do what Andy says and just make the second param optional and see if
> > anyone gets burned if they are assuming a leading 0 will not be
> translated
> > as radix=8 because that's how I understand Flash/AIR works
> > 2) Map parseInt to Language.parseInt and have Language.parseInt check for
> > leading 0 not followed by "x" and set radix = 10 to guarantee exact match
> > with Flash/AIR?
> >
> > Either one is fine with me.
> >
> > Thoughts?
> > -Alex
> >
> >
>

Re: [2/2] git commit: [flex-falcon] [refs/heads/develop] - apparently, parseInt in JS should always specify the radix

Posted by Andy Dufilie <an...@gmail.com>.
The latest browsers do not support the octal case anymore so I'm inclined
to say it should be left alone.  I doubt it would ever be an issue.

On Tue, Mar 15, 2016 at 7:55 PM, Alex Harui <ah...@adobe.com> wrote:

>
>
> On 3/15/16, 3:57 PM, "omuppi1@gmail.com on behalf of OmPrakash Muppirala"
> <omuppi1@gmail.com on behalf of bigosmallm@gmail.com> wrote:
>
> >I think the problematic part is where strings start with "0".  There might
> >be some browsers adding a radix of 8.  This is a supposedly deprecated
> >feature.  There is no way of knowing what the browser would do by default
> >in this case.
>
> OK, so this is all about radix=8?
>
> I guess that leaves us two choices:
> 1) Do what Andy says and just make the second param optional and see if
> anyone gets burned if they are assuming a leading 0 will not be translated
> as radix=8 because that's how I understand Flash/AIR works
> 2) Map parseInt to Language.parseInt and have Language.parseInt check for
> leading 0 not followed by "x" and set radix = 10 to guarantee exact match
> with Flash/AIR?
>
> Either one is fine with me.
>
> Thoughts?
> -Alex
>
>

Re: [2/2] git commit: [flex-falcon] [refs/heads/develop] - apparently, parseInt in JS should always specify the radix

Posted by Alex Harui <ah...@adobe.com>.

On 3/15/16, 3:57 PM, "omuppi1@gmail.com on behalf of OmPrakash Muppirala"
<omuppi1@gmail.com on behalf of bigosmallm@gmail.com> wrote:

>I think the problematic part is where strings start with "0".  There might
>be some browsers adding a radix of 8.  This is a supposedly deprecated
>feature.  There is no way of knowing what the browser would do by default
>in this case.

OK, so this is all about radix=8?

I guess that leaves us two choices:
1) Do what Andy says and just make the second param optional and see if
anyone gets burned if they are assuming a leading 0 will not be translated
as radix=8 because that's how I understand Flash/AIR works
2) Map parseInt to Language.parseInt and have Language.parseInt check for
leading 0 not followed by "x" and set radix = 10 to guarantee exact match
with Flash/AIR?

Either one is fine with me.

Thoughts?
-Alex


Re: [2/2] git commit: [flex-falcon] [refs/heads/develop] - apparently, parseInt in JS should always specify the radix

Posted by OmPrakash Muppirala <bi...@gmail.com>.
I think the problematic part is where strings start with "0".  There might
be some browsers adding a radix of 8.  This is a supposedly deprecated
feature.  There is no way of knowing what the browser would do by default
in this case.

Thanks,
Om

On Tue, Mar 15, 2016 at 3:33 PM, Andy Dufilie <an...@gmail.com>
wrote:

> All these return the same result, so I don't think we need to specify the
> second param.  I think instead the extern file should be updated to make
> the second param optional.
>
> parseInt("0xFF00FF", 0)
> parseInt("0xFF00FF", undefined)
> parseInt("0xFF00FF")
>
>
> On Tue, Mar 15, 2016 at 4:52 PM, Alex Harui <ah...@adobe.com> wrote:
>
> >
> >
> > On 3/15/16, 1:49 PM, "Alex Harui" <ah...@adobe.com> wrote:
> >
> > >
> > >
> > >On 3/15/16, 1:35 PM, "Andy Dufilie" <an...@gmail.com> wrote:
> > >
> > >>It's not a good idea to make built-in functions behave differently in
> JS
> > >>versus AS.
> > >>
> > >>It's not a required param in AS, and this change makes the following
> > >>evaluate to true in AS but false in the cross-compiled JS:
> > >>Number("0xFF00FF") == parseInt("0xFF00FF")
> > >
> > >Ah, good point.  I didn't think about that case.  So what do you suggest
> > >we do?  We could map it to a new org.apache.flex.utils.Language.parseInt
> > >that checks the string for a leading "0x" and calls JS parseInt with the
> > >right radix.   Or should we trust that all browsers we will actually use
> > >will "do the right thing"?
> >
> > Actually, reading the MDN article again, maybe we should set the second
> > param to 0 instead of 10?
> >
> > -Alex
> >
> >
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Ob
> > jects/parseInt
> >
> >
>

Re: [2/2] git commit: [flex-falcon] [refs/heads/develop] - apparently, parseInt in JS should always specify the radix

Posted by Andy Dufilie <an...@gmail.com>.
All these return the same result, so I don't think we need to specify the
second param.  I think instead the extern file should be updated to make
the second param optional.

parseInt("0xFF00FF", 0)
parseInt("0xFF00FF", undefined)
parseInt("0xFF00FF")


On Tue, Mar 15, 2016 at 4:52 PM, Alex Harui <ah...@adobe.com> wrote:

>
>
> On 3/15/16, 1:49 PM, "Alex Harui" <ah...@adobe.com> wrote:
>
> >
> >
> >On 3/15/16, 1:35 PM, "Andy Dufilie" <an...@gmail.com> wrote:
> >
> >>It's not a good idea to make built-in functions behave differently in JS
> >>versus AS.
> >>
> >>It's not a required param in AS, and this change makes the following
> >>evaluate to true in AS but false in the cross-compiled JS:
> >>Number("0xFF00FF") == parseInt("0xFF00FF")
> >
> >Ah, good point.  I didn't think about that case.  So what do you suggest
> >we do?  We could map it to a new org.apache.flex.utils.Language.parseInt
> >that checks the string for a leading "0x" and calls JS parseInt with the
> >right radix.   Or should we trust that all browsers we will actually use
> >will "do the right thing"?
>
> Actually, reading the MDN article again, maybe we should set the second
> param to 0 instead of 10?
>
> -Alex
>
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Ob
> jects/parseInt
>
>

Re: [2/2] git commit: [flex-falcon] [refs/heads/develop] - apparently, parseInt in JS should always specify the radix

Posted by Alex Harui <ah...@adobe.com>.

On 3/15/16, 1:49 PM, "Alex Harui" <ah...@adobe.com> wrote:

>
>
>On 3/15/16, 1:35 PM, "Andy Dufilie" <an...@gmail.com> wrote:
>
>>It's not a good idea to make built-in functions behave differently in JS
>>versus AS.
>>
>>It's not a required param in AS, and this change makes the following
>>evaluate to true in AS but false in the cross-compiled JS:
>>Number("0xFF00FF") == parseInt("0xFF00FF")
>
>Ah, good point.  I didn't think about that case.  So what do you suggest
>we do?  We could map it to a new org.apache.flex.utils.Language.parseInt
>that checks the string for a leading "0x" and calls JS parseInt with the
>right radix.   Or should we trust that all browsers we will actually use
>will "do the right thing"?

Actually, reading the MDN article again, maybe we should set the second
param to 0 instead of 10?

-Alex

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Ob
jects/parseInt


Re: [2/2] git commit: [flex-falcon] [refs/heads/develop] - apparently, parseInt in JS should always specify the radix

Posted by Alex Harui <ah...@adobe.com>.

On 3/15/16, 1:35 PM, "Andy Dufilie" <an...@gmail.com> wrote:

>It's not a good idea to make built-in functions behave differently in JS
>versus AS.
>
>It's not a required param in AS, and this change makes the following
>evaluate to true in AS but false in the cross-compiled JS:
>Number("0xFF00FF") == parseInt("0xFF00FF")

Ah, good point.  I didn't think about that case.  So what do you suggest
we do?  We could map it to a new org.apache.flex.utils.Language.parseInt
that checks the string for a leading "0x" and calls JS parseInt with the
right radix.   Or should we trust that all browsers we will actually use
will "do the right thing"?

-Alex


Re: [2/2] git commit: [flex-falcon] [refs/heads/develop] - apparently, parseInt in JS should always specify the radix

Posted by Andy Dufilie <an...@gmail.com>.
It's not a good idea to make built-in functions behave differently in JS
versus AS.

It's not a required param in AS, and this change makes the following
evaluate to true in AS but false in the cross-compiled JS:
Number("0xFF00FF") == parseInt("0xFF00FF")




On Tue, Mar 15, 2016 at 3:22 PM, Alex Harui <ah...@adobe.com> wrote:

> Well, the externs defines it as a required param, and I read this:
>
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Ob
> jects/parseInt
>
> "Always specify this parameter to eliminate reader confusion and to
> guarantee predictable behavior. Different implementations produce
> different results when a radix is not specified, usually defaulting the
> value to 10."
>
> So I decided to have follow that advice.
>
> On 3/15/16, 12:17 PM, "omuppi1@gmail.com on behalf of OmPrakash Muppirala"
> <omuppi1@gmail.com on behalf of bigosmallm@gmail.com> wrote:
>
> >>
> >> apparently, parseInt in JS should always specify the radix
> >
> >
> >I don't think that is the case.  ParseInt does this by default [1] :
> >
> >If the radix parameter is omitted, JavaScript assumes the following:
> >
> >   - If the string begins with "0x", the radix is 16 (hexadecimal)
> >   - If the string begins with "0", the radix is 8 (octal). This feature
> >is
> >   deprecated
> >   - If the string begins with any other value, the radix is 10 (decimal)
> >
> >
> >[1] http://www.w3schools.com/jsref/jsref_parseint.asp
> >
> >On Tue, Mar 15, 2016 at 10:22 AM, <ah...@apache.org> wrote:
> >
> >> apparently, parseInt in JS should always specify the radix
> >>
> >>
> >> Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
> >> Commit:
> >>http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/46d54f82
> >> Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/46d54f82
> >> Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/46d54f82
> >>
> >> Branch: refs/heads/develop
> >> Commit: 46d54f829d026f55359e652038d5135dd08378e4
> >> Parents: aa6de08
> >> Author: Alex Harui <ah...@apache.org>
> >> Authored: Tue Mar 15 10:22:29 2016 -0700
> >> Committer: Alex Harui <ah...@apache.org>
> >> Committed: Tue Mar 15 10:22:29 2016 -0700
> >>
> >> ----------------------------------------------------------------------
> >>  .../codegen/js/flexjs/TestFlexJSGlobalFunctions.java | 15
> >>+++++++++++++++
> >>  .../internal/codegen/js/flexjs/JSFlexJSEmitter.java  | 11 +++++++++++
> >>  2 files changed, 26 insertions(+)
> >> ----------------------------------------------------------------------
> >>
> >>
> >>
> >>
> >>
> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/46d54f82/compiler
> >>.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFle
> >>xJSGlobalFunctions.java
> >> ----------------------------------------------------------------------
> >> diff --git
> >>
> >>a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flex
> >>js/TestFlexJSGlobalFunctions.java
> >>
> >>b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flex
> >>js/TestFlexJSGlobalFunctions.java
> >> index aaa9c92..f1be070 100644
> >> ---
> >>
> >>a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flex
> >>js/TestFlexJSGlobalFunctions.java
> >> +++
> >>
> >>b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flex
> >>js/TestFlexJSGlobalFunctions.java
> >> @@ -90,6 +90,21 @@ public class TestFlexJSGlobalFunctions extends
> >> TestGoogGlobalFunctions
> >>          assertOut("var /** @type {Array} */ a = Array(['Hello',
> >> 'World'])");
> >>      }
> >>
> >> +    @Test
> >> +    public void testParseInt()
> >> +    {
> >> +        IVariableNode node = getVariable("var a:int =
> >>parseInt('1.8');");
> >> +        asBlockWalker.visitVariable(node);
> >> +        assertOut("var /** @type {number} */ a = parseInt('1.8', 10)");
> >> +    }
> >> +
> >> +    @Test
> >> +    public void testParseIntTwoArgs()
> >> +    {
> >> +        IVariableNode node = getVariable("var a:int = parseInt('1.8',
> >> 16);");
> >> +        asBlockWalker.visitVariable(node);
> >> +        assertOut("var /** @type {number} */ a = parseInt('1.8', 16)");
> >> +    }
> >>
> >>      @Override
> >>      @Test
> >>
> >>
> >>
> >>
> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/46d54f82/compiler
> >>.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitt
> >>er.java
> >> ----------------------------------------------------------------------
> >> diff --git
> >>
> >>a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSF
> >>lexJSEmitter.java
> >>
> >>b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSF
> >>lexJSEmitter.java
> >> index d4325a7..c4c72da 100644
> >> ---
> >>
> >>a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSF
> >>lexJSEmitter.java
> >> +++
> >>
> >>b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSF
> >>lexJSEmitter.java
> >> @@ -573,6 +573,17 @@ public class JSFlexJSEmitter extends JSGoogEmitter
> >> implements IJSFlexJSEmitter
> >>                         }
> >>                         }
> >>                 }
> >> +               else if (def != null &&
> >> def.getBaseName().equals("parseInt"))
> >> +               {
> >> +                       IDefinition parentDef = def.getParent();
> >> +                       if (parentDef == null)
> >> +                       {
> >> +                       if (nameNode instanceof IdentifierNode)
> >> +                       {
> >> +                               write(", 10");
> >> +                       }
> >> +                       }
> >> +               }
> >>         }
> >>      }
> >>
> >>
> >>
>
>

Re: [2/2] git commit: [flex-falcon] [refs/heads/develop] - apparently, parseInt in JS should always specify the radix

Posted by Alex Harui <ah...@adobe.com>.
Well, the externs defines it as a required param, and I read this:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Ob
jects/parseInt

"Always specify this parameter to eliminate reader confusion and to
guarantee predictable behavior. Different implementations produce
different results when a radix is not specified, usually defaulting the
value to 10."

So I decided to have follow that advice.

On 3/15/16, 12:17 PM, "omuppi1@gmail.com on behalf of OmPrakash Muppirala"
<omuppi1@gmail.com on behalf of bigosmallm@gmail.com> wrote:

>>
>> apparently, parseInt in JS should always specify the radix
>
>
>I don't think that is the case.  ParseInt does this by default [1] :
>
>If the radix parameter is omitted, JavaScript assumes the following:
>
>   - If the string begins with "0x", the radix is 16 (hexadecimal)
>   - If the string begins with "0", the radix is 8 (octal). This feature
>is
>   deprecated
>   - If the string begins with any other value, the radix is 10 (decimal)
>
>
>[1] http://www.w3schools.com/jsref/jsref_parseint.asp
>
>On Tue, Mar 15, 2016 at 10:22 AM, <ah...@apache.org> wrote:
>
>> apparently, parseInt in JS should always specify the radix
>>
>>
>> Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
>> Commit: 
>>http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/46d54f82
>> Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/46d54f82
>> Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/46d54f82
>>
>> Branch: refs/heads/develop
>> Commit: 46d54f829d026f55359e652038d5135dd08378e4
>> Parents: aa6de08
>> Author: Alex Harui <ah...@apache.org>
>> Authored: Tue Mar 15 10:22:29 2016 -0700
>> Committer: Alex Harui <ah...@apache.org>
>> Committed: Tue Mar 15 10:22:29 2016 -0700
>>
>> ----------------------------------------------------------------------
>>  .../codegen/js/flexjs/TestFlexJSGlobalFunctions.java | 15
>>+++++++++++++++
>>  .../internal/codegen/js/flexjs/JSFlexJSEmitter.java  | 11 +++++++++++
>>  2 files changed, 26 insertions(+)
>> ----------------------------------------------------------------------
>>
>>
>>
>> 
>>http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/46d54f82/compiler
>>.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFle
>>xJSGlobalFunctions.java
>> ----------------------------------------------------------------------
>> diff --git
>> 
>>a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flex
>>js/TestFlexJSGlobalFunctions.java
>> 
>>b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flex
>>js/TestFlexJSGlobalFunctions.java
>> index aaa9c92..f1be070 100644
>> ---
>> 
>>a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flex
>>js/TestFlexJSGlobalFunctions.java
>> +++
>> 
>>b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flex
>>js/TestFlexJSGlobalFunctions.java
>> @@ -90,6 +90,21 @@ public class TestFlexJSGlobalFunctions extends
>> TestGoogGlobalFunctions
>>          assertOut("var /** @type {Array} */ a = Array(['Hello',
>> 'World'])");
>>      }
>>
>> +    @Test
>> +    public void testParseInt()
>> +    {
>> +        IVariableNode node = getVariable("var a:int =
>>parseInt('1.8');");
>> +        asBlockWalker.visitVariable(node);
>> +        assertOut("var /** @type {number} */ a = parseInt('1.8', 10)");
>> +    }
>> +
>> +    @Test
>> +    public void testParseIntTwoArgs()
>> +    {
>> +        IVariableNode node = getVariable("var a:int = parseInt('1.8',
>> 16);");
>> +        asBlockWalker.visitVariable(node);
>> +        assertOut("var /** @type {number} */ a = parseInt('1.8', 16)");
>> +    }
>>
>>      @Override
>>      @Test
>>
>>
>> 
>>http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/46d54f82/compiler
>>.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitt
>>er.java
>> ----------------------------------------------------------------------
>> diff --git
>> 
>>a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSF
>>lexJSEmitter.java
>> 
>>b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSF
>>lexJSEmitter.java
>> index d4325a7..c4c72da 100644
>> ---
>> 
>>a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSF
>>lexJSEmitter.java
>> +++
>> 
>>b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSF
>>lexJSEmitter.java
>> @@ -573,6 +573,17 @@ public class JSFlexJSEmitter extends JSGoogEmitter
>> implements IJSFlexJSEmitter
>>                         }
>>                         }
>>                 }
>> +               else if (def != null &&
>> def.getBaseName().equals("parseInt"))
>> +               {
>> +                       IDefinition parentDef = def.getParent();
>> +                       if (parentDef == null)
>> +                       {
>> +                       if (nameNode instanceof IdentifierNode)
>> +                       {
>> +                               write(", 10");
>> +                       }
>> +                       }
>> +               }
>>         }
>>      }
>>
>>
>>