mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +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:
|
* Detect the JScript [[DontEnum]] bug:
|
||||||
* IE < 9 makes an objects own properties, shadowing non-enumerable ones,
|
* In IE < 9 an objects own properties, shadowing non-enumerable ones, are
|
||||||
* non-enumerable too.
|
* made non-enumerable as well.
|
||||||
*/
|
*/
|
||||||
var hasDontEnumBug = !{ 'valueOf': 0 }.propertyIsEnumerable('valueOf');
|
var hasDontEnumBug = !{ 'valueOf': 0 }.propertyIsEnumerable('valueOf');
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@
|
|||||||
*/
|
*/
|
||||||
var reUnescaped = RegExp('\\\\|[\'\\n\\r\\t\u2028\u2029]', 'g');
|
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 = [
|
var shadowed = [
|
||||||
'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',
|
'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',
|
||||||
'toLocaleString', 'toString', 'valueOf'
|
'toLocaleString', 'toString', 'valueOf'
|
||||||
@@ -401,10 +401,10 @@
|
|||||||
) +
|
) +
|
||||||
'\n}' +
|
'\n}' +
|
||||||
(hasDontEnumBug
|
(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
|
// existing property and the `constructor` property of a prototype
|
||||||
// defaults to non-enumerable, Lo-Dash skips the `constructor`
|
// 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' +
|
'var ctor = ' + iteratedObject + '.constructor,\n' +
|
||||||
'skipCtor = ctor && ctor.prototype && ctor.prototype.constructor === ctor;\n' +
|
'skipCtor = ctor && ctor.prototype && ctor.prototype.constructor === ctor;\n' +
|
||||||
'for (var j = 0; j < 7; j++) {\n' +
|
'for (var j = 0; j < 7; j++) {\n' +
|
||||||
@@ -3064,7 +3064,7 @@
|
|||||||
func.apply(value, arguments);
|
func.apply(value, arguments);
|
||||||
|
|
||||||
// IE compatibility mode and IE < 9 have buggy Array `shift()` and `splice()`
|
// 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`.
|
// array-like-objects even though the `length` property is set to `0`.
|
||||||
// The `shift()` method is buggy in IE 8 compatibility mode, while `splice()`
|
// 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.
|
// 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
|
// explicitly call `QUnit.start()` in a CLI environment
|
||||||
if (!window.document) {
|
if (!window.document) {
|
||||||
QUnit.start();
|
QUnit.start();
|
||||||
|
|||||||
Reference in New Issue
Block a user