You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by jm...@apache.org on 2013/05/11 05:45:17 UTC

[4/6] git commit: [flex-sdk] [refs/heads/develop] - FLEX-24296 throw out of range error if passed negative index

FLEX-24296 throw out of range error if passed negative index


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/7490dc68
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/7490dc68
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/7490dc68

Branch: refs/heads/develop
Commit: 7490dc6895ad483e715556d0d2db4315a806d38b
Parents: d79d9ba
Author: Justin Mclean <jm...@apache.org>
Authored: Sat May 11 13:09:01 2013 +1000
Committer: Justin Mclean <jm...@apache.org>
Committed: Sat May 11 13:09:01 2013 +1000

----------------------------------------------------------------------
 .../src/mx/collections/ListCollectionView.as       |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/7490dc68/frameworks/projects/framework/src/mx/collections/ListCollectionView.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/collections/ListCollectionView.as b/frameworks/projects/framework/src/mx/collections/ListCollectionView.as
index 9c8ee8d..746a3e2 100644
--- a/frameworks/projects/framework/src/mx/collections/ListCollectionView.as
+++ b/frameworks/projects/framework/src/mx/collections/ListCollectionView.as
@@ -911,6 +911,14 @@ public class ListCollectionView extends Proxy
         {
             // If caller passed in a number such as 5.5, it will be floored.
             var n:Number = parseInt(String(name));
+			
+			if (n < 0)
+			{
+				var message:String = resourceManager.getString(
+					"collections", "outOfBounds", [ -1 ]);
+				throw new RangeError(message);
+			}
+			
             if (!isNaN(n))
                 index = int(n);
         }


Re: [4/6] git commit: [flex-sdk] [refs/heads/develop] - FLEX-24296 throw out of range error if passed negative index

Posted by Alex Harui <ah...@adobe.com>.
Like it!


On 5/10/13 11:45 PM, "Justin Mclean" <ju...@classsoftware.com> wrote:

> Hi,
> 
>> Like I said, probably not worth your time.  The overhead of proxy is known
>> to be pretty high.
> 
> Looking at the code I'm not even sure what the try catch is in there as there
> nothing that can throw an exception.
> 
> It probably could be simplified to (it may even be faster).
> 
>     override flash_proxy function getProperty(name:*):*
>     {
>         if (name is QName)
>             name = name.localName;
> 
>         var n:Number = parseInt(String(name));
> 
> if (isNaN(n))
>         {
>             message = resourceManager.getString(
>                 "collections", "unknownProperty", [ name ]);
>             throw new Error(message);
>         }
>         else
>         {
>    // If caller passed in a number such as 5.5, it will be floored.
>             return getItemAt(int(n));
>         }
>     }
> 
> getItemAt with throw correct exception if n < 0
> 
> Justin

-- 
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui


Re: [4/6] git commit: [flex-sdk] [refs/heads/develop] - FLEX-24296 throw out of range error if passed negative index

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> Like I said, probably not worth your time.  The overhead of proxy is known
> to be pretty high.

Looking at the code I'm not even sure what the try catch is in there as there nothing that can throw an exception.

It probably could be simplified to (it may even be faster).

    override flash_proxy function getProperty(name:*):*
    {
        if (name is QName)
            name = name.localName;

        var n:Number = parseInt(String(name));

	if (isNaN(n))
        {
            message = resourceManager.getString(
                "collections", "unknownProperty", [ name ]);
            throw new Error(message);
        }
        else
        {
	    // If caller passed in a number such as 5.5, it will be floored.
            return getItemAt(int(n));
        }
    }

getItemAt with throw correct exception if n < 0

Justin

Re: [4/6] git commit: [flex-sdk] [refs/heads/develop] - FLEX-24296 throw out of range error if passed negative index

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


On 5/10/13 11:21 PM, "Justin Mclean" <ju...@classsoftware.com> wrote:

> Hi,
> 
>> This method is often used in loops so normally I would just let it RTE
>> instead of adding an if statement.
> The overhead of getItemAt is going to be far greater than the if > 0 check but
> I'll take a look in scout to see if it makes any difference.
Like I said, probably not worth your time.  The overhead of proxy is known
to be pretty high.

> 
> Thanks,
> Justin

-- 
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui


Re: [4/6] git commit: [flex-sdk] [refs/heads/develop] - FLEX-24296 throw out of range error if passed negative index

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> This method is often used in loops so normally I would just let it RTE
> instead of adding an if statement.
The overhead of getItemAt is going to be far greater than the if > 0 check but I'll take a look in scout to see if it makes any difference.

Thanks,
Justin

Re: [4/6] git commit: [flex-sdk] [refs/heads/develop] - FLEX-24296 throw out of range error if passed negative index

