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 <aha...@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, "omup...@gmail.com on behalf of OmPrakash Muppirala"
> <omup...@gmail.com on behalf of bigosma...@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, <aha...@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 <aha...@apache.org>
> >> Authored: Tue Mar 15 10:22:29 2016 -0700
> >> Committer: Alex Harui <aha...@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");
> >> +                       }
> >> +                       }
> >> +               }
> >>         }
> >>      }
> >>
> >>
> >>
>
>

Reply via email to