Skip to content

Commit a63d54c

Browse files
committed
Handle null in array wrapper methods (fix #2472)
1 parent 41baf26 commit a63d54c

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

modules/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,8 +1653,12 @@ each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(
16531653
var method = ArrayProto[name];
16541654
_.prototype[name] = function() {
16551655
var obj = this._wrapped;
1656-
method.apply(obj, arguments);
1657-
if ((name === 'shift' || name === 'splice') && obj.length === 0) delete obj[0];
1656+
if (obj != null) {
1657+
method.apply(obj, arguments);
1658+
if ((name === 'shift' || name === 'splice') && obj.length === 0) {
1659+
delete obj[0];
1660+
}
1661+
}
16581662
return chainResult(this, obj);
16591663
};
16601664
});
@@ -1663,7 +1667,9 @@ each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(
16631667
each(['concat', 'join', 'slice'], function(name) {
16641668
var method = ArrayProto[name];
16651669
_.prototype[name] = function() {
1666-
return chainResult(this, method.apply(this._wrapped, arguments));
1670+
var obj = this._wrapped;
1671+
if (obj != null) obj = method.apply(obj, arguments);
1672+
return chainResult(this, obj);
16671673
};
16681674
});
16691675

underscore.js

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

underscore.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)