Posted by Alex Harui <ah...@adobe.com>.
No need to change this commit, this is just for the record so I can search
the archives for GIGO someday.  This is certainly a friendly thing to do,
and proxy is so slow that you probably won't be able to measure the effect
of the extra if statement, but this would otherwise be an example of a
change that violates the GIGO principle (Garbage In, Garbage Out).

This method is often used in loops so normally I would just let it RTE
instead of adding an if statement.  Again, in FlexJS, I hope we can have
friendlier debug versions of things like this so you don't pay in
production.


On 5/10/13 8:45 PM, "jmclean@apache.org" <jm...@apache.org> wrote:

> FLEX-24296 throw out of range error if passed negative index
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
> Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/7490dc68
> Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/7490dc68
> Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/7490dc68
> 
> Branch: refs/heads/develop
> Commit: 7490dc6895ad483e715556d0d2db4315a806d38b
> Parents: d79d9ba
> Author: Justin Mclean <jm...@apache.org>
> Authored: Sat May 11 13:09:01 2013 +1000
> Committer: Justin Mclean <jm...@apache.org>
> Committed: Sat May 11 13:09:01 2013 +1000
> 
> ----------------------------------------------------------------------
>  .../src/mx/collections/ListCollectionView.as       |    8 ++++++++
>  1 files changed, 8 insertions(+), 0 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/7490dc68/frameworks/proje
> cts/framework/src/mx/collections/ListCollectionView.as
> ----------------------------------------------------------------------
> diff --git 
> a/frameworks/projects/framework/src/mx/collections/ListCollectionView.as
> b/frameworks/projects/framework/src/mx/collections/ListCollectionView.as
> index 9c8ee8d..746a3e2 100644
> --- a/frameworks/projects/framework/src/mx/collections/ListCollectionView.as
> +++ b/frameworks/projects/framework/src/mx/collections/ListCollectionView.as
> @@ -911,6 +911,14 @@ public class ListCollectionView extends Proxy
>          {
>              // If caller passed in a number such as 5.5, it will be floored.
>              var n:Number = parseInt(String(name));
> +   
> +   if (n < 0)
> +   {
> +    var message:String = resourceManager.getString(
> +     "collections", "outOfBounds", [ -1 ]);
> +    throw new RangeError(message);
> +   }
> +   
>              if (!isNaN(n))
>                  index = int(n);
>          }
> 

-- 
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui


Re: [4/6] git commit: [flex-sdk] [refs/heads/develop] - FLEX-24296 throw out of range error if passed negative index

Posted by Alex Harui <ah...@adobe.com>.
No need to change this commit, this is just for the record so I can search
the archives for GIGO someday.  This is certainly a friendly thing to do,
and proxy is so slow that you probably won't be able to measure the effect
of the extra if statement, but this would otherwise be an example of a
change that violates the GIGO principle (Garbage In, Garbage Out).

This method is often used in loops so normally I would just let it RTE
instead of adding an if statement.  Again, in FlexJS, I hope we can have
friendlier debug versions of things like this so you don't pay in
production.


On 5/10/13 8:45 PM, "jmclean@apache.org" <jm...@apache.org> wrote:

> FLEX-24296 throw out of range error if passed negative index
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
> Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/7490dc68
> Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/7490dc68
> Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/7490dc68
> 
> Branch: refs/heads/develop
> Commit: 7490dc6895ad483e715556d0d2db4315a806d38b
> Parents: d79d9ba
> Author: Justin Mclean <jm...@apache.org>
> Authored: Sat May 11 13:09:01 2013 +1000
> Committer: Justin Mclean <jm...@apache.org>
> Committed: Sat May 11 13:09:01 2013 +1000
> 
> ----------------------------------------------------------------------
>  .../src/mx/collections/ListCollectionView.as       |    8 ++++++++
>  1 files changed, 8 insertions(+), 0 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/7490dc68/frameworks/proje
> cts/framework/src/mx/collections/ListCollectionView.as
> ----------------------------------------------------------------------
> diff --git 
> a/frameworks/projects/framework/src/mx/collections/ListCollectionView.as
> b/frameworks/projects/framework/src/mx/collections/ListCollectionView.as
> index 9c8ee8d..746a3e2 100644
> --- a/frameworks/projects/framework/src/mx/collections/ListCollectionView.as
> +++ b/frameworks/projects/framework/src/mx/collections/ListCollectionView.as
> @@ -911,6 +911,14 @@ public class ListCollectionView extends Proxy
>          {
>              // If caller passed in a number such as 5.5, it will be floored.
>              var n:Number = parseInt(String(name));
> +   
> +   if (n < 0)
> +   {
> +    var message:String = resourceManager.getString(
> +     "collections", "outOfBounds", [ -1 ]);
> +    throw new RangeError(message);
> +   }
> +   
>              if (!isNaN(n))
>                  index = int(n);
>          }
> 

-- 
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui