aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Angular.js18
-rw-r--r--test/AngularSpec.js4
2 files changed, 14 insertions, 8 deletions
diff --git a/src/Angular.js b/src/Angular.js
index f4cb9b51..9a607ba3 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -487,17 +487,19 @@ function map(obj, iterator, context) {
*/
function size(obj, ownPropsOnly) {
var size = 0, key;
- if (obj) {
- if (isNumber(obj.length)) {
- return obj.length;
- } else if (isObject(obj)){
- for (key in obj)
- if (!ownPropsOnly || obj.hasOwnProperty(key))
- size++;
- }
+
+ if (isArray(obj) || isString(obj)) {
+ return obj.length;
+ } else if (isObject(obj)){
+ for (key in obj)
+ if (!ownPropsOnly || obj.hasOwnProperty(key))
+ size++;
}
+
return size;
}
+
+
function includes(array, obj) {
for ( var i = 0; i < array.length; i++) {
if (obj === array[i]) return true;
diff --git a/test/AngularSpec.js b/test/AngularSpec.js
index 0a290381..61dc7cfc 100644
--- a/test/AngularSpec.js
+++ b/test/AngularSpec.js
@@ -133,6 +133,10 @@ describe('angular', function(){
expect(size('')).toBe(0);
expect(size('abc')).toBe(3);
});
+
+ it('should not rely on length property of an object to determine its size', function() {
+ expect(size({length:99})).toBe(1);
+ });
});