Ensure _.map rewrite handles objects with non-numeric length properties correctly.

Former-commit-id: 60a4f322dcd284db5bb8ad4d8d5138e52e14cce3
This commit is contained in:
John-David Dalton
2012-10-22 01:56:50 -07:00
parent 1b0a77f9a8
commit 15f5b1f830
4 changed files with 40 additions and 27 deletions

View File

@@ -41,6 +41,9 @@
/** Shortcut used to make object properties immutable */
var freeze = Object.freeze;
/** Used to set property descriptors */
var setDescriptor = Object.defineProperty;
/** Shortcut used to convert array-like objects to arrays */
var slice = [].slice;
@@ -946,6 +949,16 @@
});
deepEqual(actual, [1, 2, 3]);
});
test('should handle object arguments with non-numeric length properties', function() {
if (setDescriptor) {
var object = {};
setDescriptor(object, 'length', { 'value': 'x' });
deepEqual(_.map(object, _.identity), []);
} else {
skipTest();
}
});
}());
/*--------------------------------------------------------------------------*/