You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flex.apache.org by "Greg Dove (JIRA)" <ji...@apache.org> on 2017/03/20 06:24:41 UTC

[jira] [Commented] (FLEX-35283) parseInt Implementation

    [ https://issues.apache.org/jira/browse/FLEX-35283?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15932208#comment-15932208 ] 

Greg Dove commented on FLEX-35283:
----------------------------------

Notes:
The risk of passing the parseInt call through to the native implementation unchanged, or setting the radix to 0 or undefined is that the octal parsing could result in inconsistent behaviour on older browsers.
parseInt("010") is 10 based on es5 and later, but older browsers may convert this to 8

For a 'safe' implementation we could have the compiler fall back to GCL [1] support when parseInt does not have an explicit radix parameter specified in the as3 source:

However, theoretically we should be ok for the range of browsers that we are seeking to support (I cannot vouch for the accuracy of this data [2], but it 'seems' comprehensive):

So the first decision relates to risk of running code against a browser with the pre-es5 parseInt implementation, coupled with the liklihood that strings with leading zeros (and no 'x') will be encountered.

If we decide to accept the risk (ie. not to go for the GCL option) then Mozilla spec says to pass either undefined or 0 for radix which will result in the same behaviour as omitting the radix.

I checked on swf, trace(parseInt("0x99",0)) and trace(parseInt("0x99",undefined)) behaves the same as not specfiying the radix.

However GCC[3] states:
Note: Use of parseInt without base ["radix"] is strictly banned in Google.
If you really want to parse octal or hex based on the leader, then pass undefined as the base.

So presumably if we are to inject the second parameter via falcon-jx, it should be undefined in these cases (and not zero).

1. https://github.com/google/closure-library/blob/master/closure/goog/string/string.js#L1513
2. https://kangax.github.io/compat-table/es5/
3. https://github.com/google/closure-compiler/blob/346d4dfa1a0bd230cb339aaf258a30a1cee9ba64/externs/es3.js#L184


> parseInt Implementation
> -----------------------
>
>                 Key: FLEX-35283
>                 URL: https://issues.apache.org/jira/browse/FLEX-35283
>             Project: Apache Flex
>          Issue Type: Bug
>          Components: FalconJX
>    Affects Versions: Apache FalconJX 0.8.0
>            Reporter: Greg Dove
>            Assignee: Greg Dove
>
> parseInt does not correctly process hex strings without no second parameter
> parseInt("0x99")
> this should calculate as 153
> it is currently compiled to 
> parseInt("0x99",10)
> in js which evaluates to 0



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)