mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 23:37:49 +00:00
lodash: Add unit tests for buggy shift and splice in IE. [jddalton]
Former-commit-id: 574e4adcd024ef667302e97fffebc9bee5cbfacf
This commit is contained in:
12
lodash.js
12
lodash.js
@@ -25,8 +25,8 @@
|
||||
|
||||
/**
|
||||
* Detect the JScript [[DontEnum]] bug:
|
||||
* IE < 9 makes an objects own properties, shadowing non-enumerable ones,
|
||||
* non-enumerable too.
|
||||
* In IE < 9 an objects own properties, shadowing non-enumerable ones, are
|
||||
* made non-enumerable as well.
|
||||
*/
|
||||
var hasDontEnumBug = !{ 'valueOf': 0 }.propertyIsEnumerable('valueOf');
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
*/
|
||||
var reUnescaped = RegExp('\\\\|[\'\\n\\r\\t\u2028\u2029]', 'g');
|
||||
|
||||
/** Used to fix JScript's [[DontEnum]] bug in IE < 9 */
|
||||
/** Used to fix the JScript [[DontEnum]] bug */
|
||||
var shadowed = [
|
||||
'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',
|
||||
'toLocaleString', 'toString', 'valueOf'
|
||||
@@ -401,10 +401,10 @@
|
||||
) +
|
||||
'\n}' +
|
||||
(hasDontEnumBug
|
||||
? // because IE < 9 can't set the `[[Enumerable]]` attribute of an
|
||||
? // Because IE < 9 can't set the `[[Enumerable]]` attribute of an
|
||||
// existing property and the `constructor` property of a prototype
|
||||
// defaults to non-enumerable, Lo-Dash skips the `constructor`
|
||||
// property when it infers it's iterating over a `prototype` object
|
||||
// property when it infers it's iterating over a `prototype` object.
|
||||
'var ctor = ' + iteratedObject + '.constructor,\n' +
|
||||
'skipCtor = ctor && ctor.prototype && ctor.prototype.constructor === ctor;\n' +
|
||||
'for (var j = 0; j < 7; j++) {\n' +
|
||||
@@ -3064,7 +3064,7 @@
|
||||
func.apply(value, arguments);
|
||||
|
||||
// IE compatibility mode and IE < 9 have buggy Array `shift()` and `splice()`
|
||||
// functions that fail to remove the last element, `object[0]`, of
|
||||
// functions that fail to remove the last element, `value[0]`, of
|
||||
// array-like-objects even though the `length` property is set to `0`.
|
||||
// The `shift()` method is buggy in IE 8 compatibility mode, while `splice()`
|
||||
// is buggy regardless of mode in IE < 9 and buggy in compatibility mode in IE 9.
|
||||
|
||||
28
test/test.js
28
test/test.js
@@ -390,6 +390,34 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash(...).shift');
|
||||
|
||||
(function() {
|
||||
test('should remove the value at index `0` when length is `0` (test in IE 8 compatibility mode)', function() {
|
||||
var wrapped = _({ '0': 1, 'length': 1 });
|
||||
wrapped.shift();
|
||||
|
||||
deepEqual(wrapped.keys(), ['length']);
|
||||
equal(wrapped.first(), undefined);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash(...).splice');
|
||||
|
||||
(function() {
|
||||
test('should remove the value at index `0` when length is `0` (test in IE < 9, and in compatibility mode for IE9)', function() {
|
||||
var wrapped = _({ '0': 1, 'length': 1 });
|
||||
wrapped.splice(0, 1);
|
||||
|
||||
deepEqual(wrapped.keys(), ['length']);
|
||||
equal(wrapped.first(), undefined);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
// explicitly call `QUnit.start()` in a CLI environment
|
||||
if (!window.document) {
|
||||
QUnit.start();
|
||||
|
||||
Reference in New Issue
Block a user